diff --git a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java index cc2b1fd32ac..ab916bf926a 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java +++ b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java @@ -51,7 +51,7 @@ public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecu } else if (fieldExtras.contains(FieldProperty.OWNER)) { return new OwnerEditor(fieldName, preferences, suggestionProvider, fieldCheckers); } else if (fieldExtras.contains(FieldProperty.FILE_EDITOR)) { - return new LinkedFilesEditor(fieldName, dialogService, databaseContext, taskExecutor, suggestionProvider, fieldCheckers, preferences); + return new LinkedFilesEditor(fieldName, dialogService, databaseContext, taskExecutor, suggestionProvider, fieldCheckers, preferences, journalAbbreviationLoader); } else if (fieldExtras.contains(FieldProperty.YES_NO)) { return new OptionEditor<>(new YesNoEditorViewModel(fieldName, suggestionProvider, fieldCheckers)); } else if (fieldExtras.contains(FieldProperty.MONTH)) { diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index f3d3ba6a425..cb358e48e7d 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -20,9 +20,9 @@ import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.StringProperty; import javafx.scene.control.Alert.AlertType; +import javafx.scene.control.ButtonBar.ButtonData; import javafx.scene.control.ButtonType; -import org.jabref.Globals; import org.jabref.gui.AbstractViewModel; import org.jabref.gui.DialogService; import org.jabref.gui.IconTheme; @@ -35,12 +35,10 @@ import org.jabref.gui.filelist.FileListEntryEditor; import org.jabref.gui.util.BackgroundTask; import org.jabref.gui.util.TaskExecutor; -import org.jabref.logic.cleanup.CleanupPreferences; import org.jabref.logic.cleanup.MoveFilesCleanup; import org.jabref.logic.cleanup.RenamePdfCleanup; import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.logic.l10n.Localization; -import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.logic.net.URLDownload; import org.jabref.logic.util.io.FileUtil; import org.jabref.logic.xmp.XmpPreferences; @@ -49,13 +47,12 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.LinkedFile; import org.jabref.model.metadata.FileDirectoryPreferences; +import org.jabref.model.strings.StringUtil; import org.jabref.preferences.JabRefPreferences; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static javafx.scene.control.ButtonBar.ButtonData; - public class LinkedFileViewModel extends AbstractViewModel { private static final Logger LOGGER = LoggerFactory.getLogger(LinkedFileViewModel.class); @@ -70,33 +67,28 @@ public class LinkedFileViewModel extends AbstractViewModel { private final BibEntry entry; private final TaskExecutor taskExecutor; private final FileDirectoryPreferences fileDirectoryPreferences; - private final CleanupPreferences cleanupPreferences; - private final LayoutFormatterPreferences layoutFormatterPreferences; + private final String fileDirPattern; private final XmpPreferences xmpPreferences; private final String fileNamePattern; - /** - * @deprecated use {@link #LinkedFileViewModel(LinkedFile, BibEntry, BibDatabaseContext, TaskExecutor, DialogService, JabRefPreferences, JournalAbbreviationLoader)} instead - */ - @Deprecated - public LinkedFileViewModel(LinkedFile linkedFile, BibEntry entry, BibDatabaseContext databaseContext, TaskExecutor taskExecutor) { - this(linkedFile, entry, databaseContext, taskExecutor, new FXDialogService(), Globals.prefs, Globals.journalAbbreviationLoader); - } + public LinkedFileViewModel(LinkedFile linkedFile, + BibEntry entry, + BibDatabaseContext databaseContext, + TaskExecutor taskExecutor, + DialogService dialogService, + JabRefPreferences preferences, + JournalAbbreviationLoader abbreviationLoader) { - public LinkedFileViewModel(LinkedFile linkedFile, BibEntry entry, BibDatabaseContext databaseContext, - TaskExecutor taskExecutor, DialogService dialogService, JabRefPreferences preferences, JournalAbbreviationLoader abbreviationLoader) { this.linkedFile = linkedFile; this.databaseContext = databaseContext; this.entry = entry; this.dialogService = dialogService; this.taskExecutor = taskExecutor; - cleanupPreferences = preferences.getCleanupPreferences(abbreviationLoader); - layoutFormatterPreferences = preferences.getLayoutFormatterPreferences(abbreviationLoader); xmpPreferences = preferences.getXMPPreferences(); fileNamePattern = preferences.get(JabRefPreferences.IMPORT_FILENAMEPATTERN); fileDirectoryPreferences = preferences.getFileDirectoryPreferences(); - + fileDirPattern = preferences.getCleanupPreferences(abbreviationLoader).getFileDirPattern(); downloadOngoing.bind(downloadProgress.greaterThanOrEqualTo(0).and(downloadProgress.lessThan(1))); canWriteXMPMetadata.setValue(!linkedFile.isOnlineLink() && linkedFile.getFileType().equalsIgnoreCase("pdf")); } @@ -175,11 +167,11 @@ public void open() { boolean successful = JabRefDesktop.openExternalFileAnyFormat(databaseContext, linkedFile.getLink(), type); if (!successful) { dialogService.showErrorDialogAndWait( - Localization.lang("File not found"), - Localization.lang("Could not find file '%0'.", linkedFile.getLink())); + Localization.lang("File not found"), + Localization.lang("Could not find file '%0'.", linkedFile.getLink())); } } catch (IOException e) { - dialogService.showErrorDialogAndWait(Localization.lang("Error opening file '%0'.", getLink()), e); + dialogService.showErrorDialogAndWait(Localization.lang("Error opening file '%0'.", linkedFile.getLink()), e); } } @@ -217,26 +209,25 @@ public void rename() { Optional fileDir = databaseContext.getFirstExistingFileDir(fileDirectoryPreferences); if (!fileDir.isPresent()) { dialogService.showErrorDialogAndWait( - Localization.lang("Rename file"), - Localization.lang("File directory is not set or does not exist!")); + Localization.lang("Rename file"), + Localization.lang("File directory is not set or does not exist!")); return; } Optional file = linkedFile.findIn(databaseContext, fileDirectoryPreferences); if ((file.isPresent()) && Files.exists(file.get())) { RenamePdfCleanup pdfCleanup = new RenamePdfCleanup(false, - databaseContext, - cleanupPreferences.getFileNamePattern(), - layoutFormatterPreferences, - fileDirectoryPreferences, linkedFile); + databaseContext, + fileDirPattern, + fileDirectoryPreferences, linkedFile); String targetFileName = pdfCleanup.getTargetFileName(linkedFile, entry); boolean confirm = dialogService.showConfirmationDialogAndWait( - Localization.lang("Rename file"), - Localization.lang("Rename file to") + " " + targetFileName, - Localization.lang("Rename file"), - Localization.lang("Cancel")); + Localization.lang("Rename file"), + Localization.lang("Rename file to") + " " + targetFileName, + Localization.lang("Rename file"), + Localization.lang("Cancel")); if (confirm) { Optional fileConflictCheck = pdfCleanup.findExistingFile(linkedFile, entry); @@ -245,8 +236,8 @@ public void rename() { } } else { dialogService.showErrorDialogAndWait( - Localization.lang("File not found"), - Localization.lang("Could not find file '%0'.", linkedFile.getLink())); + Localization.lang("File not found"), + Localization.lang("Could not find file '%0'.", linkedFile.getLink())); } } @@ -257,23 +248,23 @@ private void performRenameWithConflictCheck(Optional file, RenamePdfCleanu pdfCleanup.cleanupWithException(entry); } catch (IOException e) { dialogService.showErrorDialogAndWait( - Localization.lang("Rename failed"), - Localization.lang("JabRef cannot access the file because it is being used by another process.")); + Localization.lang("Rename failed"), + Localization.lang("JabRef cannot access the file because it is being used by another process.")); } } else { confirm = dialogService.showConfirmationDialogAndWait( - Localization.lang("File exists"), - Localization.lang("'%0' exists. Overwrite file?", targetFileName), - Localization.lang("Overwrite"), - Localization.lang("Cancel")); + Localization.lang("File exists"), + Localization.lang("'%0' exists. Overwrite file?", targetFileName), + Localization.lang("Overwrite"), + Localization.lang("Cancel")); if (confirm) { try { FileUtil.renameFileWithException(fileConflictCheck.get(), file.get(), true); pdfCleanup.cleanupWithException(entry); } catch (IOException e) { dialogService.showErrorDialogAndWait( - Localization.lang("Rename failed"), - Localization.lang("JabRef cannot access the file because it is being used by another process.")); + Localization.lang("Rename failed"), + Localization.lang("JabRef cannot access the file because it is being used by another process.")); } } } @@ -289,8 +280,8 @@ public void moveToDefaultDirectory() { Optional fileDir = databaseContext.getFirstExistingFileDir(fileDirectoryPreferences); if (!fileDir.isPresent()) { dialogService.showErrorDialogAndWait( - Localization.lang("Move file"), - Localization.lang("File directory is not set or does not exist!")); + Localization.lang("Move file"), + Localization.lang("File directory is not set or does not exist!")); return; } @@ -298,23 +289,23 @@ public void moveToDefaultDirectory() { if ((file.isPresent()) && Files.exists(file.get())) { // Linked file exists, so move it MoveFilesCleanup moveFiles = new MoveFilesCleanup(databaseContext, - cleanupPreferences.getFileDirPattern(), - fileDirectoryPreferences, - layoutFormatterPreferences, linkedFile); + fileDirPattern, + fileDirectoryPreferences, + linkedFile); boolean confirm = dialogService.showConfirmationDialogAndWait( - Localization.lang("Move file"), - Localization.lang("Move file to file directory?") + " " + fileDir.get(), - Localization.lang("Move file"), - Localization.lang("Cancel")); + Localization.lang("Move file"), + Localization.lang("Move file to file directory?") + " " + fileDir.get(), + Localization.lang("Move file"), + Localization.lang("Cancel")); if (confirm) { moveFiles.cleanup(entry); } } else { // File doesn't exist, so we can't move it. dialogService.showErrorDialogAndWait( - Localization.lang("File not found"), - Localization.lang("Could not find file '%0'.", linkedFile.getLink())); + Localization.lang("File not found"), + Localization.lang("Could not find file '%0'.", linkedFile.getLink())); } } @@ -329,9 +320,11 @@ public boolean delete(FileDirectoryPreferences prefs) { ButtonType removeFromEntry = new ButtonType(Localization.lang("Remove from entry"), ButtonData.YES); ButtonType deleteFromEntry = new ButtonType(Localization.lang("Delete from disk")); Optional buttonType = dialogService.showCustomButtonDialogAndWait(AlertType.INFORMATION, - Localization.lang("Delete '%0'", file.get().toString()), - Localization.lang("Delete the selected file permanently from disk, or just remove the file from the entry? Pressing Delete will delete the file permanently from disk."), - removeFromEntry, deleteFromEntry, ButtonType.CANCEL); + Localization.lang("Delete '%0'", file.get().toString()), + Localization.lang("Delete the selected file permanently from disk, or just remove the file from the entry? Pressing Delete will delete the file permanently from disk."), + removeFromEntry, + deleteFromEntry, + ButtonType.CANCEL); if (buttonType.isPresent()) { if (buttonType.get().equals(removeFromEntry)) { @@ -345,8 +338,8 @@ public boolean delete(FileDirectoryPreferences prefs) { return true; } catch (IOException ex) { dialogService.showErrorDialogAndWait( - Localization.lang("Cannot delete file"), - Localization.lang("File permission error")); + Localization.lang("Cannot delete file"), + Localization.lang("File permission error")); LOGGER.warn("File permission error while deleting: " + linkedFile, ex); } } @@ -397,8 +390,8 @@ public void download() { Optional targetDirectory = databaseContext.getFirstExistingFileDir(fileDirectoryPreferences); if (!targetDirectory.isPresent()) { dialogService.showErrorDialogAndWait( - Localization.lang("Download file"), - Localization.lang("File directory is not set or does not exist!")); + Localization.lang("Download file"), + Localization.lang("File directory is not set or does not exist!")); return; } String suffix = suggestedType.map(ExternalFileType::getExtension).orElse(""); @@ -406,19 +399,19 @@ public void download() { Path destination = targetDirectory.get().resolve(suggestedName); BackgroundTask downloadTask = new FileDownloadTask(urlDownload.getSource(), destination) - .onSuccess(event -> { - LinkedFile newLinkedFile = LinkedFilesEditorViewModel.fromFile(destination, databaseContext.getFileDirectoriesAsPaths(fileDirectoryPreferences)); - linkedFile.setLink(newLinkedFile.getLink()); - linkedFile.setFileType(newLinkedFile.getFileType()); - }) - .onFailure(ex -> dialogService.showErrorDialogAndWait("Download failed", ex)); + .onSuccess(event -> { + LinkedFile newLinkedFile = LinkedFilesEditorViewModel.fromFile(destination, databaseContext.getFileDirectoriesAsPaths(fileDirectoryPreferences)); + linkedFile.setLink(newLinkedFile.getLink()); + linkedFile.setFileType(newLinkedFile.getFileType()); + }) + .onFailure(ex -> dialogService.showErrorDialogAndWait("Download failed", ex)); downloadProgress.bind(downloadTask.workDonePercentageProperty()); taskExecutor.execute(downloadTask); } catch (MalformedURLException exception) { dialogService.showErrorDialogAndWait( - Localization.lang("Invalid URL"), - exception); + Localization.lang("Invalid URL"), + exception); } } diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java index 53b437613ed..5ce3aa5d263 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java @@ -37,6 +37,7 @@ import org.jabref.gui.util.TaskExecutor; import org.jabref.gui.util.ViewModelListCellFactory; import org.jabref.logic.integrity.FieldCheckers; +import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; @@ -51,8 +52,10 @@ public class LinkedFilesEditor extends HBox implements FieldEditorFX { @FXML private final LinkedFilesEditorViewModel viewModel; @FXML private ListView listView; - public LinkedFilesEditor(String fieldName, DialogService dialogService, BibDatabaseContext databaseContext, TaskExecutor taskExecutor, AutoCompleteSuggestionProvider suggestionProvider, FieldCheckers fieldCheckers, JabRefPreferences preferences) { - this.viewModel = new LinkedFilesEditorViewModel(fieldName, suggestionProvider, dialogService, databaseContext, taskExecutor, fieldCheckers, preferences); + public LinkedFilesEditor(String fieldName, DialogService dialogService, BibDatabaseContext databaseContext, TaskExecutor taskExecutor, AutoCompleteSuggestionProvider suggestionProvider, + FieldCheckers fieldCheckers, + JabRefPreferences preferences, JournalAbbreviationLoader abbreviationLoader) { + this.viewModel = new LinkedFilesEditorViewModel(fieldName, suggestionProvider, dialogService, databaseContext, taskExecutor, fieldCheckers, preferences, abbreviationLoader); ControlHelper.loadFXMLForControl(this); diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java index 47bf5db615c..42c2a5d853b 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java @@ -29,6 +29,7 @@ import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.importer.FulltextFetchers; import org.jabref.logic.integrity.FieldCheckers; +import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.io.FileUtil; import org.jabref.model.database.BibDatabaseContext; @@ -47,14 +48,22 @@ public class LinkedFilesEditorViewModel extends AbstractEditorViewModel { private final BibDatabaseContext databaseContext; private final TaskExecutor taskExecutor; private final JabRefPreferences preferences; - - public LinkedFilesEditorViewModel(String fieldName, AutoCompleteSuggestionProvider suggestionProvider, DialogService dialogService, BibDatabaseContext databaseContext, TaskExecutor taskExecutor, FieldCheckers fieldCheckers, JabRefPreferences preferences) { + private final JournalAbbreviationLoader journalAbbreviationLoader; + + public LinkedFilesEditorViewModel(String fieldName, AutoCompleteSuggestionProvider suggestionProvider, + DialogService dialogService, + BibDatabaseContext databaseContext, + TaskExecutor taskExecutor, + FieldCheckers fieldCheckers, + JabRefPreferences preferences, + JournalAbbreviationLoader journalAbbreviationLoader) { super(fieldName, suggestionProvider, fieldCheckers); this.dialogService = dialogService; this.databaseContext = databaseContext; this.taskExecutor = taskExecutor; this.preferences = preferences; + this.journalAbbreviationLoader = journalAbbreviationLoader; BindingsHelper.bindContentBidirectional( files, @@ -92,7 +101,7 @@ public LinkedFileViewModel fromFile(Path file) { List fileDirectories = databaseContext.getFileDirectoriesAsPaths(preferences.getFileDirectoryPreferences()); LinkedFile linkedFile = fromFile(file, fileDirectories); - return new LinkedFileViewModel(linkedFile, entry, databaseContext, dialogService, taskExecutor); + return new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, journalAbbreviationLoader); } @@ -106,7 +115,7 @@ public BooleanProperty fulltextLookupInProgressProperty() { private List parseToFileViewModel(String stringValue) { return FileFieldParser.parse(stringValue).stream() - .map(linkedFile -> new LinkedFileViewModel(linkedFile, entry, databaseContext, dialogService, taskExecutor)) + .map(linkedFile -> new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, journalAbbreviationLoader)) .collect(Collectors.toList()); } @@ -127,10 +136,9 @@ public void addNewFile() { .build(); List fileDirectories = databaseContext.getFileDirectoriesAsPaths(preferences.getFileDirectoryPreferences()); - dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent( - newFile -> { - LinkedFile newLinkedFile = fromFile(newFile, fileDirectories); - files.add(new LinkedFileViewModel(newLinkedFile, entry, databaseContext, dialogService, taskExecutor)); + dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(newFile -> { + LinkedFile newLinkedFile = fromFile(newFile, fileDirectories); + files.add(new LinkedFileViewModel(newLinkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, journalAbbreviationLoader)); }); } @@ -156,7 +164,7 @@ private List findAssociatedNotLinkedFiles(BibEntry entry) { try { List linkedFiles = util.findAssociatedNotLinkedFiles(entry); for (LinkedFile linkedFile : linkedFiles) { - LinkedFileViewModel newLinkedFile = new LinkedFileViewModel(linkedFile, entry, databaseContext, dialogService, taskExecutor); + LinkedFileViewModel newLinkedFile = new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, journalAbbreviationLoader); newLinkedFile.markAsAutomaticallyFound(); result.add(newLinkedFile); } @@ -199,8 +207,8 @@ public void addFromURL() { } private void addFromURL(URL url) { - LinkedFileViewModel onlineFile = new LinkedFileViewModel( - new LinkedFile("", url, ""), entry, databaseContext, taskExecutor); + LinkedFileViewModel onlineFile = new LinkedFileViewModel(new LinkedFile("", url, ""), + entry, databaseContext, taskExecutor, dialogService, preferences, null); files.add(onlineFile); onlineFile.download(); } diff --git a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java index 31090c1c512..0d365ca033c 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java @@ -240,9 +240,9 @@ private TableColumn> createFileColumn() .withGraphic(this::createFileIcon) .withMenu(this::createFileMenu) .withOnMouseClickedEvent((entry, linkedFiles) -> event -> { - if (event.getButton() == MouseButton.PRIMARY && linkedFiles.size() == 1) { + if ((event.getButton() == MouseButton.PRIMARY) && (linkedFiles.size() == 1)) { // Only one linked file -> open directly - LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel(linkedFiles.get(0), entry.getEntry(), database, dialogService, Globals.TASK_EXECUTOR); + LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel(linkedFiles.get(0), entry.getEntry(), database, Globals.TASK_EXECUTOR, dialogService, Globals.prefs, Globals.journalAbbreviationLoader); linkedFileViewModel.open(); } }) @@ -258,7 +258,7 @@ private ContextMenu createFileMenu(BibEntryTableViewModel entry, List linkedFileViewModel.open()); diff --git a/src/main/java/org/jabref/logic/cleanup/CleanupWorker.java b/src/main/java/org/jabref/logic/cleanup/CleanupWorker.java index 9ed2c3dd5a3..1c7e651182b 100644 --- a/src/main/java/org/jabref/logic/cleanup/CleanupWorker.java +++ b/src/main/java/org/jabref/logic/cleanup/CleanupWorker.java @@ -72,14 +72,14 @@ private List determineCleanupActions(CleanupPreset preset) { jobs.add(new FileLinksCleanup()); } if (preset.isMovePDF()) { - jobs.add(new MoveFilesCleanup(databaseContext, fileDirPattern, fileDirectoryPreferences, layoutPrefs)); + jobs.add(new MoveFilesCleanup(databaseContext, fileDirPattern, fileDirectoryPreferences)); } if (preset.isMakePathsRelative()) { jobs.add(new RelativePathsCleanup(databaseContext, fileDirectoryPreferences)); } if (preset.isRenamePDF()) { RenamePdfCleanup cleaner = new RenamePdfCleanup(preset.isRenamePdfOnlyRelativePaths(), databaseContext, - fileNamePattern, layoutPrefs, fileDirectoryPreferences); + fileNamePattern, fileDirectoryPreferences); jobs.add(cleaner); unsuccessfulRenames += cleaner.getUnsuccessfulRenames(); } diff --git a/src/main/java/org/jabref/logic/cleanup/MoveFilesCleanup.java b/src/main/java/org/jabref/logic/cleanup/MoveFilesCleanup.java index 6ef4a5d46e9..b919576a0dd 100644 --- a/src/main/java/org/jabref/logic/cleanup/MoveFilesCleanup.java +++ b/src/main/java/org/jabref/logic/cleanup/MoveFilesCleanup.java @@ -12,7 +12,6 @@ import java.util.Optional; import java.util.stream.Collectors; -import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.logic.util.io.FileUtil; import org.jabref.model.FieldChange; import org.jabref.model.cleanup.CleanupJob; @@ -35,19 +34,17 @@ public class MoveFilesCleanup implements CleanupJob { private LinkedFile singleFileFieldCleanup; - // FIXME: remove unused parameter 'layoutPrefs' later S.G. public MoveFilesCleanup(BibDatabaseContext databaseContext, String fileDirPattern, - FileDirectoryPreferences fileDirectoryPreferences, LayoutFormatterPreferences layoutPrefs) { + FileDirectoryPreferences fileDirectoryPreferences) { this.databaseContext = Objects.requireNonNull(databaseContext); this.fileDirPattern = Objects.requireNonNull(fileDirPattern); this.fileDirectoryPreferences = Objects.requireNonNull(fileDirectoryPreferences); } public MoveFilesCleanup(BibDatabaseContext databaseContext, String fileDirPattern, - FileDirectoryPreferences fileDirectoryPreferences, LayoutFormatterPreferences prefs, - LinkedFile field) { + FileDirectoryPreferences fileDirectoryPreferences, LinkedFile field) { - this(databaseContext, fileDirPattern, fileDirectoryPreferences, prefs); + this(databaseContext, fileDirPattern, fileDirectoryPreferences); this.singleFileFieldCleanup = field; } diff --git a/src/main/java/org/jabref/logic/cleanup/RenamePdfCleanup.java b/src/main/java/org/jabref/logic/cleanup/RenamePdfCleanup.java index 3c69a6800f8..71093ba032e 100644 --- a/src/main/java/org/jabref/logic/cleanup/RenamePdfCleanup.java +++ b/src/main/java/org/jabref/logic/cleanup/RenamePdfCleanup.java @@ -12,7 +12,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.logic.util.io.FileUtil; import org.jabref.model.FieldChange; import org.jabref.model.cleanup.CleanupJob; @@ -37,10 +36,8 @@ public class RenamePdfCleanup implements CleanupJob { private int unsuccessfulRenames; private LinkedFile singleFieldCleanup; - // FIXME: (S.G.) remove unused constructor argument 'layoutPreferences' later; for now, - // however, the argument is retained in order not to change the class interface: + public RenamePdfCleanup(boolean onlyRelativePaths, BibDatabaseContext databaseContext, String fileNamePattern, - LayoutFormatterPreferences layoutPreferences, FileDirectoryPreferences fileDirectoryPreferences) { this.databaseContext = Objects.requireNonNull(databaseContext); this.onlyRelativePaths = onlyRelativePaths; @@ -49,11 +46,9 @@ public RenamePdfCleanup(boolean onlyRelativePaths, BibDatabaseContext databaseCo } public RenamePdfCleanup(boolean onlyRelativePaths, BibDatabaseContext databaseContext, String fileNamePattern, - LayoutFormatterPreferences layoutPreferences, FileDirectoryPreferences fileDirectoryPreferences, LinkedFile singleField) { - this(onlyRelativePaths, databaseContext, fileNamePattern, layoutPreferences, - fileDirectoryPreferences); + this(onlyRelativePaths, databaseContext, fileNamePattern, fileDirectoryPreferences); this.singleFieldCleanup = singleField; } diff --git a/src/test/java/org/jabref/architecture/TestArchitectureTests.java b/src/test/java/org/jabref/architecture/TestArchitectureTests.java index bf36680e4a7..c867d36b96d 100644 --- a/src/test/java/org/jabref/architecture/TestArchitectureTests.java +++ b/src/test/java/org/jabref/architecture/TestArchitectureTests.java @@ -27,13 +27,12 @@ public class TestArchitectureTests { private static final String CLASS_ORG_JABREF_PREFERENCES_TEST = "JabRefPreferencesTest"; private static final String CLASS_ORG_JABREF_PREFERENCES_MIGRATIONS_TEST = "PreferencesMigrationsTest"; private static final String CLASS_ORG_JABREF_UPDATE_TIMESTAMP_LISTENER_TEST = "UpdateTimestampListenerTest"; - private static final String CLASS_ORG_JABREF_ENTRY_EDITOR_TEST = "SourceTabTest"; private static final String CLASS_ORG_JABREF_ENTRY_EDITOR_TEST = "EntryEditorTest"; private static final String CLASS_ORG_JABREF_LINKED_FILE_VIEW_MODEL_TEST = "LinkedFileViewModelTest"; private final String forbiddenPackage; - private List exceptions; + private final List exceptions; public TestArchitectureTests(String forbiddenPackage) { this.forbiddenPackage = forbiddenPackage; diff --git a/src/test/java/org/jabref/logic/cleanup/MoveFilesCleanupTest.java b/src/test/java/org/jabref/logic/cleanup/MoveFilesCleanupTest.java index eff70c4b427..7dcb8e77167 100644 --- a/src/test/java/org/jabref/logic/cleanup/MoveFilesCleanupTest.java +++ b/src/test/java/org/jabref/logic/cleanup/MoveFilesCleanupTest.java @@ -7,7 +7,6 @@ import java.util.Arrays; import java.util.Optional; -import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.model.Defaults; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; @@ -62,8 +61,8 @@ public void movesFileFromSubfolder() throws IOException { LinkedFile fileField = new LinkedFile("", fileBefore.getAbsolutePath(), ""); entry.setField("file", FileFieldWriter.getStringRepresentation(fileField)); - cleanup = new MoveFilesCleanup(databaseContext, "", fileDirPrefs, - mock(LayoutFormatterPreferences.class)); + cleanup = new MoveFilesCleanup(databaseContext, "", fileDirPrefs); + cleanup.cleanup(entry); assertFalse(fileBefore.exists()); @@ -85,8 +84,7 @@ public void movesFileFromSubfolderMultiple() throws IOException { entry.setField("file", FileFieldWriter.getStringRepresentation( Arrays.asList(new LinkedFile("", "", ""), fileField, new LinkedFile("", "", "")))); - cleanup = new MoveFilesCleanup(databaseContext, "", fileDirPrefs, - mock(LayoutFormatterPreferences.class)); + cleanup = new MoveFilesCleanup(databaseContext, "", fileDirPrefs); cleanup.cleanup(entry); assertFalse(fileBefore.exists()); @@ -109,8 +107,8 @@ public void movesFileFromSubfolderWithFileDirPattern() throws IOException { LinkedFile fileField = new LinkedFile("", fileBefore.getAbsolutePath(), ""); entry.setField("file", FileFieldWriter.getStringRepresentation(fileField)); - cleanup = new MoveFilesCleanup(databaseContext, "[entrytype]", fileDirPrefs, - mock(LayoutFormatterPreferences.class)); + cleanup = new MoveFilesCleanup(databaseContext, "[entrytype]", fileDirPrefs); + cleanup.cleanup(entry); assertFalse(fileBefore.exists()); @@ -136,8 +134,7 @@ public void movesFileFromSubfolderWithSubdirPattern() throws IOException { LinkedFile fileField = new LinkedFile("", fileBefore.getAbsolutePath(), ""); local_entry.setField("file", FileFieldWriter.getStringRepresentation(fileField)); - cleanup = new MoveFilesCleanup(databaseContext, "[year]", fileDirPrefs, - mock(LayoutFormatterPreferences.class)); + cleanup = new MoveFilesCleanup(databaseContext, "[year]", fileDirPrefs); cleanup.cleanup(local_entry); assertFalse(fileBefore.exists()); @@ -164,8 +161,8 @@ public void movesFileFromSubfolderWithDeepSubdirPattern() throws IOException { LinkedFile fileField = new LinkedFile("", fileBefore.getAbsolutePath(), ""); local_entry.setField("file", FileFieldWriter.getStringRepresentation(fileField)); - cleanup = new MoveFilesCleanup(databaseContext, "[entrytype]/[year]/[auth]", fileDirPrefs, - mock(LayoutFormatterPreferences.class)); + cleanup = new MoveFilesCleanup(databaseContext, "[entrytype]/[year]/[auth]", fileDirPrefs); + cleanup.cleanup(local_entry); assertFalse(fileBefore.exists()); diff --git a/src/test/java/org/jabref/logic/cleanup/RenamePdfCleanupTest.java b/src/test/java/org/jabref/logic/cleanup/RenamePdfCleanupTest.java index c5be556f6d8..e169ef43c0f 100644 --- a/src/test/java/org/jabref/logic/cleanup/RenamePdfCleanupTest.java +++ b/src/test/java/org/jabref/logic/cleanup/RenamePdfCleanupTest.java @@ -58,7 +58,7 @@ public void cleanupRenamePdfRenamesFileEvenIfOnlyDifferenceIsCase() throws IOExc entry.setField("file", FileFieldWriter.getStringRepresentation(fileField)); RenamePdfCleanup cleanup = new RenamePdfCleanup(false, context, fileNamePattern, - mock(LayoutFormatterPreferences.class), fileDirPrefs); + fileDirPrefs); cleanup.cleanup(entry); LinkedFile newFileField = new LinkedFile("", "Toot.tmp", ""); @@ -75,7 +75,7 @@ public void cleanupRenamePdfRenamesWithMultipleFiles() throws IOException { new LinkedFile("", tempFile.getAbsolutePath(), ""), new LinkedFile("", "", "")))); RenamePdfCleanup cleanup = new RenamePdfCleanup(false, context, fileNamePattern, - mock(LayoutFormatterPreferences.class), fileDirPrefs); + fileDirPrefs); cleanup.cleanup(entry); assertEquals( @@ -93,7 +93,7 @@ public void cleanupRenamePdfRenamesFileStartingWithBibtexKey() throws IOExceptio entry.setField("title", "test title"); RenamePdfCleanup cleanup = new RenamePdfCleanup(false, context, fileNamePattern, - mock(LayoutFormatterPreferences.class), fileDirPrefs); + fileDirPrefs); cleanup.cleanup(entry); LinkedFile newFileField = new LinkedFile("", "Toot - test title.tmp", ""); @@ -108,9 +108,7 @@ public void cleanupRenamePdfRenamesFileInSameFolder() throws IOException { entry.setField("file", FileFieldWriter.getStringRepresentation(fileField)); entry.setField("title", "test title"); - RenamePdfCleanup cleanup = new RenamePdfCleanup(false, context, fileNamePattern, - layoutFormatterPreferences, - fileDirPrefs); + RenamePdfCleanup cleanup = new RenamePdfCleanup(false, context, fileNamePattern, fileDirPrefs); cleanup.cleanup(entry); LinkedFile newFileField = new LinkedFile("", "Toot - test title.pdf", "PDF"); @@ -125,7 +123,6 @@ public void cleanupSingleField() throws IOException { entry.setField("file", FileFieldWriter.getStringRepresentation(fileField)); entry.setField("title", "test title"); RenamePdfCleanup cleanup = new RenamePdfCleanup(false, context, fileNamePattern, - layoutFormatterPreferences, fileDirPrefs, fileField); cleanup.cleanup(entry); @@ -140,9 +137,7 @@ public void cleanupGetTargetFilename() throws IOException { String fileNamePattern = "[bibtexkey] - [fulltitle]"; testFolder.newFile("Toot.pdf"); LinkedFile fileField = new LinkedFile("", "Toot.pdf", "PDF"); - RenamePdfCleanup cleanup = new RenamePdfCleanup(false, context, fileNamePattern, - layoutFormatterPreferences, - fileDirPrefs); + RenamePdfCleanup cleanup = new RenamePdfCleanup(false, context, fileNamePattern, fileDirPrefs); entry.setField("file", FileFieldWriter.getStringRepresentation(fileField)); entry.setField("title", "test title");