From 69c47175b012da7fb8fb7eb6e377998e16294862 Mon Sep 17 00:00:00 2001 From: grimes2 Date: Wed, 21 Sep 2016 00:44:35 +0200 Subject: [PATCH 1/6] BibtexkeyChecker --- .../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 ++ 19 files changed, 67 insertions(+) create mode 100644 src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java 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..5641e2a73d0 --- /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.getField(BibEntry.KEY_FIELD); + 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()) { + 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 14b4f0535e7..ab7009cad81 100644 --- a/src/main/resources/l10n/JabRef_da.properties +++ b/src/main/resources/l10n/JabRef_da.properties @@ -2307,3 +2307,5 @@ 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 5c893ec3ac7..c1bc76e12f7 100644 --- a/src/main/resources/l10n/JabRef_de.properties +++ b/src/main/resources/l10n/JabRef_de.properties @@ -2309,3 +2309,5 @@ 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 92fe9af2f58..850b689b4d4 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -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 diff --git a/src/main/resources/l10n/JabRef_es.properties b/src/main/resources/l10n/JabRef_es.properties index e8928c414ba..b8542fed443 100644 --- a/src/main/resources/l10n/JabRef_es.properties +++ b/src/main/resources/l10n/JabRef_es.properties @@ -2307,3 +2307,5 @@ 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 cf580d83111..3be9bfc2f82 100644 --- a/src/main/resources/l10n/JabRef_fa.properties +++ b/src/main/resources/l10n/JabRef_fa.properties @@ -2310,3 +2310,5 @@ 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 cb0cd1e022c..b1fd1578681 100644 --- a/src/main/resources/l10n/JabRef_fr.properties +++ b/src/main/resources/l10n/JabRef_fr.properties @@ -2307,3 +2307,5 @@ 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 3ce63772d70..af7fe74a737 100644 --- a/src/main/resources/l10n/JabRef_in.properties +++ b/src/main/resources/l10n/JabRef_in.properties @@ -2307,3 +2307,5 @@ 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 2f6d67f6e40..d0d2d7fdd24 100644 --- a/src/main/resources/l10n/JabRef_it.properties +++ b/src/main/resources/l10n/JabRef_it.properties @@ -2307,3 +2307,5 @@ 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 b8c4082c956..0aedb6d2395 100644 --- a/src/main/resources/l10n/JabRef_ja.properties +++ b/src/main/resources/l10n/JabRef_ja.properties @@ -2305,3 +2305,5 @@ 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 5af1df32596..603b3238f8c 100644 --- a/src/main/resources/l10n/JabRef_nl.properties +++ b/src/main/resources/l10n/JabRef_nl.properties @@ -2309,3 +2309,5 @@ 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 eafb91681cf..cafee75e4b8 100644 --- a/src/main/resources/l10n/JabRef_no.properties +++ b/src/main/resources/l10n/JabRef_no.properties @@ -2309,3 +2309,5 @@ 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 507272d1738..c51f4a1ee0e 100644 --- a/src/main/resources/l10n/JabRef_pt_BR.properties +++ b/src/main/resources/l10n/JabRef_pt_BR.properties @@ -2307,3 +2307,5 @@ 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 ad8b0c498d2..b8f9bb68354 100644 --- a/src/main/resources/l10n/JabRef_ru.properties +++ b/src/main/resources/l10n/JabRef_ru.properties @@ -2310,3 +2310,5 @@ 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 b65a2788440..9f82903a8e1 100644 --- a/src/main/resources/l10n/JabRef_sv.properties +++ b/src/main/resources/l10n/JabRef_sv.properties @@ -2306,3 +2306,5 @@ 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 c4863a0c589..33e63a47466 100644 --- a/src/main/resources/l10n/JabRef_tr.properties +++ b/src/main/resources/l10n/JabRef_tr.properties @@ -2307,3 +2307,5 @@ 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 a906d6ee9b9..855046a3029 100644 --- a/src/main/resources/l10n/JabRef_vi.properties +++ b/src/main/resources/l10n/JabRef_vi.properties @@ -2309,3 +2309,5 @@ 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 bb01f9dc037..b5cb4aeda03 100644 --- a/src/main/resources/l10n/JabRef_zh.properties +++ b/src/main/resources/l10n/JabRef_zh.properties @@ -2307,3 +2307,5 @@ Invalid_ISBN\:_'%0'.= should_be_an_integer_or_normalized= should_be_normalized= + +empty_bibtexkey= From 68adcaa0724f17ba9688c49690faacb53b00ceb7 Mon Sep 17 00:00:00 2001 From: grimes2 Date: Wed, 21 Sep 2016 09:32:07 +0200 Subject: [PATCH 2/6] CHANGELOG.md and tests --- CHANGELOG.md | 1 + .../net/sf/jabref/logic/integrity/IntegrityCheckTest.java | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f1e3b9611e..97dba9c8ce4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,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/test/java/net/sf/jabref/logic/integrity/IntegrityCheckTest.java b/src/test/java/net/sf/jabref/logic/integrity/IntegrityCheckTest.java index 8f0e87c2cb2..03955efb117 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,12 @@ public void testMonthChecks() { assertWrong(withMode(createContext("month", "Lorem"), BibDatabaseMode.BIBLATEX)); } + @Test + public void testBibtexkeyChecks() { + assertCorrect(createContext("bibtexkey", "Knuth2014")); + assertCorrect(createContext("bibtexkey", "")); + } + @Test public void testBracketChecks() { assertCorrect(createContext("title", "x")); From f370908dfe49b35644968b3ba6ad27132f83370a Mon Sep 17 00:00:00 2001 From: grimes2 Date: Wed, 21 Sep 2016 12:26:35 +0200 Subject: [PATCH 3/6] Changes 1 --- .../net/sf/jabref/logic/integrity/BibtexkeyChecker.java | 7 ++++--- .../net/sf/jabref/logic/integrity/IntegrityCheckTest.java | 1 - 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java b/src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java index 5641e2a73d0..a665e0a9b1a 100644 --- a/src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java +++ b/src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java @@ -3,17 +3,18 @@ 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; +import org.apache.commons.lang3.StringUtils; + public class BibtexkeyChecker implements Checker { @Override public List check(BibEntry entry) { - Optional valuekey = entry.getField(BibEntry.KEY_FIELD); + String valuekey = entry.getCiteKey(); Optional valueauthor = entry.getField(FieldName.AUTHOR); Optional valuetitle = entry.getField(FieldName.TITLE); Optional valueyear = entry.getField(FieldName.YEAR); @@ -23,7 +24,7 @@ public List check(BibEntry entry) { return Collections.emptyList(); } - if (!valuekey.isPresent()) { + if (StringUtils.isBlank(valuekey)) { return Collections.singletonList(new IntegrityMessage( Localization.lang("empty bibtexkey") + ": " + authortitleyear, entry, BibEntry.KEY_FIELD)); } 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 03955efb117..d926085171e 100644 --- a/src/test/java/net/sf/jabref/logic/integrity/IntegrityCheckTest.java +++ b/src/test/java/net/sf/jabref/logic/integrity/IntegrityCheckTest.java @@ -114,7 +114,6 @@ public void testMonthChecks() { @Test public void testBibtexkeyChecks() { assertCorrect(createContext("bibtexkey", "Knuth2014")); - assertCorrect(createContext("bibtexkey", "")); } @Test From 7d7ec00d670028013a9fb35cf7339d0f2df653ce Mon Sep 17 00:00:00 2001 From: grimes2 Date: Wed, 21 Sep 2016 12:41:27 +0200 Subject: [PATCH 4/6] checkstyle --- .../java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java b/src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java index a665e0a9b1a..9318ee5c9f8 100644 --- a/src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java +++ b/src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java @@ -3,6 +3,7 @@ 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; From d4f6ee903a22017aa15271c45a1374f9e1ca99ff Mon Sep 17 00:00:00 2001 From: grimes2 Date: Wed, 21 Sep 2016 22:17:36 +0200 Subject: [PATCH 5/6] Change 2 --- .../java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java b/src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java index 9318ee5c9f8..e44b639e1a3 100644 --- a/src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java +++ b/src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java @@ -9,13 +9,10 @@ import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.FieldName; -import org.apache.commons.lang3.StringUtils; - public class BibtexkeyChecker implements Checker { @Override public List check(BibEntry entry) { - String valuekey = entry.getCiteKey(); Optional valueauthor = entry.getField(FieldName.AUTHOR); Optional valuetitle = entry.getField(FieldName.TITLE); Optional valueyear = entry.getField(FieldName.YEAR); @@ -25,7 +22,7 @@ public List check(BibEntry entry) { return Collections.emptyList(); } - if (StringUtils.isBlank(valuekey)) { + if (!entry.getCiteKeyOptional().isPresent() || entry.getCiteKeyOptional().get().isEmpty()) { return Collections.singletonList(new IntegrityMessage( Localization.lang("empty bibtexkey") + ": " + authortitleyear, entry, BibEntry.KEY_FIELD)); } From c73c4087454a81fc04ab8615a712d1dd421daeef Mon Sep 17 00:00:00 2001 From: grimes2 Date: Thu, 22 Sep 2016 12:37:50 +0200 Subject: [PATCH 6/6] Change 3 --- .../java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java b/src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java index e44b639e1a3..0c5bc4519c8 100644 --- a/src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java +++ b/src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java @@ -13,6 +13,7 @@ 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); @@ -22,7 +23,7 @@ public List check(BibEntry entry) { return Collections.emptyList(); } - if (!entry.getCiteKeyOptional().isPresent() || entry.getCiteKeyOptional().get().isEmpty()) { + if (!valuekey.isPresent() || valuekey.get().isEmpty()) { return Collections.singletonList(new IntegrityMessage( Localization.lang("empty bibtexkey") + ": " + authortitleyear, entry, BibEntry.KEY_FIELD)); }