-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix lookup fulltext document not finding files #5216
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
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2731f8f
Fix issue #3874
PedroPerozin 47656e7
Fix travis
PedroPerozin 2fc1c49
Fix checkstyle Issue #3874
PedroPerozin ec3ad69
Fix import order Issue #3874
PedroPerozin 88118f4
Change variable name Issue#3874
PedroPerozin 33fb6c5
Merge branch 'master' of git://github.com/PedroPerozin/jabref into fi…
Siedlerchr 4ef1460
Merge remote-tracking branch 'upstream/master' into fixlookupfulltext
Siedlerchr d2c4724
Fulltext lookup now searches for local files before
Siedlerchr 1846b24
Merge remote-tracking branch 'upstream/master' into fixlookupfulltext
Siedlerchr f81fa9e
fix formatting
Siedlerchr 5559f9c
Fixes l10n
Siedlerchr 4f079a3
fix indendation, add comment
Siedlerchr a0965dc
Merge remote-tracking branch 'upstream/master' into fixlookupfulltext
Siedlerchr 14ade56
separate find fulltext and download methods
Siedlerchr eed70a5
fix indent to make the intellij people happy...
Siedlerchr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
@@ -16,6 +17,7 @@ | |
import org.jabref.gui.externalfiletype.ExternalFileTypes; | ||
import org.jabref.gui.fieldeditors.LinkedFileViewModel; | ||
import org.jabref.gui.fieldeditors.LinkedFilesEditorViewModel; | ||
import org.jabref.gui.undo.NamedCompound; | ||
import org.jabref.gui.util.BackgroundTask; | ||
import org.jabref.logic.importer.FulltextFetchers; | ||
import org.jabref.logic.l10n.Localization; | ||
|
@@ -38,6 +40,7 @@ public class FindFullTextAction extends SimpleCommand { | |
|
||
private final BasePanel basePanel; | ||
private final DialogService dialogService; | ||
private final FulltextFetchers fetchers = new FulltextFetchers(Globals.prefs.getImportFormatPreferences()); | ||
|
||
public FindFullTextAction(BasePanel basePanel) { | ||
this.basePanel = basePanel; | ||
|
@@ -55,12 +58,11 @@ public void execute() { | |
if (basePanel.getSelectedEntries().size() >= WARNING_LIMIT) { | ||
boolean confirmDownload = dialogService.showConfirmationDialogAndWait( | ||
Localization.lang("Look up full text documents"), | ||
Localization.lang( | ||
"You are about to look up full text documents for %0 entries.", | ||
String.valueOf(basePanel.getSelectedEntries().size())) + "\n" | ||
+ Localization.lang("JabRef will send at least one request per entry to a publisher.") | ||
+ "\n" | ||
+ Localization.lang("Do you still want to continue?"), | ||
Localization.lang("You are about to look up full text documents for %0 entries.", | ||
String.valueOf(basePanel.getSelectedEntries().size())) + "\n" | ||
+ Localization.lang("JabRef will send at least one request per entry to a publisher.") | ||
+ "\n" | ||
+ Localization.lang("Do you still want to continue?"), | ||
Localization.lang("Look up full text documents"), | ||
Localization.lang("Cancel")); | ||
|
||
|
@@ -70,31 +72,43 @@ public void execute() { | |
} | ||
} | ||
|
||
Task<Map<BibEntry, Optional<URL>>> findFullTextsTask = new Task<Map<BibEntry, Optional<URL>>>() { | ||
lookupFullText(); | ||
} | ||
|
||
private void lookupFullText() { | ||
AutoSetFileLinksUtil util = new AutoSetFileLinksUtil(basePanel.getBibDatabaseContext(), Globals.prefs.getFilePreferences(), Globals.prefs.getAutoLinkPreferences(), ExternalFileTypes.getInstance()); | ||
|
||
Task<List<BibEntry>> linkFilesTask = new Task<List<BibEntry>>() { | ||
|
||
@Override | ||
protected Map<BibEntry, Optional<URL>> call() { | ||
protected List<BibEntry> call() { | ||
return util.linkAssociatedFiles(basePanel.getSelectedEntries(), new NamedCompound("")); | ||
} | ||
|
||
@Override | ||
protected void succeeded() { | ||
Map<BibEntry, Optional<URL>> downloads = new ConcurrentHashMap<>(); | ||
int count = 0; | ||
for (BibEntry entry : basePanel.getSelectedEntries()) { | ||
FulltextFetchers fetchers = new FulltextFetchers(Globals.prefs.getImportFormatPreferences()); | ||
downloads.put(entry, fetchers.findFullTextPDF(entry)); | ||
updateProgress(++count, basePanel.getSelectedEntries().size()); | ||
|
||
for (BibEntry entry : getValue()) { | ||
if (entry.getFiles().isEmpty()) { | ||
downloads.put(entry, fetchers.findFullTextPDF(entry)); | ||
} else { | ||
dialogService.notify(Localization.lang("Full text document found already on disk for entry %0. Not downloaded again.", | ||
entry.getCiteKeyOptional().orElse(Localization.lang("undefined")))); | ||
} | ||
} | ||
return downloads; | ||
downloadMissingFullTexts(downloads); | ||
} | ||
}; | ||
|
||
findFullTextsTask.setOnSucceeded(value -> downloadFullTexts(findFullTextsTask.getValue())); | ||
|
||
dialogService.showProgressDialogAndWait( | ||
Localization.lang("Look up full text documents"), | ||
Localization.lang("Looking for full text document..."), | ||
findFullTextsTask); | ||
dialogService.showProgressDialogAndWait(Localization.lang("Look up full text documents"), | ||
Localization.lang("Looking for full text document..."), | ||
linkFilesTask); | ||
Globals.TASK_EXECUTOR.execute(linkFilesTask); | ||
|
||
Globals.TASK_EXECUTOR.execute(findFullTextsTask); | ||
} | ||
|
||
private void downloadFullTexts(Map<BibEntry, Optional<URL>> downloads) { | ||
private void downloadMissingFullTexts(Map<BibEntry, Optional<URL>> downloads) { | ||
for (Map.Entry<BibEntry, Optional<URL>> download : downloads.entrySet()) { | ||
BibEntry entry = download.getKey(); | ||
Optional<URL> result = download.getValue(); | ||
|
@@ -104,16 +118,17 @@ private void downloadFullTexts(Map<BibEntry, Optional<URL>> downloads) { | |
if (!dir.isPresent()) { | ||
|
||
dialogService.showErrorDialogAndWait(Localization.lang("Directory not found"), | ||
Localization.lang("Main file directory not set!") + " " + Localization.lang("Preferences") | ||
+ " -> " + Localization.lang("File")); | ||
Localization.lang("Main file directory not set!") + " " | ||
+ Localization.lang("Preferences") | ||
+ " -> " + Localization.lang("File")); | ||
return; | ||
} | ||
//Download and link full text | ||
addLinkedFileFromURL(result.get(), entry, dir.get()); | ||
|
||
} else { | ||
dialogService.notify(Localization.lang("No full text document found for entry %0.", | ||
entry.getCiteKeyOptional().orElse(Localization.lang("undefined")))); | ||
entry.getCiteKeyOptional().orElse(Localization.lang("undefined")))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't change the indent. |
||
} | ||
} | ||
} | ||
|
@@ -132,33 +147,33 @@ private void addLinkedFileFromURL(URL url, BibEntry entry, Path targetDirectory) | |
if (!entry.getFiles().contains(newLinkedFile)) { | ||
|
||
LinkedFileViewModel onlineFile = new LinkedFileViewModel( | ||
newLinkedFile, | ||
Siedlerchr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
entry, | ||
basePanel.getBibDatabaseContext(), | ||
Globals.TASK_EXECUTOR, | ||
dialogService, | ||
JabRefPreferences.getInstance().getXMPPreferences(), | ||
JabRefPreferences.getInstance().getFilePreferences(), | ||
ExternalFileTypes.getInstance()); | ||
newLinkedFile, | ||
entry, | ||
basePanel.getBibDatabaseContext(), | ||
Globals.TASK_EXECUTOR, | ||
dialogService, | ||
JabRefPreferences.getInstance().getXMPPreferences(), | ||
JabRefPreferences.getInstance().getFilePreferences(), | ||
ExternalFileTypes.getInstance()); | ||
|
||
try { | ||
URLDownload urlDownload = new URLDownload(newLinkedFile.getLink()); | ||
BackgroundTask<Path> downloadTask = onlineFile.prepareDownloadTask(targetDirectory, urlDownload); | ||
downloadTask.onSuccess(destination -> { | ||
LinkedFile downloadedFile = LinkedFilesEditorViewModel.fromFile( | ||
destination, | ||
Siedlerchr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
basePanel.getBibDatabaseContext().getFileDirectoriesAsPaths(JabRefPreferences.getInstance().getFilePreferences()), ExternalFileTypes.getInstance()); | ||
destination, | ||
basePanel.getBibDatabaseContext().getFileDirectoriesAsPaths(JabRefPreferences.getInstance().getFilePreferences()), ExternalFileTypes.getInstance()); | ||
entry.addFile(downloadedFile); | ||
dialogService.notify(Localization.lang("Finished downloading full text document for entry %0.", | ||
entry.getCiteKeyOptional().orElse(Localization.lang("undefined")))); | ||
Siedlerchr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
entry.getCiteKeyOptional().orElse(Localization.lang("undefined")))); | ||
}); | ||
Globals.TASK_EXECUTOR.execute(downloadTask); | ||
} catch (MalformedURLException exception) { | ||
dialogService.showErrorDialogAndWait(Localization.lang("Invalid URL"), exception); | ||
} | ||
} else { | ||
dialogService.notify(Localization.lang("Full text document for entry %0 already linked.", | ||
entry.getCiteKeyOptional().orElse(Localization.lang("undefined")))); | ||
Siedlerchr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
entry.getCiteKeyOptional().orElse(Localization.lang("undefined")))); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.