From 96fb8c7a888372b1190b949dc78943ecb9fae959 Mon Sep 17 00:00:00 2001 From: Dominik Voigt Date: Tue, 20 Apr 2021 22:40:54 +0200 Subject: [PATCH 01/13] Change TimeStampToDateAndModify from PostOpenMigration to CleanupJob --- .../jabref/logic/importer/OpenDatabase.java | 1 - .../TimeStampToDateAddAndModify.java | 61 +++++++++++-------- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/jabref/logic/importer/OpenDatabase.java b/src/main/java/org/jabref/logic/importer/OpenDatabase.java index 8fec03796a9..8255ccc7e05 100644 --- a/src/main/java/org/jabref/logic/importer/OpenDatabase.java +++ b/src/main/java/org/jabref/logic/importer/OpenDatabase.java @@ -73,7 +73,6 @@ private static void performLoadDatabaseMigrations(ParserResult parserResult, Tim List postOpenMigrations = Arrays.asList( new ConvertLegacyExplicitGroups(), new ConvertMarkingToGroups(), - new TimeStampToDateAddAndModify(timestampPreferences), new SpecialFieldsToSeparateFields(keywordDelimited) ); diff --git a/src/main/java/org/jabref/migrations/TimeStampToDateAddAndModify.java b/src/main/java/org/jabref/migrations/TimeStampToDateAddAndModify.java index b260009a0d4..45fdc311fd7 100644 --- a/src/main/java/org/jabref/migrations/TimeStampToDateAddAndModify.java +++ b/src/main/java/org/jabref/migrations/TimeStampToDateAddAndModify.java @@ -3,10 +3,14 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.Optional; -import org.jabref.logic.importer.ParserResult; +import org.jabref.logic.cleanup.CleanupJob; import org.jabref.logic.preferences.TimestampPreferences; +import org.jabref.model.FieldChange; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.Date; import org.jabref.model.entry.field.Field; @@ -18,7 +22,7 @@ * If the old updateTimestamp setting is enabled, the timestamp field for each entry are migrated to the date-modified field. * Otherwise it is migrated to the date-added field. */ -public class TimeStampToDateAddAndModify implements PostOpenMigration { +public class TimeStampToDateAddAndModify implements CleanupJob { private final boolean interpretTimeStampAsModificationDate; private final Field timeStampField; @@ -30,34 +34,16 @@ public TimeStampToDateAddAndModify(TimestampPreferences timestampPreferences) { timeStampField = timestampPreferences.getTimestampField(); } - @Override - public void performMigration(ParserResult parserResult) { - parserResult.getDatabase().getEntries().forEach(this::migrateEntry); - } - - private void migrateEntry(BibEntry entry) { - // Query entries for their timestamp field entries - entry.getField(timeStampField).ifPresent(timeStamp -> { - String formattedTimeStamp = formatTimeStamp(timeStamp); - if (interpretTimeStampAsModificationDate) { - entry.setField(StandardField.MODIFICATIONDATE, formattedTimeStamp); - } else { - entry.setField(StandardField.CREATIONDATE, formattedTimeStamp); - } - entry.clearField(timeStampField); - }); - } - /** * Formats the time stamp into the local date and time format. * If the existing timestamp could not be parsed, the day/month/year "1" is used. * For the time portion 00:00:00 is used. */ - private String formatTimeStamp(String timeStamp) { + private Optional formatTimeStamp(String timeStamp) { Optional parsedDate = Date.parse(timeStamp); if (parsedDate.isEmpty()) { - // What to do if the date cannot be parsed? Do we need the custom date format possibly? - return timestampPreferences.now(); + // In case the given timestamp could not be parsed + return Optional.empty(); } else { Date date = parsedDate.get(); int year = date.getYear().orElse(1); @@ -66,7 +52,7 @@ private String formatTimeStamp(String timeStamp) { LocalDateTime localDateTime = LocalDateTime.of(year, month, day, 0, 0); // Remove any time unites smaller than seconds localDateTime.truncatedTo(ChronoUnit.SECONDS); - return localDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME); + return Optional.of(localDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)); } } @@ -80,4 +66,31 @@ private int getMonth(Date date) { } return 1; } + + @Override + public List cleanup(BibEntry entry) { + // Query entries for their timestamp field entries + if (entry.getField(timeStampField).isPresent()) { + Optional formattedTimeStamp = formatTimeStamp(entry.getField(timeStampField).get()); + if (formattedTimeStamp.isEmpty()) { + // In case the timestamp could not be parsed, do nothing to not lose data + return Collections.emptyList(); + } + entry.clearField(timeStampField); + List changeList = new ArrayList<>(); + FieldChange changeTo; + // Add removal of timestamp field + changeList.add(new FieldChange(entry, StandardField.TIMESTAMP, formattedTimeStamp.get(), "")); + if (interpretTimeStampAsModificationDate) { + entry.setField(StandardField.MODIFICATIONDATE, formattedTimeStamp.get()); + changeTo = new FieldChange(entry, StandardField.MODIFICATIONDATE, entry.getField(StandardField.MODIFICATIONDATE).orElse(""), formattedTimeStamp.get()); + } else { + entry.setField(StandardField.CREATIONDATE, formattedTimeStamp.get()); + changeTo = new FieldChange(entry, StandardField.CREATIONDATE, entry.getField(StandardField.CREATIONDATE).orElse(""), formattedTimeStamp.get()); + } + changeList.add(changeTo); + return changeList; + } + return Collections.emptyList(); + } } From e6532fe13d4561456a333a5dd6f84093bf72b71e Mon Sep 17 00:00:00 2001 From: Dominik Voigt Date: Wed, 21 Apr 2021 23:11:13 +0200 Subject: [PATCH 02/13] Add UI and logic for timestamp cleanup to creation and modification date. --- .../org/jabref/gui/cleanup/CleanupAction.java | 3 +- .../gui/cleanup/CleanupPresetPanel.fxml | 5 + .../gui/cleanup/CleanupPresetPanel.java | 10 ++ .../jabref/logic/cleanup/CleanupPreset.java | 2 + .../jabref/logic/cleanup/CleanupWorker.java | 9 +- .../cleanup/TimeStampToCreationDate.java} | 17 +-- .../cleanup/TimeStampToModificationDate.java | 87 +++++++++++++++ .../jabref/logic/importer/OpenDatabase.java | 1 - src/main/resources/l10n/JabRef_en.properties | 3 + .../logic/cleanup/CleanupWorkerTest.java | 3 +- .../jabref/logic/cleanup/ISSNCleanupTest.java | 3 +- .../cleanup/TimeStampToCreationDateTest.java} | 102 +++--------------- .../TimeStampToModificationDateTest.java | 94 ++++++++++++++++ 13 files changed, 234 insertions(+), 105 deletions(-) rename src/main/java/org/jabref/{migrations/TimeStampToDateAddAndModify.java => logic/cleanup/TimeStampToCreationDate.java} (78%) create mode 100644 src/main/java/org/jabref/logic/cleanup/TimeStampToModificationDate.java rename src/test/java/org/jabref/{migrations/TimeStampToDateAddAndModifyTest.java => logic/cleanup/TimeStampToCreationDateTest.java} (61%) create mode 100644 src/test/java/org/jabref/logic/cleanup/TimeStampToModificationDateTest.java diff --git a/src/main/java/org/jabref/gui/cleanup/CleanupAction.java b/src/main/java/org/jabref/gui/cleanup/CleanupAction.java index 982cffb2eb3..abce5122c80 100644 --- a/src/main/java/org/jabref/gui/cleanup/CleanupAction.java +++ b/src/main/java/org/jabref/gui/cleanup/CleanupAction.java @@ -94,7 +94,8 @@ private void doCleanup(BibDatabaseContext databaseContext, CleanupPreset preset, // Create and run cleaner CleanupWorker cleaner = new CleanupWorker( databaseContext, - preferences.getCleanupPreferences(Globals.journalAbbreviationRepository)); + preferences.getCleanupPreferences(Globals.journalAbbreviationRepository), + preferences.getTimestampPreferences()); List changes = cleaner.cleanup(preset, entry); diff --git a/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.fxml b/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.fxml index 608cdc12823..07ffae48695 100644 --- a/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.fxml +++ b/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.fxml @@ -5,6 +5,7 @@ + @@ -28,6 +29,10 @@ text="%Convert to biblatex format (for example, move the value of the 'journal' field to 'journaltitle')"/> + + diff --git a/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java b/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java index 3d94fee18bc..3c327fca7c7 100644 --- a/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java +++ b/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java @@ -36,6 +36,8 @@ public class CleanupPresetPanel extends VBox { @FXML private CheckBox cleanUpUpgradeExternalLinks; @FXML private CheckBox cleanUpBiblatex; @FXML private CheckBox cleanUpBibtex; + @FXML private CheckBox cleanUpTimestampToCreationDate; + @FXML private CheckBox cleanUpTimestampToModificationDate; @FXML private FieldFormatterCleanupsPanel formatterCleanupsPanel; public CleanupPresetPanel(BibDatabaseContext databaseContext, CleanupPreset cleanupPreset, FilePreferences filePreferences) { @@ -85,6 +87,8 @@ private void updateDisplay(CleanupPreset preset) { cleanUpUpgradeExternalLinks.setSelected(preset.isActive(CleanupPreset.CleanupStep.CLEAN_UP_UPGRADE_EXTERNAL_LINKS)); cleanUpBiblatex.setSelected(preset.isActive(CleanupPreset.CleanupStep.CONVERT_TO_BIBLATEX)); cleanUpBibtex.setSelected(preset.isActive(CleanupPreset.CleanupStep.CONVERT_TO_BIBTEX)); + cleanUpTimestampToCreationDate.setSelected(preset.isActive(CleanupPreset.CleanupStep.CONVERT_TIMESTAMP_TO_CREATIONDATE)); + cleanUpTimestampToModificationDate.setSelected(preset.isActive(CleanupPreset.CleanupStep.CONVERT_TIMESTAMP_TO_MODIFICATIONDATE)); cleanUpISSN.setSelected(preset.isActive(CleanupPreset.CleanupStep.CLEAN_UP_ISSN)); formatterCleanupsPanel.cleanupsDisableProperty().setValue(!preset.getFormatterCleanups().isEnabled()); formatterCleanupsPanel.cleanupsProperty().setValue(FXCollections.observableArrayList(preset.getFormatterCleanups().getConfiguredActions())); @@ -124,6 +128,12 @@ public CleanupPreset getCleanupPreset() { if (cleanUpBibtex.isSelected()) { activeJobs.add(CleanupPreset.CleanupStep.CONVERT_TO_BIBTEX); } + if (cleanUpTimestampToCreationDate.isSelected()) { + activeJobs.add(CleanupPreset.CleanupStep.CONVERT_TIMESTAMP_TO_CREATIONDATE); + } + if (cleanUpTimestampToModificationDate.isSelected()) { + activeJobs.add(CleanupPreset.CleanupStep.CONVERT_TIMESTAMP_TO_MODIFICATIONDATE); + } activeJobs.add(CleanupPreset.CleanupStep.FIX_FILE_LINKS); diff --git a/src/main/java/org/jabref/logic/cleanup/CleanupPreset.java b/src/main/java/org/jabref/logic/cleanup/CleanupPreset.java index d35d70affdb..de901e97e93 100644 --- a/src/main/java/org/jabref/logic/cleanup/CleanupPreset.java +++ b/src/main/java/org/jabref/logic/cleanup/CleanupPreset.java @@ -65,6 +65,8 @@ public enum CleanupStep { * Converts to bibtex format */ CONVERT_TO_BIBTEX, + CONVERT_TIMESTAMP_TO_CREATIONDATE, + CONVERT_TIMESTAMP_TO_MODIFICATIONDATE, MOVE_PDF, FIX_FILE_LINKS, CLEAN_UP_ISSN diff --git a/src/main/java/org/jabref/logic/cleanup/CleanupWorker.java b/src/main/java/org/jabref/logic/cleanup/CleanupWorker.java index 1fe79ea0258..0eabdb802f2 100644 --- a/src/main/java/org/jabref/logic/cleanup/CleanupWorker.java +++ b/src/main/java/org/jabref/logic/cleanup/CleanupWorker.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.Objects; +import org.jabref.logic.preferences.TimestampPreferences; import org.jabref.model.FieldChange; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; @@ -13,10 +14,12 @@ public class CleanupWorker { private final BibDatabaseContext databaseContext; private final FilePreferences filePreferences; + private final TimestampPreferences timestampPreferences; - public CleanupWorker(BibDatabaseContext databaseContext, CleanupPreferences cleanupPreferences) { + public CleanupWorker(BibDatabaseContext databaseContext, CleanupPreferences cleanupPreferences, TimestampPreferences timestampPreferences) { this.databaseContext = databaseContext; this.filePreferences = cleanupPreferences.getFilePreferences(); + this.timestampPreferences = timestampPreferences; } public List cleanup(CleanupPreset preset, BibEntry entry) { @@ -65,6 +68,10 @@ private CleanupJob toJob(CleanupPreset.CleanupStep action) { return new ConvertToBiblatexCleanup(); case CONVERT_TO_BIBTEX: return new ConvertToBibtexCleanup(); + case CONVERT_TIMESTAMP_TO_CREATIONDATE: + return new TimeStampToCreationDate(timestampPreferences); + case CONVERT_TIMESTAMP_TO_MODIFICATIONDATE: + return new TimeStampToModificationDate(timestampPreferences); case MOVE_PDF: return new MoveFilesCleanup(databaseContext, filePreferences); case FIX_FILE_LINKS: diff --git a/src/main/java/org/jabref/migrations/TimeStampToDateAddAndModify.java b/src/main/java/org/jabref/logic/cleanup/TimeStampToCreationDate.java similarity index 78% rename from src/main/java/org/jabref/migrations/TimeStampToDateAddAndModify.java rename to src/main/java/org/jabref/logic/cleanup/TimeStampToCreationDate.java index 45fdc311fd7..d19a923be26 100644 --- a/src/main/java/org/jabref/migrations/TimeStampToDateAddAndModify.java +++ b/src/main/java/org/jabref/logic/cleanup/TimeStampToCreationDate.java @@ -1,4 +1,4 @@ -package org.jabref.migrations; +package org.jabref.logic.cleanup; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -22,14 +22,12 @@ * If the old updateTimestamp setting is enabled, the timestamp field for each entry are migrated to the date-modified field. * Otherwise it is migrated to the date-added field. */ -public class TimeStampToDateAddAndModify implements CleanupJob { +public class TimeStampToCreationDate implements CleanupJob { private final boolean interpretTimeStampAsModificationDate; private final Field timeStampField; - private final TimestampPreferences timestampPreferences; - public TimeStampToDateAddAndModify(TimestampPreferences timestampPreferences) { - this.timestampPreferences = timestampPreferences; + public TimeStampToCreationDate(TimestampPreferences timestampPreferences) { interpretTimeStampAsModificationDate = timestampPreferences.shouldUpdateTimestamp(); timeStampField = timestampPreferences.getTimestampField(); } @@ -81,13 +79,8 @@ public List cleanup(BibEntry entry) { FieldChange changeTo; // Add removal of timestamp field changeList.add(new FieldChange(entry, StandardField.TIMESTAMP, formattedTimeStamp.get(), "")); - if (interpretTimeStampAsModificationDate) { - entry.setField(StandardField.MODIFICATIONDATE, formattedTimeStamp.get()); - changeTo = new FieldChange(entry, StandardField.MODIFICATIONDATE, entry.getField(StandardField.MODIFICATIONDATE).orElse(""), formattedTimeStamp.get()); - } else { - entry.setField(StandardField.CREATIONDATE, formattedTimeStamp.get()); - changeTo = new FieldChange(entry, StandardField.CREATIONDATE, entry.getField(StandardField.CREATIONDATE).orElse(""), formattedTimeStamp.get()); - } + entry.setField(StandardField.CREATIONDATE, formattedTimeStamp.get()); + changeTo = new FieldChange(entry, StandardField.CREATIONDATE, entry.getField(StandardField.CREATIONDATE).orElse(""), formattedTimeStamp.get()); changeList.add(changeTo); return changeList; } diff --git a/src/main/java/org/jabref/logic/cleanup/TimeStampToModificationDate.java b/src/main/java/org/jabref/logic/cleanup/TimeStampToModificationDate.java new file mode 100644 index 00000000000..fbf3be4c9ee --- /dev/null +++ b/src/main/java/org/jabref/logic/cleanup/TimeStampToModificationDate.java @@ -0,0 +1,87 @@ +package org.jabref.logic.cleanup; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +import org.jabref.logic.cleanup.CleanupJob; +import org.jabref.logic.preferences.TimestampPreferences; +import org.jabref.model.FieldChange; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.Date; +import org.jabref.model.entry.field.Field; +import org.jabref.model.entry.field.StandardField; + +/** + * This class handles the migration from timestamp field to creationdate and modificationdate fields. + *

+ * If the old updateTimestamp setting is enabled, the timestamp field for each entry are migrated to the date-modified field. + * Otherwise it is migrated to the date-added field. + */ +public class TimeStampToModificationDate implements CleanupJob { + + private final Field timeStampField; + + public TimeStampToModificationDate(TimestampPreferences timestampPreferences) { + timeStampField = timestampPreferences.getTimestampField(); + } + + /** + * Formats the time stamp into the local date and time format. + * If the existing timestamp could not be parsed, the day/month/year "1" is used. + * For the time portion 00:00:00 is used. + */ + private Optional formatTimeStamp(String timeStamp) { + Optional parsedDate = Date.parse(timeStamp); + if (parsedDate.isEmpty()) { + // In case the given timestamp could not be parsed + return Optional.empty(); + } else { + Date date = parsedDate.get(); + int year = date.getYear().orElse(1); + int month = getMonth(date); + int day = date.getDay().orElse(1); + LocalDateTime localDateTime = LocalDateTime.of(year, month, day, 0, 0); + // Remove any time unites smaller than seconds + localDateTime.truncatedTo(ChronoUnit.SECONDS); + return Optional.of(localDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)); + } + } + + /** + * Returns the month value of the passed date if available. + * Otherwise returns the current month. + */ + private int getMonth(Date date) { + if (date.getMonth().isPresent()) { + return date.getMonth().get().getNumber(); + } + return 1; + } + + @Override + public List cleanup(BibEntry entry) { + // Query entries for their timestamp field entries + if (entry.getField(timeStampField).isPresent()) { + Optional formattedTimeStamp = formatTimeStamp(entry.getField(timeStampField).get()); + if (formattedTimeStamp.isEmpty()) { + // In case the timestamp could not be parsed, do nothing to not lose data + return Collections.emptyList(); + } + entry.clearField(timeStampField); + List changeList = new ArrayList<>(); + FieldChange changeTo; + // Add removal of timestamp field + changeList.add(new FieldChange(entry, StandardField.TIMESTAMP, formattedTimeStamp.get(), "")); + entry.setField(StandardField.MODIFICATIONDATE, formattedTimeStamp.get()); + changeTo = new FieldChange(entry, StandardField.MODIFICATIONDATE, entry.getField(StandardField.MODIFICATIONDATE).orElse(""), formattedTimeStamp.get()); + changeList.add(changeTo); + return changeList; + } + return Collections.emptyList(); + } +} diff --git a/src/main/java/org/jabref/logic/importer/OpenDatabase.java b/src/main/java/org/jabref/logic/importer/OpenDatabase.java index 8255ccc7e05..e109892c895 100644 --- a/src/main/java/org/jabref/logic/importer/OpenDatabase.java +++ b/src/main/java/org/jabref/logic/importer/OpenDatabase.java @@ -13,7 +13,6 @@ import org.jabref.migrations.ConvertMarkingToGroups; import org.jabref.migrations.PostOpenMigration; import org.jabref.migrations.SpecialFieldsToSeparateFields; -import org.jabref.migrations.TimeStampToDateAddAndModify; import org.jabref.model.util.FileUpdateMonitor; import org.slf4j.Logger; diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index c75a24158dd..f830e3fd5d3 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2292,3 +2292,6 @@ Import\ settings=Import settings Custom\ DOI\ URI=Custom DOI URI Customization=Customization Use\ custom\ DOI\ base\ URI\ for\ article\ access=Use custom DOI base URI for article access + +Convert\ timestamp\ fields\ to\ creationdate\ field=Convert timestamp fields to creationdate field +Convert\ timestamp\ fields\ to\ modificationdate\ field=Convert timestamp fields to modificationdate field diff --git a/src/test/java/org/jabref/logic/cleanup/CleanupWorkerTest.java b/src/test/java/org/jabref/logic/cleanup/CleanupWorkerTest.java index f2215b97912..a0f8601f523 100644 --- a/src/test/java/org/jabref/logic/cleanup/CleanupWorkerTest.java +++ b/src/test/java/org/jabref/logic/cleanup/CleanupWorkerTest.java @@ -19,6 +19,7 @@ import org.jabref.logic.formatter.bibtexfields.UnitsToLatexFormatter; import org.jabref.logic.formatter.casechanger.ProtectTermsFormatter; import org.jabref.logic.layout.LayoutFormatterPreferences; +import org.jabref.logic.preferences.TimestampPreferences; import org.jabref.logic.protectedterms.ProtectedTermsLoader; import org.jabref.logic.protectedterms.ProtectedTermsPreferences; import org.jabref.model.FieldChange; @@ -65,7 +66,7 @@ void setUp(@TempDir Path bibFolder) throws IOException { when(fileDirPrefs.shouldStoreFilesRelativeToBib()).thenReturn(true); worker = new CleanupWorker(context, - new CleanupPreferences(mock(LayoutFormatterPreferences.class), fileDirPrefs)); + new CleanupPreferences(mock(LayoutFormatterPreferences.class), fileDirPrefs), mock(TimestampPreferences.class)); } @Test diff --git a/src/test/java/org/jabref/logic/cleanup/ISSNCleanupTest.java b/src/test/java/org/jabref/logic/cleanup/ISSNCleanupTest.java index daf131f728e..f4be912cb47 100644 --- a/src/test/java/org/jabref/logic/cleanup/ISSNCleanupTest.java +++ b/src/test/java/org/jabref/logic/cleanup/ISSNCleanupTest.java @@ -3,6 +3,7 @@ import java.util.Optional; import org.jabref.logic.layout.LayoutFormatterPreferences; +import org.jabref.logic.preferences.TimestampPreferences; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; @@ -21,7 +22,7 @@ public class ISSNCleanupTest { @BeforeEach public void setUp() { worker = new CleanupWorker(mock(BibDatabaseContext.class), - new CleanupPreferences(mock(LayoutFormatterPreferences.class), mock(FilePreferences.class))); + new CleanupPreferences(mock(LayoutFormatterPreferences.class), mock(FilePreferences.class)), mock(TimestampPreferences.class)); } @Test diff --git a/src/test/java/org/jabref/migrations/TimeStampToDateAddAndModifyTest.java b/src/test/java/org/jabref/logic/cleanup/TimeStampToCreationDateTest.java similarity index 61% rename from src/test/java/org/jabref/migrations/TimeStampToDateAddAndModifyTest.java rename to src/test/java/org/jabref/logic/cleanup/TimeStampToCreationDateTest.java index eaabac2cc10..2b13a24eb7c 100644 --- a/src/test/java/org/jabref/migrations/TimeStampToDateAddAndModifyTest.java +++ b/src/test/java/org/jabref/logic/cleanup/TimeStampToCreationDateTest.java @@ -1,8 +1,9 @@ -package org.jabref.migrations; +package org.jabref.logic.cleanup; import java.util.List; import java.util.stream.Stream; +import org.jabref.logic.cleanup.TimeStampToCreationDate; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.preferences.TimestampPreferences; import org.jabref.model.entry.BibEntry; @@ -17,11 +18,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -class TimeStampToDateAddAndModifyTest { +class TimeStampToCreationDateTest { - private static Field customTimeStampField = new UnknownField("dateOfCreation"); + private static final Field customTimeStampField = new UnknownField("dateOfCreation"); - private TimestampPreferences timestampPreferences = Mockito.mock(TimestampPreferences.class); + private final TimestampPreferences timestampPreferences = Mockito.mock(TimestampPreferences.class); public void makeMockReturnCustomField() { Mockito.when(timestampPreferences.getTimestampField()).then(invocation -> customTimeStampField); @@ -31,14 +32,6 @@ public void makeMockReturnStandardField() { Mockito.when(timestampPreferences.getTimestampField()).then(invocation -> StandardField.TIMESTAMP); } - public void makeMockToMigrateToCreationDate() { - Mockito.when(timestampPreferences.shouldUpdateTimestamp()).then(invocation -> Boolean.FALSE); - } - - public void makeMockToMigrateToModificationDate() { - Mockito.when(timestampPreferences.shouldUpdateTimestamp()).then(invocation -> Boolean.TRUE); - } - public static Stream standardFieldToCreationDate() { return Stream.of( Arguments.of( @@ -62,12 +55,10 @@ public static Stream standardFieldToCreationDate() { @ParameterizedTest @MethodSource("standardFieldToCreationDate") public void withStandardFieldToCreationDate(BibEntry expected, BibEntry input) { - makeMockToMigrateToCreationDate(); makeMockReturnStandardField(); - TimeStampToDateAddAndModify migrator = new TimeStampToDateAddAndModify(timestampPreferences); - ParserResult entries = new ParserResult(List.of(input)); - migrator.performMigration(entries); - assertEquals(List.of(expected), entries.getDatabase().getEntries()); + TimeStampToCreationDate migrator = new TimeStampToCreationDate(timestampPreferences); + migrator.cleanup(input); + assertEquals(expected, input); } public static Stream customFieldToCreationDate() { @@ -93,74 +84,10 @@ public static Stream customFieldToCreationDate() { @ParameterizedTest @MethodSource("customFieldToCreationDate") public void withCustomFieldToCreationDate(BibEntry expected, BibEntry input) { - makeMockToMigrateToCreationDate(); - makeMockReturnCustomField(); - TimeStampToDateAddAndModify migrator = new TimeStampToDateAddAndModify(timestampPreferences); - ParserResult entries = new ParserResult(List.of(input)); - migrator.performMigration(entries); - assertEquals(List.of(expected), entries.getDatabase().getEntries()); - } - - public static Stream standardFieldToModificationDate() { - return Stream.of( - Arguments.of( - new BibEntry().withField(StandardField.MODIFICATIONDATE, "2018-09-10T00:00:00"), - new BibEntry().withField(StandardField.TIMESTAMP, "2018-09-10") - ), - Arguments.of( - new BibEntry().withField(StandardField.MODIFICATIONDATE, "2020-12-24T00:00:00"), - new BibEntry().withField(StandardField.TIMESTAMP, "2020-12-24") - ), - Arguments.of( - new BibEntry().withField(StandardField.MODIFICATIONDATE, "2020-12-31T00:00:00"), - new BibEntry().withField(StandardField.TIMESTAMP, "2020-12-31") - ) - ); - } - - /** - * Tests migration to modificationdate if the users uses the default ISO yyyy-mm-dd format and the standard timestamp field - */ - @ParameterizedTest - @MethodSource("standardFieldToModificationDate") - public void withStandardFieldToModificationDate(BibEntry expected, BibEntry input) { - makeMockToMigrateToModificationDate(); - makeMockReturnStandardField(); - TimeStampToDateAddAndModify migrator = new TimeStampToDateAddAndModify(timestampPreferences); - ParserResult entries = new ParserResult(List.of(input)); - migrator.performMigration(entries); - assertEquals(List.of(expected), entries.getDatabase().getEntries()); - } - - public static Stream customFieldToModificationDate() { - return Stream.of( - Arguments.of( - new BibEntry().withField(StandardField.MODIFICATIONDATE, "2018-09-10T00:00:00"), - new BibEntry().withField(customTimeStampField, "2018-09-10") - ), - Arguments.of( - new BibEntry().withField(StandardField.MODIFICATIONDATE, "2020-12-24T00:00:00"), - new BibEntry().withField(customTimeStampField, "2020-12-24") - ), - Arguments.of( - new BibEntry().withField(StandardField.MODIFICATIONDATE, "2020-12-31T00:00:00"), - new BibEntry().withField(customTimeStampField, "2020-12-31") - ) - ); - } - - /** - * Tests migration to modificationdate if the users uses the default ISO yyyy-mm-dd format and a custom timestamp field - */ - @ParameterizedTest - @MethodSource("customFieldToModificationDate") - public void withCustomFieldToModificationDate(BibEntry expected, BibEntry input) { - makeMockToMigrateToModificationDate(); makeMockReturnCustomField(); - TimeStampToDateAddAndModify migrator = new TimeStampToDateAddAndModify(timestampPreferences); - ParserResult entries = new ParserResult(List.of(input)); - migrator.performMigration(entries); - assertEquals(List.of(expected), entries.getDatabase().getEntries()); + TimeStampToCreationDate migrator = new TimeStampToCreationDate(timestampPreferences); + migrator.cleanup(input); + assertEquals(expected, input); } public static Stream entriesMigratedToCreationDateFromDifferentFormats() { @@ -244,12 +171,11 @@ public static Stream entriesMigratedToCreationDateFromDifferentFormat @ParameterizedTest @MethodSource("entriesMigratedToCreationDateFromDifferentFormats") public void withDifferentFormats(BibEntry expected, BibEntry input) { - makeMockToMigrateToCreationDate(); makeMockReturnStandardField(); - TimeStampToDateAddAndModify migrator = new TimeStampToDateAddAndModify(timestampPreferences); + TimeStampToCreationDate migrator = new TimeStampToCreationDate(timestampPreferences); ParserResult parserResult = new ParserResult(List.of(input)); - migrator.performMigration(parserResult); - assertEquals(List.of(expected), parserResult.getDatabase().getEntries()); + migrator.cleanup(input); + assertEquals(expected, input); } } diff --git a/src/test/java/org/jabref/logic/cleanup/TimeStampToModificationDateTest.java b/src/test/java/org/jabref/logic/cleanup/TimeStampToModificationDateTest.java new file mode 100644 index 00000000000..63101f54d12 --- /dev/null +++ b/src/test/java/org/jabref/logic/cleanup/TimeStampToModificationDateTest.java @@ -0,0 +1,94 @@ +package org.jabref.logic.cleanup; + +import java.util.List; +import java.util.stream.Stream; + +import org.jabref.logic.cleanup.TimeStampToCreationDate; +import org.jabref.logic.cleanup.TimeStampToModificationDate; +import org.jabref.logic.importer.ParserResult; +import org.jabref.logic.preferences.TimestampPreferences; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.Field; +import org.jabref.model.entry.field.StandardField; +import org.jabref.model.entry.field.UnknownField; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.mockito.Mockito; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class TimeStampToModificationDateTest { + + private static Field customTimeStampField = new UnknownField("dateOfCreation"); + + private TimestampPreferences timestampPreferences = Mockito.mock(TimestampPreferences.class); + + public void makeMockReturnCustomField() { + Mockito.when(timestampPreferences.getTimestampField()).then(invocation -> customTimeStampField); + } + + public void makeMockReturnStandardField() { + Mockito.when(timestampPreferences.getTimestampField()).then(invocation -> StandardField.TIMESTAMP); + } + + /** + * Tests migration to modificationdate if the users uses the default ISO yyyy-mm-dd format and the standard timestamp field + */ + @ParameterizedTest + @MethodSource("standardFieldToModificationDate") + public void withStandardFieldToModificationDate(BibEntry expected, BibEntry input) { + makeMockReturnStandardField(); + TimeStampToModificationDate migrator = new TimeStampToModificationDate(timestampPreferences); + migrator.cleanup(input); + assertEquals(expected, input); + } + + public static Stream customFieldToModificationDate() { + return Stream.of( + Arguments.of( + new BibEntry().withField(StandardField.MODIFICATIONDATE, "2018-09-10T00:00:00"), + new BibEntry().withField(customTimeStampField, "2018-09-10") + ), + Arguments.of( + new BibEntry().withField(StandardField.MODIFICATIONDATE, "2020-12-24T00:00:00"), + new BibEntry().withField(customTimeStampField, "2020-12-24") + ), + Arguments.of( + new BibEntry().withField(StandardField.MODIFICATIONDATE, "2020-12-31T00:00:00"), + new BibEntry().withField(customTimeStampField, "2020-12-31") + ) + ); + } + + /** + * Tests migration to modificationdate if the users uses the default ISO yyyy-mm-dd format and a custom timestamp field + */ + @ParameterizedTest + @MethodSource("customFieldToModificationDate") + public void withCustomFieldToModificationDate(BibEntry expected, BibEntry input) { + makeMockReturnCustomField(); + TimeStampToModificationDate migrator = new TimeStampToModificationDate(timestampPreferences); + ParserResult entries = new ParserResult(List.of(input)); + migrator.cleanup(input); + assertEquals(expected, input); + } + + public static Stream standardFieldToModificationDate() { + return Stream.of( + Arguments.of( + new BibEntry().withField(StandardField.MODIFICATIONDATE, "2018-09-10T00:00:00"), + new BibEntry().withField(StandardField.TIMESTAMP, "2018-09-10") + ), + Arguments.of( + new BibEntry().withField(StandardField.MODIFICATIONDATE, "2020-12-24T00:00:00"), + new BibEntry().withField(StandardField.TIMESTAMP, "2020-12-24") + ), + Arguments.of( + new BibEntry().withField(StandardField.MODIFICATIONDATE, "2020-12-31T00:00:00"), + new BibEntry().withField(StandardField.TIMESTAMP, "2020-12-31") + ) + ); + } +} From c9780790256dfe5de78091749412a5ef7d0adfb9 Mon Sep 17 00:00:00 2001 From: Dominik Voigt Date: Mon, 26 Apr 2021 09:47:14 +0200 Subject: [PATCH 03/13] Ensure timestamp migration does not modify modification date --- src/main/java/org/jabref/gui/UpdateTimestampListener.java | 3 ++- .../org/jabref/logic/cleanup/TimeStampToCreationDate.java | 6 ++++-- .../jabref/logic/cleanup/TimeStampToModificationDate.java | 6 ++++-- .../org/jabref/model/entry/event/EntriesEventSource.java | 1 + 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jabref/gui/UpdateTimestampListener.java b/src/main/java/org/jabref/gui/UpdateTimestampListener.java index 0efc6878d2b..f6c8f9ff9dd 100644 --- a/src/main/java/org/jabref/gui/UpdateTimestampListener.java +++ b/src/main/java/org/jabref/gui/UpdateTimestampListener.java @@ -1,5 +1,6 @@ package org.jabref.gui; +import org.jabref.model.entry.event.EntriesEventSource; import org.jabref.model.entry.event.EntryChangedEvent; import org.jabref.model.entry.field.StandardField; import org.jabref.preferences.PreferencesService; @@ -18,7 +19,7 @@ class UpdateTimestampListener { @Subscribe public void listen(EntryChangedEvent event) { - if (preferencesService.getTimestampPreferences().shouldAddModificationDate()) { + if (preferencesService.getTimestampPreferences().shouldAddModificationDate() && event.getEntriesEventSource() != EntriesEventSource.CLEANUP_TIMESTAMP) { event.getBibEntry().setField(StandardField.MODIFICATIONDATE, preferencesService.getTimestampPreferences().now()); } diff --git a/src/main/java/org/jabref/logic/cleanup/TimeStampToCreationDate.java b/src/main/java/org/jabref/logic/cleanup/TimeStampToCreationDate.java index d19a923be26..58c7a1d61fd 100644 --- a/src/main/java/org/jabref/logic/cleanup/TimeStampToCreationDate.java +++ b/src/main/java/org/jabref/logic/cleanup/TimeStampToCreationDate.java @@ -13,6 +13,7 @@ import org.jabref.model.FieldChange; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.Date; +import org.jabref.model.entry.event.EntriesEventSource; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.StandardField; @@ -74,12 +75,13 @@ public List cleanup(BibEntry entry) { // In case the timestamp could not be parsed, do nothing to not lose data return Collections.emptyList(); } - entry.clearField(timeStampField); + // Setting the EventSource is necessary to circumvent the update of the modification date during timestamp migration + entry.clearField(timeStampField, EntriesEventSource.CLEANUP_TIMESTAMP); List changeList = new ArrayList<>(); FieldChange changeTo; // Add removal of timestamp field changeList.add(new FieldChange(entry, StandardField.TIMESTAMP, formattedTimeStamp.get(), "")); - entry.setField(StandardField.CREATIONDATE, formattedTimeStamp.get()); + entry.setField(StandardField.CREATIONDATE, formattedTimeStamp.get(), EntriesEventSource.CLEANUP_TIMESTAMP); changeTo = new FieldChange(entry, StandardField.CREATIONDATE, entry.getField(StandardField.CREATIONDATE).orElse(""), formattedTimeStamp.get()); changeList.add(changeTo); return changeList; diff --git a/src/main/java/org/jabref/logic/cleanup/TimeStampToModificationDate.java b/src/main/java/org/jabref/logic/cleanup/TimeStampToModificationDate.java index fbf3be4c9ee..bbde55cb278 100644 --- a/src/main/java/org/jabref/logic/cleanup/TimeStampToModificationDate.java +++ b/src/main/java/org/jabref/logic/cleanup/TimeStampToModificationDate.java @@ -13,6 +13,7 @@ import org.jabref.model.FieldChange; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.Date; +import org.jabref.model.entry.event.EntriesEventSource; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.StandardField; @@ -72,12 +73,13 @@ public List cleanup(BibEntry entry) { // In case the timestamp could not be parsed, do nothing to not lose data return Collections.emptyList(); } - entry.clearField(timeStampField); + // Setting the EventSource is necessary to circumvent the update of the modification date during timestamp migration + entry.clearField(timeStampField, EntriesEventSource.CLEANUP_TIMESTAMP); List changeList = new ArrayList<>(); FieldChange changeTo; // Add removal of timestamp field changeList.add(new FieldChange(entry, StandardField.TIMESTAMP, formattedTimeStamp.get(), "")); - entry.setField(StandardField.MODIFICATIONDATE, formattedTimeStamp.get()); + entry.setField(StandardField.MODIFICATIONDATE, formattedTimeStamp.get(), EntriesEventSource.CLEANUP_TIMESTAMP); changeTo = new FieldChange(entry, StandardField.MODIFICATIONDATE, entry.getField(StandardField.MODIFICATIONDATE).orElse(""), formattedTimeStamp.get()); changeList.add(changeTo); return changeList; diff --git a/src/main/java/org/jabref/model/entry/event/EntriesEventSource.java b/src/main/java/org/jabref/model/entry/event/EntriesEventSource.java index ede1ea5285c..913fffcd2ab 100644 --- a/src/main/java/org/jabref/model/entry/event/EntriesEventSource.java +++ b/src/main/java/org/jabref/model/entry/event/EntriesEventSource.java @@ -7,5 +7,6 @@ public enum EntriesEventSource { LOCAL, SHARED, UNDO, + CLEANUP_TIMESTAMP, SAVE_ACTION } From 58a6171cf33bdadbd1dadc86459a76e232d79c71 Mon Sep 17 00:00:00 2001 From: Dominik Voigt Date: Mon, 26 Apr 2021 14:09:45 +0200 Subject: [PATCH 04/13] Make cleanup to creationdate and modificationdate mutually exclusive using radio buttons --- .../org/jabref/gui/cleanup/CleanupPresetPanel.fxml | 14 ++++++++++---- .../org/jabref/gui/cleanup/CleanupPresetPanel.java | 7 +++++-- .../org/jabref/logic/cleanup/CleanupPreset.java | 1 + src/main/resources/l10n/JabRef_en.properties | 6 ++++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.fxml b/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.fxml index 07ffae48695..a89b11d0a3c 100644 --- a/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.fxml +++ b/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.fxml @@ -5,9 +5,13 @@ + + + + - - + + + diff --git a/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java b/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java index 3c327fca7c7..7b8ff241d96 100644 --- a/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java +++ b/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java @@ -10,6 +10,7 @@ import javafx.fxml.FXML; import javafx.scene.control.CheckBox; import javafx.scene.control.Label; +import javafx.scene.control.RadioButton; import javafx.scene.layout.VBox; import org.jabref.gui.commonfxcontrols.FieldFormatterCleanupsPanel; @@ -36,8 +37,9 @@ public class CleanupPresetPanel extends VBox { @FXML private CheckBox cleanUpUpgradeExternalLinks; @FXML private CheckBox cleanUpBiblatex; @FXML private CheckBox cleanUpBibtex; - @FXML private CheckBox cleanUpTimestampToCreationDate; - @FXML private CheckBox cleanUpTimestampToModificationDate; + @FXML private RadioButton cleanUpTimestampToCreationDate; + @FXML private RadioButton cleanUpTimestampToModificationDate; + @FXML private RadioButton noTimestampCleanup; @FXML private FieldFormatterCleanupsPanel formatterCleanupsPanel; public CleanupPresetPanel(BibDatabaseContext databaseContext, CleanupPreset cleanupPreset, FilePreferences filePreferences) { @@ -89,6 +91,7 @@ private void updateDisplay(CleanupPreset preset) { cleanUpBibtex.setSelected(preset.isActive(CleanupPreset.CleanupStep.CONVERT_TO_BIBTEX)); cleanUpTimestampToCreationDate.setSelected(preset.isActive(CleanupPreset.CleanupStep.CONVERT_TIMESTAMP_TO_CREATIONDATE)); cleanUpTimestampToModificationDate.setSelected(preset.isActive(CleanupPreset.CleanupStep.CONVERT_TIMESTAMP_TO_MODIFICATIONDATE)); + cleanUpTimestampToModificationDate.setSelected(preset.isActive(CleanupPreset.CleanupStep.DO_NOT_CONVERT_TIMESTAMP)); cleanUpISSN.setSelected(preset.isActive(CleanupPreset.CleanupStep.CLEAN_UP_ISSN)); formatterCleanupsPanel.cleanupsDisableProperty().setValue(!preset.getFormatterCleanups().isEnabled()); formatterCleanupsPanel.cleanupsProperty().setValue(FXCollections.observableArrayList(preset.getFormatterCleanups().getConfiguredActions())); diff --git a/src/main/java/org/jabref/logic/cleanup/CleanupPreset.java b/src/main/java/org/jabref/logic/cleanup/CleanupPreset.java index de901e97e93..b97196aad8a 100644 --- a/src/main/java/org/jabref/logic/cleanup/CleanupPreset.java +++ b/src/main/java/org/jabref/logic/cleanup/CleanupPreset.java @@ -67,6 +67,7 @@ public enum CleanupStep { CONVERT_TO_BIBTEX, CONVERT_TIMESTAMP_TO_CREATIONDATE, CONVERT_TIMESTAMP_TO_MODIFICATIONDATE, + DO_NOT_CONVERT_TIMESTAMP, MOVE_PDF, FIX_FILE_LINKS, CLEAN_UP_ISSN diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 7e3f3e95200..36105681d20 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2297,5 +2297,7 @@ Use\ custom\ DOI\ base\ URI\ for\ article\ access=Use custom DOI base URI for ar Unable\ to\ find\ valid\ certification\ path\ to\ requested\ target(%0),\ download\ anyway?=Unable to find valid certification path to requested target(%0), download anyway? Download\ operation\ canceled.=Download operation canceled. -Convert\ timestamp\ fields\ to\ creationdate\ field=Convert timestamp fields to creationdate field -Convert\ timestamp\ fields\ to\ modificationdate\ field=Convert timestamp fields to modificationdate field +Convert\ timestamp\ field\ to\ creationdate\ field=Convert timestamp field to creationdate field +Convert\ timestamp\ field\ to\ modificationdate\ field=Convert timestamp field to modificationdate field +Do\ not\ convert\ timestamp\ field=Do not convert timestamp field + From d5a1d56c1c231f0a125ce2a112d282c8a64d8716 Mon Sep 17 00:00:00 2001 From: Dominik Voigt Date: Tue, 27 Apr 2021 20:40:46 +0200 Subject: [PATCH 05/13] Add mutually exclusive checkboxes for migration options for the bibentry format and the timestamp migration --- .../gui/cleanup/CleanupPresetPanel.fxml | 6 ++-- .../gui/cleanup/CleanupPresetPanel.java | 31 ++++++++++++++++--- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.fxml b/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.fxml index a89b11d0a3c..e84e68ce228 100644 --- a/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.fxml +++ b/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.fxml @@ -33,12 +33,10 @@ text="%Convert to biblatex format (for example, move the value of the 'journal' field to 'journaltitle')"/> - - - diff --git a/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java b/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java index 7b8ff241d96..6957e66a556 100644 --- a/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java +++ b/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java @@ -10,7 +10,6 @@ import javafx.fxml.FXML; import javafx.scene.control.CheckBox; import javafx.scene.control.Label; -import javafx.scene.control.RadioButton; import javafx.scene.layout.VBox; import org.jabref.gui.commonfxcontrols.FieldFormatterCleanupsPanel; @@ -37,9 +36,8 @@ public class CleanupPresetPanel extends VBox { @FXML private CheckBox cleanUpUpgradeExternalLinks; @FXML private CheckBox cleanUpBiblatex; @FXML private CheckBox cleanUpBibtex; - @FXML private RadioButton cleanUpTimestampToCreationDate; - @FXML private RadioButton cleanUpTimestampToModificationDate; - @FXML private RadioButton noTimestampCleanup; + @FXML private CheckBox cleanUpTimestampToCreationDate; + @FXML private CheckBox cleanUpTimestampToModificationDate; @FXML private FieldFormatterCleanupsPanel formatterCleanupsPanel; public CleanupPresetPanel(BibDatabaseContext databaseContext, CleanupPreset cleanupPreset, FilePreferences filePreferences) { @@ -73,7 +71,30 @@ private void init(CleanupPreset cleanupPreset, FilePreferences filePreferences) .concat(": ") .concat(filePreferences.getFileNamePattern()); cleanupRenamePDFLabel.setText(currentPattern); - + cleanUpBibtex.selectedProperty().addListener( + (observable, oldValue, newValue) -> { + if (newValue) { + cleanUpBiblatex.selectedProperty().setValue(false); + } + }); + cleanUpBiblatex.selectedProperty().addListener( + (observable, oldValue, newValue) -> { + if (newValue) { + cleanUpBibtex.selectedProperty().setValue(false); + } + }); + cleanUpTimestampToCreationDate.selectedProperty().addListener( + (observable, oldValue, newValue) -> { + if (newValue) { + cleanUpTimestampToModificationDate.selectedProperty().setValue(false); + } + }); + cleanUpTimestampToModificationDate.selectedProperty().addListener( + (observable, oldValue, newValue) -> { + if (newValue) { + cleanUpTimestampToCreationDate.selectedProperty().setValue(false); + } + }); updateDisplay(cleanupPreset); } From ee0c3753163d5873b4dfcc595164cdb6cc4ec56a Mon Sep 17 00:00:00 2001 From: Dominik Voigt Date: Tue, 27 Apr 2021 22:29:10 +0200 Subject: [PATCH 06/13] Remove unused import --- .../java/org/jabref/logic/cleanup/TimeStampToCreationDate.java | 1 - .../org/jabref/logic/cleanup/TimeStampToModificationDate.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/main/java/org/jabref/logic/cleanup/TimeStampToCreationDate.java b/src/main/java/org/jabref/logic/cleanup/TimeStampToCreationDate.java index 58c7a1d61fd..3e29da42578 100644 --- a/src/main/java/org/jabref/logic/cleanup/TimeStampToCreationDate.java +++ b/src/main/java/org/jabref/logic/cleanup/TimeStampToCreationDate.java @@ -8,7 +8,6 @@ import java.util.List; import java.util.Optional; -import org.jabref.logic.cleanup.CleanupJob; import org.jabref.logic.preferences.TimestampPreferences; import org.jabref.model.FieldChange; import org.jabref.model.entry.BibEntry; diff --git a/src/main/java/org/jabref/logic/cleanup/TimeStampToModificationDate.java b/src/main/java/org/jabref/logic/cleanup/TimeStampToModificationDate.java index bbde55cb278..6006484f7ff 100644 --- a/src/main/java/org/jabref/logic/cleanup/TimeStampToModificationDate.java +++ b/src/main/java/org/jabref/logic/cleanup/TimeStampToModificationDate.java @@ -8,7 +8,6 @@ import java.util.List; import java.util.Optional; -import org.jabref.logic.cleanup.CleanupJob; import org.jabref.logic.preferences.TimestampPreferences; import org.jabref.model.FieldChange; import org.jabref.model.entry.BibEntry; From e5ea66a05548dc3ab7cd7e96db7097bf7cbe6c8c Mon Sep 17 00:00:00 2001 From: Dominik Voigt Date: Tue, 27 Apr 2021 22:29:57 +0200 Subject: [PATCH 07/13] Remove unused field --- .../java/org/jabref/logic/cleanup/TimeStampToCreationDate.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/org/jabref/logic/cleanup/TimeStampToCreationDate.java b/src/main/java/org/jabref/logic/cleanup/TimeStampToCreationDate.java index 3e29da42578..2d69a224853 100644 --- a/src/main/java/org/jabref/logic/cleanup/TimeStampToCreationDate.java +++ b/src/main/java/org/jabref/logic/cleanup/TimeStampToCreationDate.java @@ -24,11 +24,9 @@ */ public class TimeStampToCreationDate implements CleanupJob { - private final boolean interpretTimeStampAsModificationDate; private final Field timeStampField; public TimeStampToCreationDate(TimestampPreferences timestampPreferences) { - interpretTimeStampAsModificationDate = timestampPreferences.shouldUpdateTimestamp(); timeStampField = timestampPreferences.getTimestampField(); } From 19e338d489f8147b85ffa4862575d2f73bc350b4 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Sat, 1 May 2021 17:03:32 +0200 Subject: [PATCH 08/13] Added comment on misunderstandable exception check --- src/main/java/org/jabref/gui/UpdateTimestampListener.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/jabref/gui/UpdateTimestampListener.java b/src/main/java/org/jabref/gui/UpdateTimestampListener.java index f6c8f9ff9dd..2ccc4a72d3c 100644 --- a/src/main/java/org/jabref/gui/UpdateTimestampListener.java +++ b/src/main/java/org/jabref/gui/UpdateTimestampListener.java @@ -19,6 +19,8 @@ class UpdateTimestampListener { @Subscribe public void listen(EntryChangedEvent event) { + // The event source needs to be checked, since the timestamp is always updated on every change. The cleanup formatter is an exception to that behaviour, + // since it just should move the contents from the timestamp field to modificationdate or creationdate. if (preferencesService.getTimestampPreferences().shouldAddModificationDate() && event.getEntriesEventSource() != EntriesEventSource.CLEANUP_TIMESTAMP) { event.getBibEntry().setField(StandardField.MODIFICATIONDATE, preferencesService.getTimestampPreferences().now()); From 236930d8b08d77d6623ecb4ed3c78f221b1300ef Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sat, 1 May 2021 17:14:38 +0200 Subject: [PATCH 09/13] Fix order of tests --- .../TimeStampToModificationDateTest.java | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/test/java/org/jabref/logic/cleanup/TimeStampToModificationDateTest.java b/src/test/java/org/jabref/logic/cleanup/TimeStampToModificationDateTest.java index 63101f54d12..9dd2e48894c 100644 --- a/src/test/java/org/jabref/logic/cleanup/TimeStampToModificationDateTest.java +++ b/src/test/java/org/jabref/logic/cleanup/TimeStampToModificationDateTest.java @@ -33,8 +33,25 @@ public void makeMockReturnStandardField() { Mockito.when(timestampPreferences.getTimestampField()).then(invocation -> StandardField.TIMESTAMP); } + public static Stream standardFieldToModificationDate() { + return Stream.of( + Arguments.of( + new BibEntry().withField(StandardField.MODIFICATIONDATE, "2018-09-10T00:00:00"), + new BibEntry().withField(StandardField.TIMESTAMP, "2018-09-10") + ), + Arguments.of( + new BibEntry().withField(StandardField.MODIFICATIONDATE, "2020-12-24T00:00:00"), + new BibEntry().withField(StandardField.TIMESTAMP, "2020-12-24") + ), + Arguments.of( + new BibEntry().withField(StandardField.MODIFICATIONDATE, "2020-12-31T00:00:00"), + new BibEntry().withField(StandardField.TIMESTAMP, "2020-12-31") + ) + ); + } + /** - * Tests migration to modificationdate if the users uses the default ISO yyyy-mm-dd format and the standard timestamp field + * Tests migration to field "modificationdate" if the users uses the default ISO yyyy-mm-dd format and the standard timestamp field */ @ParameterizedTest @MethodSource("standardFieldToModificationDate") @@ -63,7 +80,7 @@ public static Stream customFieldToModificationDate() { } /** - * Tests migration to modificationdate if the users uses the default ISO yyyy-mm-dd format and a custom timestamp field + * Tests migration to field "modificationdate" if the users uses the default ISO yyyy-mm-dd format and a custom timestamp field */ @ParameterizedTest @MethodSource("customFieldToModificationDate") @@ -74,21 +91,4 @@ public void withCustomFieldToModificationDate(BibEntry expected, BibEntry input) migrator.cleanup(input); assertEquals(expected, input); } - - public static Stream standardFieldToModificationDate() { - return Stream.of( - Arguments.of( - new BibEntry().withField(StandardField.MODIFICATIONDATE, "2018-09-10T00:00:00"), - new BibEntry().withField(StandardField.TIMESTAMP, "2018-09-10") - ), - Arguments.of( - new BibEntry().withField(StandardField.MODIFICATIONDATE, "2020-12-24T00:00:00"), - new BibEntry().withField(StandardField.TIMESTAMP, "2020-12-24") - ), - Arguments.of( - new BibEntry().withField(StandardField.MODIFICATIONDATE, "2020-12-31T00:00:00"), - new BibEntry().withField(StandardField.TIMESTAMP, "2020-12-31") - ) - ); - } } From f4e6a3861d8ed95c97d06bbe92c7964799c68f0b Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sat, 1 May 2021 17:15:55 +0200 Subject: [PATCH 10/13] Remove dead code --- .../jabref/logic/cleanup/TimeStampToModificationDateTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/org/jabref/logic/cleanup/TimeStampToModificationDateTest.java b/src/test/java/org/jabref/logic/cleanup/TimeStampToModificationDateTest.java index 9dd2e48894c..cbcde7928a5 100644 --- a/src/test/java/org/jabref/logic/cleanup/TimeStampToModificationDateTest.java +++ b/src/test/java/org/jabref/logic/cleanup/TimeStampToModificationDateTest.java @@ -87,7 +87,6 @@ public static Stream customFieldToModificationDate() { public void withCustomFieldToModificationDate(BibEntry expected, BibEntry input) { makeMockReturnCustomField(); TimeStampToModificationDate migrator = new TimeStampToModificationDate(timestampPreferences); - ParserResult entries = new ParserResult(List.of(input)); migrator.cleanup(input); assertEquals(expected, input); } From 451bf3d6493c9287592eea2f883afdbae0ec774f Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sat, 1 May 2021 17:30:43 +0200 Subject: [PATCH 11/13] fix lanuage --- src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.fxml | 4 ++-- src/main/resources/l10n/JabRef_en.properties | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.fxml b/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.fxml index e84e68ce228..72183521894 100644 --- a/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.fxml +++ b/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.fxml @@ -34,9 +34,9 @@ + text="%Convert timestamp field to field 'creationdate'"/> + text="%Convert timestamp field to field 'modificationdate'"/> diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 36105681d20..7bbc176507b 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2297,7 +2297,6 @@ Use\ custom\ DOI\ base\ URI\ for\ article\ access=Use custom DOI base URI for ar Unable\ to\ find\ valid\ certification\ path\ to\ requested\ target(%0),\ download\ anyway?=Unable to find valid certification path to requested target(%0), download anyway? Download\ operation\ canceled.=Download operation canceled. -Convert\ timestamp\ field\ to\ creationdate\ field=Convert timestamp field to creationdate field -Convert\ timestamp\ field\ to\ modificationdate\ field=Convert timestamp field to modificationdate field -Do\ not\ convert\ timestamp\ field=Do not convert timestamp field +Convert\ timestamp\ field\ to\ field\ 'creationdate'=Convert timestamp field to field 'creationdate' +Convert\ timestamp\ field\ to\ field\ 'modificationdate'=Convert timestamp field to field 'modificationdate' From 35186ba235f7aebe8cccd0ce65c081554fa80367 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sat, 1 May 2021 17:35:10 +0200 Subject: [PATCH 12/13] Fix checkstyle --- .../jabref/logic/cleanup/TimeStampToModificationDateTest.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/test/java/org/jabref/logic/cleanup/TimeStampToModificationDateTest.java b/src/test/java/org/jabref/logic/cleanup/TimeStampToModificationDateTest.java index cbcde7928a5..79f3fbc8438 100644 --- a/src/test/java/org/jabref/logic/cleanup/TimeStampToModificationDateTest.java +++ b/src/test/java/org/jabref/logic/cleanup/TimeStampToModificationDateTest.java @@ -1,11 +1,7 @@ package org.jabref.logic.cleanup; -import java.util.List; import java.util.stream.Stream; -import org.jabref.logic.cleanup.TimeStampToCreationDate; -import org.jabref.logic.cleanup.TimeStampToModificationDate; -import org.jabref.logic.importer.ParserResult; import org.jabref.logic.preferences.TimestampPreferences; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.Field; From f1346549d99112a3bdaa2cc4deae30f263a76819 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sat, 1 May 2021 17:44:46 +0200 Subject: [PATCH 13/13] Fix checkstyle --- .../logic/cleanup/TimeStampToCreationDateTest.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/test/java/org/jabref/logic/cleanup/TimeStampToCreationDateTest.java b/src/test/java/org/jabref/logic/cleanup/TimeStampToCreationDateTest.java index 2b13a24eb7c..6cfbb82029f 100644 --- a/src/test/java/org/jabref/logic/cleanup/TimeStampToCreationDateTest.java +++ b/src/test/java/org/jabref/logic/cleanup/TimeStampToCreationDateTest.java @@ -3,7 +3,6 @@ import java.util.List; import java.util.stream.Stream; -import org.jabref.logic.cleanup.TimeStampToCreationDate; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.preferences.TimestampPreferences; import org.jabref.model.entry.BibEntry; @@ -20,12 +19,12 @@ class TimeStampToCreationDateTest { - private static final Field customTimeStampField = new UnknownField("dateOfCreation"); + private static final Field CUSTOM_TIME_STAMP_FIELD = new UnknownField("dateOfCreation"); private final TimestampPreferences timestampPreferences = Mockito.mock(TimestampPreferences.class); public void makeMockReturnCustomField() { - Mockito.when(timestampPreferences.getTimestampField()).then(invocation -> customTimeStampField); + Mockito.when(timestampPreferences.getTimestampField()).then(invocation -> CUSTOM_TIME_STAMP_FIELD); } public void makeMockReturnStandardField() { @@ -65,15 +64,15 @@ public static Stream customFieldToCreationDate() { return Stream.of( Arguments.of( new BibEntry().withField(StandardField.CREATIONDATE, "2018-09-10T00:00:00"), - new BibEntry().withField(customTimeStampField, "2018-09-10") + new BibEntry().withField(CUSTOM_TIME_STAMP_FIELD, "2018-09-10") ), Arguments.of( new BibEntry().withField(StandardField.CREATIONDATE, "2020-12-24T00:00:00"), - new BibEntry().withField(customTimeStampField, "2020-12-24") + new BibEntry().withField(CUSTOM_TIME_STAMP_FIELD, "2020-12-24") ), Arguments.of( new BibEntry().withField(StandardField.CREATIONDATE, "2020-12-31T00:00:00"), - new BibEntry().withField(customTimeStampField, "2020-12-31") + new BibEntry().withField(CUSTOM_TIME_STAMP_FIELD, "2020-12-31") ) ); }