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

Issue #4269 & #3874 #5110

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
29 changes: 18 additions & 11 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.io.IOException;
import java.net.URL;
import java.nio.file.Path;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -96,18 +97,24 @@ public void update() {
DownloadExternalFile fileDownload = new DownloadExternalFile(basePanel.frame(),
basePanel.getBibDatabaseContext(), entry);
try {
fileDownload.download(result.get(), "application/pdf", file -> {
DefaultTaskExecutor.runInJavaFXThread(() -> {
Optional<FieldChange> fieldChange = entry.addFile(file);
if (fieldChange.isPresent()) {
UndoableFieldChange edit = new UndoableFieldChange(entry, FieldName.FILE,
entry.getField(FieldName.FILE).orElse(null), fieldChange.get().getNewValue());
basePanel.getUndoManager().addEdit(edit);
basePanel.markBaseChanged();
}
});
String str = dir.toString() + entry.getField(FieldName.FILE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work because dir is an optional. You would need get() first.
Also, File class should be avoided. Better use the path class and the other classes from the nio package:
https://docs.oracle.com/javase/tutorial/essential/io/fileio.html

And your code does not really solve the problem stated in the issue.
The idea is that JabRef previously searched for the file in all directories and linked it, if found.
If not found, it would download the file.

So the idea here would be to first link local files. This is already implemented in the AutoSetFileLinksUtil.
This could be reused or the method called before.

File f = new File(str);
if (f.isFile()) {
return;
} else {
fileDownload.download(result.get(), "application/pdf", file -> {
DefaultTaskExecutor.runInJavaFXThread(() -> {
Optional<FieldChange> fieldChange = entry.addFile(file);
if (fieldChange.isPresent()) {
UndoableFieldChange edit = new UndoableFieldChange(entry, FieldName.FILE,
entry.getField(FieldName.FILE).orElse(null), fieldChange.get().getNewValue());
basePanel.getUndoManager().addEdit(edit);
basePanel.markBaseChanged();
}
});

});
});
}
} catch (IOException e) {
LOGGER.warn("Problem downloading file", e);
basePanel.output(Localization.lang("Full text document download failed for entry %0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class BiblatexEntryTypes {

{
addAllRequired(FieldName.AUTHOR, FieldName.TITLE,
FieldName.orFields(FieldName.JOURNAL, FieldName.JOURNALTITLE),
FieldName.orFields(FieldName.JOURNALTITLE),
FieldName.orFields(FieldName.YEAR, FieldName.DATE));
addAllOptional(FieldName.TRANSLATOR, FieldName.ANNOTATOR, FieldName.COMMENTATOR, FieldName.SUBTITLE,
FieldName.TITLEADDON, FieldName.EDITOR, FieldName.EDITORA, FieldName.EDITORB, FieldName.EDITORC,
Expand Down