Skip to content

Commit

Permalink
Refactor FetchAndMergeEntry to MergingIdBasedFetcher in logic layer
Browse files Browse the repository at this point in the history
- Create IdBasedFetcherFactory.java
- Move class from gui to org.jabref.logic.importer.fetcher
- Extract WebFetchers.getIdBasedFetcherForField as parameter for flexibility
- Replace DialogService with NotificationService to improve UX
- Rename class to MergingIdBasedFetcher for clarity
- Update all usages of FetchAndMergeEntry
  • Loading branch information
KUMOAWAI committed Oct 20, 2024
1 parent 74f2473 commit 93a9a8d
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 152 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.jabref.gui.keyboard.KeyBinding;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.menus.ChangeEntryTypeMenu;
import org.jabref.gui.mergeentries.FetchAndMergeEntry;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.undo.CountingUndoManager;
Expand All @@ -53,6 +52,7 @@
import org.jabref.logic.help.HelpFile;
import org.jabref.logic.importer.EntryBasedFetcher;
import org.jabref.logic.importer.WebFetchers;
import org.jabref.logic.importer.fetcher.MergingIdBasedFetcher;
import org.jabref.logic.importer.fileformat.PdfMergeMetadataImporter;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.util.BuildInfo;
Expand Down Expand Up @@ -450,7 +450,7 @@ private void setupToolBar() {
}

private void fetchAndMerge(EntryBasedFetcher fetcher) {
new FetchAndMergeEntry(libraryTab.getBibDatabaseContext(), taskExecutor, preferences, dialogService, undoManager).fetchAndMerge(currentlyEditedEntry, fetcher);
new MergingIdBasedFetcher(libraryTab.getBibDatabaseContext(), taskExecutor, preferences, dialogService, undoManager).fetchAndMerge(currentlyEditedEntry, fetcher);
}

public void setFocusToField(Field field) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.gui.autocompleter.SuggestionProvider;
import org.jabref.gui.mergeentries.FetchAndMergeEntry;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.logic.importer.fetcher.MergingIdBasedFetcher;
import org.jabref.logic.integrity.FieldCheckers;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.TaskExecutor;
Expand Down Expand Up @@ -46,7 +46,7 @@ public void showJournalInfo(Button journalInfoButton) {

public void fetchBibliographyInformation(BibEntry bibEntry) {
stateManager.getActiveDatabase().ifPresentOrElse(
databaseContext -> new FetchAndMergeEntry(databaseContext, taskExecutor, preferences, dialogService, undoManager)
databaseContext -> new MergingIdBasedFetcher(databaseContext, taskExecutor, preferences, dialogService, undoManager)
.fetchAndMerge(bibEntry, StandardField.ISSN),
() -> dialogService.notify(Localization.lang("No library selected"))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import org.jabref.gui.StateManager;
import org.jabref.gui.autocompleter.SuggestionProvider;
import org.jabref.gui.desktop.os.NativeDesktop;
import org.jabref.gui.mergeentries.FetchAndMergeEntry;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.logic.importer.fetcher.CrossRef;
import org.jabref.logic.importer.fetcher.MergingIdBasedFetcher;
import org.jabref.logic.integrity.FieldCheckers;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.BackgroundTask;
Expand Down Expand Up @@ -58,7 +58,7 @@ public void lookupIdentifier(BibEntry bibEntry) {
@Override
public void fetchBibliographyInformation(BibEntry bibEntry) {
stateManager.getActiveDatabase().ifPresentOrElse(
databaseContext -> new FetchAndMergeEntry(databaseContext, taskExecutor, preferences, dialogService, undoManager)
databaseContext -> new MergingIdBasedFetcher(databaseContext, taskExecutor, preferences, dialogService, undoManager)
.fetchAndMerge(entry, field),
() -> dialogService.notify(Localization.lang("No library selected"))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.gui.autocompleter.SuggestionProvider;
import org.jabref.gui.mergeentries.FetchAndMergeEntry;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.logic.importer.fetcher.MergingIdBasedFetcher;
import org.jabref.logic.integrity.FieldCheckers;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.TaskExecutor;
Expand Down Expand Up @@ -34,7 +34,7 @@ public ISBNIdentifierEditorViewModel(SuggestionProvider<?> suggestionProvider,
@Override
public void fetchBibliographyInformation(BibEntry bibEntry) {
stateManager.getActiveDatabase().ifPresentOrElse(
databaseContext -> new FetchAndMergeEntry(databaseContext, taskExecutor, preferences, dialogService, undoManager)
databaseContext -> new MergingIdBasedFetcher(databaseContext, taskExecutor, preferences, dialogService, undoManager)
.fetchAndMerge(entry, field),
() -> dialogService.notify(Localization.lang("No library selected"))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.jabref.gui.actions.ActionHelper;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.logic.importer.fetcher.MergingIdBasedFetcher;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.TaskExecutor;
import org.jabref.model.entry.BibEntry;
Expand All @@ -33,7 +34,7 @@ public MergeWithFetchedEntryAction(DialogService dialogService,
this.undoManager = undoManager;

this.executable.bind(ActionHelper.needsEntriesSelected(1, stateManager)
.and(ActionHelper.isAnyFieldSetForSelectedEntry(FetchAndMergeEntry.SUPPORTED_IDENTIFIER_FIELDS, stateManager)));
.and(ActionHelper.isAnyFieldSetForSelectedEntry(MergingIdBasedFetcher.SUPPORTED_IDENTIFIER_FIELDS, stateManager)));
}

@Override
Expand All @@ -49,14 +50,14 @@ public void execute() {
}

BibEntry originalEntry = stateManager.getSelectedEntries().getFirst();
FetchAndMergeEntry fetchAndMergeEntry = new FetchAndMergeEntry(
MergingIdBasedFetcher mergingIdBasedFetcher = new MergingIdBasedFetcher(
stateManager.getActiveDatabase().get(),
taskExecutor,
preferences,
dialogService,
undoManager
);

fetchAndMergeEntry.fetchAndMerge(originalEntry);
mergingIdBasedFetcher.fetchAndMerge(originalEntry);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.jabref.gui.actions.ActionHelper;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.logic.importer.fetcher.MergingIdBasedFetcher;
import org.jabref.logic.util.TaskExecutor;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
Expand Down Expand Up @@ -65,10 +66,10 @@ public void execute() {
return;
}

// Create an instance of FetchAndMergeEntry to perform the batch fetch and merge operation
// Create an instance of MergingIdBasedFetcher to perform the batch fetch and merge operation
BibDatabaseContext bibDatabaseContext = libraryTab.getBibDatabaseContext();
FetchAndMergeEntry fetchAndMergeEntry = new FetchAndMergeEntry(bibDatabaseContext, taskExecutor, preferences, dialogService, undoManager);
MergingIdBasedFetcher mergingIdBasedFetcher = new MergingIdBasedFetcher(bibDatabaseContext, taskExecutor, preferences, dialogService, undoManager);

fetchAndMergeEntry.fetchAndMergeBatch(selectedEntries);
mergingIdBasedFetcher.fetchAndMergeBatch(selectedEntries);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.jabref.logic.importer.fetcher;

import java.util.Optional;

import org.jabref.logic.importer.IdBasedFetcher;
import org.jabref.model.entry.field.Field;

@FunctionalInterface
public interface IdBasedFetcherFactory {
Optional<IdBasedFetcher> getFetcherForField(Field field);
}
Loading

0 comments on commit 93a9a8d

Please sign in to comment.