Verified Owner
Top Inners Fields Constructors Methods
org.jabref.gui.externalfiles

public Class ImportHandler

extends Object
Class Inheritance
Imports
java.io.ByteArrayInputStream, .IOException, java.nio.charset.StandardCharsets, java.nio.file.Path, java.util.ArrayDeque, .ArrayList, .Collection, .Deque, .List, .Locale, .Optional, .Set, java.util.concurrent.CompletableFuture, javafx.application.Platform, javafx.scene.input.TransferMode, org.jabref.gui.DialogService, .StateManager, org.jabref.gui.duplicationFinder.DuplicateResolverDialog, org.jabref.gui.fieldeditors.LinkedFileViewModel, org.jabref.gui.importer.actions.AddGroupImportEntriesAction, org.jabref.gui.libraryproperties.constants.ConstantsItemModel, org.jabref.gui.mergeentries.multiwaymerge.MultiMergeEntriesView, org.jabref.gui.preferences.GuiPreferences, org.jabref.gui.util.DragDrop, .UiTaskExecutor, org.jabref.logic.FilePreferences, org.jabref.logic.citationkeypattern.CitationKeyGenerator, org.jabref.logic.database.DuplicateCheck, org.jabref.logic.externalfiles.ExternalFilesContentImporter, .LinkedFileTransferHelper, org.jabref.logic.importer.CompositeIdFetcher, .FetcherException, .ImportCleanup, .ImportException, .ImportFormatReader, .ImportFormatReader.ImportResult, .ParseException, .ParserResult, org.jabref.logic.importer.fileformat.BibtexParser, org.jabref.logic.importer.fileformat.pdf.PdfMergeMetadataImporter, org.jabref.logic.l10n.Localization, org.jabref.logic.net.URLDownload, org.jabref.logic.undo.UndoManager, .UndoSuspension, org.jabref.logic.util.BackgroundTask, .StandardFileType, .TaskExecutor, .URLUtil, .UpdateField, org.jabref.logic.util.io.FileUtil, org.jabref.model.TransferInformation, org.jabref.model.database.BibDatabase, .BibDatabaseContext, .KeyCollisionException, org.jabref.model.entry.BibEntry, .BibEntryTypesManager, .BibtexString, .LinkedFile, org.jabref.model.entry.field.StandardField, org.jabref.model.groups.ExplicitGroup, .GroupEntryChanger, .GroupTreeNode, org.jabref.model.undo.UndoableInsertEntries, .UndoableRemoveEntries, org.jabref.model.util.FileUpdateMonitor, .OptionalUtil, com.airhacks.afterburner.injection.Injector, com.google.common.annotations.VisibleForTesting, org.jspecify.annotations.NonNull, .Nullable, org.slf4j.Logger, .LoggerFactory

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static record
private static record

Field Summary

Modifier and TypeField and Description
private final ExternalFilesContentImporter
private final DialogService
private boolean
private final Deque<ImportHandler.DuplicateDecisionRequest>
private static final Set<String>
private final ExternalFilesEntryLinker
private static final String
private final FilePreferences
private final FileUpdateMonitor
private final ImportFormatReader
private static final Logger
private final GuiPreferences
private DuplicateResolverDialog.DuplicateResolverResult
private final StateManager
private final BibDatabaseContext
private final TaskExecutor
private final UndoManager

Constructor Summary

AccessConstructor and Description
public
ImportHandler(BibDatabaseContext targetBibDatabaseContext, GuiPreferences preferences, FileUpdateMonitor fileupdateMonitor, UndoManager undoManager, StateManager stateManager, DialogService dialogService, TaskExecutor taskExecutor)

Method Summary

Modifier and TypeMethod and Description
private void
private void
private BibEntry
public boolean
canImportAsBibEntry(Path file)

Checks whether the given file should be imported as bibliographic entries rather than attached as a file to an existing entry.

pack-priv BibEntry
private void
pack-priv ImportHandler.AutoDetectionImportOutcome
public void
private void
public Optional<BibEntry>
findDuplicate(BibEntry entryToCheck)

private void
generateKeys(List<BibEntry>
entries to generate keys for
entries
)

Generate keys for given entries if globally configured - or citation key is empty

public CompletableFuture<DuplicateDecisionResult>
public ExternalFilesEntryLinker
public @NonNull List<@NonNull BibEntry>
private @NonNull Optional<BibEntry>
handleDecisionResult(BibEntry originalEntry, BibEntry duplicateEntry, DuplicateDecisionResult decisionResult)

public CompletableFuture<Optional<BibEntry>>
private List<BibEntry>
public List<BibEntry>
public void
importCleanedEntries(@Nullable TransferInformation transferInformation, List<BibEntry> entries)

Adds already cleaned entries to the library, as one undo step.

public void
importEntries(List<BibEntry> entries)

Cleans up the given entries and adds them to the library.

public void
public void
public void
private void
importEntryWithDuplicateCheck(@Nullable TransferInformation transferInformation, BibEntry
the entry to import (original will not be modified)
entry
,
DuplicateResolverDialog.DuplicateResolverResult
the duplicate resolution strategy to apply
decision
,
EntryImportHandlerTracker
tracks the import status of the entry
tracker
)

Imports an entry into the database with duplicate checking and handling.

public org.jabref.logic.util.BackgroundTask<List<ImportFilesResultItemViewModel>>
importFilesInBackground(final List<Path> files, TransferMode transferMode)

public void
private void
insertImported(List<BibEntry> entriesToAdd, UndoSuspension suspended)

Inserts the imported entries and releases the library the import held.

private void
private void
removeReplacedDuplicate(BibEntry duplicateEntry)

Removes the entry that the import replaces or merges into, recording it.

private void
private DuplicateDecisionResult
public void
private List<BibEntry>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contentImporterback to summary
private final ExternalFilesContentImporter contentImporter
dialogServiceback to summary
private final DialogService dialogService
duplicateDecisionDialogInProgressback to summary
private boolean duplicateDecisionDialogInProgress
duplicateDecisionRequestsback to summary
private final Deque<ImportHandler.DuplicateDecisionRequest> duplicateDecisionRequests
EXCLUDED_CENTER_DROP_EXTENSIONSback to summary
private static final Set<String> EXCLUDED_CENTER_DROP_EXTENSIONS
fileLinkerback to summary
private final ExternalFilesEntryLinker fileLinker
FILENAME_FALLBACKback to summary
private static final String FILENAME_FALLBACK
filePreferencesback to summary
private final FilePreferences filePreferences
fileUpdateMonitorback to summary
private final FileUpdateMonitor fileUpdateMonitor
importFormatReaderback to summary
private final ImportFormatReader importFormatReader
LOGGERback to summary
private static final Logger LOGGER
preferencesback to summary
private final GuiPreferences preferences
rememberedBatchDuplicateDecisionback to summary
private DuplicateResolverDialog.DuplicateResolverResult rememberedBatchDuplicateDecision
stateManagerback to summary
private final StateManager stateManager
targetBibDatabaseContextback to summary
private final BibDatabaseContext targetBibDatabaseContext
taskExecutorback to summary
private final TaskExecutor taskExecutor
undoManagerback to summary
private final UndoManager undoManager

Constructor Detail

ImportHandlerback to summary
public ImportHandler(BibDatabaseContext targetBibDatabaseContext, GuiPreferences preferences, FileUpdateMonitor fileupdateMonitor, UndoManager undoManager, StateManager stateManager, DialogService dialogService, TaskExecutor taskExecutor)

Method Detail

addToGroupsback to summary
private void addToGroups(List<BibEntry> entries, Collection<GroupTreeNode> groups)
addToImportEntriesGroupback to summary
private void addToImportEntriesGroup(List<BibEntry> entriesToInsert)
adjustLinkedFilesForTargetIfRequiredback to summary
private BibEntry adjustLinkedFilesForTargetIfRequired(@Nullable TransferInformation transferInformation, BibEntry entry)
canImportAsBibEntryback to summary
public boolean canImportAsBibEntry(Path file)

Checks whether the given file should be imported as bibliographic entries rather than attached as a file to an existing entry. Excludes PDFs and generic document/data file extensions (.txt, .xml, .yml, .yaml) which are intended to be attached as files.

cleanUpEntryback to summary
pack-priv BibEntry cleanUpEntry(BibEntry entry)
Annotations
@VisibleForTesting
continueImportAfterDuplicateHandlingback to summary
private void continueImportAfterDuplicateHandling(@Nullable TransferInformation transferInformation, BibEntry entryForImport, EntryImportHandlerTracker tracker)
createAutoDetectionImportOutcomeback to summary
pack-priv ImportHandler.AutoDetectionImportOutcome createAutoDetectionImportOutcome(Path file, ImportResult importResult)
downloadLinkedFilesback to summary
public void downloadLinkedFiles(BibEntry entry)
enqueueDuplicateDecisionRequestback to summary
private void enqueueDuplicateDecisionRequest(ImportHandler.DuplicateDecisionRequest request)
findDuplicateback to summary
public Optional<BibEntry> findDuplicate(BibEntry entryToCheck)
generateKeysback to summary
private void generateKeys(List<BibEntry> entries)

Generate keys for given entries if globally configured - or citation key is empty

Parameters
entries:List<BibEntry>

entries to generate keys for

getDuplicateDecisionback to summary
public CompletableFuture<DuplicateDecisionResult> getDuplicateDecision(BibEntry originalEntry, BibEntry duplicateEntry, DuplicateResolverDialog.DuplicateResolverResult decision)
getFileLinkerback to summary
public ExternalFilesEntryLinker getFileLinker()
handleBibTeXDataback to summary
public @NonNull List<@NonNull BibEntry> handleBibTeXData(@NonNull String entries)
handleDecisionResultback to summary
private @NonNull Optional<BibEntry> handleDecisionResult(BibEntry originalEntry, BibEntry duplicateEntry, DuplicateDecisionResult decisionResult)
handleDuplicatesback to summary
public CompletableFuture<Optional<BibEntry>> handleDuplicates(BibEntry originalEntry, BibEntry duplicateEntry, DuplicateResolverDialog.DuplicateResolverResult decision)
handlePdfUrlback to summary
private List<BibEntry> handlePdfUrl(String pdfUrl) throws IOException
handleStringDataback to summary
public List<BibEntry> handleStringData(String data) throws org.jabref.logic.importer.FetcherException
importCleanedEntriesback to summary
public void importCleanedEntries(@Nullable TransferInformation transferInformation, List<BibEntry> entries)

Adds already cleaned entries to the library, as one undo step.

The step is opened here rather than left to the caller, because this is where the entries reach the library: a caller that forgot would insert entries the journal knows nothing about, which is a library that says it needs no saving. The group assignment this sets off joins the same step, so taking the import back takes the assignments with it.

importEntriesback to summary
public void importEntries(List<BibEntry> entries)

Cleans up the given entries and adds them to the library.

Actions include generating a citation key if configured

importEntriesWithDuplicateCheckback to summary
public void importEntriesWithDuplicateCheck(@Nullable TransferInformation transferInformation, List<BibEntry> entriesToAdd)
importEntriesWithDuplicateCheckback to summary
public void importEntriesWithDuplicateCheck(@Nullable TransferInformation transferInformation, List<BibEntry> entriesToAdd, EntryImportHandlerTracker tracker)
importEntryWithDuplicateCheckback to summary
public void importEntryWithDuplicateCheck(@Nullable TransferInformation transferInformation, BibEntry entry)
importEntryWithDuplicateCheckback to summary
private void importEntryWithDuplicateCheck(@Nullable TransferInformation transferInformation, BibEntry entry, DuplicateResolverDialog.DuplicateResolverResult decision, EntryImportHandlerTracker tracker)

Imports an entry into the database with duplicate checking and handling. Creates a copy of the entry for processing - the original entry parameter is not modified. The copied entry may be modified during cleanup and duplicate handling.

Parameters
entry:BibEntry

the entry to import (original will not be modified)

decision:DuplicateResolverDialog.DuplicateResolverResult

the duplicate resolution strategy to apply

tracker:EntryImportHandlerTracker

tracks the import status of the entry

importFilesInBackgroundback to summary
public org.jabref.logic.util.BackgroundTask<List<ImportFilesResultItemViewModel>> importFilesInBackground(final List<Path> files, TransferMode transferMode)
importStringConstantsWithDuplicateCheckback to summary
public void importStringConstantsWithDuplicateCheck(Collection<BibtexString> stringConstants)
insertImportedback to summary
private void insertImported(List<BibEntry> entriesToAdd, UndoSuspension suspended)

Inserts the imported entries and releases the library the import held.

importCleanedEntries records the insert as one step, so the files imported together are one Ctrl+Z, and what the insert sets off — group assignment, and the tab's automatic assignment to the selected groups — is recorded inside that step rather than after it.

processDuplicateDecisionQueueback to summary
private void processDuplicateDecisionQueue()
removeReplacedDuplicateback to summary
private void removeReplacedDuplicate(BibEntry duplicateEntry)

Removes the entry that the import replaces or merges into, recording it.

Its own step, because it happens well before the import it makes room for — the decision is asked of the user asynchronously. Undoing the import therefore takes the imported entry back out, and undoing once more brings the replaced entry back, rather than leaving the library without either.

resetBatchDuplicateDecisionStateback to summary
private void resetBatchDuplicateDecisionState()
resolveDuplicateDecisionback to summary
private DuplicateDecisionResult resolveDuplicateDecision(BibEntry originalEntry, BibEntry duplicateEntry, DuplicateResolverDialog.DuplicateResolverResult decision)
setAutomaticFieldsback to summary
public void setAutomaticFields(List<BibEntry> entries)
tryImportFormatsback to summary
private List<BibEntry> tryImportFormats(String data)
org.jabref.gui.externalfiles back to summary

pack-priv final Record ImportHandler.AutoDetectionImportOutcome

extends Record
Class Inheritance
Record Components
entriesToAdd:List<BibEntry> 
success:boolean 
message:String 

Field Summary

Modifier and TypeField and Description
private final List<BibEntry>
entriesToAdd

Record Component accessed by entriesToAdd().

private final String
message

Record Component accessed by message().

private final boolean
success

Record Component accessed by success().

Constructor Summary

AccessConstructor and Description
pack-priv
AutoDetectionImportOutcome(List<BibEntry> entriesToAdd, boolean success, String message)

Method Summary

Modifier and TypeMethod and Description
public List<BibEntry>
entriesToAdd()

Record Component getter of entriesToAdd.

public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public String
message()

Record Component getter of message.

public boolean
success()

Record Component getter of success.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

entriesToAddback to summary
private final List<BibEntry> entriesToAdd

Record Component accessed by entriesToAdd().

messageback to summary
private final String message

Record Component accessed by message().

successback to summary
private final boolean success

Record Component accessed by success().

Constructor Detail

AutoDetectionImportOutcomeback to summary
pack-priv AutoDetectionImportOutcome(List<BibEntry> entriesToAdd, boolean success, String message)

Method Detail

entriesToAddback to summary
public List<BibEntry> entriesToAdd()

Record Component getter of entriesToAdd.

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

messageback to summary
public String message()

Record Component getter of message.

successback to summary
public boolean success()

Record Component getter of success.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

org.jabref.gui.externalfiles back to summary

private final Record ImportHandler.DuplicateDecisionRequest

extends Record
Class Inheritance
Record Components
originalEntry:BibEntry 
duplicateEntry:BibEntry 
decision:DuplicateResolverDialog.DuplicateResolverResult 
result:CompletableFuture<DuplicateDecisionResult> 

Field Summary

Modifier and TypeField and Description
private final DuplicateResolverDialog.DuplicateResolverResult
decision

Record Component accessed by decision().

private final BibEntry
duplicateEntry

Record Component accessed by duplicateEntry().

private final BibEntry
originalEntry

Record Component accessed by originalEntry().

private final CompletableFuture<DuplicateDecisionResult>
result

Record Component accessed by result().

Constructor Summary

AccessConstructor and Description
private
private

Method Summary

Modifier and TypeMethod and Description
public DuplicateResolverDialog.DuplicateResolverResult
decision()

Record Component getter of decision.

public BibEntry
duplicateEntry()

Record Component getter of duplicateEntry.

public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public BibEntry
originalEntry()

Record Component getter of originalEntry.

public CompletableFuture<DuplicateDecisionResult>
result()

Record Component getter of result.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

decisionback to summary
private final DuplicateResolverDialog.DuplicateResolverResult decision

Record Component accessed by decision().

duplicateEntryback to summary
private final BibEntry duplicateEntry

Record Component accessed by duplicateEntry().

originalEntryback to summary
private final BibEntry originalEntry

Record Component accessed by originalEntry().

resultback to summary
private final CompletableFuture<DuplicateDecisionResult> result

Record Component accessed by result().

Constructor Detail

DuplicateDecisionRequestback to summary
private DuplicateDecisionRequest(BibEntry originalEntry, BibEntry duplicateEntry, DuplicateResolverDialog.DuplicateResolverResult decision)
DuplicateDecisionRequestback to summary
private DuplicateDecisionRequest(BibEntry originalEntry, BibEntry duplicateEntry, DuplicateResolverDialog.DuplicateResolverResult decision, CompletableFuture<DuplicateDecisionResult> result)

Method Detail

decisionback to summary
public DuplicateResolverDialog.DuplicateResolverResult decision()

Record Component getter of decision.

duplicateEntryback to summary
public BibEntry duplicateEntry()

Record Component getter of duplicateEntry.

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

originalEntryback to summary
public BibEntry originalEntry()

Record Component getter of originalEntry.

resultback to summary
public CompletableFuture<DuplicateDecisionResult> result()

Record Component getter of result.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.