Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Added feature to add server timezone when connecting to shared database #4483

Merged
merged 2 commits into from
Nov 15, 2018
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 @@ -11,6 +11,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
## [Unreleased]

### Changed
- Added server timezone parameter when connecting to a shared database.
- We updated the dialog for setting up general fields.
- URL field formatting is updated. All whitespace chars, located at the beginning/ending of the url, are trimmed automatically
- We changed the behavior of the field formatting dialog such that the `bibtexkey` is not changed when formatting all fields or all text fields.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
<CheckBox fx:id="useSSL" mnemonicParsing="false" text="%Use SSL" GridPane.rowIndex="5" />
<TextField fx:id="fileKeystore" GridPane.columnIndex="1" GridPane.rowIndex="6" />
<Button fx:id="browseKeystore" mnemonicParsing="false" onAction="#showOpenKeystoreFileDialog" text="%Browse" GridPane.columnIndex="2" GridPane.rowIndex="6" />
<Label text="%Server Timezone:" GridPane.rowIndex="8"/>
<TextField fx:id="serverTimezone" GridPane.columnIndex="1" GridPane.columnSpan="2" GridPane.rowIndex="8" />
<GridPane>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class SharedDatabaseLoginDialogView extends BaseDialog<Void> {
@FXML private TextField fileKeystore;
@FXML private PasswordField passwordKeystore;
@FXML private Button browseKeystore;
@FXML private TextField serverTimezone;

@Inject private DialogService dialogService;

Expand Down Expand Up @@ -83,6 +84,7 @@ private void initialize() {
user.textProperty().bindBidirectional(viewModel.userProperty());
password.textProperty().bindBidirectional(viewModel.passwordProperty());
port.textProperty().bindBidirectional(viewModel.portProperty());
serverTimezone.textProperty().bindBidirectional(viewModel.serverTimezoneProperty());
databaseType.valueProperty().bindBidirectional(viewModel.selectedDbmstypeProperty());

folder.textProperty().bindBidirectional(viewModel.folderProperty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class SharedDatabaseLoginDialogViewModel extends AbstractViewModel {
private final StringProperty keystore = new SimpleStringProperty("");
private final BooleanProperty useSSL = new SimpleBooleanProperty();
private final StringProperty keyStorePasswordProperty = new SimpleStringProperty("");
private final StringProperty serverTimezone = new SimpleStringProperty("");

private final JabRefFrame frame;
private final DialogService dialogService;
Expand Down Expand Up @@ -118,6 +119,7 @@ public void openDatabase() {
connectionProperties.setPassword(password.getValue());
connectionProperties.setUseSSL(useSSL.getValue());
connectionProperties.setKeyStore(keystore.getValue());
connectionProperties.setServerTimezone(serverTimezone.getValue());

setupKeyStore();
openSharedDatabase(connectionProperties);
Expand Down Expand Up @@ -200,6 +202,7 @@ private void setPreferences() {
prefs.setUser(user.getValue());
prefs.setUseSSL(useSSL.getValue());
prefs.setKeystoreFile(keystore.getValue());
prefs.setServerTimezone(serverTimezone.getValue());

if (rememberPassword.get()) {
try {
Expand Down Expand Up @@ -364,4 +367,6 @@ public ValidationStatus keystoreValidation() {
public ValidationStatus formValidation() {
return formValidator.getValidationStatus();
}

public StringProperty serverTimezoneProperty() { return serverTimezone; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class DBMSConnectionProperties implements DatabaseConnectionProperties {
private String user;
private String password;
private boolean useSSL;
private String serverTimezone;

//Not needed for connection, but stored for future login
private String keyStore;
Expand All @@ -41,14 +42,15 @@ public DBMSConnectionProperties(SharedDatabasePreferences prefs) {
}

public DBMSConnectionProperties(DBMSType type, String host, int port, String database, String user,
String password, boolean useSSL) {
String password, boolean useSSL, String serverTimezone) {
this.type = type;
this.host = host;
this.port = port;
this.database = database;
this.user = user;
this.password = password;
this.useSSL = useSSL;
this.serverTimezone = serverTimezone;
}

@Override
Expand Down Expand Up @@ -118,6 +120,11 @@ public String getUrl() {
return type.getUrl(host, port, database);
}

@Override
public String getServerTimezone() { return serverTimezone; }

public void setServerTimezone(String serverTimezone) { this.serverTimezone = serverTimezone; }

/**
* Returns username, password and ssl as Properties Object
* @return Properties with values for user, password and ssl
Expand All @@ -126,6 +133,7 @@ public Properties asProperties() {
Properties props = new Properties();
props.setProperty("user", user);
props.setProperty("password", password);
props.setProperty("serverTimezone", serverTimezone);

if (useSSL) {
props.setProperty("ssl", Boolean.toString(useSSL));
Expand Down Expand Up @@ -161,7 +169,9 @@ public boolean equals(Object obj) {
&& Objects.equals(port, properties.getPort())
&& Objects.equals(database, properties.getDatabase())
&& Objects.equals(user, properties.getUser())
&& Objects.equals(useSSL, properties.isUseSSL());
&& Objects.equals(useSSL, properties.isUseSSL())
&& Objects.equals(serverTimezone, properties.getServerTimezone());

}

@Override
Expand All @@ -184,6 +194,7 @@ private void setFromPreferences(SharedDatabasePreferences prefs) {
prefs.getPort().ifPresent(thePort -> this.port = Integer.parseInt(thePort));
prefs.getName().ifPresent(theDatabase -> this.database = theDatabase);
prefs.getKeyStoreFile().ifPresent(theKeystore -> this.keyStore = theKeystore);
prefs.getServerTimezone().ifPresent(theServerTimezone -> this.serverTimezone = theServerTimezone);
this.setUseSSL(prefs.isUseSSL());

if (prefs.getUser().isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class SharedDatabasePreferences {
private static final String SHARED_DATABASE_REMEMBER_PASSWORD = "sharedDatabaseRememberPassword";
private static final String SHARED_DATABASE_USE_SSL = "sharedDatabaseUseSSL";
private static final String SHARED_DATABASE_KEYSTORE_FILE = "sharedDatabaseKeyStoreFile";
private static final String SHARED_DATABASE_SERVER_TIMEZONE = "sharedDatabaseServerTimezone";

// This {@link Preferences} is used only for things which should not appear in real JabRefPreferences due to security reasons.
private final Preferences internalPrefs;
Expand Down Expand Up @@ -72,6 +73,10 @@ public Optional<String> getKeyStoreFile() {
return getOptionalValue(SHARED_DATABASE_KEYSTORE_FILE);
}

public Optional<String> getServerTimezone() {
return getOptionalValue(SHARED_DATABASE_SERVER_TIMEZONE);
}

public boolean getRememberPassword() {
return internalPrefs.getBoolean(SHARED_DATABASE_REMEMBER_PASSWORD, false);
}
Expand Down Expand Up @@ -116,6 +121,10 @@ public void setKeystoreFile(String keystoreFile) {
internalPrefs.put(SHARED_DATABASE_KEYSTORE_FILE, keystoreFile);
}

public void setServerTimezone(String serverTimezone) {
internalPrefs.put(SHARED_DATABASE_SERVER_TIMEZONE, serverTimezone);
}

public void clearPassword() {
internalPrefs.remove(SHARED_DATABASE_PASSWORD);
}
Expand All @@ -142,6 +151,7 @@ public void putAllDBMSConnectionProperties(DatabaseConnectionProperties properti
setUser(properties.getUser());
setUseSSL(properties.isUseSSL());
setKeystoreFile(properties.getKeyStore());
setServerTimezone(properties.getServerTimezone());

try {
setPassword(new Password(properties.getPassword().toCharArray(), properties.getUser()).encrypt());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public interface DatabaseConnectionProperties {

boolean isUseSSL();

String getServerTimezone();

}
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2227,6 +2227,7 @@ User\:=User\:
Keystore\ password\:=Keystore password\:
Keystore\:=Keystore\:
Password\:=Password\:
Server\ Timezone\:=Server Timezone\:
Remember\ Password=Remember Password
Use\ SSL=Use SSL
Move\ preprint\ information\ from\ 'URL'\ and\ 'journal'\ field\ to\ the\ 'eprint'\ field=Move preprint information from 'URL' and 'journal' field to the 'eprint' field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public void testGetConnection(DBMSType dbmsType) throws SQLException, InvalidDBM
@Test
public void testGetConnectionFail(DBMSType dbmsType) throws SQLException, InvalidDBMSConnectionPropertiesException {
assertThrows(SQLException.class,
() -> new DBMSConnection(new DBMSConnectionProperties(dbmsType, "XXXX", 0, "XXXX", "XXXX", "XXXX", false)).getConnection());
() -> new DBMSConnection(new DBMSConnectionProperties(dbmsType, "XXXX", 0, "XXXX", "XXXX", "XXXX", false, "XXXX")).getConnection());
}
}
6 changes: 3 additions & 3 deletions src/test/java/org/jabref/logic/shared/TestConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public static DBMSConnection getTestDBMSConnection(DBMSType dbmsType) throws SQL
public static DBMSConnectionProperties getTestConnectionProperties(DBMSType dbmsType) {

if (dbmsType == DBMSType.MYSQL) {
return new DBMSConnectionProperties(dbmsType, "localhost", dbmsType.getDefaultPort(), "jabref", "root", "", false);
return new DBMSConnectionProperties(dbmsType, "localhost", dbmsType.getDefaultPort(), "jabref", "root", "", false, "");
}

if (dbmsType == DBMSType.POSTGRESQL) {
return new DBMSConnectionProperties(dbmsType, "localhost", dbmsType.getDefaultPort(), "jabref", "postgres", "", false);
return new DBMSConnectionProperties(dbmsType, "localhost", dbmsType.getDefaultPort(), "jabref", "postgres", "", false, "");
}

if (dbmsType == DBMSType.ORACLE) {
return new DBMSConnectionProperties(dbmsType, "localhost", dbmsType.getDefaultPort(), "xe", "travis", "travis", false);
return new DBMSConnectionProperties(dbmsType, "localhost", dbmsType.getDefaultPort(), "xe", "travis", "travis", false, "");
}

return new DBMSConnectionProperties();
Expand Down