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 threading cleanup in performSearch #7672

Merged
merged 5 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -38,6 +38,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

### Fixed

- We fixed an issue where an exception occured when importing entries from a web search [#7606](https://github.com/JabRef/jabref/issues/7606)
- We fixed an issue where the table column sort order was not properly stored and resulted in unsorted eports [#7524](https://github.com/JabRef/jabref/issues/7524)
- We fixed an issue where the value of the field `school` or `institution` would be printed twice in the HTML Export [forum#2634](https://discourse.jabref.org/t/problem-with-exporting-techreport-phdthesis-mastersthesis-to-html/2634)
- We fixed an issue preventing to connect to a shared database. [#7570](https://github.com/JabRef/jabref/pull/7570)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import javax.swing.undo.UndoManager;

Expand All @@ -23,9 +24,11 @@
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.database.DatabaseMerger;
import org.jabref.logic.database.DuplicateCheck;
import org.jabref.logic.importer.ImportCleanup;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.LinkedFile;
Expand All @@ -52,6 +55,7 @@ public class ImportEntriesViewModel extends AbstractViewModel {
private final PreferencesService preferences;
private final BibEntryTypesManager entryTypesManager;

private final ImportCleanup cleanup = new ImportCleanup(BibDatabaseMode.BIBTEX);
Copy link
Member

Choose a reason for hiding this comment

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

If one uses the user database, then this would immediately take care of #1018 as well, right?

/**
* @param databaseContext the database to import into
* @param task the task executed for parsing the selected files(s).
Expand All @@ -78,10 +82,13 @@ public ImportEntriesViewModel(BackgroundTask<ParserResult> task,
this.message.bind(task.messageProperty());

task.onSuccess(parserResult -> {

// store the complete parser result (to import groups, ... later on)
this.parserResult = parserResult;

List<BibEntry> resultEntries = parserResult.getDatabase().getEntries().stream().map(cleanup::doPostCleanup).collect(Collectors.toList());
Copy link
Member

Choose a reason for hiding this comment

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

An idea would be to move this cleanup to the ImportHandler for consistency reasons.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is already part of the importHandler for importing external files

public void importEntries(List<BibEntry> entries) {
ImportCleanup cleanup = new ImportCleanup(bibdatabase.getMode());
cleanup.doPostCleanup(entries);
bibdatabase.getDatabase().insertEntries(entries);

Copy link
Member

Choose a reason for hiding this comment

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

Okay, then I don't get why you added it in the dialog. The buildImportHandlerThenImportEntries method uses the import handler to import entries.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah thanks, then it can be removed here. Totally overlooked that this is called.

// fill in the list for the user, where one can select the entries to import
entries.addAll(parserResult.getDatabase().getEntries());
entries.addAll(resultEntries);
}).onFailure(ex -> {
LOGGER.error("Error importing", ex);
dialogService.showErrorDialogAndWait(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public List<BibEntry> performSearch(QueryNode luceneQuery) throws FetcherExcepti
}
})
.limit(maximumNumberOfReturnedResults)
.map(cleanup::doPostCleanup)
tobiasdiez marked this conversation as resolved.
Show resolved Hide resolved
.collect(Collectors.toList());
}
}