-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Fix removal of special fields when syncing them via keywords #3438
Conversation
When reading the code, one would expect to find all methods concerned with keywords next to each other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor code changes, apart from that code looks good. And great that you created tests
CHANGELOG.md
Outdated
@@ -47,6 +47,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# | |||
- We fixed an issue where fetching entries from crossref that had no titles caused an error [#3376](https://github.com/JabRef/jabref/issues/3376) | |||
- We fixed an issue where the same Java Look and Feel would be listed more than once in the Preferences. [#3391](https://github.com/JabRef/jabref/issues/3391) | |||
- We fixed an issue where errors in citation styles triggered an exception when opening the preferences dialog [#3389](https://github.com/JabRef/jabref/issues/3389) | |||
- We fixed an issue where special fields (such as **printed**) could not be cleared when syncing special fields via the keywords [#3432](https://github.com/JabRef/jabref/issues/3432) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a very minor issue, for field names in changelog we usually use backticks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if it does NOT reference a bibtex field? With "printed", I refer to the "special field" here.
|
||
Optional<FieldChange> change = entry.replaceKeywords(keyWords, newValue, keywordDelimiter); | ||
change.ifPresent(changeValue -> fieldChanges.add(changeValue)); | ||
if (newValue.isPresent()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can chain nested optionals with map, it will then only be executed if a value is present
SpecialFieldsUtils.updateField(specialField, specialFieldKeyword.get(), entry, true, true, ','); | ||
// Remove it | ||
List<FieldChange> changes = SpecialFieldsUtils.updateField(specialField, specialFieldKeyword.get(), entry, true, true, ','); | ||
assertTrue(changes.size() > 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid checking such things with size, instead directly create a list expected and use assertEquals
public void removeKeywordsWithNonExistingKeywordsDoesNothing() { | ||
keywordEntry.putKeywords(Arrays.asList("kw1", "kw2"), ','); | ||
Optional<FieldChange> change = keywordEntry.removeKeywords(KeywordList.parse("kw3, kw4", ','), ','); | ||
assertEquals(Optional.empty(), change); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned above, better to directly compare the result to a pre defined list with the keywords which you already use to add the keywords
So just do expected= arrrays.aslist(kw1,kw2)
Made the requested changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my point of view looks good now. Thank you very much for your contribution.
Our policy requires that a second core dev reviews your code before we can merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good. I just have one suggestion for improvement, and then this PR can be merged.
return putKeywords(keywordList, keywordDelimiter); | ||
} | ||
|
||
public Optional<FieldChange> replaceKeywords(KeywordList keywordsToReplace, Optional<Keyword> newValue, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please change the type of newValue
to be just Keyword
(instead of an optional around it). Accepting the optional, but then not properly acting on empty ones, actually lead to this problem. So I think we should fix its root.
Requested change for JabRef#3438
Thanks @tobiasdiez for pointing that out - fixed it. |
Fixes a bug where JabRef special fields (such as 'printed', 'relevant', ...) were not cleared (e.g. removing the 'printed' flag) when using synchronization of special fields via the bibtex keywords field.
See #3432 for more details.