From 788f395b4c08c2fe3559f0d1f088e8397c2bc3c9 Mon Sep 17 00:00:00 2001 From: Catarina Gomes Date: Thu, 7 May 2020 00:36:57 +0100 Subject: [PATCH 01/20] ISSUE :: 6224 - allow merging of year and date if identical --- .../org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java b/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java index 1bb29ec6dfe..470c5e945ba 100644 --- a/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java +++ b/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java @@ -39,6 +39,12 @@ public List cleanup(BibEntry entry) { entry.clearField(StandardField.YEAR).ifPresent(changes::add); entry.clearField(StandardField.MONTH).ifPresent(changes::add); }); + } else { + // If field date is filled it should be removed the year and date fields + entry.getFieldOrAlias(StandardField.DATE).ifPresent(newDate -> { + entry.clearField(StandardField.YEAR).ifPresent(changes::add); + entry.clearField(StandardField.MONTH).ifPresent(changes::add); + }); } return changes; } From 05518d2838c26a108b190c7f7f1f8bf9e0e66571 Mon Sep 17 00:00:00 2001 From: Catarina Gomes Date: Thu, 7 May 2020 00:42:34 +0100 Subject: [PATCH 02/20] fix comment --- .../java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java b/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java index 470c5e945ba..1a82ec5f9b8 100644 --- a/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java +++ b/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java @@ -40,7 +40,7 @@ public List cleanup(BibEntry entry) { entry.clearField(StandardField.MONTH).ifPresent(changes::add); }); } else { - // If field date is filled it should be removed the year and date fields + // If field date is filled it should be removed the year and month fields entry.getFieldOrAlias(StandardField.DATE).ifPresent(newDate -> { entry.clearField(StandardField.YEAR).ifPresent(changes::add); entry.clearField(StandardField.MONTH).ifPresent(changes::add); From 93de4bcdcd4f430fc2113f123be99c47879c0325 Mon Sep 17 00:00:00 2001 From: Catarina Gomes Date: Thu, 7 May 2020 12:34:29 +0100 Subject: [PATCH 03/20] Updated Changelog.md file with fixed issue --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 762f841e60d..567a4c2f2c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue where JabRef switched to discrete graphics under macOS [#5935](https://github.com/JabRef/jabref/issues/5935) - We fixed an issue where the Preferences entry preview will be unexpected modified leads to Value too long exception [#6198](https://github.com/JabRef/jabref/issues/6198) - We fixed an issue where custom jstyles for Open/LibreOffice would only be valid if a layout line for the entry type `default` was at the end of the layout section [#6303](https://github.com/JabRef/jabref/issues/6303) +- We fixed an issue where clear year and month field when converting to biblatex [#6224](https://github.com/JabRef/jabref/issues/6224) ### Removed From 29ae438c8d9877897f706887b9b077cbfd60864d Mon Sep 17 00:00:00 2001 From: Catarina Gomes Date: Thu, 7 May 2020 13:36:12 +0100 Subject: [PATCH 04/20] Fix changelog.md file --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 567a4c2f2c5..a94ffa5c7dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,7 +54,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue where JabRef switched to discrete graphics under macOS [#5935](https://github.com/JabRef/jabref/issues/5935) - We fixed an issue where the Preferences entry preview will be unexpected modified leads to Value too long exception [#6198](https://github.com/JabRef/jabref/issues/6198) - We fixed an issue where custom jstyles for Open/LibreOffice would only be valid if a layout line for the entry type `default` was at the end of the layout section [#6303](https://github.com/JabRef/jabref/issues/6303) -- We fixed an issue where clear year and month field when converting to biblatex [#6224](https://github.com/JabRef/jabref/issues/6224) +- We fixed an issue where year and month fields were not cleared when converting to biblatex [#6224](https://github.com/JabRef/jabref/issues/6224) ### Removed From 559e7490cbb3ffcf56899b983296a92a82dda8b5 Mon Sep 17 00:00:00 2001 From: Catarina Gomes Date: Fri, 8 May 2020 01:17:13 +0100 Subject: [PATCH 05/20] Check If date field is filled and is equal to year it should be removed the year and month fields --- .../logic/cleanup/ConvertToBiblatexCleanup.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java b/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java index 1a82ec5f9b8..8f1fe44e28f 100644 --- a/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java +++ b/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Optional; import org.jabref.model.FieldChange; import org.jabref.model.cleanup.CleanupJob; @@ -17,6 +18,7 @@ */ public class ConvertToBiblatexCleanup implements CleanupJob { + @SuppressWarnings("checkstyle:WhitespaceAround") @Override public List cleanup(BibEntry entry) { List changes = new ArrayList<>(); @@ -40,13 +42,17 @@ public List cleanup(BibEntry entry) { entry.clearField(StandardField.MONTH).ifPresent(changes::add); }); } else { - // If field date is filled it should be removed the year and month fields - entry.getFieldOrAlias(StandardField.DATE).ifPresent(newDate -> { - entry.clearField(StandardField.YEAR).ifPresent(changes::add); - entry.clearField(StandardField.MONTH).ifPresent(changes::add); + // If date field is filled and is equal to year it should be removed the year and month fields + entry.getFieldOrAlias(StandardField.DATE).ifPresent(date -> { + entry.getFieldOrAlias(StandardField.YEAR).ifPresent(yearl -> { + // Get the year of the date field (4 digits). + if (date.substring(0, 4).equals(yearl)) { + entry.clearField(StandardField.YEAR).ifPresent(changes::add); + entry.clearField(StandardField.MONTH).ifPresent(changes::add); + } + }); }); } return changes; } - } From c4a4b1563247fee1d768f8a577687c86e21f4579 Mon Sep 17 00:00:00 2001 From: Catarina Gomes Date: Fri, 8 May 2020 01:19:10 +0100 Subject: [PATCH 06/20] Added unit test: Cleanup With Date Already Present And Equals To Year Removes Year And Month --- .../cleanup/ConvertToBiblatexCleanupTest.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java b/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java index b01b798618e..8f0f7c86642 100644 --- a/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java +++ b/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java @@ -33,7 +33,7 @@ public void cleanupMovesYearMonthToDate() { } @Test - public void cleanupWithDateAlreadyPresentDoesNothing() { + public void cleanupWithDateAlreadyPresentAndDifferentFromYearDoesNothing() { BibEntry entry = new BibEntry(); entry.setField(StandardField.YEAR, "2011"); entry.setField(StandardField.MONTH, "#jan#"); @@ -46,6 +46,20 @@ public void cleanupWithDateAlreadyPresentDoesNothing() { assertEquals(Optional.of("2012"), entry.getField(StandardField.DATE)); } + @Test + public void cleanupWithDateAlreadyPresentAndEqualsToYearRemovesYearAndMonth() { + BibEntry entry = new BibEntry(); + entry.setField(StandardField.YEAR, "2011"); + entry.setField(StandardField.MONTH, "#jan#"); + entry.setField(StandardField.DATE, "2011"); + + worker.cleanup(entry); + + assertEquals(Optional.empty(), entry.getField(StandardField.YEAR)); + assertEquals(Optional.empty(), entry.getField(StandardField.MONTH)); + assertEquals(Optional.of("2011"), entry.getField(StandardField.DATE)); + } + @Test public void cleanupMovesJournalToJournaltitle() { BibEntry entry = new BibEntry().withField(StandardField.JOURNAL, "Best of JabRef"); From e810e1e22b7481b48cd8514bac77d5a0392b0d98 Mon Sep 17 00:00:00 2001 From: Catarina Gomes Date: Fri, 8 May 2020 01:39:38 +0100 Subject: [PATCH 07/20] ISSUE :: 6224 - Removed Unused import - java.util.Optional --- .../java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java b/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java index 8f1fe44e28f..e155005f532 100644 --- a/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java +++ b/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java @@ -3,8 +3,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.Optional; - import org.jabref.model.FieldChange; import org.jabref.model.cleanup.CleanupJob; import org.jabref.model.entry.BibEntry; From 8750df7c83ccc3ab3c565d22e69d0d4ce2ff86ea Mon Sep 17 00:00:00 2001 From: Catarina Gomes Date: Fri, 8 May 2020 01:45:54 +0100 Subject: [PATCH 08/20] ISSUE :: 6224 - Separated org.jabref.model.FieldChange from previous imports --- .../java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java b/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java index e155005f532..49845f1a16f 100644 --- a/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java +++ b/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; + import org.jabref.model.FieldChange; import org.jabref.model.cleanup.CleanupJob; import org.jabref.model.entry.BibEntry; From bf164595b211df427825ed84ce7d6909daf33536 Mon Sep 17 00:00:00 2001 From: Catarina Gomes Date: Fri, 8 May 2020 12:42:43 +0100 Subject: [PATCH 09/20] remove checkstyle warning --- .../java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java b/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java index 49845f1a16f..49808858e53 100644 --- a/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java +++ b/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java @@ -17,7 +17,6 @@ */ public class ConvertToBiblatexCleanup implements CleanupJob { - @SuppressWarnings("checkstyle:WhitespaceAround") @Override public List cleanup(BibEntry entry) { List changes = new ArrayList<>(); From 0eb590659ab54a9a8b3a70927e1b26524b980aeb Mon Sep 17 00:00:00 2001 From: Catarina Gomes Date: Fri, 8 May 2020 16:23:45 +0100 Subject: [PATCH 10/20] Change variable newYear name --- .../org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java b/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java index 49808858e53..cbbfd5a8867 100644 --- a/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java +++ b/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java @@ -42,9 +42,9 @@ public List cleanup(BibEntry entry) { } else { // If date field is filled and is equal to year it should be removed the year and month fields entry.getFieldOrAlias(StandardField.DATE).ifPresent(date -> { - entry.getFieldOrAlias(StandardField.YEAR).ifPresent(yearl -> { + entry.getFieldOrAlias(StandardField.YEAR).ifPresent(checkYear -> { // Get the year of the date field (4 digits). - if (date.substring(0, 4).equals(yearl)) { + if (date.substring(0, 4).equals(checkYear)) { entry.clearField(StandardField.YEAR).ifPresent(changes::add); entry.clearField(StandardField.MONTH).ifPresent(changes::add); } From 5b1c8529c7cbd5a35c0ac61be23884d3a5117883 Mon Sep 17 00:00:00 2001 From: Catarina Gomes Date: Sat, 9 May 2020 17:02:17 +0100 Subject: [PATCH 11/20] Update Changelog.md --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d7b0b4e43b..b9162e795f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,9 +55,8 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue where JabRef switched to discrete graphics under macOS [#5935](https://github.com/JabRef/jabref/issues/5935) - We fixed an issue where the Preferences entry preview will be unexpected modified leads to Value too long exception [#6198](https://github.com/JabRef/jabref/issues/6198) - We fixed an issue where custom jstyles for Open/LibreOffice would only be valid if a layout line for the entry type `default` was at the end of the layout section [#6303](https://github.com/JabRef/jabref/issues/6303) -- We fixed an issue where year and month fields were not cleared when converting to biblatex [#6224](https://github.com/JabRef/jabref/issues/6224) - We fixed an issue where sort on numeric cases was broken. [#6349](https://github.com/JabRef/jabref/issues/6349) - +- We fixed an issue where year and month fields were not cleared when converting to biblatex [#6224](https://github.com/JabRef/jabref/issues/6224) ### Removed From 05c86c2428ef95a76ae758000189f55ef9e16570 Mon Sep 17 00:00:00 2001 From: Catarina Gomes Date: Sun, 10 May 2020 21:21:32 +0100 Subject: [PATCH 12/20] ISSUE :: 6224 - Added month validation and tests --- .../cleanup/ConvertToBiblatexCleanup.java | 13 ++++++++++++- .../cleanup/ConvertToBiblatexCleanupTest.java | 18 ++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java b/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java index cbbfd5a8867..8b9afe76563 100644 --- a/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java +++ b/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java @@ -7,6 +7,7 @@ import org.jabref.model.FieldChange; import org.jabref.model.cleanup.CleanupJob; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.Date; import org.jabref.model.entry.EntryConverter; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.StandardField; @@ -40,15 +41,25 @@ public List cleanup(BibEntry entry) { entry.clearField(StandardField.MONTH).ifPresent(changes::add); }); } else { - // If date field is filled and is equal to year it should be removed the year and month fields + // If the year from date field is filled and equal to year it should be removed the year field entry.getFieldOrAlias(StandardField.DATE).ifPresent(date -> { entry.getFieldOrAlias(StandardField.YEAR).ifPresent(checkYear -> { // Get the year of the date field (4 digits). if (date.substring(0, 4).equals(checkYear)) { entry.clearField(StandardField.YEAR).ifPresent(changes::add); + } + }); + + // If the month from date field is filled and is equal to month it should be removed the month field + var data = Date.parse(date); + var monthFromDate = data.get().getMonth().get().getJabRefFormat(); + entry.getFieldOrAlias(StandardField.MONTH).ifPresent(checkMonth -> { + // Check if the month is equal to month date field. + if (checkMonth.equals(monthFromDate)) { entry.clearField(StandardField.MONTH).ifPresent(changes::add); } }); + }); } return changes; diff --git a/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java b/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java index 8f0f7c86642..995c9d67cbc 100644 --- a/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java +++ b/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java @@ -33,7 +33,7 @@ public void cleanupMovesYearMonthToDate() { } @Test - public void cleanupWithDateAlreadyPresentAndDifferentFromYearDoesNothing() { + public void cleanupWithDateAlreadyPresentAndDifferentFromYearDoesNotClearTheYear() { BibEntry entry = new BibEntry(); entry.setField(StandardField.YEAR, "2011"); entry.setField(StandardField.MONTH, "#jan#"); @@ -42,6 +42,20 @@ public void cleanupWithDateAlreadyPresentAndDifferentFromYearDoesNothing() { worker.cleanup(entry); assertEquals(Optional.of("2011"), entry.getField(StandardField.YEAR)); + assertEquals(Optional.empty(), entry.getField(StandardField.MONTH)); + assertEquals(Optional.of("2012-01"), entry.getField(StandardField.DATE)); + } + + @Test + public void cleanupWithDateAlreadyPresentAndDifferentFromMonthDoesNotClearTheMonth() { + BibEntry entry = new BibEntry(); + entry.setField(StandardField.YEAR, "2012"); + entry.setField(StandardField.MONTH, "#jan#"); + entry.setField(StandardField.DATE, "2012-02"); + + worker.cleanup(entry); + + assertEquals(Optional.empty(), entry.getField(StandardField.YEAR)); assertEquals(Optional.of("#jan#"), entry.getField(StandardField.MONTH)); assertEquals(Optional.of("2012"), entry.getField(StandardField.DATE)); } @@ -57,7 +71,7 @@ public void cleanupWithDateAlreadyPresentAndEqualsToYearRemovesYearAndMonth() { assertEquals(Optional.empty(), entry.getField(StandardField.YEAR)); assertEquals(Optional.empty(), entry.getField(StandardField.MONTH)); - assertEquals(Optional.of("2011"), entry.getField(StandardField.DATE)); + assertEquals(Optional.of("2011-01"), entry.getField(StandardField.DATE)); } @Test From fb75aa507fb06251808db3d8c790b82028e8e8c1 Mon Sep 17 00:00:00 2001 From: Catarina Gomes Date: Tue, 12 May 2020 20:24:19 +0100 Subject: [PATCH 13/20] ISSUE :: 6224 - For inconsistent data: Do not overwrite/move --- .../cleanup/ConvertToBiblatexCleanup.java | 29 +++++++++---------- .../java/org/jabref/model/entry/Date.java | 3 +- .../cleanup/ConvertToBiblatexCleanupTest.java | 22 +++----------- 3 files changed, 20 insertions(+), 34 deletions(-) diff --git a/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java b/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java index 8b9afe76563..f7ac46e58ac 100644 --- a/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java +++ b/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Optional; import org.jabref.model.FieldChange; import org.jabref.model.cleanup.CleanupJob; @@ -43,23 +44,21 @@ public List cleanup(BibEntry entry) { } else { // If the year from date field is filled and equal to year it should be removed the year field entry.getFieldOrAlias(StandardField.DATE).ifPresent(date -> { - entry.getFieldOrAlias(StandardField.YEAR).ifPresent(checkYear -> { - // Get the year of the date field (4 digits). - if (date.substring(0, 4).equals(checkYear)) { - entry.clearField(StandardField.YEAR).ifPresent(changes::add); - } - }); + entry.getFieldOrAlias(StandardField.YEAR).ifPresent(year -> { + entry.getFieldOrAlias(StandardField.MONTH).ifPresent(month -> { - // If the month from date field is filled and is equal to month it should be removed the month field - var data = Date.parse(date); - var monthFromDate = data.get().getMonth().get().getJabRefFormat(); - entry.getFieldOrAlias(StandardField.MONTH).ifPresent(checkMonth -> { - // Check if the month is equal to month date field. - if (checkMonth.equals(monthFromDate)) { - entry.clearField(StandardField.MONTH).ifPresent(changes::add); - } - }); + Optional checkDate = Date.parse(date); + // Converts using this format: "MMMM, uuuu". Ex: September, 2015 + month = month.replaceAll("#", "").toLowerCase(); + month = month.substring(0, 1).toUpperCase() + month.substring(1, month.length()); + Optional checkMonthAndYear = Date.parse(month + ", " + year); + if (checkDate.isPresent() && checkMonthAndYear.isPresent() && checkDate.equals(checkMonthAndYear)) { + entry.clearField(StandardField.YEAR).ifPresent(changes::add); + entry.clearField(StandardField.MONTH).ifPresent(changes::add); + } + }); + }); }); } return changes; diff --git a/src/main/java/org/jabref/model/entry/Date.java b/src/main/java/org/jabref/model/entry/Date.java index b1655ad7c17..5cd4b586a7e 100644 --- a/src/main/java/org/jabref/model/entry/Date.java +++ b/src/main/java/org/jabref/model/entry/Date.java @@ -54,7 +54,8 @@ public static Optional parse(String dateString) { "MMMM d, uuuu", "MMMM, uuuu", "d.M.uuuu", - "uuuu.M.d", "uuuu"); + "uuuu.M.d", "uuuu", + "MMM, uuuu"); for (String formatString : formatStrings) { try { diff --git a/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java b/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java index 995c9d67cbc..4c89a8ea127 100644 --- a/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java +++ b/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java @@ -29,33 +29,18 @@ public void cleanupMovesYearMonthToDate() { assertEquals(Optional.empty(), entry.getField(StandardField.YEAR)); assertEquals(Optional.empty(), entry.getField(StandardField.MONTH)); - assertEquals(Optional.of("2011-01"), entry.getField(StandardField.DATE)); + assertEquals(Optional.of("2011"), entry.getField(StandardField.DATE)); } @Test - public void cleanupWithDateAlreadyPresentAndDifferentFromYearDoesNotClearTheYear() { + public void cleanupWithDateAlreadyPresentDoesNothing() { BibEntry entry = new BibEntry(); entry.setField(StandardField.YEAR, "2011"); entry.setField(StandardField.MONTH, "#jan#"); entry.setField(StandardField.DATE, "2012"); - worker.cleanup(entry); assertEquals(Optional.of("2011"), entry.getField(StandardField.YEAR)); - assertEquals(Optional.empty(), entry.getField(StandardField.MONTH)); - assertEquals(Optional.of("2012-01"), entry.getField(StandardField.DATE)); - } - - @Test - public void cleanupWithDateAlreadyPresentAndDifferentFromMonthDoesNotClearTheMonth() { - BibEntry entry = new BibEntry(); - entry.setField(StandardField.YEAR, "2012"); - entry.setField(StandardField.MONTH, "#jan#"); - entry.setField(StandardField.DATE, "2012-02"); - - worker.cleanup(entry); - - assertEquals(Optional.empty(), entry.getField(StandardField.YEAR)); assertEquals(Optional.of("#jan#"), entry.getField(StandardField.MONTH)); assertEquals(Optional.of("2012"), entry.getField(StandardField.DATE)); } @@ -65,7 +50,7 @@ public void cleanupWithDateAlreadyPresentAndEqualsToYearRemovesYearAndMonth() { BibEntry entry = new BibEntry(); entry.setField(StandardField.YEAR, "2011"); entry.setField(StandardField.MONTH, "#jan#"); - entry.setField(StandardField.DATE, "2011"); + entry.setField(StandardField.DATE, "2011-01"); worker.cleanup(entry); @@ -83,4 +68,5 @@ public void cleanupMovesJournalToJournaltitle() { assertEquals(Optional.empty(), entry.getField(StandardField.JOURNAL)); assertEquals(Optional.of("Best of JabRef"), entry.getField(StandardField.JOURNALTITLE)); } + } From 3541c2f96568650b25d04acc6bdf10faf55fa7e6 Mon Sep 17 00:00:00 2001 From: Catarina Gomes Date: Tue, 12 May 2020 20:33:31 +0100 Subject: [PATCH 14/20] ISSUE :: 6224 - Fix Test --- .../logic/cleanup/ConvertToBiblatexCleanupTest.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java b/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java index 4c89a8ea127..19e2fd0b7fa 100644 --- a/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java +++ b/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java @@ -33,20 +33,21 @@ public void cleanupMovesYearMonthToDate() { } @Test - public void cleanupWithDateAlreadyPresentDoesNothing() { + public void cleanupWithDateAlreadyPresentAndDifferentFromYearDoesNothing() { BibEntry entry = new BibEntry(); entry.setField(StandardField.YEAR, "2011"); entry.setField(StandardField.MONTH, "#jan#"); - entry.setField(StandardField.DATE, "2012"); + entry.setField(StandardField.DATE, "2012-01"); + worker.cleanup(entry); assertEquals(Optional.of("2011"), entry.getField(StandardField.YEAR)); assertEquals(Optional.of("#jan#"), entry.getField(StandardField.MONTH)); - assertEquals(Optional.of("2012"), entry.getField(StandardField.DATE)); + assertEquals(Optional.of("2012-01"), entry.getField(StandardField.DATE)); } @Test - public void cleanupWithDateAlreadyPresentAndEqualsToYearRemovesYearAndMonth() { + public void cleanupWithDateAlreadyPresentAndEqualsToYearAndMonth() { BibEntry entry = new BibEntry(); entry.setField(StandardField.YEAR, "2011"); entry.setField(StandardField.MONTH, "#jan#"); From 935f65616dbc3053eba514326aaea9c1fe13f81f Mon Sep 17 00:00:00 2001 From: Catarina Gomes Date: Tue, 12 May 2020 20:38:59 +0100 Subject: [PATCH 15/20] ISSUE :: 6224 - Added month checking Test --- .../cleanup/ConvertToBiblatexCleanupTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java b/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java index 19e2fd0b7fa..3cfc4fad414 100644 --- a/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java +++ b/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java @@ -46,6 +46,20 @@ public void cleanupWithDateAlreadyPresentAndDifferentFromYearDoesNothing() { assertEquals(Optional.of("2012-01"), entry.getField(StandardField.DATE)); } + @Test + public void cleanupWithDateAlreadyPresentAndDifferentFromMonthDoesNothing() { + BibEntry entry = new BibEntry(); + entry.setField(StandardField.YEAR, "2011"); + entry.setField(StandardField.MONTH, "#jan#"); + entry.setField(StandardField.DATE, "2011-02"); + + worker.cleanup(entry); + + assertEquals(Optional.of("2011"), entry.getField(StandardField.YEAR)); + assertEquals(Optional.of("#jan#"), entry.getField(StandardField.MONTH)); + assertEquals(Optional.of("2011-02"), entry.getField(StandardField.DATE)); + } + @Test public void cleanupWithDateAlreadyPresentAndEqualsToYearAndMonth() { BibEntry entry = new BibEntry(); From c2b1950ef575e4f5b784d93e33c71b0ba3ad5645 Mon Sep 17 00:00:00 2001 From: Catarina Gomes Date: Tue, 12 May 2020 20:47:42 +0100 Subject: [PATCH 16/20] ISSUE :: 6224 - Fix Test --- .../org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java b/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java index 3cfc4fad414..701dbf6a26b 100644 --- a/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java +++ b/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java @@ -29,7 +29,7 @@ public void cleanupMovesYearMonthToDate() { assertEquals(Optional.empty(), entry.getField(StandardField.YEAR)); assertEquals(Optional.empty(), entry.getField(StandardField.MONTH)); - assertEquals(Optional.of("2011"), entry.getField(StandardField.DATE)); + assertEquals(Optional.of("2011-01"), entry.getField(StandardField.DATE)); } @Test From 5604f3c6fcd157006e7a8606cc04f115f0aed4fb Mon Sep 17 00:00:00 2001 From: Catarina Gomes Date: Wed, 13 May 2020 20:04:24 +0100 Subject: [PATCH 17/20] ISSUE :: 6224 - Change Date.parse --- .../cleanup/ConvertToBiblatexCleanup.java | 21 +++++++------------ .../java/org/jabref/model/entry/Date.java | 3 +-- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java b/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java index f7ac46e58ac..006bf203f9e 100644 --- a/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java +++ b/src/main/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanup.java @@ -44,21 +44,14 @@ public List cleanup(BibEntry entry) { } else { // If the year from date field is filled and equal to year it should be removed the year field entry.getFieldOrAlias(StandardField.DATE).ifPresent(date -> { - entry.getFieldOrAlias(StandardField.YEAR).ifPresent(year -> { - entry.getFieldOrAlias(StandardField.MONTH).ifPresent(month -> { + Optional newDate = Date.parse(date); + Optional checkDate = Date.parse(entry.getFieldOrAlias(StandardField.YEAR), + entry.getFieldOrAlias(StandardField.MONTH), Optional.empty()); - Optional checkDate = Date.parse(date); - // Converts using this format: "MMMM, uuuu". Ex: September, 2015 - month = month.replaceAll("#", "").toLowerCase(); - month = month.substring(0, 1).toUpperCase() + month.substring(1, month.length()); - Optional checkMonthAndYear = Date.parse(month + ", " + year); - - if (checkDate.isPresent() && checkMonthAndYear.isPresent() && checkDate.equals(checkMonthAndYear)) { - entry.clearField(StandardField.YEAR).ifPresent(changes::add); - entry.clearField(StandardField.MONTH).ifPresent(changes::add); - } - }); - }); + if (checkDate.equals(newDate)) { + entry.clearField(StandardField.YEAR).ifPresent(changes::add); + entry.clearField(StandardField.MONTH).ifPresent(changes::add); + } }); } return changes; diff --git a/src/main/java/org/jabref/model/entry/Date.java b/src/main/java/org/jabref/model/entry/Date.java index 5cd4b586a7e..b1655ad7c17 100644 --- a/src/main/java/org/jabref/model/entry/Date.java +++ b/src/main/java/org/jabref/model/entry/Date.java @@ -54,8 +54,7 @@ public static Optional parse(String dateString) { "MMMM d, uuuu", "MMMM, uuuu", "d.M.uuuu", - "uuuu.M.d", "uuuu", - "MMM, uuuu"); + "uuuu.M.d", "uuuu"); for (String formatString : formatStrings) { try { From 28e9c6d50e4c7436b4d473086f1e4a472eeaa920 Mon Sep 17 00:00:00 2001 From: Catarina Gomes Date: Wed, 13 May 2020 20:16:51 +0100 Subject: [PATCH 18/20] ISSUE :: 6224 - Update Date class --- src/main/java/org/jabref/model/entry/Date.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/model/entry/Date.java b/src/main/java/org/jabref/model/entry/Date.java index b1655ad7c17..58ed22d7d4f 100644 --- a/src/main/java/org/jabref/model/entry/Date.java +++ b/src/main/java/org/jabref/model/entry/Date.java @@ -40,6 +40,7 @@ public Date(TemporalAccessor date) { * - "dd-MM-yyyy" (covers 15-1-2009) * - "d.M.uuuu" (covers 15.1.2015) * - "uuuu.M.d" (covers 2015.1.15) + * - "MMM, uuuu" (covers Jan, 2020) * The code is essentially taken from http://stackoverflow.com/questions/4024544/how-to-parse-dates-in-multiple-formats-using-simpledateformat. */ public static Optional parse(String dateString) { @@ -54,7 +55,9 @@ public static Optional parse(String dateString) { "MMMM d, uuuu", "MMMM, uuuu", "d.M.uuuu", - "uuuu.M.d", "uuuu"); + "uuuu.M.d", "uuuu", + "MMM, uuuu" + ); for (String formatString : formatStrings) { try { From 3c0d2a4caaab6b912252080bfaddf7787bf44276 Mon Sep 17 00:00:00 2001 From: Catarina Gomes Date: Wed, 13 May 2020 20:52:01 +0100 Subject: [PATCH 19/20] ISSUE :: 6224 - Fix Date --- src/main/java/org/jabref/model/entry/Date.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/model/entry/Date.java b/src/main/java/org/jabref/model/entry/Date.java index 58ed22d7d4f..41bb884b48e 100644 --- a/src/main/java/org/jabref/model/entry/Date.java +++ b/src/main/java/org/jabref/model/entry/Date.java @@ -56,8 +56,7 @@ public static Optional parse(String dateString) { "MMMM, uuuu", "d.M.uuuu", "uuuu.M.d", "uuuu", - "MMM, uuuu" - ); + "MMM, uuuu"); for (String formatString : formatStrings) { try { From 3b910f66b8b61a36cc4402b0e29cee7d599ebbba Mon Sep 17 00:00:00 2001 From: Catarina Gomes Date: Thu, 14 May 2020 00:02:20 +0100 Subject: [PATCH 20/20] ISSUE :: 6224 - Added new test --- .../cleanup/ConvertToBiblatexCleanupTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java b/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java index 701dbf6a26b..8c215028ba9 100644 --- a/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java +++ b/src/test/java/org/jabref/logic/cleanup/ConvertToBiblatexCleanupTest.java @@ -60,6 +60,20 @@ public void cleanupWithDateAlreadyPresentAndDifferentFromMonthDoesNothing() { assertEquals(Optional.of("2011-02"), entry.getField(StandardField.DATE)); } + @Test + public void cleanupWithEmptyDateDoesNothing() { + BibEntry entry = new BibEntry(); + entry.setField(StandardField.YEAR, ""); + entry.setField(StandardField.MONTH, ""); + entry.setField(StandardField.DATE, ""); + + worker.cleanup(entry); + + assertEquals(Optional.empty(), entry.getField(StandardField.YEAR)); + assertEquals(Optional.empty(), entry.getField(StandardField.MONTH)); + assertEquals(Optional.empty(), entry.getField(StandardField.DATE)); + } + @Test public void cleanupWithDateAlreadyPresentAndEqualsToYearAndMonth() { BibEntry entry = new BibEntry();