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 endnote importer when keyword style is null #7084

Merged
merged 3 commits into from
Nov 10, 2020
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ inserting new citations in a OpenOffic/LibreOffice document. [#6957](https://git
- We fixed an issue where the JabRef GUI does not highlight the "All entries" group on start-up [#6691](https://github.com/JabRef/jabref/issues/6691)
- We fixed an issue where a custom dark theme was not applied to the entry preview tab [7068](https://github.com/JabRef/jabref/issues/7068)
- We fixed an issue where modifications to the Custom preview layout in the preferences were not saved [#6447](https://github.com/JabRef/jabref/issues/6447)
- We fixed an issue where errors from imports were not shown to the user [#7084](https://github.com/JabRef/jabref/pull/7084)
- We fixed an issue where the EndNote XML Import would fail on empty keywords tags [forum#2387](https://discourse.jabref.org/t/importing-in-unknown-format-fails-to-import-xml-library-from-bookends-export/2387)

### Removed

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/DefaultInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.protectedterms.ProtectedTermsLoader;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.PreferencesService;

Expand Down Expand Up @@ -46,6 +47,8 @@ private static Object createDependency(Class<?> clazz) {
return Globals.clipboardManager;
} else if (clazz == UndoManager.class) {
return Globals.undoManager;
} else if (clazz == BibEntryTypesManager.class) {
return Globals.entryTypesManager;
} else {
try {
return clazz.newInstance();
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/jabref/gui/importer/ImportAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ public void automatedImport(List<String> filenames) {
frame.addTab(parserResult.getDatabaseContext(), true);
dialogService.notify(Localization.lang("Imported entries") + ": " + parserResult.getDatabase().getEntries().size());
})
.executeWith(taskExecutor);
.onFailure(ex-> {
LOGGER.error("Error importing", ex);
dialogService.notify(Localization.lang("Error importing. See the error log for details."));
})
.executeWith(taskExecutor);
} else {
final LibraryTab libraryTab = frame.getCurrentLibraryTab();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.types.EntryType;
import org.jabref.model.entry.types.StandardEntryType;
Expand All @@ -59,6 +60,7 @@ public class ImportEntriesDialog extends BaseDialog<Boolean> {
@Inject private UndoManager undoManager;
@Inject private PreferencesService preferences;
@Inject private StateManager stateManager;
@Inject private BibEntryTypesManager entryTypesManager;
@Inject private FileUpdateMonitor fileUpdateMonitor;
private final BibDatabaseContext database;

Expand Down Expand Up @@ -94,7 +96,7 @@ public ImportEntriesDialog(BibDatabaseContext database, BackgroundTask<ParserRes

@FXML
private void initialize() {
viewModel = new ImportEntriesViewModel(task, taskExecutor, database, dialogService, undoManager, preferences, stateManager, fileUpdateMonitor);
viewModel = new ImportEntriesViewModel(task, taskExecutor, database, dialogService, undoManager, preferences, stateManager, entryTypesManager, fileUpdateMonitor);
Label placeholder = new Label();
placeholder.textProperty().bind(viewModel.messageProperty());
entriesListView.setPlaceholder(placeholder);
Expand Down
21 changes: 16 additions & 5 deletions src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import org.jabref.gui.AbstractViewModel;
import org.jabref.gui.DialogService;
import org.jabref.gui.Globals;
import org.jabref.gui.JabRefGUI;
import org.jabref.gui.StateManager;
import org.jabref.gui.duplicationFinder.DuplicateResolverDialog;
Expand All @@ -28,13 +27,19 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.LinkedFile;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.FilePreferences;
import org.jabref.preferences.PreferencesService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ImportEntriesViewModel extends AbstractViewModel {

private static final Logger LOGGER = LoggerFactory.getLogger(ImportAction.class);

private final StringProperty message;
private final TaskExecutor taskExecutor;
private final BibDatabaseContext databaseContext;
Expand All @@ -45,6 +50,7 @@ public class ImportEntriesViewModel extends AbstractViewModel {
private ParserResult parserResult = null;
private final ObservableList<BibEntry> entries;
private final PreferencesService preferences;
private final BibEntryTypesManager entryTypesManager;

/**
* @param databaseContext the database to import into
Expand All @@ -57,13 +63,15 @@ public ImportEntriesViewModel(BackgroundTask<ParserResult> task,
UndoManager undoManager,
PreferencesService preferences,
StateManager stateManager,
BibEntryTypesManager entryTypesManager,
FileUpdateMonitor fileUpdateMonitor) {
this.taskExecutor = taskExecutor;
this.databaseContext = databaseContext;
this.dialogService = dialogService;
this.undoManager = undoManager;
this.preferences = preferences;
this.stateManager = stateManager;
this.entryTypesManager = entryTypesManager;
this.fileUpdateMonitor = fileUpdateMonitor;
this.entries = FXCollections.observableArrayList();
this.message = new SimpleStringProperty();
Expand All @@ -74,6 +82,9 @@ public ImportEntriesViewModel(BackgroundTask<ParserResult> task,
this.parserResult = parserResult;
// fill in the list for the user, where one can select the entries to import
entries.addAll(parserResult.getDatabase().getEntries());
}).onFailure(ex -> {
LOGGER.error("Error importing", ex);
dialogService.showErrorDialogAndWait(ex);
}).executeWith(taskExecutor);
}

Expand All @@ -91,7 +102,7 @@ public ObservableList<BibEntry> getEntries() {

public boolean hasDuplicate(BibEntry entry) {
return findInternalDuplicate(entry).isPresent() ||
new DuplicateCheck(Globals.entryTypesManager)
new DuplicateCheck(entryTypesManager)
.containsDuplicate(databaseContext.getDatabase(), entry, databaseContext.getMode()).isPresent();
}

Expand Down Expand Up @@ -122,7 +133,7 @@ public void importEntries(List<BibEntry> entriesToImport, boolean shouldDownload
} else {
buildImportHandlerThenImportEntries(entriesToImport);
}
}).executeWith(Globals.TASK_EXECUTOR);
}).executeWith(taskExecutor);
} else {
buildImportHandlerThenImportEntries(entriesToImport);
}
Expand Down Expand Up @@ -182,7 +193,7 @@ private Optional<BibEntry> findInternalDuplicate(BibEntry entry) {
if (othEntry.equals(entry)) {
continue; // Don't compare the entry to itself
}
if (new DuplicateCheck(Globals.entryTypesManager).isDuplicate(entry, othEntry, databaseContext.getMode())) {
if (new DuplicateCheck(entryTypesManager).isDuplicate(entry, othEntry, databaseContext.getMode())) {
return Optional.of(othEntry);
}
}
Expand All @@ -191,7 +202,7 @@ private Optional<BibEntry> findInternalDuplicate(BibEntry entry) {

public void resolveDuplicate(BibEntry entry) {
// First, try to find duplicate in the existing library
Optional<BibEntry> other = new DuplicateCheck(Globals.entryTypesManager).containsDuplicate(databaseContext.getDatabase(), entry, databaseContext.getMode());
Optional<BibEntry> other = new DuplicateCheck(entryTypesManager).containsDuplicate(databaseContext.getDatabase(), entry, databaseContext.getMode());
if (other.isPresent()) {
DuplicateResolverDialog dialog = new DuplicateResolverDialog(other.get(),
entry, DuplicateResolverDialog.DuplicateResolverType.INSPECTION, databaseContext, stateManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,12 @@ private Optional<String> getUrlValue(Url url) {
private List<String> getKeywords(Record record) {
Keywords keywords = record.getKeywords();
if (keywords != null) {

return keywords.getKeyword()
.stream()
.map(keyword -> keyword.getStyle().getContent())
.map(keyword -> keyword.getStyle())
.filter(Objects::nonNull)
.map(style->style.getContent())
.collect(Collectors.toList());
} else {
return Collections.emptyList();
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 @@ -2278,3 +2278,5 @@ Connection\ successful\!=Connection successful\!
Generate\ groups\ from\ keywords\ in\ the\ following\ field=Generate groups from keywords in the following field
Generate\ groups\ for\ author\ last\ names=Generate groups for author last names
Regular\ expression=Regular expression

Error\ importing.\ See\ the\ error\ log\ for\ details.=Error importing. See the error log for details.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
% Encoding: UTF-8

@Article{,
author = {Lim, RCH},
title = {Painless Laser Acupuncture for Smoking Cessation.},
doi = {10.1089/acu.2018.1295},
note = {FFT available, not read on 7/2/18},
number = {3},
pages = {159-162},
url = {https://www.ncbi.nlm.nih.gov/pubmed/29937971},
volume = {30},
isbn = {1933-6586},
journal = {Med Acupunct},
keywords = {anxiety; craving; dependency; destress; health restoration; },
year = {2018},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<xml>
<records>
<record>
<database name="Some databases" path="/test/asdf">LASER Acu.1281 mapping conv .bdb</database>
<source-app name="Bookends" version="12.8.5">Bookends</source-app>
<rec-number>55549</rec-number>
<ref-type name="Journal Article">17</ref-type>
<contributors>
<authors>
<author>
<style face="normal" size="100%">Lim, RCH</style>
</author>
</authors>
</contributors>
<auth-address>
<style face="normal" size="100%">Laser Acupuncture Centre, Singapore.</style>
</auth-address>
<titles>
<title>
<style face="normal" size="100%">Painless Laser Acupuncture for Smoking Cessation.</style>
</title>
<secondary-title>
<style face="normal" size="100%">Med Acupunct</style>
</secondary-title>
</titles>
<pages>
<style face="normal" size="100%">159-162</style>
</pages>
<number>
<style face="normal" size="100%">3</style>
</number>
<volume>
<style face="normal" size="100%">30</style>
</volume>
<dates>
<year>
<style face="normal" size="100%">2018</style>
</year>
<pub-dates>
<date>
<style face="normal" size="100%">Jun 01</style>
</date>
</pub-dates>
</dates>
<keywords>
<keyword />
<keyword>
<style face="bold" size="12" />
<style face="normal" size="12">anxiety; craving; dependency; destress; health restoration</style>
</keyword>
<keyword>
<style face="normal" size="12" />
</keyword>
</keywords>
<notes>
<style face="normal" size="100%">FFT available, not read on 7/2/18</style>
</notes>
<label>
<style face="normal" size="12">29937971</style>
</label>
<urls>
<related-urls>
<url>
<style face="normal" size="100%">https://www.ncbi.nlm.nih.gov/pubmed/29937971</style>
</url>
</related-urls>
<pdf-urls />
</urls>
<isbn>
<style face="normal" size="100%">1933-6586</style>
</isbn>
<user16>
<style face="normal" size="100%">PMC6011367</style>
</user16>
<electronic-resource-num>
<style face="normal" size="100%">10.1089/acu.2018.1295</style>
</electronic-resource-num>
<accession-num>
<style face="normal" size="100%">29937971</style>
</accession-num>
</record>
</records>
</xml>