From 2731f8f6a38041d50bfde6e898904aca739929c5 Mon Sep 17 00:00:00 2001 From: pedroperozin Date: Thu, 11 Jul 2019 16:25:55 -0300 Subject: [PATCH 01/11] Fix issue #3874 --- .../jabref/gui/externalfiles/FindFullTextAction.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java index 4e47d41b61d..d0967135422 100644 --- a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java +++ b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java @@ -70,14 +70,20 @@ public void execute() { } } - Task>> findFullTextsTask = new Task>>() { + Task>> findFullTextsTask = new Task>>() { @Override protected Map> call() { Map> downloads = new ConcurrentHashMap<>(); int count = 0; + AutoSetFileLinksUtil util = new AutoSetFileLinksUtil(basePanel.getBibDatabaseContext(), Globals.prefs.getFilePreferences(), Globals.prefs.getAutoLinkPreferences(), ExternalFileTypes.getInstance()); + util.linkAssociatedFiles(basePanel.getSelectedEntries(), new NamedCompound("")); + for (BibEntry entry : basePanel.getSelectedEntries()) { - FulltextFetchers fetchers = new FulltextFetchers(Globals.prefs.getImportFormatPreferences()); - downloads.put(entry, fetchers.findFullTextPDF(entry)); + List l = entry.getFiles(); + if(l.isEmpty()){ + FulltextFetchers fetchers = new FulltextFetchers(Globals.prefs.getImportFormatPreferences()); + downloads.put(entry, fetchers.findFullTextPDF(entry)); + } updateProgress(++count, basePanel.getSelectedEntries().size()); } return downloads; From 47656e71d0c34ce7a841af2bfb96444ff9cab1a8 Mon Sep 17 00:00:00 2001 From: pedroperozin Date: Thu, 11 Jul 2019 16:35:08 -0300 Subject: [PATCH 02/11] Fix travis --- .../java/org/jabref/gui/externalfiles/FindFullTextAction.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java index d0967135422..e1b08da92c3 100644 --- a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java +++ b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java @@ -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; @@ -17,6 +18,7 @@ import org.jabref.gui.fieldeditors.LinkedFileViewModel; import org.jabref.gui.fieldeditors.LinkedFilesEditorViewModel; import org.jabref.gui.util.BackgroundTask; +import org.jabref.gui.undo.NamedCompound; import org.jabref.logic.importer.FulltextFetchers; import org.jabref.logic.l10n.Localization; import org.jabref.logic.net.URLDownload; From 2fc1c493d7e29b85676135f4d7b70144e508aabd Mon Sep 17 00:00:00 2001 From: pedroperozin Date: Thu, 11 Jul 2019 16:47:11 -0300 Subject: [PATCH 03/11] Fix checkstyle Issue #3874 --- .../java/org/jabref/gui/externalfiles/FindFullTextAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java index e1b08da92c3..e331fcbface 100644 --- a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java +++ b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java @@ -82,7 +82,7 @@ protected Map> call() { for (BibEntry entry : basePanel.getSelectedEntries()) { List l = entry.getFiles(); - if(l.isEmpty()){ + if (l.isEmpty()) { FulltextFetchers fetchers = new FulltextFetchers(Globals.prefs.getImportFormatPreferences()); downloads.put(entry, fetchers.findFullTextPDF(entry)); } From ec3ad6915f24bc054da8ab39a1c81d51fee75264 Mon Sep 17 00:00:00 2001 From: pedroperozin Date: Thu, 11 Jul 2019 16:52:37 -0300 Subject: [PATCH 04/11] Fix import order Issue #3874 --- .../java/org/jabref/gui/externalfiles/FindFullTextAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java index e331fcbface..3f9354d3934 100644 --- a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java +++ b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java @@ -17,8 +17,8 @@ import org.jabref.gui.externalfiletype.ExternalFileTypes; import org.jabref.gui.fieldeditors.LinkedFileViewModel; import org.jabref.gui.fieldeditors.LinkedFilesEditorViewModel; -import org.jabref.gui.util.BackgroundTask; import org.jabref.gui.undo.NamedCompound; +import org.jabref.gui.util.BackgroundTask; import org.jabref.logic.importer.FulltextFetchers; import org.jabref.logic.l10n.Localization; import org.jabref.logic.net.URLDownload; From 88118f43c6453d2f77652fca9d53d53419cc56fc Mon Sep 17 00:00:00 2001 From: pedroperozin Date: Thu, 11 Jul 2019 17:09:16 -0300 Subject: [PATCH 05/11] Change variable name Issue#3874 --- .../java/org/jabref/gui/externalfiles/FindFullTextAction.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java index 3f9354d3934..4e0d3010f2e 100644 --- a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java +++ b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java @@ -81,8 +81,8 @@ protected Map> call() { util.linkAssociatedFiles(basePanel.getSelectedEntries(), new NamedCompound("")); for (BibEntry entry : basePanel.getSelectedEntries()) { - List l = entry.getFiles(); - if (l.isEmpty()) { + List fileList = entry.getFiles(); + if (fileList.isEmpty()) { FulltextFetchers fetchers = new FulltextFetchers(Globals.prefs.getImportFormatPreferences()); downloads.put(entry, fetchers.findFullTextPDF(entry)); } From d2c4724e1f10d78857c6aaacbe572b2c3ba89e36 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 24 Aug 2019 17:27:24 +0200 Subject: [PATCH 06/11] Fulltext lookup now searches for local files before --- .../gui/externalfiles/FindFullTextAction.java | 70 ++++++++++--------- src/main/resources/l10n/JabRef_en.properties | 2 + 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java index 4e0d3010f2e..16530525625 100644 --- a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java +++ b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java @@ -56,15 +56,15 @@ 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("Look up full text documents"), - Localization.lang("Cancel")); + 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("Look up full text documents"), + Localization.lang("Cancel")); if (!confirmDownload) { basePanel.output(Localization.lang("Operation canceled.")); @@ -72,22 +72,25 @@ public void execute() { } } - Task>> findFullTextsTask = new Task>>() { + Task>> findFullTextsTask = new Task>>() { + @Override protected Map> call() { Map> downloads = new ConcurrentHashMap<>(); int count = 0; AutoSetFileLinksUtil util = new AutoSetFileLinksUtil(basePanel.getBibDatabaseContext(), Globals.prefs.getFilePreferences(), Globals.prefs.getAutoLinkPreferences(), ExternalFileTypes.getInstance()); - util.linkAssociatedFiles(basePanel.getSelectedEntries(), new NamedCompound("")); + List changed = util.linkAssociatedFiles(basePanel.getSelectedEntries(), new NamedCompound("")); - for (BibEntry entry : basePanel.getSelectedEntries()) { - List fileList = entry.getFiles(); - if (fileList.isEmpty()) { + for (BibEntry entry : changed) { + if (entry.getFiles().isEmpty()) { FulltextFetchers fetchers = new FulltextFetchers(Globals.prefs.getImportFormatPreferences()); downloads.put(entry, fetchers.findFullTextPDF(entry)); + } else { + downloads.put(entry, Optional.empty()); } updateProgress(++count, basePanel.getSelectedEntries().size()); } + return downloads; } }; @@ -95,9 +98,9 @@ protected Map> call() { findFullTextsTask.setOnSucceeded(value -> downloadFullTexts(findFullTextsTask.getValue())); dialogService.showProgressDialogAndWait( - Localization.lang("Look up full text documents"), - Localization.lang("Looking for full text document..."), - findFullTextsTask); + Localization.lang("Look up full text documents"), + Localization.lang("Looking for full text document..."), + findFullTextsTask); Globals.TASK_EXECUTOR.execute(findFullTextsTask); } @@ -112,16 +115,19 @@ private void downloadFullTexts(Map> 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 if (!result.isPresent() && !entry.getFiles().isEmpty()) { + dialogService.notify(Localization.lang("Full text document found already on disk for entry %0", entry.getCiteKeyOptional().orElse(Localization.lang("undefined")))); + } 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")))); } } } @@ -140,25 +146,25 @@ private void addLinkedFileFromURL(URL url, BibEntry entry, Path targetDirectory) if (!entry.getFiles().contains(newLinkedFile)) { LinkedFileViewModel onlineFile = new LinkedFileViewModel( - newLinkedFile, - 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 downloadTask = onlineFile.prepareDownloadTask(targetDirectory, urlDownload); downloadTask.onSuccess(destination -> { LinkedFile downloadedFile = LinkedFilesEditorViewModel.fromFile( - destination, - 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")))); + entry.getCiteKeyOptional().orElse(Localization.lang("undefined")))); }); Globals.TASK_EXECUTOR.execute(downloadTask); } catch (MalformedURLException exception) { @@ -166,7 +172,7 @@ private void addLinkedFileFromURL(URL url, BibEntry entry, Path targetDirectory) } } else { dialogService.notify(Localization.lang("Full text document for entry %0 already linked.", - entry.getCiteKeyOptional().orElse(Localization.lang("undefined")))); + entry.getCiteKeyOptional().orElse(Localization.lang("undefined")))); } } } diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 7a7a1bd3881..be32af907c7 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2108,3 +2108,5 @@ Selected\ entry\ does\ not\ have\ an\ associated\ BibTeX\ key.=Selected entry do Current\ search\ directory\:=Current search directory: Set\ LaTeX\ file\ directory=Set LaTeX file directory Group\ color=Group color + +Full\ text\ document\ found\ already\ on\ disk\ for\ entry\ %0=Full text document found already on disk for entry %0 From f81fa9e685e3ced391d63e5bd6e12d7d1c1df6c3 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 25 Aug 2019 11:12:34 +0200 Subject: [PATCH 07/11] fix formatting extract fetchers to the top --- .../gui/externalfiles/FindFullTextAction.java | 57 +++++++++---------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java index 16530525625..156d284ec1a 100644 --- a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java +++ b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java @@ -40,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; @@ -56,15 +57,15 @@ 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("Look up full text documents"), - Localization.lang("Cancel")); + 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("Look up full text documents"), + Localization.lang("Cancel")); if (!confirmDownload) { basePanel.output(Localization.lang("Operation canceled.")); @@ -83,14 +84,12 @@ protected Map> call() { for (BibEntry entry : changed) { if (entry.getFiles().isEmpty()) { - FulltextFetchers fetchers = new FulltextFetchers(Globals.prefs.getImportFormatPreferences()); downloads.put(entry, fetchers.findFullTextPDF(entry)); } else { downloads.put(entry, Optional.empty()); } updateProgress(++count, basePanel.getSelectedEntries().size()); } - return downloads; } }; @@ -98,9 +97,9 @@ protected Map> call() { findFullTextsTask.setOnSucceeded(value -> downloadFullTexts(findFullTextsTask.getValue())); dialogService.showProgressDialogAndWait( - Localization.lang("Look up full text documents"), - Localization.lang("Looking for full text document..."), - findFullTextsTask); + Localization.lang("Look up full text documents"), + Localization.lang("Looking for full text document..."), + findFullTextsTask); Globals.TASK_EXECUTOR.execute(findFullTextsTask); } @@ -115,15 +114,15 @@ private void downloadFullTexts(Map> 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 if (!result.isPresent() && !entry.getFiles().isEmpty()) { - dialogService.notify(Localization.lang("Full text document found already on disk for entry %0", entry.getCiteKeyOptional().orElse(Localization.lang("undefined")))); + dialogService.notify(Localization.lang("Full text document found already on disk for entry %0. Not downloaded again.", entry.getCiteKeyOptional().orElse(Localization.lang("undefined")))); } else { dialogService.notify(Localization.lang("No full text document found for entry %0.", @@ -146,25 +145,25 @@ private void addLinkedFileFromURL(URL url, BibEntry entry, Path targetDirectory) if (!entry.getFiles().contains(newLinkedFile)) { LinkedFileViewModel onlineFile = new LinkedFileViewModel( - newLinkedFile, - 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 downloadTask = onlineFile.prepareDownloadTask(targetDirectory, urlDownload); downloadTask.onSuccess(destination -> { LinkedFile downloadedFile = LinkedFilesEditorViewModel.fromFile( - destination, - 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")))); + entry.getCiteKeyOptional().orElse(Localization.lang("undefined")))); }); Globals.TASK_EXECUTOR.execute(downloadTask); } catch (MalformedURLException exception) { @@ -172,7 +171,7 @@ private void addLinkedFileFromURL(URL url, BibEntry entry, Path targetDirectory) } } else { dialogService.notify(Localization.lang("Full text document for entry %0 already linked.", - entry.getCiteKeyOptional().orElse(Localization.lang("undefined")))); + entry.getCiteKeyOptional().orElse(Localization.lang("undefined")))); } } } From 5559f9c457990b38024498c727aaff37bd9d0211 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 25 Aug 2019 11:32:27 +0200 Subject: [PATCH 08/11] Fixes l10n --- src/main/resources/l10n/JabRef_en.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 5ddfa400384..9ba01ac9941 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2112,4 +2112,4 @@ Current\ search\ directory\:=Current search directory: Set\ LaTeX\ file\ directory=Set LaTeX file directory Group\ color=Group color -Full\ text\ document\ found\ already\ on\ disk\ for\ entry\ %0=Full text document found already on disk for entry %0 +Full\ text\ document\ found\ already\ on\ disk\ for\ entry\ %0.\ Not\ downloaded\ again.=Full text document found already on disk for entry %0. Not downloaded again. From 4f079a33bd4146bda692ae7a36e1f7eb7f54118e Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 25 Aug 2019 12:01:34 +0200 Subject: [PATCH 09/11] fix indendation, add comment --- .../org/jabref/gui/externalfiles/FindFullTextAction.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java index 156d284ec1a..37132bd17be 100644 --- a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java +++ b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java @@ -86,6 +86,8 @@ protected Map> call() { if (entry.getFiles().isEmpty()) { downloads.put(entry, fetchers.findFullTextPDF(entry)); } else { + //we need to add the entry with an empty url. The real download only happens later if the url is not empty. + //empty url and file field indicates that we already have the file downloads.put(entry, Optional.empty()); } updateProgress(++count, basePanel.getSelectedEntries().size()); @@ -122,11 +124,11 @@ private void downloadFullTexts(Map> downloads) { addLinkedFileFromURL(result.get(), entry, dir.get()); } else if (!result.isPresent() && !entry.getFiles().isEmpty()) { - dialogService.notify(Localization.lang("Full text document found already on disk for entry %0. Not downloaded again.", entry.getCiteKeyOptional().orElse(Localization.lang("undefined")))); - + dialogService.notify(Localization.lang("Full text document found already on disk for entry %0. Not downloaded again.", + entry.getCiteKeyOptional().orElse(Localization.lang("undefined")))); } 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")))); } } } From 14ade569e891301b4e27f453713773a8c4c18f65 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 27 Oct 2019 21:50:07 +0100 Subject: [PATCH 10/11] separate find fulltext and download methods --- .../gui/externalfiles/FindFullTextAction.java | 92 +++++++++---------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java index 37132bd17be..c609888ad32 100644 --- a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java +++ b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java @@ -57,15 +57,14 @@ 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("Look up full text documents"), - Localization.lang("Cancel")); + 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("Look up full text documents"), + Localization.lang("Cancel")); if (!confirmDownload) { basePanel.output(Localization.lang("Operation canceled.")); @@ -73,40 +72,43 @@ public void execute() { } } - Task>> findFullTextsTask = new Task>>() { + lookupFullText(); + } + + private void lookupFullText() { + AutoSetFileLinksUtil util = new AutoSetFileLinksUtil(basePanel.getBibDatabaseContext(), Globals.prefs.getFilePreferences(), Globals.prefs.getAutoLinkPreferences(), ExternalFileTypes.getInstance()); + + Task> linkFilesTask = new Task>() { @Override - protected Map> call() { + protected List call() { + return util.linkAssociatedFiles(basePanel.getSelectedEntries(), new NamedCompound("")); + } + + @Override + protected void succeeded() { Map> downloads = new ConcurrentHashMap<>(); - int count = 0; - AutoSetFileLinksUtil util = new AutoSetFileLinksUtil(basePanel.getBibDatabaseContext(), Globals.prefs.getFilePreferences(), Globals.prefs.getAutoLinkPreferences(), ExternalFileTypes.getInstance()); - List changed = util.linkAssociatedFiles(basePanel.getSelectedEntries(), new NamedCompound("")); - for (BibEntry entry : changed) { + for (BibEntry entry : getValue()) { if (entry.getFiles().isEmpty()) { downloads.put(entry, fetchers.findFullTextPDF(entry)); } else { - //we need to add the entry with an empty url. The real download only happens later if the url is not empty. - //empty url and file field indicates that we already have the file - downloads.put(entry, Optional.empty()); + dialogService.notify(Localization.lang("Full text document found already on disk for entry %0. Not downloaded again.", + entry.getCiteKeyOptional().orElse(Localization.lang("undefined")))); } - updateProgress(++count, basePanel.getSelectedEntries().size()); } - 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> downloads) { + private void downloadMissingFullTexts(Map> downloads) { for (Map.Entry> download : downloads.entrySet()) { BibEntry entry = download.getKey(); Optional result = download.getValue(); @@ -116,19 +118,17 @@ private void downloadFullTexts(Map> 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 if (!result.isPresent() && !entry.getFiles().isEmpty()) { - dialogService.notify(Localization.lang("Full text document found already on disk for entry %0. Not downloaded again.", - entry.getCiteKeyOptional().orElse(Localization.lang("undefined")))); } 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")))); } } } @@ -147,25 +147,25 @@ private void addLinkedFileFromURL(URL url, BibEntry entry, Path targetDirectory) if (!entry.getFiles().contains(newLinkedFile)) { LinkedFileViewModel onlineFile = new LinkedFileViewModel( - newLinkedFile, - 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 downloadTask = onlineFile.prepareDownloadTask(targetDirectory, urlDownload); downloadTask.onSuccess(destination -> { LinkedFile downloadedFile = LinkedFilesEditorViewModel.fromFile( - destination, - 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")))); + entry.getCiteKeyOptional().orElse(Localization.lang("undefined")))); }); Globals.TASK_EXECUTOR.execute(downloadTask); } catch (MalformedURLException exception) { @@ -173,7 +173,7 @@ private void addLinkedFileFromURL(URL url, BibEntry entry, Path targetDirectory) } } else { dialogService.notify(Localization.lang("Full text document for entry %0 already linked.", - entry.getCiteKeyOptional().orElse(Localization.lang("undefined")))); + entry.getCiteKeyOptional().orElse(Localization.lang("undefined")))); } } } From eed70a54a2a0c7b7f591061f1479f1d8474919cd Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 27 Oct 2019 21:58:52 +0100 Subject: [PATCH 11/11] fix indent to make the intellij people happy... --- .../gui/externalfiles/FindFullTextAction.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java index c609888ad32..f86dc56478c 100644 --- a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java +++ b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java @@ -57,14 +57,14 @@ 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("Look up full text documents"), - Localization.lang("Cancel")); + 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("Look up full text documents"), + Localization.lang("Cancel")); if (!confirmDownload) { basePanel.output(Localization.lang("Operation canceled."));