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

Fix removal of special fields when syncing them via keywords #3438

Merged
merged 6 commits into from
Nov 20, 2017

Conversation

derTimme
Copy link
Contributor

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.

  • Change in CHANGELOG.md described
  • Tests created for changes
  • Manually tested changed features in running JabRef

See #3432 for more details.

Copy link
Member

@Siedlerchr Siedlerchr left a 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)
Copy link
Member

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

Copy link
Contributor Author

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()) {
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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)

@derTimme
Copy link
Contributor Author

Made the requested changes.

Copy link
Member

@Siedlerchr Siedlerchr left a 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

Copy link
Member

@tobiasdiez tobiasdiez left a 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,
Copy link
Member

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.

@derTimme
Copy link
Contributor Author

Thanks @tobiasdiez for pointing that out - fixed it.

@tobiasdiez tobiasdiez merged commit fe07fcd into JabRef:master Nov 20, 2017
@derTimme derTimme deleted the fix-for-issue-3432 branch November 20, 2017 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants