Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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: 1 addition & 1 deletion src/main/java/org/jabref/gui/JabRefMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private static void applyPreferences(PreferencesService preferences) {
Globals.journalAbbreviationRepository = JournalAbbreviationLoader.loadRepository(preferences.getJournalAbbreviationPreferences());

// Build list of Import and Export formats
Globals.IMPORT_FORMAT_READER.resetImportFormats(preferences.getImportFormatPreferences(),
Globals.IMPORT_FORMAT_READER.resetImportFormats(preferences.getImportSettingsPreferences(), preferences.getImportFormatPreferences(),
preferences.getXmpPreferences(), Globals.getFileUpdateMonitor());
Globals.entryTypesManager.addCustomOrModifiedTypes(preferences.getBibEntryTypes(BibDatabaseMode.BIBTEX),
preferences.getBibEntryTypes(BibDatabaseMode.BIBLATEX));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jabref.gui.bibtexextractor;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.undo.UndoManager;
Expand Down Expand Up @@ -32,7 +33,7 @@ public class BibtexExtractorViewModel {

private final StringProperty inputTextProperty = new SimpleStringProperty("");
private final DialogService dialogService;
private final GrobidCitationFetcher currentCitationfetcher;
private final PreferencesService preferencesService;
private final TaskExecutor taskExecutor;
private final ImportHandler importHandler;

Expand All @@ -45,7 +46,7 @@ public BibtexExtractorViewModel(BibDatabaseContext bibdatabaseContext,
StateManager stateManager) {

this.dialogService = dialogService;
currentCitationfetcher = new GrobidCitationFetcher(preferencesService.getImportFormatPreferences());
this.preferencesService = preferencesService;
this.taskExecutor = taskExecutor;
this.importHandler = new ImportHandler(
bibdatabaseContext,
Expand All @@ -61,7 +62,22 @@ public StringProperty inputTextProperty() {
}

public void startParsing() {
BackgroundTask.wrap(() -> currentCitationfetcher.performSearch(inputTextProperty.getValue()))
if (preferencesService.getImportSettingsPreferences().isGrobidEnabled()) {
parseUsingGrobid();
} else {
parseUsingBibtexExtractor();
}
}

private void parseUsingBibtexExtractor() {
BibEntry parsedEntry = new BibtexExtractor().extract(inputTextProperty.getValue());
importHandler.importEntries(List.of(parsedEntry));
trackNewEntry(parsedEntry, "ParseWithBibTeXExtractor");
}

private void parseUsingGrobid() {
GrobidCitationFetcher grobidCitationFetcher = new GrobidCitationFetcher(preferencesService.getImportSettingsPreferences(), preferencesService.getImportFormatPreferences());
BackgroundTask.wrap(() -> grobidCitationFetcher.performSearch(inputTextProperty.getValue()))
.onRunning(() -> dialogService.notify(Localization.lang("Your text is being parsed...")))
.onFailure((e) -> {
if (e instanceof FetcherException) {
Expand All @@ -76,14 +92,14 @@ public void startParsing() {
dialogService.notify(Localization.lang("%0 entries were parsed from your query.", String.valueOf(parsedEntries.size())));
importHandler.importEntries(parsedEntries);
for (BibEntry bibEntry : parsedEntries) {
trackNewEntry(bibEntry);
trackNewEntry(bibEntry, "ParseWithGrobid");
}
}).executeWith(taskExecutor);
}

private void trackNewEntry(BibEntry bibEntry) {
private void trackNewEntry(BibEntry bibEntry, String eventMessage) {
Map<String, String> properties = new HashMap<>();
properties.put("EntryType", bibEntry.typeProperty().getValue().getName());
Globals.getTelemetryClient().ifPresent(client -> client.trackEvent("ParseWithGrobid", properties, new HashMap<>()));
Globals.getTelemetryClient().ifPresent(client -> client.trackEvent(eventMessage, properties, new HashMap<>()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,18 @@ public ExtractBibtexDialog() {

buttonParse = (Button) getDialogPane().lookupButton(parseButtonType);
buttonParse.setTooltip(new Tooltip((Localization.lang("Starts the extraction and adds the resulting entries to the currently opened database"))));
buttonParse.setOnAction(event -> viewModel.startParsing());
buttonParse.setOnAction(event -> {
if (!preferencesService.getImportSettingsPreferences().isGrobidEnabled() && !preferencesService.getImportSettingsPreferences().isGrobidOptOut()) {
boolean confirmGrobidUsage = dialogService.showConfirmationDialogWithOptOutAndWait(
"Remote services",
"Allow sending PDF files and raw citation strings to a JabRef online service (Grobid) to determine Metadata",
"Use BibTeX parser instead",
this::optOutOfGrobid
);
preferencesService.storeImportSettingsPreferences(preferencesService.getImportSettingsPreferences().withGrobidEnabled(confirmGrobidUsage));
}
viewModel.startParsing();
});
buttonParse.disableProperty().bind(viewModel.inputTextProperty().isEmpty());
}

Expand All @@ -56,4 +67,8 @@ private void initialize() {
this.viewModel = new BibtexExtractorViewModel(database, dialogService, preferencesService, fileUpdateMonitor, taskExecutor, undoManager, stateManager);
input.textProperty().bindBidirectional(viewModel.inputTextProperty());
}

private void optOutOfGrobid(boolean optOut) {
preferencesService.storeImportSettingsPreferences(preferencesService.getImportSettingsPreferences().withGrobidOptOut(optOut));
}
}
19 changes: 18 additions & 1 deletion src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.jabref.logic.help.HelpFile;
import org.jabref.logic.importer.EntryBasedFetcher;
import org.jabref.logic.importer.WebFetchers;
import org.jabref.logic.importer.fileformat.PdfMergeMetadataImporter;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.Field;
Expand Down Expand Up @@ -355,11 +356,27 @@ private void setupToolBar() {

// Add menu for fetching bibliographic information
ContextMenu fetcherMenu = new ContextMenu();
for (EntryBasedFetcher fetcher : WebFetchers.getEntryBasedFetchers(preferencesService.getImportFormatPreferences(), preferencesService.getFilePreferences(), databaseContext, preferencesService.getDefaultEncoding())) {
for (EntryBasedFetcher fetcher : WebFetchers.getEntryBasedFetchers(preferencesService.getImportSettingsPreferences(), preferencesService.getImportFormatPreferences(), preferencesService.getFilePreferences(), databaseContext, preferencesService.getDefaultEncoding())) {
MenuItem fetcherMenuItem = new MenuItem(fetcher.getName());
fetcherMenuItem.setOnAction(event -> fetchAndMerge(fetcher));
fetcherMenu.getItems().add(fetcherMenuItem);
}
// Treat the PdfMergeMetadataImporter separately since if the use never accepted or disabled grobid, we ask to enable it
MenuItem pdfMergeMetadataImporterMenuItem = new MenuItem("PDFmergemetadata");
pdfMergeMetadataImporterMenuItem.setOnAction(event -> {
if (!preferencesService.getImportSettingsPreferences().isGrobidEnabled() && !preferencesService.getImportSettingsPreferences().isGrobidOptOut()) {
boolean confirmGrobidUsage = dialogService.showConfirmationDialogWithOptOutAndWait(
"Remote services",
"Allow sending PDF files and raw citation strings to a JabRef online service (Grobid) to determine Metadata",
"Use other importers instead",
(optOut) -> preferencesService.storeImportSettingsPreferences(preferencesService.getImportSettingsPreferences().withGrobidOptOut(optOut))
);
preferencesService.storeImportSettingsPreferences(preferencesService.getImportSettingsPreferences().withGrobidEnabled(confirmGrobidUsage));
}
PdfMergeMetadataImporter.EntryBasedFetcherWrapper pdfMergeMetadataImporter= new PdfMergeMetadataImporter.EntryBasedFetcherWrapper(preferencesService.getImportSettingsPreferences(), preferencesService.getImportFormatPreferences(), preferencesService.getFilePreferences(), databaseContext, preferencesService.getDefaultEncoding());
fetchAndMerge(pdfMergeMetadataImporter);
});
fetcherMenu.getItems().add(pdfMergeMetadataImporterMenuItem);
fetcherButton.setOnMouseClicked(event -> fetcherMenu.show(fetcherButton, Side.RIGHT, 0, 0));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ImportHandler(BibDatabaseContext database,
this.stateManager = stateManager;

this.linker = new ExternalFilesEntryLinker(externalFileTypes, preferencesService.getFilePreferences(), database);
this.contentImporter = new ExternalFilesContentImporter(preferencesService.getImportFormatPreferences(), preferencesService.getTimestampPreferences());
this.contentImporter = new ExternalFilesContentImporter(preferencesService.getImportSettingsPreferences(), preferencesService.getImportFormatPreferences(), preferencesService.getTimestampPreferences());
this.undoManager = undoManager;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void storeSettings() {
.map(ImporterViewModel::getLogic)
.collect(Collectors.toSet()));
Globals.IMPORT_FORMAT_READER.resetImportFormats(
preferences.getImportSettingsPreferences(),
preferences.getImportFormatPreferences(),
preferences.getXmpPreferences(),
Globals.getFileUpdateMonitor());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,11 @@

<Label styleClass="sectionHeader" text="%Export sort order"/>
<SaveOrderConfigPanel fx:id="exportOrderPanel"/>

<Label styleClass="sectionHeader" text="%Remote services"/>
<CheckBox fx:id="grobidEnabled" text="%Allow sending PDF files and raw citation strings to a JabRef online service (Grobid) to determine Metadata"/>
<HBox alignment="CENTER_LEFT" spacing="10.0">
<Label text="%Grobid URL" />
<TextField fx:id="grobidURL" HBox.hgrow="ALWAYS"/>
</HBox>
</fx:root>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class ImportExportTab extends AbstractPreferenceTabView<ImportExportTabVi

@FXML private SaveOrderConfigPanel exportOrderPanel;

@FXML private CheckBox grobidEnabled;
@FXML private TextField grobidURL;

public ImportExportTab() {
ViewLoader.view(this)
.root(this)
Expand All @@ -45,5 +48,9 @@ public void initialize() {
exportOrderPanel.sortableFieldsProperty().bind(viewModel.sortableFieldsProperty());
exportOrderPanel.sortCriteriaProperty().bindBidirectional(viewModel.sortCriteriaProperty());
exportOrderPanel.setCriteriaLimit(3);

grobidEnabled.selectedProperty().bindBidirectional(viewModel.grobidEnabledProperty());
grobidURL.textProperty().bindBidirectional(viewModel.grobidURLProperty());
grobidURL.disableProperty().bind(grobidEnabled.selectedProperty().not());
Copy link
Member

Choose a reason for hiding this comment

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

Could be done in directly in FXML. (disabled=${grobidEnabled.selected}) or similar. Lot's of examples elsewhere...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think that's possible here because you can't do the negation in fxml. It needs to be disabled if grobidEnabled is NOT selected.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class ImportExportTabViewModel implements PreferenceTabViewModel {
private final ListProperty<Field> sortableFieldsProperty = new SimpleListProperty<>(FXCollections.observableArrayList());
private final ListProperty<SortCriterionViewModel> sortCriteriaProperty = new SimpleListProperty<>(FXCollections.observableArrayList(new ArrayList<>()));

private final BooleanProperty grobidEnabledProperty = new SimpleBooleanProperty();
private final StringProperty grobidURLProperty = new SimpleStringProperty("");

private final PreferencesService preferencesService;
private final DOIPreferences initialDOIPreferences;
private final ImportSettingsPreferences initialImportSettingsPreferences;
Expand Down Expand Up @@ -67,12 +70,15 @@ public void setValues() {
sortCriteriaProperty.addAll(initialExportOrder.getSortCriteria().stream()
.map(SortCriterionViewModel::new)
.collect(Collectors.toList()));

grobidEnabledProperty.setValue(initialImportSettingsPreferences.isGrobidEnabled());
grobidURLProperty.setValue(initialImportSettingsPreferences.getGrobidURL());
}

@Override
public void storeSettings() {
preferencesService.storeImportSettingsPreferences(new ImportSettingsPreferences(
generateKeyOnImportProperty.getValue()));
generateKeyOnImportProperty.getValue(), grobidEnabledProperty.getValue(), preferencesService.getImportSettingsPreferences().isGrobidOptOut(), grobidURLProperty.getValue()));

preferencesService.storeDOIPreferences(new DOIPreferences(
useCustomDOIProperty.getValue(),
Expand Down Expand Up @@ -118,4 +124,12 @@ public ListProperty<Field> sortableFieldsProperty() {
public ListProperty<SortCriterionViewModel> sortCriteriaProperty() {
return sortCriteriaProperty;
}

public BooleanProperty grobidEnabledProperty() {
return grobidEnabledProperty;
}

public StringProperty grobidURLProperty() {
return grobidURLProperty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,25 @@
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.importer.fileformat.PdfMergeMetadataImporter;
import org.jabref.logic.importer.fileformat.PdfXmpImporter;
import org.jabref.logic.importer.importsettings.ImportSettingsPreferences;
import org.jabref.logic.preferences.TimestampPreferences;
import org.jabref.model.util.FileUpdateMonitor;

public class ExternalFilesContentImporter {

private final ImportSettingsPreferences importSettingsPreferences;
private final ImportFormatPreferences importFormatPreferences;
private final TimestampPreferences timestampPreferences;

public ExternalFilesContentImporter(ImportFormatPreferences importFormatPreferences, TimestampPreferences timestampPreferences) {
public ExternalFilesContentImporter(ImportSettingsPreferences importSettingsPreferences, ImportFormatPreferences importFormatPreferences, TimestampPreferences timestampPreferences) {
this.importSettingsPreferences = importSettingsPreferences;
this.importFormatPreferences = importFormatPreferences;
this.timestampPreferences = timestampPreferences;
}

public ParserResult importPDFContent(Path file) {
try {
return new PdfMergeMetadataImporter(importFormatPreferences).importDatabase(file, StandardCharsets.UTF_8);
return new PdfMergeMetadataImporter(importSettingsPreferences, importFormatPreferences).importDatabase(file, StandardCharsets.UTF_8);
} catch (IOException e) {
return ParserResult.fromError(e);
}
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/org/jabref/logic/importer/ImportFormatReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.SortedSet;
import java.util.TreeSet;

import org.jabref.logic.importer.fetcher.GrobidCitationFetcher;
import org.jabref.logic.importer.fileformat.BibTeXMLImporter;
import org.jabref.logic.importer.fileformat.BiblioscapeImporter;
import org.jabref.logic.importer.fileformat.BibtexImporter;
Expand All @@ -32,6 +31,7 @@
import org.jabref.logic.importer.fileformat.RepecNepImporter;
import org.jabref.logic.importer.fileformat.RisImporter;
import org.jabref.logic.importer.fileformat.SilverPlatterImporter;
import org.jabref.logic.importer.importsettings.ImportSettingsPreferences;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.preferences.TimestampPreferences;
import org.jabref.logic.xmp.XmpPreferences;
Expand All @@ -52,7 +52,7 @@ public class ImportFormatReader {

private ImportFormatPreferences importFormatPreferences;

public void resetImportFormats(ImportFormatPreferences newImportFormatPreferences, XmpPreferences xmpPreferences, FileUpdateMonitor fileMonitor) {
public void resetImportFormats(ImportSettingsPreferences importSettingsPreferences, ImportFormatPreferences newImportFormatPreferences, XmpPreferences xmpPreferences, FileUpdateMonitor fileMonitor) {
this.importFormatPreferences = newImportFormatPreferences;

formats.clear();
Expand All @@ -68,11 +68,13 @@ public void resetImportFormats(ImportFormatPreferences newImportFormatPreference
formats.add(new ModsImporter(importFormatPreferences));
formats.add(new MsBibImporter());
formats.add(new OvidImporter());
formats.add(new PdfMergeMetadataImporter(importFormatPreferences));
formats.add(new PdfMergeMetadataImporter(importSettingsPreferences, importFormatPreferences));
formats.add(new PdfVerbatimBibTextImporter(importFormatPreferences));
formats.add(new PdfContentImporter(importFormatPreferences));
formats.add(new PdfEmbeddedBibFileImporter(importFormatPreferences));
formats.add(new PdfGrobidImporter(GrobidCitationFetcher.GROBID_URL, importFormatPreferences));
if (importSettingsPreferences.isGrobidEnabled()) {
formats.add(new PdfGrobidImporter(importSettingsPreferences, importFormatPreferences));
}
formats.add(new PdfXmpImporter(xmpPreferences));
formats.add(new RepecNepImporter(importFormatPreferences));
formats.add(new RisImporter());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/logic/importer/WebFetchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.jabref.logic.importer.fetcher.TitleFetcher;
import org.jabref.logic.importer.fetcher.ZbMATH;
import org.jabref.logic.importer.fileformat.PdfMergeMetadataImporter;
import org.jabref.logic.importer.importsettings.ImportSettingsPreferences;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.StandardField;
Expand Down Expand Up @@ -137,15 +138,14 @@ public static SortedSet<IdBasedFetcher> getIdBasedFetchers(ImportFormatPreferenc
/**
* @return sorted set containing entry based fetchers
*/
public static SortedSet<EntryBasedFetcher> getEntryBasedFetchers(ImportFormatPreferences importFormatPreferences, FilePreferences filePreferences, BibDatabaseContext databaseContext, Charset defaultEncoding) {
public static SortedSet<EntryBasedFetcher> getEntryBasedFetchers(ImportSettingsPreferences importSettingsPreferences, ImportFormatPreferences importFormatPreferences, FilePreferences filePreferences, BibDatabaseContext databaseContext, Charset defaultEncoding) {
SortedSet<EntryBasedFetcher> set = new TreeSet<>(Comparator.comparing(WebFetcher::getName));
set.add(new AstrophysicsDataSystem(importFormatPreferences));
set.add(new DoiFetcher(importFormatPreferences));
set.add(new IsbnFetcher(importFormatPreferences));
set.add(new MathSciNet(importFormatPreferences));
set.add(new CrossRef());
set.add(new ZbMATH(importFormatPreferences));
set.add(new PdfMergeMetadataImporter.EntryBasedFetcherWrapper(importFormatPreferences, filePreferences, databaseContext, defaultEncoding));
return set;
}

Expand Down
Loading