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

Add restoration functionality for shared database #2014

Merged
merged 4 commits into from
Sep 22, 2016

Conversation

obraliar
Copy link
Contributor

@obraliar obraliar commented Sep 20, 2016

Related to #1703:

Session restore: JabRef should open all [shared] tabs after startup.

-> Decision: Open from last connection.

  • Internal quality assurance
  • Change in CHANGELOG.md described
  • Manually tested changed features in running JabRef
  • Check documentation status (Issue created for outdated help page at help.jabref.org?)

@obraliar obraliar force-pushed the RestoreSharedDatabaseTab branch from 0bccbc6 to 412a412 Compare September 20, 2016 11:13
try {
new SharedDatabaseUIManager(mainFrame, keywordSeparator).openLastSharedDatabaseTab(isFocused);
} catch (ClassNotFoundException | SQLException | DatabaseNotSupportedException e) {
LOGGER.error("Failed to restore shared database. Use connection dialog to connect.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the exception e as second parameter to the logger.error (there is already an overload for that=

Copy link
Contributor Author

@obraliar obraliar Sep 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intentionally didn't add it, cause those exceptions basically inform the user about the failure. It's not a real problem. But I think it's better to use LOGGER.info(...). Done.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay. It's just about that in case of a real exception, e.g. soemthing is wrong it helps the developers to debug the root cause ;)

@obraliar obraliar force-pushed the RestoreSharedDatabaseTab branch from 412a412 to 2be310d Compare September 20, 2016 11:41
- Restoration of the last shared database tab which was sucessfully connected
- Popup of the connection dialog for the case that the new connection wasn't sucessfull
- Reorganisation of DBMSConnectionProperties & OpenSharedDatabaseDialog (simplification)
Copy link
Contributor

@tschechlovdev tschechlovdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made some minor comments

}
}

if (prefs.getHost().isPresent()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could use prefs.getHost().ifPresent(prefsHost -> this.host = prefsHost).
This avoids the if statements

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

try {
this.password = new Password(prefs.getPassword().get().toCharArray(), prefs.getUser().get()).decrypt();
} catch (UnsupportedEncodingException | GeneralSecurityException e) {
LOGGER.error("Could not decrypt pasword" + e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace + with ,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}

if (prefs.getPort().isPresent()) {
this.port = Integer.parseInt(prefs.getPort().get());
Copy link
Contributor

@tschechlovdev tschechlovdev Sep 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should catch here the NumberFormatException and log, if the port contains some values that cannot converted to an int. Or is this somewhere else done?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A NumberFormatException can never occur, except hard changes in prefs (on the file system or registry) were made.

}

if (prefs.getUser().isPresent()) {
this.user = prefs.getUser().get();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't add here if(prefs.getPassword.isPresent())? Then you don't have to check twice if user is present.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you mean ifPresent...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As well the user as the password is required for the class Password. It takes the Username as secret key. Therefore I have to check both. Or am I understanding sth. wrong?

Copy link
Contributor

@tschechlovdev tschechlovdev Sep 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, here I meant isPresent. You check here for user.isPresent and below you check whether password.isPresent and user.isPresent. So why don't combine both:

    if(prefs.getUser().isPresent() { 
      this.user = ...
       if(prefs.getPassword().isPresent() {
            this.password = ....
        }
      }

So then you have only one check if prefs.getUser.isPresent and not twice.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When both is required you could just combine the two with and &&

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok nevermind. That's ok how it is.

Copy link
Contributor Author

@obraliar obraliar Sep 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah you mean sth. like:

if (A) {
   x = ...
}
if (A && B) {
   y = ...
}

=>

if (A) {
   x = ...
      if (B) {
         y = ...
      }
}

Here you can save one check (A). 👍

Done.

@obraliar
Copy link
Contributor Author

@tschechlovdev Thanks for suggestions 👍. Appropriate changes have been applied.

@obraliar obraliar force-pushed the RestoreSharedDatabaseTab branch 2 times, most recently from 94fe423 to d8257e7 Compare September 20, 2016 19:43
}
}

if (!prefs.getPassword().isPresent()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could combine this if and the if statement above with an if / else if like the following:

if(!prefs.getPassword().isPresent()) {
    ...
} else if(prefs.getPassword().isPresent() && prefs.getUser().isPresent()){
  ....
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, now I choosed the option from above.

Copy link
Contributor

@tschechlovdev tschechlovdev Sep 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's ok 👍
But then please delete
prefs.getUser().ifPresent(theUser -> this.user = theUser); ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yeah. Done.

@obraliar obraliar force-pushed the RestoreSharedDatabaseTab branch 2 times, most recently from 5c0f46a to eea0629 Compare September 20, 2016 21:13
@obraliar obraliar force-pushed the RestoreSharedDatabaseTab branch from eea0629 to 5d30b42 Compare September 20, 2016 22:23
@tschechlovdev tschechlovdev added status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers and removed stupro-ready-for-internal-review labels Sep 20, 2016
@tschechlovdev tschechlovdev changed the title [WIP] Add restoration functionality for shared database Add restoration functionality for shared database Sep 20, 2016
 - Fix Conflicts in:
		CHANGELOG.md
		src/main/java/net/sf/jabref/gui/JabRefFrame.java
		src/main/java/net/sf/jabref/gui/shared/OpenSharedDatabaseDialog.java
		src/main/java/net/sf/jabref/gui/shared/SharedDatabaseUIManager.java
@obraliar obraliar force-pushed the RestoreSharedDatabaseTab branch 2 times, most recently from b917634 to 5d3e8c1 Compare September 22, 2016 15:33
@koppor
Copy link
Member

koppor commented Sep 22, 2016

Went through with Admir. LGTM.

@koppor koppor merged commit e1b2aa3 into JabRef:master Sep 22, 2016
zesaro pushed a commit to zesaro/jabref that referenced this pull request Nov 22, 2016
- Restoration of the last shared database tab which was sucessfully connected
- Popup of the connection dialog for the case that the new connection wasn't sucessfull
- Reorganisation of DBMSConnectionProperties & OpenSharedDatabaseDialog (simplification)
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants