Skip to content

Commit d2c4724

Browse files
committed
Fulltext lookup now searches for local files before
1 parent 4ef1460 commit d2c4724

File tree

2 files changed

+40
-32
lines changed

2 files changed

+40
-32
lines changed

Diff for: src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java

+38-32
Original file line numberDiff line numberDiff line change
@@ -56,48 +56,51 @@ public void execute() {
5656

5757
if (basePanel.getSelectedEntries().size() >= WARNING_LIMIT) {
5858
boolean confirmDownload = dialogService.showConfirmationDialogAndWait(
59-
Localization.lang("Look up full text documents"),
60-
Localization.lang(
61-
"You are about to look up full text documents for %0 entries.",
62-
String.valueOf(basePanel.getSelectedEntries().size())) + "\n"
63-
+ Localization.lang("JabRef will send at least one request per entry to a publisher.")
64-
+ "\n"
65-
+ Localization.lang("Do you still want to continue?"),
66-
Localization.lang("Look up full text documents"),
67-
Localization.lang("Cancel"));
59+
Localization.lang("Look up full text documents"),
60+
Localization.lang(
61+
"You are about to look up full text documents for %0 entries.",
62+
String.valueOf(basePanel.getSelectedEntries().size())) + "\n"
63+
+ Localization.lang("JabRef will send at least one request per entry to a publisher.")
64+
+ "\n"
65+
+ Localization.lang("Do you still want to continue?"),
66+
Localization.lang("Look up full text documents"),
67+
Localization.lang("Cancel"));
6868

6969
if (!confirmDownload) {
7070
basePanel.output(Localization.lang("Operation canceled."));
7171
return;
7272
}
7373
}
7474

75-
Task<Map<BibEntry, Optional<URL>>> findFullTextsTask = new Task<Map<BibEntry, Optional<URL>>>() {
75+
Task<Map<BibEntry, Optional<URL>>> findFullTextsTask = new Task<Map<BibEntry, Optional<URL>>>() {
76+
7677
@Override
7778
protected Map<BibEntry, Optional<URL>> call() {
7879
Map<BibEntry, Optional<URL>> downloads = new ConcurrentHashMap<>();
7980
int count = 0;
8081
AutoSetFileLinksUtil util = new AutoSetFileLinksUtil(basePanel.getBibDatabaseContext(), Globals.prefs.getFilePreferences(), Globals.prefs.getAutoLinkPreferences(), ExternalFileTypes.getInstance());
81-
util.linkAssociatedFiles(basePanel.getSelectedEntries(), new NamedCompound(""));
82+
List<BibEntry> changed = util.linkAssociatedFiles(basePanel.getSelectedEntries(), new NamedCompound(""));
8283

83-
for (BibEntry entry : basePanel.getSelectedEntries()) {
84-
List<LinkedFile> fileList = entry.getFiles();
85-
if (fileList.isEmpty()) {
84+
for (BibEntry entry : changed) {
85+
if (entry.getFiles().isEmpty()) {
8686
FulltextFetchers fetchers = new FulltextFetchers(Globals.prefs.getImportFormatPreferences());
8787
downloads.put(entry, fetchers.findFullTextPDF(entry));
88+
} else {
89+
downloads.put(entry, Optional.empty());
8890
}
8991
updateProgress(++count, basePanel.getSelectedEntries().size());
9092
}
93+
9194
return downloads;
9295
}
9396
};
9497

9598
findFullTextsTask.setOnSucceeded(value -> downloadFullTexts(findFullTextsTask.getValue()));
9699

97100
dialogService.showProgressDialogAndWait(
98-
Localization.lang("Look up full text documents"),
99-
Localization.lang("Looking for full text document..."),
100-
findFullTextsTask);
101+
Localization.lang("Look up full text documents"),
102+
Localization.lang("Looking for full text document..."),
103+
findFullTextsTask);
101104

102105
Globals.TASK_EXECUTOR.execute(findFullTextsTask);
103106
}
@@ -112,16 +115,19 @@ private void downloadFullTexts(Map<BibEntry, Optional<URL>> downloads) {
112115
if (!dir.isPresent()) {
113116

114117
dialogService.showErrorDialogAndWait(Localization.lang("Directory not found"),
115-
Localization.lang("Main file directory not set!") + " " + Localization.lang("Preferences")
116-
+ " -> " + Localization.lang("File"));
118+
Localization.lang("Main file directory not set!") + " " + Localization.lang("Preferences")
119+
+ " -> " + Localization.lang("File"));
117120
return;
118121
}
119122
//Download and link full text
120123
addLinkedFileFromURL(result.get(), entry, dir.get());
121124

125+
} else if (!result.isPresent() && !entry.getFiles().isEmpty()) {
126+
dialogService.notify(Localization.lang("Full text document found already on disk for entry %0", entry.getCiteKeyOptional().orElse(Localization.lang("undefined"))));
127+
122128
} else {
123129
dialogService.notify(Localization.lang("No full text document found for entry %0.",
124-
entry.getCiteKeyOptional().orElse(Localization.lang("undefined"))));
130+
entry.getCiteKeyOptional().orElse(Localization.lang("undefined"))));
125131
}
126132
}
127133
}
@@ -140,33 +146,33 @@ private void addLinkedFileFromURL(URL url, BibEntry entry, Path targetDirectory)
140146
if (!entry.getFiles().contains(newLinkedFile)) {
141147

142148
LinkedFileViewModel onlineFile = new LinkedFileViewModel(
143-
newLinkedFile,
144-
entry,
145-
basePanel.getBibDatabaseContext(),
146-
Globals.TASK_EXECUTOR,
147-
dialogService,
148-
JabRefPreferences.getInstance().getXMPPreferences(),
149-
JabRefPreferences.getInstance().getFilePreferences(),
150-
ExternalFileTypes.getInstance());
149+
newLinkedFile,
150+
entry,
151+
basePanel.getBibDatabaseContext(),
152+
Globals.TASK_EXECUTOR,
153+
dialogService,
154+
JabRefPreferences.getInstance().getXMPPreferences(),
155+
JabRefPreferences.getInstance().getFilePreferences(),
156+
ExternalFileTypes.getInstance());
151157

152158
try {
153159
URLDownload urlDownload = new URLDownload(newLinkedFile.getLink());
154160
BackgroundTask<Path> downloadTask = onlineFile.prepareDownloadTask(targetDirectory, urlDownload);
155161
downloadTask.onSuccess(destination -> {
156162
LinkedFile downloadedFile = LinkedFilesEditorViewModel.fromFile(
157-
destination,
158-
basePanel.getBibDatabaseContext().getFileDirectoriesAsPaths(JabRefPreferences.getInstance().getFilePreferences()), ExternalFileTypes.getInstance());
163+
destination,
164+
basePanel.getBibDatabaseContext().getFileDirectoriesAsPaths(JabRefPreferences.getInstance().getFilePreferences()), ExternalFileTypes.getInstance());
159165
entry.addFile(downloadedFile);
160166
dialogService.notify(Localization.lang("Finished downloading full text document for entry %0.",
161-
entry.getCiteKeyOptional().orElse(Localization.lang("undefined"))));
167+
entry.getCiteKeyOptional().orElse(Localization.lang("undefined"))));
162168
});
163169
Globals.TASK_EXECUTOR.execute(downloadTask);
164170
} catch (MalformedURLException exception) {
165171
dialogService.showErrorDialogAndWait(Localization.lang("Invalid URL"), exception);
166172
}
167173
} else {
168174
dialogService.notify(Localization.lang("Full text document for entry %0 already linked.",
169-
entry.getCiteKeyOptional().orElse(Localization.lang("undefined"))));
175+
entry.getCiteKeyOptional().orElse(Localization.lang("undefined"))));
170176
}
171177
}
172178
}

Diff for: src/main/resources/l10n/JabRef_en.properties

+2
Original file line numberDiff line numberDiff line change
@@ -2108,3 +2108,5 @@ Selected\ entry\ does\ not\ have\ an\ associated\ BibTeX\ key.=Selected entry do
21082108
Current\ search\ directory\:=Current search directory:
21092109
Set\ LaTeX\ file\ directory=Set LaTeX file directory
21102110
Group\ color=Group color
2111+
2112+
Full\ text\ document\ found\ already\ on\ disk\ for\ entry\ %0=Full text document found already on disk for entry %0

0 commit comments

Comments
 (0)