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 for unlinked file importer that did not import all importable files (#8444) #8582

Merged
merged 1 commit into from
Mar 21, 2022
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue when reading non-UTF-8 encoded. When no encoding header is present, the encoding is now detected from the file content (and the preference option is disregarded) [#8417](https://github.com/JabRef/jabref/issues/8417)
- We fixed an issue where pasting a URL was replacing + signs by spaces making the URL unreachable. [#8448](https://github.com/JabRef/jabref/issues/8448)
- We fixed an issue where creating subsidiary files from aux files created with some versions of biblatex would produce incorrect results. [#8513](https://github.com/JabRef/jabref/issues/8513)
- We fixed an issue where not all found unlinked local files were imported correctly due to some race condition. [#8444](https://github.com/JabRef/jabref/issues/8444)

### Removed

Expand Down
17 changes: 8 additions & 9 deletions src/main/java/org/jabref/gui/externalfiles/ImportHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,25 @@ public ExternalFilesEntryLinker getLinker() {
return linker;
}

public BackgroundTask<List<ImportFilesResultItemViewModel>> importFilesInBackground(List<Path> files) {
public BackgroundTask<List<ImportFilesResultItemViewModel>> importFilesInBackground(final List<Path> files) {
return new BackgroundTask<>() {
private int counter;
private List<BibEntry> entriesToAdd;
private final List<ImportFilesResultItemViewModel> results = new ArrayList<>();

@Override
protected List<ImportFilesResultItemViewModel> call() {
counter = 1;
CompoundEdit ce = new CompoundEdit();
for (Path file: files) {
entriesToAdd = Collections.emptyList();
for (final Path file : files) {
final List<BibEntry> entriesToAdd = new ArrayList<>();

if (isCanceled()) {
break;
}

DefaultTaskExecutor.runInJavaFXThread(() -> {
updateMessage(Localization.lang("Processing file %0", file.getFileName()));
updateProgress(counter, files.size() - 1);
updateProgress(counter, files.size() - 1d);
});

try {
Expand All @@ -100,10 +99,10 @@ protected List<ImportFilesResultItemViewModel> call() {
}

if (!pdfEntriesInFile.isEmpty()) {
entriesToAdd = pdfEntriesInFile;
entriesToAdd.addAll(pdfEntriesInFile);
addResultToList(file, true, Localization.lang("Importing using extracted PDF data"));
} else {
entriesToAdd = Collections.singletonList(createEmptyEntryWithLink(file));
entriesToAdd.add(createEmptyEntryWithLink(file));
addResultToList(file, false, Localization.lang("No metadata found. Creating empty entry with file link"));
}
} else if (FileUtil.isBibFile(file)) {
Expand All @@ -112,10 +111,10 @@ protected List<ImportFilesResultItemViewModel> call() {
addResultToList(file, false, bibtexParserResult.getErrorMessage());
}

entriesToAdd = bibtexParserResult.getDatabaseContext().getEntries();
entriesToAdd.addAll(bibtexParserResult.getDatabaseContext().getEntries());
addResultToList(file, false, Localization.lang("Importing bib entry"));
} else {
entriesToAdd = Collections.singletonList(createEmptyEntryWithLink(file));
entriesToAdd.add(createEmptyEntryWithLink(file));
addResultToList(file, false, Localization.lang("No BibTeX data found. Creating empty entry with file link"));
}
} catch (IOException ex) {
Expand Down