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

Preferences for Grobid #8002

Merged
merged 14 commits into from
Aug 21, 2021
Merged

Preferences for Grobid #8002

merged 14 commits into from
Aug 21, 2021

Conversation

btut
Copy link
Contributor

@btut btut commented Aug 19, 2021

Implements two new preferences in ImportSettingsPreferences:

  • grobidEnabled
  • grobidURL

The preferences are used in the Fetchers and Importers that use Grobid. Creating a GrobidService while grobidEnabled is false will result in an UnsupportedOperationException.

Fixes #8000

image

  • [] Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • [] Checked documentation: Is the information available and up to date? If not created an issue at https://github.com/JabRef/user-documentation/issues or, even better, submitted a pull request to the documentation repository.

@btut
Copy link
Contributor Author

btut commented Aug 19, 2021

There are two things left to do:

  • In Add preferences + popup for usage of GROBID #8000 we discussed showing a popup dialogue when a user tries to import using Grobid for the first time. How/where/when should we do that? Do we need to introduce one more preference to store if it is actually the first time?
  • This also affects the GrobidCitationFetcher that is already released. The problem here (in comparison to the GrobidPdfImporter) is that we do not have any alternatives in place. Shall we deactivate the option to import plaintext altogether if Grobid is disabled?

@Siedlerchr
Copy link
Member

Siedlerchr commented Aug 19, 2021

You can use public boolean showConfirmationDialogWithOptOutAndWait(String title, String content
You need to store the decision in the prefs and obbiously check if they are true before showing the dialog

Example:

              boolean continueImport = dialogService.showConfirmationDialogWithOptOutAndWait(Localization.lang("Duplicates found"),
                            Localization.lang("There are possible duplicates that haven't been resolved. Continue?"),
                            Localization.lang("Continue with import"),
                            Localization.lang("Cancel import"),
                            Localization.lang("Do not ask again"),
                            optOut -> preferences.setShouldWarnAboutDuplicatesForImport(!optOut));

@btut
Copy link
Contributor Author

btut commented Aug 19, 2021

Looks promising, but I am having trouble deciding when to show the dialogue.

We can show it either when JabRef opens. This is the easiest option to implement but a little intrusive.

The second option is to show it when a user triggers an action that requires Grobid.

There are multiple actions that trigger Grobid:

I started implementing the second option, but there is a lot of code to change and it is not pretty IMHO.
I implemented it for two of the points above in e5222ce so you can understand what I mean. The plain-text one does not even work yet - I guess it's because of nested dialogues?

What do you think? Shall I continue implementing it that way or do we want to go the first route, asking the users when JabRef launches? They can immediately opt out and never see the dialogue again.

@koppor
Copy link
Member

koppor commented Aug 19, 2021

The second option is to show it when a user triggers an action that requires Grobid.

This is the behavior, I would expect.

Later, we can add some welcome screen enabling well-used default preferences (enable all online services, ...). Refs koppor#96.

I started implementing the second option, but there is a lot of code to change and it is not pretty IMHO.

Yeah. I would still keep the number of questions at the start low.

I implemented it for two of the points above in e5222ce so you can understand what I mean. The plain-text one does not even work yet - I guess it's because of nested dialogues?

OMG - nested dialogues. A work around could be to "cheat" and show the confirmation before the other. However, this is not a very good approach ^^.

@btut btut self-assigned this Aug 20, 2021
@btut btut added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Aug 20, 2021
@btut btut requested review from calixtus and koppor August 20, 2021 12:56
@btut btut marked this pull request as ready for review August 20, 2021 14:04
Copy link
Member

@calixtus calixtus left a comment

Choose a reason for hiding this comment

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

Some nitpicks for codestyle and readability.
Did not expect to grow introduction of prefs for grobid so large, but seems reasonable.
Use of Globals is not nice, but in the current state of JabRefPreferences necessary, @DominikVoigt and me are diving into this issue these days.


grobidEnabled.selectedProperty().bindBidirectional(viewModel.grobidEnabledProperty());
grobidURL.textProperty().bindBidirectional(viewModel.grobidURLProperty());
grobidURL.disableProperty().bind(grobidEnabled.selectedProperty().not());
Copy link
Member

Choose a reason for hiding this comment

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

Could be done in directly in FXML. (disabled=${grobidEnabled.selected}) or similar. Lot's of examples elsewhere...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think that's possible here because you can't do the negation in fxml. It needs to be disabled if grobidEnabled is NOT selected.

@@ -72,6 +73,11 @@ public void processInvalidCitationTest() {
assertThrows(IOException.class, () -> grobidService.processCitation("iiiiiiiiiiiiiiiiiiiiiiii", importFormatPreferences, GrobidService.ConsolidateCitations.WITH_METADATA));
}

@Test
public void failsWhenGrobidDisabled() {
assertThrows(UnsupportedOperationException.class, () -> new GrobidService(new ImportSettingsPreferences(false, false, false, "http://grobid.jabref.org:8070")));
Copy link
Member

Choose a reason for hiding this comment

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

Maybe extract the ImportSettingsPreferences (I hate that name) to a separate variable, following the typical test scheme:

// given
...
// when
...
// then
...

See https://blog.codecentric.de/en/2017/09/given-when-then-in-junit-tests/ for example

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extracting is easy and I agree it is more readable. For the 'when' clause, since I expect an exception, something like this would be necessary. In my opition expectThrows is easier to read though. Is it ok to violate given-when-then in this case?

Copy link
Member

Choose a reason for hiding this comment

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

This is not a hard law, but a suggestion. Should make reading and understanding tests easier. If in this case it's not, then ok.

src/main/java/org/jabref/gui/entryeditor/EntryEditor.java Outdated Show resolved Hide resolved
src/main/java/org/jabref/gui/entryeditor/EntryEditor.java Outdated Show resolved Hide resolved
@calixtus
Copy link
Member

Changelog necessary?

@btut
Copy link
Contributor Author

btut commented Aug 21, 2021

Changelog necessary?

You are right, since this also affects the plaintext-import that was already released, a Changelog entry is necessary.

@calixtus calixtus merged commit 07712ce into JabRef:main Aug 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
project: GSoC 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.

Add preferences + popup for usage of GROBID
4 participants