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

Fix lookup fulltext document not finding files #5216

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -71,13 +74,22 @@ public void execute() {
}

Task<Map<BibEntry, Optional<URL>>> findFullTextsTask = new Task<Map<BibEntry, Optional<URL>>>() {

@Override
protected Map<BibEntry, Optional<URL>> call() {
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));
AutoSetFileLinksUtil util = new AutoSetFileLinksUtil(basePanel.getBibDatabaseContext(), Globals.prefs.getFilePreferences(), Globals.prefs.getAutoLinkPreferences(), ExternalFileTypes.getInstance());
List<BibEntry> changed = util.linkAssociatedFiles(basePanel.getSelectedEntries(), new NamedCompound(""));

for (BibEntry entry : changed) {
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
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());
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
}
updateProgress(++count, basePanel.getSelectedEntries().size());
}
return downloads;
Expand Down Expand Up @@ -111,6 +123,9 @@ private void downloadFullTexts(Map<BibEntry, Optional<URL>> downloads) {
//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"))));
Expand Down Expand Up @@ -138,7 +153,7 @@ private void addLinkedFileFromURL(URL url, BibEntry entry, Path targetDirectory)
Globals.TASK_EXECUTOR,
dialogService,
JabRefPreferences.getInstance().getXMPPreferences(),
JabRefPreferences.getInstance().getFilePreferences(),
JabRefPreferences.getInstance().getFilePreferences(),
ExternalFileTypes.getInstance());

try {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2111,3 +2111,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.\ Not\ downloaded\ again.=Full text document found already on disk for entry %0. Not downloaded again.