Skip to content

Commit

Permalink
Mega changes
Browse files Browse the repository at this point in the history
  • Loading branch information
InAnYan committed Dec 18, 2024
1 parent e3ba5e6 commit 7c9bb38
Show file tree
Hide file tree
Showing 32 changed files with 504 additions and 694 deletions.
1 change: 1 addition & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,6 @@
requires mslinks;
requires org.antlr.antlr4.runtime;
requires org.libreoffice.uno;
requires org.jetbrains.annotations;
// endregion
}
8 changes: 4 additions & 4 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,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.logic.importer.fileformat.PdfImporter;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.util.BuildInfo;
import org.jabref.logic.util.TaskExecutor;
Expand Down Expand Up @@ -439,12 +439,12 @@ private void setupToolBar() {
databaseContext);
for (EntryBasedFetcher fetcher : entryBasedFetchers) {
MenuItem fetcherMenuItem = new MenuItem(fetcher.getName());
if (fetcher instanceof PdfMergeMetadataImporter.EntryBasedFetcherWrapper) {
if (fetcher instanceof PdfImporter.EntryBasedFetcherWrapper) {
// Handle Grobid Opt-In in case of the PdfMergeMetadataImporter
fetcherMenuItem.setOnAction(event -> {
GrobidUseDialogHelper.showAndWaitIfUserIsUndecided(dialogService, preferences.getGrobidPreferences());
PdfMergeMetadataImporter.EntryBasedFetcherWrapper pdfMergeMetadataImporter =
new PdfMergeMetadataImporter.EntryBasedFetcherWrapper(
PdfImporter.EntryBasedFetcherWrapper pdfMergeMetadataImporter =
new PdfImporter.EntryBasedFetcherWrapper(
preferences.getImportFormatPreferences(),
preferences.getFilePreferences(),
databaseContext);
Expand Down
38 changes: 18 additions & 20 deletions src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,13 @@
import org.jabref.gui.linkedfile.DeleteFileAction;
import org.jabref.gui.linkedfile.DownloadLinkedFileAction;
import org.jabref.gui.linkedfile.LinkedFileEditDialog;
import org.jabref.gui.mergeentries.MultiMergeEntriesView;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.gui.util.ControlHelper;
import org.jabref.logic.FilePreferences;
import org.jabref.logic.externalfiles.LinkedFileHandler;
import org.jabref.logic.importer.Importer;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.importer.fileformat.PdfContentImporter;
import org.jabref.logic.importer.fileformat.PdfEmbeddedBibFileImporter;
import org.jabref.logic.importer.fileformat.PdfGrobidImporter;
import org.jabref.logic.importer.fileformat.PdfVerbatimBibtexImporter;
import org.jabref.logic.importer.fileformat.PdfXmpImporter;
import org.jabref.logic.importer.fileformat.PdfImporter;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.TaskExecutor;
import org.jabref.logic.util.io.FileUtil;
Expand Down Expand Up @@ -455,22 +450,25 @@ public ValidationStatus fileExistsValidationStatus() {
return fileExistsValidator.getValidationStatus();
}

public void parsePdfMetadataAndShowMergeDialog() {
public void parsePdfMetadata() {
linkedFile.findIn(databaseContext, preferences.getFilePreferences()).ifPresent(filePath -> {
MultiMergeEntriesView dialog = new MultiMergeEntriesView(preferences, taskExecutor);
dialog.setTitle(Localization.lang("Merge PDF metadata"));
dialog.addSource(Localization.lang("Entry"), entry);
dialog.addSource(Localization.lang("Verbatim"), wrapImporterToSupplier(new PdfVerbatimBibtexImporter(preferences.getImportFormatPreferences()), filePath));
dialog.addSource(Localization.lang("Embedded"), wrapImporterToSupplier(new PdfEmbeddedBibFileImporter(preferences.getImportFormatPreferences()), filePath));
if (preferences.getGrobidPreferences().isGrobidEnabled()) {
dialog.addSource("Grobid", wrapImporterToSupplier(new PdfGrobidImporter(preferences.getImportFormatPreferences()), filePath));
}
dialog.addSource(Localization.lang("XMP metadata"), wrapImporterToSupplier(new PdfXmpImporter(preferences.getXmpPreferences()), filePath));
dialog.addSource(Localization.lang("Content"), wrapImporterToSupplier(new PdfContentImporter(), filePath));
dialogService.showCustomDialogAndWait(dialog).ifPresent(newEntry -> {
try {
PdfImporter importer = new PdfImporter(preferences.getImportFormatPreferences());
ParserResult result = importer.importDatabase(filePath);

// This code duplication is the result of mixing 2 idioms: exceptions in method specification
// vs exceptions in return type.
if (result.isInvalid()) {
LOGGER.error("Unable to extract PDF metadata: {}", result.getErrorMessage());
dialogService.notify(Localization.lang("Unable to extract PDF metadata: %0", result.getErrorMessage()));
}

databaseContext.getDatabase().removeEntry(entry);
databaseContext.getDatabase().insertEntry(newEntry);
});
databaseContext.getDatabase().insertEntries(result.getDatabase().getEntries());
} catch (Exception e) {
LOGGER.error("Unable to extract PDF metadata", e);
dialogService.notify(Localization.lang("Unable to extract PDF metadata: %0", e.getMessage()));
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private Node createFileDisplay(LinkedFileViewModel linkedFile) {
parsePdfMetadata.visibleProperty().bind(linkedFile.isOfflinePdfProperty());
parsePdfMetadata.setOnAction(event -> {
GrobidUseDialogHelper.showAndWaitIfUserIsUndecided(dialogService, preferences.getGrobidPreferences());
linkedFile.parsePdfMetadataAndShowMergeDialog();
linkedFile.parsePdfMetadata();
});
parsePdfMetadata.getStyleClass().setAll("icon-button");

Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/jabref/gui/importer/ImportCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
import org.jabref.logic.importer.ImportFormatReader;
import org.jabref.logic.importer.Importer;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.importer.fileformat.PdfGrobidImporter;
import org.jabref.logic.importer.fileformat.PdfMergeMetadataImporter;
import org.jabref.logic.importer.fileformat.PdfImporter;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.preferences.CliPreferences;
import org.jabref.logic.util.BackgroundTask;
Expand Down Expand Up @@ -153,8 +152,7 @@ private ParserResult doImport(List<Path> files, Importer importFormat) throws IO
imports.add(importFormatReader.importUnknownFormat(filename, fileUpdateMonitor));
} else {
UiTaskExecutor.runAndWaitInJavaFXThread(() -> {
if (((importer.get() instanceof PdfGrobidImporter)
|| (importer.get() instanceof PdfMergeMetadataImporter))
if (importer.get() instanceof PdfImporter
&& GrobidUseDialogHelper.showAndWaitIfUserIsUndecided(dialogService, preferences.getGrobidPreferences())) {
importFormatReader.reset();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.OpenDatabase;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.importer.fileformat.PdfMergeMetadataImporter;
import org.jabref.logic.importer.fileformat.PdfImporter;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.util.FileUpdateMonitor;

Expand All @@ -21,7 +21,7 @@ public ExternalFilesContentImporter(ImportFormatPreferences importFormatPreferen

public ParserResult importPDFContent(Path file, BibDatabaseContext context, FilePreferences filePreferences) {
try {
return new PdfMergeMetadataImporter(importFormatPreferences).importDatabase(file, context, filePreferences);
return new PdfImporter(importFormatPreferences).importDatabase(file, context, filePreferences);
} catch (IOException e) {
return ParserResult.fromError(e);
}
Expand Down
16 changes: 2 additions & 14 deletions src/main/java/org/jabref/logic/importer/ImportFormatReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@
import org.jabref.logic.importer.fileformat.ModsImporter;
import org.jabref.logic.importer.fileformat.MsBibImporter;
import org.jabref.logic.importer.fileformat.OvidImporter;
import org.jabref.logic.importer.fileformat.PdfContentImporter;
import org.jabref.logic.importer.fileformat.PdfEmbeddedBibFileImporter;
import org.jabref.logic.importer.fileformat.PdfGrobidImporter;
import org.jabref.logic.importer.fileformat.PdfMergeMetadataImporter;
import org.jabref.logic.importer.fileformat.PdfVerbatimBibtexImporter;
import org.jabref.logic.importer.fileformat.PdfXmpImporter;
import org.jabref.logic.importer.fileformat.PdfImporter;
import org.jabref.logic.importer.fileformat.RepecNepImporter;
import org.jabref.logic.importer.fileformat.RisImporter;
import org.jabref.logic.l10n.Localization;
Expand Down Expand Up @@ -74,14 +69,7 @@ public void reset() {
formats.add(new ModsImporter(importFormatPreferences));
formats.add(new MsBibImporter());
formats.add(new OvidImporter());
formats.add(new PdfMergeMetadataImporter(importFormatPreferences));
formats.add(new PdfVerbatimBibtexImporter(importFormatPreferences));
formats.add(new PdfContentImporter());
formats.add(new PdfEmbeddedBibFileImporter(importFormatPreferences));
if (importFormatPreferences.grobidPreferences().isGrobidEnabled()) {
formats.add(new PdfGrobidImporter(importFormatPreferences));
}
formats.add(new PdfXmpImporter(importFormatPreferences.xmpPreferences()));
formats.add(new PdfImporter(importFormatPreferences));
formats.add(new RepecNepImporter(importFormatPreferences));
formats.add(new RisImporter());
formats.add(new CffImporter(citationKeyPatternPreferences));
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 @@ -48,7 +48,7 @@
import org.jabref.logic.importer.fetcher.TitleFetcher;
import org.jabref.logic.importer.fetcher.ZbMATH;
import org.jabref.logic.importer.fetcher.isbntobibtex.IsbnFetcher;
import org.jabref.logic.importer.fileformat.PdfMergeMetadataImporter;
import org.jabref.logic.importer.fileformat.PdfImporter;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.StandardField;
Expand Down Expand Up @@ -180,7 +180,7 @@ public static SortedSet<EntryBasedFetcher> getEntryBasedFetchers(ImporterPrefere

// Uses the PDFs - and then uses the parsed DOI. Makes it 10% a web fetcher.
// We list it here, because otherwise, it would be much more effort (other UI button, ...)
set.add(new PdfMergeMetadataImporter.EntryBasedFetcherWrapper(importFormatPreferences, filePreferences, databaseContext));
set.add(new PdfImporter.EntryBasedFetcherWrapper(importFormatPreferences, filePreferences, databaseContext));

return set;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.jabref.logic.importer.AuthorListParser;
import org.jabref.logic.importer.Importer;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.importer.fileformat.pdf.PdfFirstPageBibExtractor;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.FileType;
import org.jabref.logic.util.StandardFileType;
Expand All @@ -43,7 +44,7 @@
* <p>
* Currently, IEEE two column format is supported.
* <p>
* To extract a {@link BibEntry} matching the PDF, see {@link PdfContentImporter}.
* To extract a {@link BibEntry} matching the PDF, see {@link PdfFirstPageBibExtractor}.
* <p>
* TODO: This class is similar to {@link org.jabref.logic.importer.plaincitation.RuleBasedPlainCitationParser}, we need to unify them.
*/
Expand Down

This file was deleted.

Loading

0 comments on commit 7c9bb38

Please sign in to comment.