From d512ebbef6fc57c74703c6d6bc821723fd63de91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Lange?= Date: Thu, 22 Sep 2016 13:02:30 +0200 Subject: [PATCH] Implemented BibtexkeyChecker (#2022) * BibtexkeyChecker * CHANGELOG.md and tests * Changes 1 * checkstyle * Change 2 * Change 3 --- CHANGELOG.md | 1 + .../logic/integrity/BibtexkeyChecker.java | 33 +++++++++++++++++++ .../logic/integrity/IntegrityCheck.java | 1 + src/main/resources/l10n/JabRef_da.properties | 2 ++ src/main/resources/l10n/JabRef_de.properties | 2 ++ src/main/resources/l10n/JabRef_en.properties | 1 + src/main/resources/l10n/JabRef_es.properties | 2 ++ src/main/resources/l10n/JabRef_fa.properties | 2 ++ src/main/resources/l10n/JabRef_fr.properties | 2 ++ src/main/resources/l10n/JabRef_in.properties | 2 ++ src/main/resources/l10n/JabRef_it.properties | 2 ++ src/main/resources/l10n/JabRef_ja.properties | 2 ++ src/main/resources/l10n/JabRef_nl.properties | 2 ++ src/main/resources/l10n/JabRef_no.properties | 2 ++ .../resources/l10n/JabRef_pt_BR.properties | 2 ++ src/main/resources/l10n/JabRef_ru.properties | 2 ++ src/main/resources/l10n/JabRef_sv.properties | 2 ++ src/main/resources/l10n/JabRef_tr.properties | 2 ++ src/main/resources/l10n/JabRef_vi.properties | 2 ++ src/main/resources/l10n/JabRef_zh.properties | 2 ++ .../logic/integrity/IntegrityCheckTest.java | 5 +++ 21 files changed, 73 insertions(+) create mode 100644 src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java diff --git a/CHANGELOG.md b/CHANGELOG.md index ba3a7b88d85..196767e028e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - UP / Down / Tab / shift+Tab 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 diff --git a/src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java b/src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java new file mode 100644 index 00000000000..0c5bc4519c8 --- /dev/null +++ b/src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java @@ -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 check(BibEntry entry) { + Optional valuekey = entry.getCiteKeyOptional(); + Optional valueauthor = entry.getField(FieldName.AUTHOR); + Optional valuetitle = entry.getField(FieldName.TITLE); + Optional 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(); + } +} diff --git a/src/main/java/net/sf/jabref/logic/integrity/IntegrityCheck.java b/src/main/java/net/sf/jabref/logic/integrity/IntegrityCheck.java index 2825cc7fc5b..d51f6e901da 100644 --- a/src/main/java/net/sf/jabref/logic/integrity/IntegrityCheck.java +++ b/src/main/java/net/sf/jabref/logic/integrity/IntegrityCheck.java @@ -50,6 +50,7 @@ private List 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)); diff --git a/src/main/resources/l10n/JabRef_da.properties b/src/main/resources/l10n/JabRef_da.properties index 4dcf72358e3..cb39a217431 100644 --- a/src/main/resources/l10n/JabRef_da.properties +++ b/src/main/resources/l10n/JabRef_da.properties @@ -2297,3 +2297,5 @@ Select_last_entry= Invalid_ISBN\:_'%0'.= should_be_an_integer_or_normalized= should_be_normalized= + +empty_bibtexkey= diff --git a/src/main/resources/l10n/JabRef_de.properties b/src/main/resources/l10n/JabRef_de.properties index 9370a1a2afe..5e27b916fa6 100644 --- a/src/main/resources/l10n/JabRef_de.properties +++ b/src/main/resources/l10n/JabRef_de.properties @@ -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= diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 9e9ebf1a266..df3d897f629 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -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 diff --git a/src/main/resources/l10n/JabRef_es.properties b/src/main/resources/l10n/JabRef_es.properties index b899b91574c..acfaec9101e 100644 --- a/src/main/resources/l10n/JabRef_es.properties +++ b/src/main/resources/l10n/JabRef_es.properties @@ -2297,3 +2297,5 @@ Select_last_entry= Invalid_ISBN\:_'%0'.= should_be_an_integer_or_normalized= should_be_normalized= + +empty_bibtexkey= diff --git a/src/main/resources/l10n/JabRef_fa.properties b/src/main/resources/l10n/JabRef_fa.properties index 3ea7984c800..94687a3815e 100644 --- a/src/main/resources/l10n/JabRef_fa.properties +++ b/src/main/resources/l10n/JabRef_fa.properties @@ -2297,3 +2297,5 @@ Select_last_entry= Invalid_ISBN\:_'%0'.= should_be_an_integer_or_normalized= should_be_normalized= + +empty_bibtexkey= diff --git a/src/main/resources/l10n/JabRef_fr.properties b/src/main/resources/l10n/JabRef_fr.properties index 4dc4b36416b..360ca0e01f6 100644 --- a/src/main/resources/l10n/JabRef_fr.properties +++ b/src/main/resources/l10n/JabRef_fr.properties @@ -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= diff --git a/src/main/resources/l10n/JabRef_in.properties b/src/main/resources/l10n/JabRef_in.properties index fd5a950bedb..33c35e278e8 100644 --- a/src/main/resources/l10n/JabRef_in.properties +++ b/src/main/resources/l10n/JabRef_in.properties @@ -2297,3 +2297,5 @@ Select_last_entry= Invalid_ISBN\:_'%0'.= should_be_an_integer_or_normalized= should_be_normalized= + +empty_bibtexkey= diff --git a/src/main/resources/l10n/JabRef_it.properties b/src/main/resources/l10n/JabRef_it.properties index 2bb7c5e67d4..f574a701bec 100644 --- a/src/main/resources/l10n/JabRef_it.properties +++ b/src/main/resources/l10n/JabRef_it.properties @@ -2297,3 +2297,5 @@ Select_last_entry= Invalid_ISBN\:_'%0'.= should_be_an_integer_or_normalized= should_be_normalized= + +empty_bibtexkey= diff --git a/src/main/resources/l10n/JabRef_ja.properties b/src/main/resources/l10n/JabRef_ja.properties index 60ca92f09cb..63f83754bce 100644 --- a/src/main/resources/l10n/JabRef_ja.properties +++ b/src/main/resources/l10n/JabRef_ja.properties @@ -2297,3 +2297,5 @@ Select_last_entry=最後の項目を選択 Invalid_ISBN\:_'%0'.= should_be_an_integer_or_normalized= should_be_normalized= + +empty_bibtexkey= diff --git a/src/main/resources/l10n/JabRef_nl.properties b/src/main/resources/l10n/JabRef_nl.properties index dbd6df21bb8..9416ae87c68 100644 --- a/src/main/resources/l10n/JabRef_nl.properties +++ b/src/main/resources/l10n/JabRef_nl.properties @@ -2297,3 +2297,5 @@ Select_last_entry= Invalid_ISBN\:_'%0'.= should_be_an_integer_or_normalized= should_be_normalized= + +empty_bibtexkey= diff --git a/src/main/resources/l10n/JabRef_no.properties b/src/main/resources/l10n/JabRef_no.properties index 770e0588ec1..f4b312e7c33 100644 --- a/src/main/resources/l10n/JabRef_no.properties +++ b/src/main/resources/l10n/JabRef_no.properties @@ -2297,3 +2297,5 @@ Select_last_entry= Invalid_ISBN\:_'%0'.= should_be_an_integer_or_normalized= should_be_normalized= + +empty_bibtexkey= diff --git a/src/main/resources/l10n/JabRef_pt_BR.properties b/src/main/resources/l10n/JabRef_pt_BR.properties index 4733a3c66ab..e1d21ac1725 100644 --- a/src/main/resources/l10n/JabRef_pt_BR.properties +++ b/src/main/resources/l10n/JabRef_pt_BR.properties @@ -2297,3 +2297,5 @@ Select_last_entry= Invalid_ISBN\:_'%0'.= should_be_an_integer_or_normalized= should_be_normalized= + +empty_bibtexkey= diff --git a/src/main/resources/l10n/JabRef_ru.properties b/src/main/resources/l10n/JabRef_ru.properties index 2d1f2985900..7f53ccf7077 100644 --- a/src/main/resources/l10n/JabRef_ru.properties +++ b/src/main/resources/l10n/JabRef_ru.properties @@ -2297,3 +2297,5 @@ Select_last_entry= Invalid_ISBN\:_'%0'.= should_be_an_integer_or_normalized= should_be_normalized= + +empty_bibtexkey= diff --git a/src/main/resources/l10n/JabRef_sv.properties b/src/main/resources/l10n/JabRef_sv.properties index 12ed8fedd5e..ab9a1c87679 100644 --- a/src/main/resources/l10n/JabRef_sv.properties +++ b/src/main/resources/l10n/JabRef_sv.properties @@ -2297,3 +2297,5 @@ Select_last_entry= Invalid_ISBN\:_'%0'.= should_be_an_integer_or_normalized= should_be_normalized= + +empty_bibtexkey= diff --git a/src/main/resources/l10n/JabRef_tr.properties b/src/main/resources/l10n/JabRef_tr.properties index c4c167cf740..e9b13c31772 100644 --- a/src/main/resources/l10n/JabRef_tr.properties +++ b/src/main/resources/l10n/JabRef_tr.properties @@ -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= diff --git a/src/main/resources/l10n/JabRef_vi.properties b/src/main/resources/l10n/JabRef_vi.properties index 779579d6d01..f60613cbfa9 100644 --- a/src/main/resources/l10n/JabRef_vi.properties +++ b/src/main/resources/l10n/JabRef_vi.properties @@ -2297,3 +2297,5 @@ Select_last_entry= Invalid_ISBN\:_'%0'.= should_be_an_integer_or_normalized= should_be_normalized= + +empty_bibtexkey= diff --git a/src/main/resources/l10n/JabRef_zh.properties b/src/main/resources/l10n/JabRef_zh.properties index bd969e68e21..ed1aa2b3311 100644 --- a/src/main/resources/l10n/JabRef_zh.properties +++ b/src/main/resources/l10n/JabRef_zh.properties @@ -2297,3 +2297,5 @@ Select_last_entry= Invalid_ISBN\:_'%0'.= should_be_an_integer_or_normalized= should_be_normalized= + +empty_bibtexkey= diff --git a/src/test/java/net/sf/jabref/logic/integrity/IntegrityCheckTest.java b/src/test/java/net/sf/jabref/logic/integrity/IntegrityCheckTest.java index 4671b73c74d..a5eb5313f1e 100644 --- a/src/test/java/net/sf/jabref/logic/integrity/IntegrityCheckTest.java +++ b/src/test/java/net/sf/jabref/logic/integrity/IntegrityCheckTest.java @@ -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"));