Skip to content
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

Merged
merged 14 commits into from
Oct 31, 2017
Merged

Rework AutoSetFileLinks #3368

merged 14 commits into from
Oct 31, 2017

Conversation

Siedlerchr
Copy link
Member

@Siedlerchr Siedlerchr commented Oct 28, 2017

Fixes #3346

  • Change in CHANGELOG.md described
  • Tests created for changes
  • Screenshots added (for bigger UI changes)
  • Manually tested changed features in running JabRef
  • Check documentation status (Issue created for outdated help page at help.jabref.org?)
  • If you changed the localization: Did you run gradle localizationUpdate?

@Siedlerchr Siedlerchr added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Oct 28, 2017
Copy link
Member

@tobiasdiez tobiasdiez left a 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();
Copy link
Member

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))
Copy link
Member

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
Copy link
Member

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) {
Copy link
Member

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?

TODO: remove duplicate findings
Only call setFiles when pressing F7
Fix javafx thread error
use streams in externalfiletype
remove javadoc params
* upstream/master:
  Refactorings (#3370)

# Conflicts:
#	src/main/java/org/jabref/gui/externalfiles/AutoSetLinks.java
#	src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java
@Siedlerchr
Copy link
Member Author

@tobiasdiez I now moved the common code to an own method in a class in the gui.
It can't be moved to logic because it depends on ExternalFileType
I tried adding a test for it, but even with extensive mocking, ExternalFileTypes are again the problem - Because it's a singleton class...Mockito is not able to mock it.

* 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);
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

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?)

Copy link
Member Author

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

Copy link
Member

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.

@tobiasdiez
Copy link
Member

Thanks for the further refactoring. The code looks better now!

Concerning the tests, you should be able to extract ExternalFileTypes.getInstance() to a method parameter and then simply pass a mock(ExternalFileTypes.class) in the test.

@Siedlerchr
Copy link
Member Author

Thanks for the hints. I was no able to create a test and to faciliate the code

Copy link
Member

@tobiasdiez tobiasdiez left a 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.

@Siedlerchr Siedlerchr merged commit 551cb91 into master Oct 31, 2017
@Siedlerchr Siedlerchr deleted the autofilelink branch October 31, 2017 10:09
Siedlerchr added a commit that referenced this pull request Oct 31, 2017
* 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
Siedlerchr added a commit that referenced this pull request Nov 1, 2017
* 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)
  ...
Siedlerchr added a commit that referenced this pull request Nov 3, 2017
* 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
Siedlerchr added a commit that referenced this pull request Nov 4, 2017
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants