-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Relink moved files [Find Unlinked Files part] #13842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Note that your PR will not be reviewed/accepted until you have gone through the mandatory checks in the description and marked each of them them exactly in the format of |
jabgui/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogViewModel.java
Show resolved
Hide resolved
jabgui/src/test/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogViewModelTest.java
Outdated
Show resolved
Hide resolved
jabgui/src/test/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogViewModelTest.java
Outdated
Show resolved
Hide resolved
|
jabgui/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogViewModel.java
Outdated
Show resolved
Hide resolved
| List<LinkedFile> filesToAdd = new ArrayList<>(); | ||
|
|
||
| for (LinkedFile brokenLink : currentFiles) { | ||
| if (brokenLink.findIn(bibDatabase, preferences.getFilePreferences()).isPresent()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this just duplicated? You add all those to entriesWithBrokenLInks that are not present so why checking them again here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not all.. only entries having at least one broken link... though it could be improved thnks for letting know
jabgui/src/test/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogViewModelTest.java
Outdated
Show resolved
Hide resolved
| @Test | ||
| void fixBrokenLinksInLargeDatabase(@TempDir Path tempDir) throws IOException { | ||
| Path testRoot = tempDir.resolve("test"); | ||
| List<BibEntry> entries = new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use modern Java data structures. Instead of using new ArrayList<>(), use List.of() for creating an empty list.
jabgui/src/test/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogViewModelTest.java
Show resolved
Hide resolved
jabgui/src/test/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogViewModelTest.java
Show resolved
Hide resolved
|
Your pull request needs to link an issue correctly. To ease organizational workflows, please link this pull-request to the issue with syntax as described in https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue:
Examples
|
|
@trag-bot didn't find any issues in the code! ✅✨ |
|
Is this PR ready for review? |
I did changes could anyone please review it? Thanks. |
|
Great, we will look into it. |
|
Your code currently does not meet JabRef's code guidelines. We use OpenRewrite to ensure "modern" Java coding practices. You can see which checks are failing by locating the box "Some checks were not successful" on the pull request page. To see the test output, locate "Source Code Tests / OpenRewrite (pull_request)" and click on it. The issues found can be automatically fixed. Please execute the gradle task |
koppor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this - and your patience.
Attached some comments 😅
| // Verify specific file links were updated to correct relative paths | ||
| assertEquals(Optional.of(newPdf1Location.toString()), entry1.getFiles().stream().filter(file -> file.getLink().equals(newPdf1Location.toString())).findFirst().map(LinkedFile::getLink)); | ||
| assertEquals(Optional.of(newDocLocation.toString()), entry1.getFiles().stream().filter(file -> file.getLink().equals(newDocLocation.toString())).findFirst().map(LinkedFile::getLink)); | ||
| assertEquals(Optional.of(newPdf2Location.toString()), entry2.getFiles().stream().filter(file -> file.getLink().equals(newPdf2Location.toString())).findFirst().map(LinkedFile::getLink)); | ||
| assertEquals(Optional.of(newTxtLocation.toString()), entry2.getFiles().stream().filter(file -> file.getLink().equals(newTxtLocation.toString())).findFirst().map(LinkedFile::getLink)); | ||
| assertEquals(Optional.of(newPptLocation.toString()), entry3.getFiles().stream().filter(file -> file.getLink().equals(newPptLocation.toString())).findFirst().map(LinkedFile::getLink)); | ||
|
|
||
| // Verify that files with similar names but different extensions were not incorrectly matched | ||
| assertEquals(Optional.empty(), entry1.getFiles().stream().filter(file -> file.getLink().contains("research-paper.txt")).findFirst().map(LinkedFile::getLink)); | ||
|
|
||
| assertEquals(Optional.empty(), entry2.getFiles().stream().filter(file -> file.getLink().contains("thesis.docx")).findFirst().map(LinkedFile::getLink)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cant the whole BibDatabase be compared? - If not, please add a code comment why there are multiple assert statements.
| } | ||
|
|
||
| @Test | ||
| void fixBrokenLinksInLargeDatabase(@TempDir Path tempDir) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not what the test does. The test checks the size of the result list -- Please adapt the test name
| void fixBrokenLinksInLargeDatabase(@TempDir Path tempDir) throws IOException { | |
| void correctCountOfUnlinkedFiles(@TempDir Path tempDir) throws IOException { |
| BibEntry entry = new BibEntry(StandardEntryType.Misc); | ||
| LinkedFile brokenLink = new LinkedFile("", oldPath.toString(), "PDF"); | ||
| entry.addFile(brokenLink); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if .withFiles could be used. - also in the other tests. -- Use it with List.of(...) and do the new LinkedFile inside.
| // For testing purposes | ||
| public int resultListSize() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // For testing purposes | |
| public int resultListSize() { | |
| // @VisibleForTesting | |
| int resultListSize() { |
| entry.setFiles(currentFiles); | ||
| } | ||
| } catch (IOException e) { | ||
| LOGGER.error("Error finding associated files for entry", e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if the data structures are consistent in all error cases. Shouldn't the try/catch be more close to the points where the exception can occur and an appropriate handling take place?
Are results consistent in all cases? Maybe yes, but that deserves a code comment.
| resultList.clear(); | ||
| resultList.addAll(results); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a Java comment - why this is done.
| return linkedFiles; | ||
| return linkedFiles.stream().toList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels not OK - promising a list in the method contract, but internally a set with a random order.
Please convert the result type to Set and also adapt the callers. Then, you will see if there is a list assumption anywhere -- and if there should be an ordering done. If an ordering needs to be done, either do it here (Maybe, use SortedSet). Or do it at the place where sorting is needed.
| treeRootProperty.setValue(Optional.empty()); | ||
| } | ||
|
|
||
| public void findAndFixBrokenLinks(Path searchDirectory) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method needs a JavaDoc comment
Maybe also the name needs to be adjusted --> fixBrokenLinksAndReturnStillBroken
Is it possible NOT to use a global variable resultList?
Finally, this should go to org.jabref.logic.util.io.FileUtil, because, it is NOT a UI thing, but a logic (which could be used by JabKit, too)
Closes #9798
This PR relinks files, if it has been moved by user.
Steps to test
Mandatory checks
CHANGELOG.mdin a way that is understandable for the average user (if change is visible to the user)