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

Implemented BibtexkeyChecker #2022

Merged
merged 6 commits into from
Sep 22, 2016
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 @@ -40,6 +40,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- <kbd>UP</kbd> / <kbd>Down</kbd> / <kbd>Tab</kbd> / <kbd>shift+Tab</kbd> in the search result frame have now the same functionality as in the main table.
- Importer for MODS format added
- [#2012](https://github.com/JabRef/jabref/issues/2012) Implemented integrity check for `month` field: Should be an integer or normalized (BibLaTeX), Should be normalized (BibTeX)
- [#1779](https://github.com/JabRef/jabref/issues/1779) Implemented integrity check for `bibtexkey` field: Empty bibtexkey

### Fixed
- Fixed selecting an entry out of multiple duplicates
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package net.sf.jabref.logic.integrity;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

import net.sf.jabref.logic.integrity.IntegrityCheck.Checker;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.FieldName;

public class BibtexkeyChecker implements Checker {

@Override
public List<IntegrityMessage> check(BibEntry entry) {
Optional<String> valuekey = entry.getCiteKeyOptional();
Optional<String> valueauthor = entry.getField(FieldName.AUTHOR);
Optional<String> valuetitle = entry.getField(FieldName.TITLE);
Optional<String> valueyear = entry.getField(FieldName.YEAR);
String authortitleyear = entry.getAuthorTitleYear(100);

if (!valueauthor.isPresent() || !valuetitle.isPresent() || !valueyear.isPresent()) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this if statement. So if an entry is missing an author (or title/year) and also has no bibtexkey, then no warning will be printed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is because getAuthorTitleYear(i) requires, that all three field exist. Otherwise some check tests are failing.

Copy link
Member

Choose a reason for hiding this comment

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

Judging based on the code, I think getAuthorTitleYear would return N/A: N/A (N/A) in the case where the fields are missing. I would suggest that you change the order of the if statements.
If the key is empty, then we definitely want to report a message. But if then all the author, title and year are empty, we use BibEntry.toString (it is a bit ugly) or otherwise we use getAuthorTitleYear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing the order of the if statements causes the fail of all checker tests:
java.lang.AssertionError: expected:<[]> but was:<[[] in bibtexkey: empty bibtexkey: N/A: "N/A" (N/A)]

return Collections.emptyList();
}

if (!valuekey.isPresent() || valuekey.get().isEmpty()) {
return Collections.singletonList(new IntegrityMessage(
Localization.lang("empty bibtexkey") + ": " + authortitleyear, entry, BibEntry.KEY_FIELD));
}

return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private List<IntegrityMessage> checkBibtexEntry(BibEntry entry) {

result.addAll(new BracketChecker(FieldName.TITLE).check(entry));
result.addAll(new YearChecker().check(entry));
result.addAll(new BibtexkeyChecker().check(entry));
result.addAll(new EditionChecker(bibDatabaseContext).check(entry));
result.addAll(new NoteChecker(bibDatabaseContext).check(entry));
result.addAll(new HowpublishedChecker(bibDatabaseContext).check(entry));
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_da.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2307,3 +2307,5 @@ Invalid_ISBN\:_'%0'.=

should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2309,3 +2309,5 @@ Invalid_ISBN\:_'%0'.=

should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
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 @@ -2302,3 +2302,4 @@ Select_last_entry=Select_last_entry
Invalid_ISBN\:_'%0'.=Invalid_ISBN\:_'%0'.
should_be_an_integer_or_normalized=should_be_an_integer_or_normalized
should_be_normalized=should_be_normalized
empty_bibtexkey=empty_bibtexkey
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2307,3 +2307,5 @@ Invalid_ISBN\:_'%0'.=

should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_fa.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2310,3 +2310,5 @@ Invalid_ISBN\:_'%0'.=

should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2307,3 +2307,5 @@ Invalid_ISBN\:_'%0'.=ISBN_invalide_:_%0.

should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_in.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2307,3 +2307,5 @@ Invalid_ISBN\:_'%0'.=

should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2307,3 +2307,5 @@ Invalid_ISBN\:_'%0'.=

should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2305,3 +2305,5 @@ Invalid_ISBN\:_'%0'.=

should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2309,3 +2309,5 @@ Invalid_ISBN\:_'%0'.=

should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_no.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2309,3 +2309,5 @@ Invalid_ISBN\:_'%0'.=

should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2307,3 +2307,5 @@ Invalid_ISBN\:_'%0'.=

should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2310,3 +2310,5 @@ Invalid_ISBN\:_'%0'.=

should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_sv.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2306,3 +2306,5 @@ Invalid_ISBN\:_'%0'.=

should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_tr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2307,3 +2307,5 @@ Invalid_ISBN\:_'%0'.=Geçersiz_ISBN\:_'%0'.

should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_vi.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2309,3 +2309,5 @@ Invalid_ISBN\:_'%0'.=

should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2307,3 +2307,5 @@ Invalid_ISBN\:_'%0'.=

should_be_an_integer_or_normalized=
should_be_normalized=

empty_bibtexkey=
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ public void testMonthChecks() {
assertWrong(withMode(createContext("month", "Lorem"), BibDatabaseMode.BIBLATEX));
}

@Test
public void testBibtexkeyChecks() {
assertCorrect(createContext("bibtexkey", "Knuth2014"));
Copy link
Member

Choose a reason for hiding this comment

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

Could you do one assertCorrect per Test please? 😇

Copy link
Member

Choose a reason for hiding this comment

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

As we now have a class for each checker, we should also create a test class for each checker separately.
But I would think that is content for a new PR

Copy link
Contributor Author

@grimes2 grimes2 Sep 22, 2016

Choose a reason for hiding this comment

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

Removed my thumb up. A separate test class for every checker is too much (for evt. one or two entries). I think, it is better to organize the checker tests by fields (in methods) and not by checker classes.

}

@Test
public void testBracketChecks() {
assertCorrect(createContext("title", "x"));
Expand Down