Skip to content

Commit

Permalink
Implemented BibtexkeyChecker (#2022)
Browse files Browse the repository at this point in the history
* BibtexkeyChecker

* CHANGELOG.md and tests

* Changes 1

* checkstyle

* Change 2

* Change 3
  • Loading branch information
Jürgen Lange authored and tobiasdiez committed Sep 22, 2016
1 parent ddd610d commit d512ebb
Show file tree
Hide file tree
Showing 21 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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()) {
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 @@ -2297,3 +2297,5 @@ Select_last_entry=
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 @@ -2297,3 +2297,5 @@ Select_last_entry=Letzten_Eintrag_auswählen
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 @@ -2297,3 +2297,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 @@ -2297,3 +2297,5 @@ Select_last_entry=
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 @@ -2297,3 +2297,5 @@ Select_last_entry=
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 @@ -2297,3 +2297,5 @@ Select_last_entry=Sélectionner_la_dernière_entrée
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 @@ -2297,3 +2297,5 @@ Select_last_entry=
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 @@ -2297,3 +2297,5 @@ Select_last_entry=
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 @@ -2297,3 +2297,5 @@ Select_last_entry=最後の項目を選択
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 @@ -2297,3 +2297,5 @@ Select_last_entry=
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 @@ -2297,3 +2297,5 @@ Select_last_entry=
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 @@ -2297,3 +2297,5 @@ Select_last_entry=
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 @@ -2297,3 +2297,5 @@ Select_last_entry=
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 @@ -2297,3 +2297,5 @@ Select_last_entry=
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 @@ -2297,3 +2297,5 @@ Select_last_entry=Son_girdiyi_seç
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 @@ -2297,3 +2297,5 @@ Select_last_entry=
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 @@ -2297,3 +2297,5 @@ Select_last_entry=
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"));
}

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

0 comments on commit d512ebb

Please sign in to comment.