Rework AutoSetFileLinks#3368
Conversation
tobiasdiez
left a comment
There was a problem hiding this comment.
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(); |
|
|
||
| foundAny = true; | ||
| Optional<ExternalFileType> type = FileHelper.getFileExtension(foundFile) | ||
| .map(extension -> ExternalFileTypes.getInstance().getExternalFileTypeByExt(extension)) |
| try { | ||
| return file.isPresent() && Files.isSameFile(file.get(), foundFile); | ||
| } catch (IOException e) { | ||
| // TODO Auto-generated catch block |
| 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.
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.
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.
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.
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.
Ah yes, did not have this in mind. Will think about another solution
There was a problem hiding this comment.
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 |
tobiasdiez
left a comment
There was a problem hiding this comment.
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?