From 935d625e2dcf58b8d6157567f12bd349accaff1e Mon Sep 17 00:00:00 2001 From: Ronak Lakhotia Date: Fri, 8 Feb 2019 22:24:21 +0800 Subject: [PATCH 1/3] Add Integrity check for books with edition reported as 1 --- .../java/org/jabref/logic/integrity/EditionChecker.java | 8 +++++++- .../org/jabref/logic/integrity/IntegrityCheckTest.java | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/logic/integrity/EditionChecker.java b/src/main/java/org/jabref/logic/integrity/EditionChecker.java index 54a1869bfe2..072c7a4a4f1 100644 --- a/src/main/java/org/jabref/logic/integrity/EditionChecker.java +++ b/src/main/java/org/jabref/logic/integrity/EditionChecker.java @@ -14,6 +14,7 @@ public class EditionChecker implements ValueChecker { private static final Predicate FIRST_LETTER_CAPITALIZED = Pattern.compile("^[A-Z]").asPredicate(); private static final Predicate ONLY_NUMERALS_OR_LITERALS = Pattern.compile("^([0-9]+|[^0-9].+)$") .asPredicate(); + private static final String FIRST_EDITION = "1"; private final BibDatabaseContext bibDatabaseContextEdition; @@ -44,10 +45,15 @@ public Optional checkValue(String value) { } //BibTeX - if (!bibDatabaseContextEdition.isBiblatexMode() && !FIRST_LETTER_CAPITALIZED.test(value.trim())) { + if (!bibDatabaseContextEdition.isBiblatexMode() && !FIRST_LETTER_CAPITALIZED.test(value.trim()) && + !value.equals(FIRST_EDITION)) { return Optional.of(Localization.lang("should have the first letter capitalized")); } + if (value.equals(FIRST_EDITION)) { + return Optional.of(Localization.lang("edition of book reported as just 1")); + } + return Optional.empty(); } } diff --git a/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java b/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java index 54a1d715e99..8fb2bb73aeb 100644 --- a/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java +++ b/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java @@ -86,6 +86,7 @@ void testEditionChecks() { withMode(createContext("edition", "Third, revised and expanded edition"), BibDatabaseMode.BIBLATEX)); assertCorrect(withMode(createContext("edition", "Edition 2000"), BibDatabaseMode.BIBLATEX)); assertWrong(withMode(createContext("edition", "2nd"), BibDatabaseMode.BIBLATEX)); + assertWrong(createContext("edition", "1")); } @Test From 6da731c6c8da9a75af613144cae058a0303c7cc4 Mon Sep 17 00:00:00 2001 From: Ronak Lakhotia Date: Fri, 8 Feb 2019 23:00:27 +0800 Subject: [PATCH 2/3] Edit localization file --- src/main/resources/l10n/JabRef_en.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 6e5e0d1a2af..f8291d55412 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -1986,6 +1986,7 @@ Sumatra\ Reader=Sumatra Reader shared=shared should\ contain\ an\ integer\ or\ a\ literal=should contain an integer or a literal should\ have\ the\ first\ letter\ capitalized=should have the first letter capitalized +edition\ of\ book\ reported\ as\ just\ 1=edition of book reported as just 1 Tools=Tools What\'s\ new\ in\ this\ version?=What\'s new in this version? Want\ to\ help?=Want to help? From b858a2c02ab8c97f817a2ab4c96cd0ff110db6ae Mon Sep 17 00:00:00 2001 From: Ronak Lakhotia Date: Sun, 10 Feb 2019 20:41:13 +0800 Subject: [PATCH 3/3] Reorder conditional checks --- .../org/jabref/logic/integrity/EditionChecker.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jabref/logic/integrity/EditionChecker.java b/src/main/java/org/jabref/logic/integrity/EditionChecker.java index 072c7a4a4f1..c382fe7eab1 100644 --- a/src/main/java/org/jabref/logic/integrity/EditionChecker.java +++ b/src/main/java/org/jabref/logic/integrity/EditionChecker.java @@ -39,21 +39,20 @@ public Optional checkValue(String value) { return Optional.empty(); } + if (value.equals(FIRST_EDITION)) { + return Optional.of(Localization.lang("edition of book reported as just 1")); + } + //biblatex if (bibDatabaseContextEdition.isBiblatexMode() && !ONLY_NUMERALS_OR_LITERALS.test(value.trim())) { return Optional.of(Localization.lang("should contain an integer or a literal")); } //BibTeX - if (!bibDatabaseContextEdition.isBiblatexMode() && !FIRST_LETTER_CAPITALIZED.test(value.trim()) && - !value.equals(FIRST_EDITION)) { + if (!bibDatabaseContextEdition.isBiblatexMode() && !FIRST_LETTER_CAPITALIZED.test(value.trim())) { return Optional.of(Localization.lang("should have the first letter capitalized")); } - if (value.equals(FIRST_EDITION)) { - return Optional.of(Localization.lang("edition of book reported as just 1")); - } - return Optional.empty(); } }