-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add feature relinking moved file #10954
Conversation
…xception and refactored.
We added file relinking functionality after a file is moved when clicking the "Automatically set file links" button. Implementation based and improved upon work done in closed issue [JabRef#10526]. [JabRef#9798]
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.
I quickly ran through the code to provide initial feedback.
You text says, you would move a file, but your main code does not (which is good). I wonder why an exception is risen in the main code. If JabRef looks up files, there should be no exception thrown to the ultimate caller. Please catch the exception approriatly.
See, if a user moved a file and JabRef cannot relink, it should stay at the old location.
Please also add a test case for the exceptions - if possible. You could try https://github.com/google/jimfs for it.
You added a single test, not sure if that is enough. Maybe add the test case described int he issue. There is folder-a
and I did not find the term folder-a
in your code.
@@ -21,6 +21,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv | |||
- When pasting HTML into the abstract or a comment field, the hypertext is automatically converted to Markdown. [#10558](https://github.com/JabRef/jabref/issues/10558) | |||
- We added the possibility to redownload files that had been present but are no longer in the specified location. [#10848](https://github.com/JabRef/jabref/issues/10848) | |||
- We added the citation key pattern `[camelN]`. Equivalent to the first N words of the `[camel]` pattern. | |||
- We added file relinking functionality after a file is moved when clicking the "Automatically set file links" button. Implementation based and improved upon work done in closed issue [#10526]. [#9798] |
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.
CHANGELOG is only for user-facing changes. You can just remove the last part.
Please add a full link to the issue as shown in the other lines of the CHANGELOG.md
@@ -188,7 +189,7 @@ private Optional<ParserResult> importFile(Path file, String importFormat) { | |||
} | |||
} | |||
|
|||
public void processArguments() { | |||
public void processArguments() throws FileNotFoundException { |
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.
Please add JavaDoc @throws
to state when this exception is thrown.
It is strange that upon startup of JabRef something is happening.
The issue itself has two headings "First implementation" and "Follow-up implementation". I cannot relate something happening on startup at each of the headings. Maybe you can explain?
fileExceptions.add(exception); | ||
} | ||
|
||
public List<BibEntry> getChangedEntries() { | ||
return changedEntries; | ||
} | ||
|
||
public List<IOException> getFileExceptions() { | ||
public List<String> getFileExceptions() { |
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.
Why reduction to weaker type? String
should not be used if more finer-grainded data types are available.
if (changed) { | ||
result.addBibEntry(entry); | ||
} | ||
// Run Relinking Process |
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 comment does not say anything... You can extract a method to group statements together.
The algorithm itself should be explained
List<String> exceptions = results.exceptions(); | ||
assertEquals(Collections.emptyList(), exceptions); | ||
|
||
// Change Entry to match required result and run method on bib |
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.
"required result" is too unspecifiy. Explain, what is the intention.
|
||
for (LinkedFile file : listlinked) { | ||
Path path = Path.of(file.getLink()); | ||
if (!Files.exists(path)) { |
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 incomplete.
Use org.jabref.logic.util.io.FileUtil#find(org.jabref.model.database.BibDatabaseContext, java.lang.String, org.jabref.preferences.FilePreferences)
Reason: JabRef has multiple directories to store files. See https://docs.jabref.org/finding-sorting-and-cleaning-entries/filelinks#directories-for-files for an explanation.
|
||
String fileNameString = filePath.getFileName().toString(); | ||
|
||
List<Path> fileLocations = searchFileInDirectoryAndSubdirectories(Path.of(directoryPath), fileNameString); |
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.
Wrong start. Search in databaseContext.getFileDirectories(filePreferences)
only.
exceptions.add(fileNameString); | ||
throw new FileNotFoundException(); |
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.
No exception here. Just leave the link as is.
Exceptions are huge derivations from the normal results.
See, if I have a library wtih 10000 PDFs, moved 20 files and 19 can be relinked, the whole processing should not be stopped if one file cannot be found.
It is OK to report a list of files which could not be relinked. If this is hard, then just log the non-found files.
.filter(path -> path.getFileName().toString().equals(targetFileName)) | ||
.forEach(paths::add); | ||
} catch (IOException e) { | ||
// Handle any exceptions 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.
This seems to be ChatGPT generated.
You can simply log the exception.
List<Path> output = new ArrayList<>(); | ||
for (Path p : paths) { | ||
output.add(p); | ||
} | ||
return output; |
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.
What is this?
Why not return paths
?
@@ -75,7 +79,7 @@ public LinkFilesResult linkAssociatedFiles(List<BibEntry> entries, NamedCompound | |||
try { | |||
linkedFiles = findAssociatedNotLinkedFiles(entry); | |||
} catch (IOException e) { | |||
result.addFileException(e); | |||
result.addFileException(String.valueOf(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.
Can you please describe, why this change seems necessary?
At #9798 (comment) the authors said, they won't continue. |
Closes #9798
We implemented a solution for the first implementation mentioned in the issue. This implementation is based on the work made in closed issue #10526. Their code was incomplete based on the suggestions made and we implemented those changes. Refactored the code and associated classes to allow for a FileNotFoundException. The class performs a move operation more traditionally than copying and deleting as previously. The relinkingFiles method now returns a list of not found file names. The test setup has been altered to not affect all tests. The searchFileInDirectoryAndSubdirectories method now returns List instead of string. Additional tests were made for the class.
Changes were produced primarily through test-driven development, wherein functionality was added or adapted after testing its associated mechanics.
We would love to hear your feedback on what is done so far. Were there limitations with the work done in issue #10526? After all we saw the comment about implementing a FileWatcher system recently, and were curious if that is a path worth pursuing still?
Mandatory checks
CHANGELOG.md
described in a way that is understandable for the average user (if applicable)