-
-
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
Rework AutoSetFileLinks #3368
Rework AutoSetFileLinks #3368
Conversation
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.
The code looks good to me, besides some smaller points. However, I have to admit that I don't really understand what this auto-set method does in detail. Thus I would recommend to do a bit of refactoring, extract all the logic code to a new class in logic and add tests for this new class. I know this is additional work, but in view of the recent issues related to the autolink feature, tests would be a huge help.
return file.isPresent() && Files.isSameFile(file.get(), foundFile); | ||
} catch (IOException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); |
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 proper logging here.
|
||
foundAny = true; | ||
Optional<ExternalFileType> type = FileHelper.getFileExtension(foundFile) | ||
.map(extension -> ExternalFileTypes.getInstance().getExternalFileTypeByExt(extension)) |
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 flatmap instead?
try { | ||
return file.isPresent() && Files.isSameFile(file.get(), foundFile); | ||
} catch (IOException e) { | ||
// TODO Auto-generated catch block |
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.
proper logging
@@ -165,14 +166,25 @@ public void bindToEntry(BibEntry entry) { | |||
List<Path> newFiles = fileFinder.findAssociatedFiles(entry, dirs, extensions); | |||
|
|||
List<LinkedFileViewModel> result = new ArrayList<>(); | |||
for (Path newFile : newFiles) { | |||
boolean alreadyLinked = files.get().stream() | |||
for (Path foundFile : newFiles) { |
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 code now seems to have a huge overlap with the above changes. Can you please try to extract the common code?
Only call setFiles when pressing F7 Fix javafx thread error
use streams in externalfiletype
* upstream/master: Refactorings (#3370) # Conflicts: # src/main/java/org/jabref/gui/externalfiles/AutoSetLinks.java # src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java
@tobiasdiez I now moved the common code to an own method in a class in the gui. |
* upstream/master: revert wrongly commited changes # Conflicts: # src/main/java/org/jabref/gui/externalfiles/AutoSetLinks.java # src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java
String strType = type.isPresent() ? type.get().getName() : ""; | ||
|
||
LinkedFile linkedFile = new LinkedFile("", foundFile.toString(), strType); | ||
linkedFiles.put(entryFilePair.getKey(), linkedFile); |
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.
If I see it correctly, we are only returning one file per entry although the file finder may find more than 1, right?
Personally, I would restructure the code a bit more: instead of calling findassociatedNotLinkedFiles(List<BibEntry> entries,...
in the method findassociatedNotLinkedFiles(BibEntry entry,...
, I would iterate over all bib entries and call the method for on entry, i.e.
findassociatedNotLinkedFiles(List<BibEntry> entries) {
for(entry in entries) {
append(findassociatedNotLinkedFiles(entry));
}
}
Or is there is good reason to not do this?
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 changed the code so that multiple files will be added, except if there already exists the same file. That's why I return a map now
In the lines above I iterate over all pairs of entries and files
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.
Sorry, I don't really understand what you mean. Since you return a map, there is by definition only one returned file per entry (since the key in the map is unique). What you need is a multimap (we use a library that provides these...no idea which...guava?)
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.
Ah yes, did not have this in mind. Will think about another solution
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 think the code gets considerably more easy if you just do the check for one entry (and not a collection) and return a list of to-be-added links. Then the caller can iterate over it.
Thanks for the further refactoring. The code looks better now! Concerning the tests, you should be able to extract |
Thanks for the hints. I was no able to create a test and to faciliate the code |
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.
Thanks for the quick follow-ups! The code looks good to me now.
* upstream/master: Rework AutoSetFileLinks (#3368) revert wrongly commited changes Refactorings (#3370) Fix freezing when running cleanup file operations like rename (#3315) This additional style setting for IDEA (#3355) Fix checkstyle Add proper equals to content selector Source tab entry duplication (#3360) Use CITE_COMMENT not only for external latex editors but also for cop… (#3351) Updating with new translations (#3348) Upgrade error-prone (#3350) Jabref_pt_BR partially updated (#3349) Delete unused code Extract difference finder from gui to logic Used late initialization for context menus (#3340) Remove unnecessary EntrySorter Move existing code to gui and rename change classes to view model Small code improvements
* upstream/master: (79 commits) Update richtext and flowless (#3386) Source tab: hide notification pane when code is correct again (#3387) Titles are optional at crossref (#3378) Update entry for every change in the source panel (#3366) Rework AutoSetFileLinks (#3368) revert wrongly commited changes Refactorings (#3370) Fix freezing when running cleanup file operations like rename (#3315) This additional style setting for IDEA (#3355) Fix checkstyle Add proper equals to content selector Source tab entry duplication (#3360) Use CITE_COMMENT not only for external latex editors but also for cop… (#3351) Updating with new translations (#3348) Upgrade error-prone (#3350) Jabref_pt_BR partially updated (#3349) Delete unused code Extract difference finder from gui to logic Used late initialization for context menus (#3340) Fix NPE when calling with bib file as cmd argument (#3343) ...
* upstream/master: (22 commits) Improve SyncLang.py (#3184) Config intellj code style to adhere to empty lines checkstyle rule (#3365) Don't list same look and feels more than once (#3393) progessdialog and result table are now shown correclty on copy files Export pdf/linked files (#3147) Added checking integrity dialog (#3388) Update richtext and flowless (#3386) Source tab: hide notification pane when code is correct again (#3387) Titles are optional at crossref (#3378) Update entry for every change in the source panel (#3366) Rework AutoSetFileLinks (#3368) revert wrongly commited changes Refactorings (#3370) Fix freezing when running cleanup file operations like rename (#3315) This additional style setting for IDEA (#3355) Fix checkstyle Add proper equals to content selector Delete unused code Extract difference finder from gui to logic Remove unnecessary EntrySorter ... # Conflicts: # src/main/java/org/jabref/gui/entryeditor/SourceTab.java
* upstream/master: (26 commits) Fix static localized text (#3400) Fix problems in source editor (#3398) Fix MathSciNet fetcher (#3402) Fix NPE when saving new file Improve SyncLang.py (#3184) Config intellj code style to adhere to empty lines checkstyle rule (#3365) Don't list same look and feels more than once (#3393) progessdialog and result table are now shown correclty on copy files Export pdf/linked files (#3147) Added checking integrity dialog (#3388) Update richtext and flowless (#3386) Source tab: hide notification pane when code is correct again (#3387) Titles are optional at crossref (#3378) Update entry for every change in the source panel (#3366) Rework AutoSetFileLinks (#3368) revert wrongly commited changes Refactorings (#3370) Fix freezing when running cleanup file operations like rename (#3315) This additional style setting for IDEA (#3355) Fix checkstyle ... # Conflicts: # CHANGELOG.md
Fixes #3346
gradle localizationUpdate
?