Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Prohibit more than one connections to the same shared database #2024

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Importer for MODS format added
- [#2012](https://github.com/JabRef/jabref/issues/2012) Implemented integrity check for `month` field: Should be an integer or normalized (BibLaTeX), Should be normalized (BibTeX)
- [#1779](https://github.com/JabRef/jabref/issues/1779) Implemented integrity check for `bibtexkey` field: Empty bibtexkey
- Prohibit more than one connections to the same shared database.

### Fixed
- Fixed selecting an entry out of multiple duplicates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.UnsupportedEncodingException;
import java.security.GeneralSecurityException;
import java.sql.SQLException;
import java.util.List;
import java.util.Optional;
import java.util.Set;

Expand All @@ -30,6 +31,8 @@

import net.sf.jabref.Globals;
import net.sf.jabref.JabRefException;
import net.sf.jabref.JabRefGUI;
import net.sf.jabref.gui.BasePanel;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.help.HelpAction;
import net.sf.jabref.logic.help.HelpFile;
Expand Down Expand Up @@ -94,6 +97,14 @@ public OpenSharedDatabaseDialog(JabRefFrame frame) {
}

public void openSharedDatabase() {

if (isSharedDatabaseAlreadyPresent()) {
JOptionPane.showMessageDialog(OpenSharedDatabaseDialog.this,
Localization.lang("You are already connected to a database using entered connection details."),
Localization.lang("Warning"), JOptionPane.WARNING_MESSAGE);
return;
}

setLoadingConnectButtonText(true);

try {
Expand Down Expand Up @@ -368,4 +379,18 @@ private void setLoadingConnectButtonText(boolean isLoading) {
}
}

/**
* Checks whether a database with the given @link {@link DBMSConnectionProperties} is already opened.
*/
private boolean isSharedDatabaseAlreadyPresent() {
List<BasePanel> panels = JabRefGUI.getMainFrame().getBasePanelList();
for (BasePanel panel : panels) {
DBMSConnectionProperties dbmsConnectionProperties = panel.getBibDatabaseContext().getDBMSSynchronizer()
.getDBProcessor().getDBMSConnectionProperties();
if (this.connectionProperties.equals(dbmsConnectionProperties)) {
return true;
}
}
return false;
}
}
11 changes: 11 additions & 0 deletions src/main/java/net/sf/jabref/shared/DBMSConnectionProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ public void setPassword(String password) {
this.password = password;
}

/**
* Compares all properties except the password.
*/
public boolean equals(DBMSConnectionProperties properties) {
return this.type.equals(properties.getType())
&& this.host.equalsIgnoreCase(properties.getHost())
&& this.port == properties.getPort()
&& this.database.equals(properties.getDatabase())
&& this.user.equals(properties.getUser());
}

/**
* Gets all required data from {@link SharedDatabasePreferences} and sets them if present.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/net/sf/jabref/shared/DBMSProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,10 @@ public static DBMSProcessor getProcessorInstance(DBMSConnection connection) {
return null; // can never happen except new types were added without updating this method.
}

public DBMSConnectionProperties getDBMSConnectionProperties() {
return this.connectionProperties;
}

/**
* Listens for notifications from DBMS.
* Needs to be implemented if LiveUpdate is supported by the DBMS
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_da.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
You_are_already_connected_to_a_database_using_entered_connection_details.=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
You_are_already_connected_to_a_database_using_entered_connection_details.=Eine_Datenbankverbindung_mit_den_eingegebenen_Verbindungsinformationen_besteht_bereits.
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2246,6 +2246,8 @@ Shared_entry_is_no_longer_present=Shared_entry_is_no_longer_present
The_BibEntry_you_currently_work_on_has_been_deleted_on_the_shared_side.=The_BibEntry_you_currently_work_on_has_been_deleted_on_the_shared_side.
You_can_restore_the_entry_using_the_"Undo"_operation.=You_can_restore_the_entry_using_the_"Undo"_operation.
Remember_password?=Remember_password?
You_are_already_connected_to_a_database_using_entered_connection_details.=You_are_already_connected_to_a_database_using_entered_connection_details.

Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?=Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?
New_technical_report=New_technical_report

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
You_are_already_connected_to_a_database_using_entered_connection_details.=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_fa.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
You_are_already_connected_to_a_database_using_entered_connection_details.=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2298,4 +2298,5 @@ Invalid_ISBN\:_'%0'.=ISBN_invalide_:_%0.
should_be_an_integer_or_normalized=devrait_être_un_entier_ou_une_abréviation_standard
should_be_normalized=devrait_être_une_abréviation_standard

You_are_already_connected_to_a_database_using_entered_connection_details.=
empty_bibtexkey=Clef_BibTeX_vide
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_in.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
You_are_already_connected_to_a_database_using_entered_connection_details.=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
You_are_already_connected_to_a_database_using_entered_connection_details.=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
You_are_already_connected_to_a_database_using_entered_connection_details.=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
You_are_already_connected_to_a_database_using_entered_connection_details.=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_no.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
You_are_already_connected_to_a_database_using_entered_connection_details.=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
You_are_already_connected_to_a_database_using_entered_connection_details.=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
You_are_already_connected_to_a_database_using_entered_connection_details.=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_sv.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
You_are_already_connected_to_a_database_using_entered_connection_details.=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_tr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
You_are_already_connected_to_a_database_using_entered_connection_details.=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_vi.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
You_are_already_connected_to_a_database_using_entered_connection_details.=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
You_are_already_connected_to_a_database_using_entered_connection_details.=