From 9fb953398f14b0fbe051bc6fb644d6d40036055d Mon Sep 17 00:00:00 2001 From: Anna Date: Sun, 14 Nov 2021 16:10:47 -0600 Subject: [PATCH 01/18] Update LinkedFilesEditor.java Disable MOVE_FILE_TO_FOLDER_AND_RENAME using the same logic as MOVE_FILE_TO_FOLDER --- .../java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java index a13eeb6a310..e41ccd247ef 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java @@ -294,12 +294,12 @@ public ContextAction(StandardActions command, LinkedFileViewModel linkedFile, Pr this.executable.bind( switch (command) { - case RENAME_FILE_TO_PATTERN, MOVE_FILE_TO_FOLDER_AND_RENAME -> Bindings.createBooleanBinding( + case RENAME_FILE_TO_PATTERN -> Bindings.createBooleanBinding( () -> !linkedFile.getFile().isOnlineLink() && linkedFile.getFile().findIn(databaseContext, preferencesService.getFilePreferences()).isPresent() && !linkedFile.isGeneratedNameSameAsOriginal(), linkedFile.getFile().linkProperty(), bibEntry.getValue().map(BibEntry::getFieldsObservable).orElse(null)); - case MOVE_FILE_TO_FOLDER -> Bindings.createBooleanBinding( + case MOVE_FILE_TO_FOLDER, MOVE_FILE_TO_FOLDER_AND_RENAME -> Bindings.createBooleanBinding( () -> !linkedFile.getFile().isOnlineLink() && linkedFile.getFile().findIn(databaseContext, preferencesService.getFilePreferences()).isPresent() && !linkedFile.isGeneratedPathSameAsOriginal(), From b8da9cfe400f794b10653d5cead62f44cc5a2d0c Mon Sep 17 00:00:00 2001 From: Anna Date: Sun, 14 Nov 2021 17:16:04 -0600 Subject: [PATCH 02/18] Update FileHelper.java --- src/main/java/org/jabref/model/util/FileHelper.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/org/jabref/model/util/FileHelper.java b/src/main/java/org/jabref/model/util/FileHelper.java index 25509e50c69..160e6ff1029 100644 --- a/src/main/java/org/jabref/model/util/FileHelper.java +++ b/src/main/java/org/jabref/model/util/FileHelper.java @@ -10,6 +10,7 @@ import java.util.Locale; import java.util.Objects; import java.util.Optional; +import java.util.function.BiPredicate; import org.jabref.model.database.BibDatabaseContext; import org.jabref.preferences.FilePreferences; @@ -25,6 +26,10 @@ public class FileHelper { + public static boolean equals(Path left, Path right, BiPredicate equality) { + return equality.test(left, right); + } + /** * Returns the extension of a file or Optional.empty() if the file does not have one (no . in name). * From fcbc66f0ec4da0594e0f73ff7c71dc865602572b Mon Sep 17 00:00:00 2001 From: Anna Date: Sun, 14 Nov 2021 17:16:12 -0600 Subject: [PATCH 03/18] Update LinkedFileViewModel.java --- .../gui/fieldeditors/LinkedFileViewModel.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index 6d3d3ac2988..0806df2a921 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -60,7 +60,7 @@ import org.jabref.model.entry.LinkedFile; import org.jabref.model.strings.StringUtil; import org.jabref.model.util.FileHelper; -import org.jabref.model.util.OptionalUtil; +import org.jabref.preferences.FilePreferences; import org.jabref.preferences.PreferencesService; import de.saxsys.mvvmfx.utils.validation.FunctionBasedValidator; @@ -332,9 +332,29 @@ public boolean isGeneratedNameSameAsOriginal() { * @return true if suggested filepath is same as existing filepath. */ public boolean isGeneratedPathSameAsOriginal() { - Optional newDir = databaseContext.getFirstExistingFileDir(preferences.getFilePreferences()); + FilePreferences filePreferences = preferences.getFilePreferences(); + Optional newDir = databaseContext.getFirstExistingFileDir(filePreferences); + if (newDir.isEmpty()) { + // could not find default path + return false; + } + + // append File directory pattern if exits + String targetDirectoryName = ""; + if (!filePreferences.getFileDirectoryPattern().isEmpty()) { + targetDirectoryName = FileUtil.createDirNameFromPattern( + databaseContext.getDatabase(), + entry, + filePreferences.getFileDirectoryPattern()); + } + Path targetDir = newDir.get().resolve(targetDirectoryName); Optional currentDir = linkedFile.findIn(databaseContext, preferences.getFilePreferences()).map(Path::getParent); + if (currentDir.isEmpty()) { + // Could not find file + return false; + } + Path oldDir = currentDir.get(); BiPredicate equality = (fileA, fileB) -> { try { @@ -343,7 +363,7 @@ public boolean isGeneratedPathSameAsOriginal() { return false; } }; - return OptionalUtil.equals(newDir, currentDir, equality); + return FileHelper.equals(targetDir, oldDir, equality); } public void moveToDefaultDirectoryAndRename() { From b18bbefe163b8c4f36da06e8d17d241b8e5ce90f Mon Sep 17 00:00:00 2001 From: Anna Date: Mon, 15 Nov 2021 23:20:23 -0600 Subject: [PATCH 04/18] Update FileHelper.java Added Javadoc comment --- src/main/java/org/jabref/model/util/FileHelper.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/org/jabref/model/util/FileHelper.java b/src/main/java/org/jabref/model/util/FileHelper.java index 160e6ff1029..ff71c6cb1e2 100644 --- a/src/main/java/org/jabref/model/util/FileHelper.java +++ b/src/main/java/org/jabref/model/util/FileHelper.java @@ -26,6 +26,14 @@ public class FileHelper { + /** + * Returns if the two paths are identical. + * + * @param left one of the two paths for comparison + * @param right the second path for comparison + * @param equality a predicate of two paths arguments + * @return true if the two paths are identical + */ public static boolean equals(Path left, Path right, BiPredicate equality) { return equality.test(left, right); } From b5a1656111832bf98e43c1f6c6b33bd8dd829757 Mon Sep 17 00:00:00 2001 From: Anna Date: Sat, 20 Nov 2021 16:54:18 -0600 Subject: [PATCH 05/18] Update LinkedFileViewModelTest.java --- .../org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java b/src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java index 32967ed0d34..3750ada57fa 100644 --- a/src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java +++ b/src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java @@ -255,6 +255,7 @@ void isNotSamePath() { linkedFile = new LinkedFile("desc", tempFile, "pdf"); databaseContext = mock(BibDatabaseContext.class); when(filePreferences.getFileNamePattern()).thenReturn("[citationkey]"); + when(filePreferences.getFileDirectoryPattern()).thenReturn("[entrytype]"); when(databaseContext.getFirstExistingFileDir(filePreferences)).thenReturn(Optional.of(Path.of("/home"))); LinkedFileViewModel viewModel = new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, externalFileType); @@ -266,6 +267,7 @@ void isSamePath() { linkedFile = new LinkedFile("desc", tempFile, "pdf"); databaseContext = mock(BibDatabaseContext.class); when(filePreferences.getFileNamePattern()).thenReturn("[citationkey]"); + when(filePreferences.getFileDirectoryPattern()).thenReturn("[entrytype]"); when(databaseContext.getFirstExistingFileDir(filePreferences)).thenReturn(Optional.of(tempFile.getParent())); LinkedFileViewModel viewModel = new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, externalFileType); From 2498240b70073fb6c4836b896757fc85944098a3 Mon Sep 17 00:00:00 2001 From: Anna Date: Sat, 20 Nov 2021 17:02:24 -0600 Subject: [PATCH 06/18] Update LinkedFileViewModelTest.java --- .../org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java b/src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java index 3750ada57fa..af3b5a9ae12 100644 --- a/src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java +++ b/src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java @@ -255,7 +255,7 @@ void isNotSamePath() { linkedFile = new LinkedFile("desc", tempFile, "pdf"); databaseContext = mock(BibDatabaseContext.class); when(filePreferences.getFileNamePattern()).thenReturn("[citationkey]"); - when(filePreferences.getFileDirectoryPattern()).thenReturn("[entrytype]"); + when(filePreferences.getFileDirectoryPattern()).thenReturn(""); when(databaseContext.getFirstExistingFileDir(filePreferences)).thenReturn(Optional.of(Path.of("/home"))); LinkedFileViewModel viewModel = new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, externalFileType); @@ -267,7 +267,7 @@ void isSamePath() { linkedFile = new LinkedFile("desc", tempFile, "pdf"); databaseContext = mock(BibDatabaseContext.class); when(filePreferences.getFileNamePattern()).thenReturn("[citationkey]"); - when(filePreferences.getFileDirectoryPattern()).thenReturn("[entrytype]"); + when(filePreferences.getFileDirectoryPattern()).thenReturn(""); when(databaseContext.getFirstExistingFileDir(filePreferences)).thenReturn(Optional.of(tempFile.getParent())); LinkedFileViewModel viewModel = new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, externalFileType); From ced2753755b160506c0295e00d2768d96024160b Mon Sep 17 00:00:00 2001 From: Anna Date: Sat, 20 Nov 2021 17:41:53 -0600 Subject: [PATCH 07/18] Update LinkedFileViewModelTest.java Adds test to test if isGeneratedPathSameAsOriginal takes into consideration File directory pattern --- .../fieldeditors/LinkedFileViewModelTest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java b/src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java index af3b5a9ae12..e4e7d331aef 100644 --- a/src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java +++ b/src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java @@ -1,5 +1,6 @@ package org.jabref.gui.fieldeditors; +import java.io.IOException; import java.net.CookieHandler; import java.net.CookieManager; import java.net.CookiePolicy; @@ -22,6 +23,7 @@ import org.jabref.gui.util.BackgroundTask; import org.jabref.gui.util.CurrentThreadTaskExecutor; import org.jabref.gui.util.TaskExecutor; +import org.jabref.logic.externalfiles.LinkedFileHandler; import org.jabref.logic.net.URLDownload; import org.jabref.logic.xmp.XmpPreferences; import org.jabref.model.database.BibDatabaseContext; @@ -274,6 +276,35 @@ void isSamePath() { assertTrue(viewModel.isGeneratedPathSameAsOriginal()); } + // Tests if isGeneratedPathSameAsOriginal takes into consideration File directory pattern + @Test + void isNotSamePathWithPattern() { + linkedFile = new LinkedFile("desc", tempFile, "pdf"); + System.out.println(tempFile.getParent()); + databaseContext = mock(BibDatabaseContext.class); + when(filePreferences.getFileNamePattern()).thenReturn("[citationkey]"); + when(filePreferences.getFileDirectoryPattern()).thenReturn("[entrytype]"); + when(databaseContext.getFirstExistingFileDir(filePreferences)).thenReturn(Optional.of(tempFile.getParent())); + + LinkedFileViewModel viewModel = new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, externalFileType); + assertFalse(viewModel.isGeneratedPathSameAsOriginal()); + } + + // Tests if isGeneratedPathSameAsOriginal takes into consideration File directory pattern + @Test + void isSamePathWithPattern() throws IOException { + linkedFile = new LinkedFile("desc", tempFile, "pdf"); + databaseContext = mock(BibDatabaseContext.class); + when(filePreferences.getFileNamePattern()).thenReturn("[citationkey]"); + when(filePreferences.getFileDirectoryPattern()).thenReturn("[entrytype]"); + when(databaseContext.getFirstExistingFileDir(filePreferences)).thenReturn(Optional.of(tempFile.getParent())); + + LinkedFileHandler fileHandler = new LinkedFileHandler(linkedFile, entry, databaseContext, filePreferences); + fileHandler.moveToDefaultDirectory(); + + LinkedFileViewModel viewModel = new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, externalFileType); + assertTrue(viewModel.isGeneratedPathSameAsOriginal()); + } // Tests if added parameters to mimeType gets parsed to correct format. @Test From 66a8a7e3c5709b455cddd23706f48e38f8d7effc Mon Sep 17 00:00:00 2001 From: Anna Date: Sat, 20 Nov 2021 18:18:26 -0600 Subject: [PATCH 08/18] Update FileUtilTest.java Adds unit tests for FileHelper.equals --- .../jabref/logic/util/io/FileUtilTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/test/java/org/jabref/logic/util/io/FileUtilTest.java b/src/test/java/org/jabref/logic/util/io/FileUtilTest.java index f1b9d1f76d2..5ddeeac6b8d 100644 --- a/src/test/java/org/jabref/logic/util/io/FileUtilTest.java +++ b/src/test/java/org/jabref/logic/util/io/FileUtilTest.java @@ -10,6 +10,7 @@ import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; +import java.util.function.BiPredicate; import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.model.entry.BibEntry; @@ -383,4 +384,28 @@ void testIsNotBibFile() throws IOException { Path bibFile = Files.createFile(rootDir.resolve("test.pdf")); assertFalse(FileUtil.isBibFile(bibFile)); } + + @Test + void testFilePathNotEqual(){ + BiPredicate equality = (fileA, fileB) -> { + try { + return Files.isSameFile(fileA, fileB); + } catch (IOException e) { + return false; + } + }; + assertFalse(FileHelper.equals(existingTestFile, otherExistingTestFile, equality)); + } + + @Test + void testFilePathEqual(){ + BiPredicate equality = (fileA, fileB) -> { + try { + return Files.isSameFile(fileA, fileB); + } catch (IOException e) { + return false; + } + }; + assertTrue(FileHelper.equals(existingTestFile, existingTestFile, equality)); + } } From 3e6e977db228ca5d5af41482051261f63256cae4 Mon Sep 17 00:00:00 2001 From: Anna Date: Sun, 21 Nov 2021 11:58:04 -0600 Subject: [PATCH 09/18] Update FileUtilTest.java --- src/test/java/org/jabref/logic/util/io/FileUtilTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/jabref/logic/util/io/FileUtilTest.java b/src/test/java/org/jabref/logic/util/io/FileUtilTest.java index 5ddeeac6b8d..8278361760e 100644 --- a/src/test/java/org/jabref/logic/util/io/FileUtilTest.java +++ b/src/test/java/org/jabref/logic/util/io/FileUtilTest.java @@ -8,9 +8,9 @@ import java.util.Arrays; import java.util.List; import java.util.Optional; +import java.util.function.BiPredicate; import java.util.stream.Collectors; import java.util.stream.Stream; -import java.util.function.BiPredicate; import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.model.entry.BibEntry; @@ -386,7 +386,7 @@ void testIsNotBibFile() throws IOException { } @Test - void testFilePathNotEqual(){ + void testFilePathNotEqual() { BiPredicate equality = (fileA, fileB) -> { try { return Files.isSameFile(fileA, fileB); @@ -398,7 +398,7 @@ void testFilePathNotEqual(){ } @Test - void testFilePathEqual(){ + void testFilePathEqual() { BiPredicate equality = (fileA, fileB) -> { try { return Files.isSameFile(fileA, fileB); From a81205e901d67aeb71be7e79924dd3323e05c617 Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 25 Nov 2021 22:10:33 -0500 Subject: [PATCH 10/18] Update LinkedFileViewModelTest.java --- .../org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java b/src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java index e4e7d331aef..6c4ddf69385 100644 --- a/src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java +++ b/src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java @@ -280,7 +280,6 @@ void isSamePath() { @Test void isNotSamePathWithPattern() { linkedFile = new LinkedFile("desc", tempFile, "pdf"); - System.out.println(tempFile.getParent()); databaseContext = mock(BibDatabaseContext.class); when(filePreferences.getFileNamePattern()).thenReturn("[citationkey]"); when(filePreferences.getFileDirectoryPattern()).thenReturn("[entrytype]"); From 4f4739fb8990b21d9db3c03a6ff28b953de39a14 Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 25 Nov 2021 22:13:36 -0500 Subject: [PATCH 11/18] Update LinkedFileViewModel.java --- .../org/jabref/gui/fieldeditors/LinkedFileViewModel.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index 0806df2a921..ec2c4872764 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -333,8 +333,8 @@ public boolean isGeneratedNameSameAsOriginal() { */ public boolean isGeneratedPathSameAsOriginal() { FilePreferences filePreferences = preferences.getFilePreferences(); - Optional newDir = databaseContext.getFirstExistingFileDir(filePreferences); - if (newDir.isEmpty()) { + Optional baseDir = databaseContext.getFirstExistingFileDir(filePreferences); + if (baseDir.isEmpty()) { // could not find default path return false; } @@ -347,7 +347,7 @@ public boolean isGeneratedPathSameAsOriginal() { entry, filePreferences.getFileDirectoryPattern()); } - Path targetDir = newDir.get().resolve(targetDirectoryName); + Path targetDir = baseDir.get().resolve(targetDirectoryName); Optional currentDir = linkedFile.findIn(databaseContext, preferences.getFilePreferences()).map(Path::getParent); if (currentDir.isEmpty()) { From 836819e0d804dde1903a06431f010663045baf27 Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 25 Nov 2021 22:55:03 -0500 Subject: [PATCH 12/18] Update LinkedFileViewModel.java --- .../gui/fieldeditors/LinkedFileViewModel.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index ec2c4872764..7e4e67e8307 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -340,16 +340,15 @@ public boolean isGeneratedPathSameAsOriginal() { } // append File directory pattern if exits - String targetDirectoryName = ""; - if (!filePreferences.getFileDirectoryPattern().isEmpty()) { - targetDirectoryName = FileUtil.createDirNameFromPattern( - databaseContext.getDatabase(), - entry, - filePreferences.getFileDirectoryPattern()); - } + String targetDirectoryName = FileUtil.createDirNameFromPattern( + databaseContext.getDatabase(), + entry, + filePreferences.getFileDirectoryPattern()); + Path targetDir = baseDir.get().resolve(targetDirectoryName); Optional currentDir = linkedFile.findIn(databaseContext, preferences.getFilePreferences()).map(Path::getParent); + System.out.println(linkedFile.findIn(databaseContext, preferences.getFilePreferences())); if (currentDir.isEmpty()) { // Could not find file return false; From 4d710ba6d0d6f1bb390e965726c83a363a14a2b1 Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 25 Nov 2021 22:59:37 -0500 Subject: [PATCH 13/18] Update LinkedFileViewModel.java --- .../java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index 7e4e67e8307..101dee8469e 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -344,11 +344,10 @@ public boolean isGeneratedPathSameAsOriginal() { databaseContext.getDatabase(), entry, filePreferences.getFileDirectoryPattern()); - + Path targetDir = baseDir.get().resolve(targetDirectoryName); Optional currentDir = linkedFile.findIn(databaseContext, preferences.getFilePreferences()).map(Path::getParent); - System.out.println(linkedFile.findIn(databaseContext, preferences.getFilePreferences())); if (currentDir.isEmpty()) { // Could not find file return false; From 03dbdb9795ed1d2008893885671932cd9d906389 Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 25 Nov 2021 23:07:06 -0500 Subject: [PATCH 14/18] Update LinkedFileViewModel.java --- .../org/jabref/gui/fieldeditors/LinkedFileViewModel.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index 101dee8469e..50f27f6bb5e 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -60,6 +60,7 @@ import org.jabref.model.entry.LinkedFile; import org.jabref.model.strings.StringUtil; import org.jabref.model.util.FileHelper; +import org.jabref.model.util.OptionalUtil; import org.jabref.preferences.FilePreferences; import org.jabref.preferences.PreferencesService; @@ -345,14 +346,13 @@ public boolean isGeneratedPathSameAsOriginal() { entry, filePreferences.getFileDirectoryPattern()); - Path targetDir = baseDir.get().resolve(targetDirectoryName); + Optional targetDir = baseDir.map(dir -> dir.resolve(targetDirectoryName)); Optional currentDir = linkedFile.findIn(databaseContext, preferences.getFilePreferences()).map(Path::getParent); if (currentDir.isEmpty()) { // Could not find file return false; } - Path oldDir = currentDir.get(); BiPredicate equality = (fileA, fileB) -> { try { @@ -361,7 +361,7 @@ public boolean isGeneratedPathSameAsOriginal() { return false; } }; - return FileHelper.equals(targetDir, oldDir, equality); + return OptionalUtil.equals(targetDir, currentDir, equality); } public void moveToDefaultDirectoryAndRename() { From da804bd764921f24a1a86d70025e9805d3316aff Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 25 Nov 2021 23:07:25 -0500 Subject: [PATCH 15/18] Update FileHelper.java removed newly added function, which is no longer needed --- src/main/java/org/jabref/model/util/FileHelper.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/main/java/org/jabref/model/util/FileHelper.java b/src/main/java/org/jabref/model/util/FileHelper.java index ff71c6cb1e2..25509e50c69 100644 --- a/src/main/java/org/jabref/model/util/FileHelper.java +++ b/src/main/java/org/jabref/model/util/FileHelper.java @@ -10,7 +10,6 @@ import java.util.Locale; import java.util.Objects; import java.util.Optional; -import java.util.function.BiPredicate; import org.jabref.model.database.BibDatabaseContext; import org.jabref.preferences.FilePreferences; @@ -26,18 +25,6 @@ public class FileHelper { - /** - * Returns if the two paths are identical. - * - * @param left one of the two paths for comparison - * @param right the second path for comparison - * @param equality a predicate of two paths arguments - * @return true if the two paths are identical - */ - public static boolean equals(Path left, Path right, BiPredicate equality) { - return equality.test(left, right); - } - /** * Returns the extension of a file or Optional.empty() if the file does not have one (no . in name). * From c071548751b29d6fa5bdd1f243a6056eac1161d1 Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 25 Nov 2021 23:07:56 -0500 Subject: [PATCH 16/18] Update FileUtilTest.java removed newly added tests for the function no longer exist --- .../jabref/logic/util/io/FileUtilTest.java | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/src/test/java/org/jabref/logic/util/io/FileUtilTest.java b/src/test/java/org/jabref/logic/util/io/FileUtilTest.java index 8278361760e..f1b9d1f76d2 100644 --- a/src/test/java/org/jabref/logic/util/io/FileUtilTest.java +++ b/src/test/java/org/jabref/logic/util/io/FileUtilTest.java @@ -8,7 +8,6 @@ import java.util.Arrays; import java.util.List; import java.util.Optional; -import java.util.function.BiPredicate; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -384,28 +383,4 @@ void testIsNotBibFile() throws IOException { Path bibFile = Files.createFile(rootDir.resolve("test.pdf")); assertFalse(FileUtil.isBibFile(bibFile)); } - - @Test - void testFilePathNotEqual() { - BiPredicate equality = (fileA, fileB) -> { - try { - return Files.isSameFile(fileA, fileB); - } catch (IOException e) { - return false; - } - }; - assertFalse(FileHelper.equals(existingTestFile, otherExistingTestFile, equality)); - } - - @Test - void testFilePathEqual() { - BiPredicate equality = (fileA, fileB) -> { - try { - return Files.isSameFile(fileA, fileB); - } catch (IOException e) { - return false; - } - }; - assertTrue(FileHelper.equals(existingTestFile, existingTestFile, equality)); - } } From f9630b64f8574eb059ac891de24467c946503ec1 Mon Sep 17 00:00:00 2001 From: "Anna (Ruoyu) Qian" Date: Thu, 25 Nov 2021 22:16:33 -0600 Subject: [PATCH 17/18] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6876f448adb..74a22fca276 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve ## [Unreleased] ### Added - +- We fixed an issue where the actions to move a file to a directory were incorrectly disabled. [#7908](https://github.com/JabRef/jabref/issues/7908) - We added confirmation dialog when user wants to close a library where any empty entires are detected. [#8096](https://github.com/JabRef/jabref/issues/8096) - We added import support for CFF files. [#7945](https://github.com/JabRef/jabref/issues/7945) - We added the option to copy the DOI of an entry directly from the context menu copy submenu. [#7826](https://github.com/JabRef/jabref/issues/7826) From ec98c2f5761d9ba95f0983151d4bfde53ae9bc55 Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 25 Nov 2021 23:23:49 -0500 Subject: [PATCH 18/18] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74a22fca276..2de5bba52ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve ## [Unreleased] ### Added -- We fixed an issue where the actions to move a file to a directory were incorrectly disabled. [#7908](https://github.com/JabRef/jabref/issues/7908) + - We added confirmation dialog when user wants to close a library where any empty entires are detected. [#8096](https://github.com/JabRef/jabref/issues/8096) - We added import support for CFF files. [#7945](https://github.com/JabRef/jabref/issues/7945) - We added the option to copy the DOI of an entry directly from the context menu copy submenu. [#7826](https://github.com/JabRef/jabref/issues/7826) @@ -47,6 +47,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve ### Fixed +- We fixed an issue where the actions to move a file to a directory were incorrectly disabled. [#7908](https://github.com/JabRef/jabref/issues/7908) - We fixed an issue where an exception occurred when a linked online file was edited in the entry editor [#8008](https://github.com/JabRef/jabref/issues/8008) - We fixed an issue when checking for a new version when JabRef is used behind a corporate proxy. [#7884](https://github.com/JabRef/jabref/issues/7884) - We fixed some icons that were drawn in the wrong color when JabRef used a custom theme. [#7853](https://github.com/JabRef/jabref/issues/7853)