diff --git a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java index 5148990b3be..5e817d5291c 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java +++ b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java @@ -65,6 +65,8 @@ public static FieldEditorFX getForField(final Field field, return new JournalEditor(field, suggestionProvider, fieldCheckers); } else if (fieldProperties.contains(FieldProperty.DOI) || fieldProperties.contains(FieldProperty.EPRINT) || fieldProperties.contains(FieldProperty.ISBN)) { return new IdentifierEditor(field, suggestionProvider, fieldCheckers); + } else if (fieldProperties.contains(FieldProperty.ISSN)) { + return new ISSNEditor(field, suggestionProvider, fieldCheckers); } else if (field == StandardField.OWNER) { return new OwnerEditor(field, suggestionProvider, fieldCheckers); } else if (field == StandardField.GROUPS) { @@ -97,8 +99,6 @@ public static FieldEditorFX getForField(final Field field, return new KeywordsEditor(field, suggestionProvider, fieldCheckers, preferences, undoManager); } else if (field == InternalField.KEY_FIELD) { return new CitationKeyEditor(field, suggestionProvider, fieldCheckers, databaseContext); - } else if (field == StandardField.ISSN) { - return new ISSNEditor(field, suggestionProvider, fieldCheckers); } else { // default return new SimpleEditor(field, suggestionProvider, fieldCheckers, preferences, isMultiLine, undoManager); diff --git a/src/main/java/org/jabref/gui/fieldeditors/ISSNEditor.fxml b/src/main/java/org/jabref/gui/fieldeditors/ISSNEditor.fxml index 021a0f24f60..44d70fb78c4 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/ISSNEditor.fxml +++ b/src/main/java/org/jabref/gui/fieldeditors/ISSNEditor.fxml @@ -3,13 +3,11 @@ - - + - - + diff --git a/src/main/java/org/jabref/gui/fieldeditors/ISSNEditor.java b/src/main/java/org/jabref/gui/fieldeditors/ISSNEditor.java index db100d37416..7fc01a07c4a 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/ISSNEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/ISSNEditor.java @@ -1,5 +1,7 @@ package org.jabref.gui.fieldeditors; +import java.util.Optional; + import javax.swing.undo.UndoManager; import javafx.fxml.FXML; @@ -8,6 +10,7 @@ import javafx.scene.layout.HBox; import org.jabref.gui.DialogService; +import org.jabref.gui.StateManager; import org.jabref.gui.autocompleter.SuggestionProvider; import org.jabref.gui.fieldeditors.contextmenu.DefaultMenu; import org.jabref.gui.util.TaskExecutor; @@ -23,11 +26,14 @@ public class ISSNEditor extends HBox implements FieldEditorFX { @FXML private ISSNEditorViewModel viewModel; @FXML private EditorTextArea textArea; @FXML private Button journalInfoButton; + @FXML private Button fetchInformationByIdentifierButton; @Inject private DialogService dialogService; @Inject private PreferencesService preferencesService; @Inject private UndoManager undoManager; @Inject private TaskExecutor taskExecutor; + @Inject private StateManager stateManager; + private Optional entry = Optional.empty(); public ISSNEditor(Field field, SuggestionProvider suggestionProvider, @@ -43,7 +49,9 @@ public ISSNEditor(Field field, fieldCheckers, taskExecutor, dialogService, - undoManager); + undoManager, + stateManager, + preferencesService); textArea.textProperty().bindBidirectional(viewModel.textProperty()); textArea.initContextMenu(new DefaultMenu(textArea)); @@ -57,6 +65,7 @@ public ISSNEditorViewModel getViewModel() { @Override public void bindToEntry(BibEntry entry) { + this.entry = Optional.of(entry); viewModel.bindToEntry(entry); } @@ -70,6 +79,11 @@ public void requestFocus() { textArea.requestFocus(); } + @FXML + private void fetchInformationByIdentifier() { + entry.ifPresent(viewModel::fetchBibliographyInformation); + } + @FXML private void showJournalInfo() { if (JournalInfoOptInDialogHelper.isJournalInfoEnabled(dialogService, preferencesService.getEntryEditorPreferences())) { diff --git a/src/main/java/org/jabref/gui/fieldeditors/ISSNEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/ISSNEditorViewModel.java index 4784580409d..89cbf76e949 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/ISSNEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/ISSNEditorViewModel.java @@ -5,14 +5,23 @@ import javafx.scene.control.Button; 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.util.TaskExecutor; import org.jabref.logic.integrity.FieldCheckers; +import org.jabref.logic.l10n.Localization; +import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.Field; +import org.jabref.model.entry.field.StandardField; +import org.jabref.preferences.PreferencesService; public class ISSNEditorViewModel extends AbstractEditorViewModel { private final TaskExecutor taskExecutor; private final DialogService dialogService; + private final UndoManager undoManager; + private final StateManager stateManager; + private final PreferencesService preferencesService; public ISSNEditorViewModel( Field field, @@ -20,13 +29,26 @@ public ISSNEditorViewModel( FieldCheckers fieldCheckers, TaskExecutor taskExecutor, DialogService dialogService, - UndoManager undoManager) { + UndoManager undoManager, + StateManager stateManager, + PreferencesService preferencesService) { super(field, suggestionProvider, fieldCheckers, undoManager); this.taskExecutor = taskExecutor; this.dialogService = dialogService; + this.undoManager = undoManager; + this.stateManager = stateManager; + this.preferencesService = preferencesService; } public void showJournalInfo(Button journalInfoButton) { PopOverUtil.showJournalInfo(journalInfoButton, entry, dialogService, taskExecutor); } + + public void fetchBibliographyInformation(BibEntry bibEntry) { + stateManager.getActiveDatabase().ifPresentOrElse( + databaseContext -> new FetchAndMergeEntry(databaseContext, taskExecutor, preferencesService, dialogService, undoManager) + .fetchAndMerge(bibEntry, StandardField.ISSN), + () -> dialogService.notify(Localization.lang("No library selected")) + ); + } } diff --git a/src/main/java/org/jabref/gui/fieldeditors/identifier/IdentifierEditor.java b/src/main/java/org/jabref/gui/fieldeditors/identifier/IdentifierEditor.java index c05501335b6..7afd5d23fde 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/identifier/IdentifierEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/identifier/IdentifierEditor.java @@ -23,13 +23,16 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.Field; -import org.jabref.model.entry.field.StandardField; import org.jabref.preferences.PreferencesService; import com.airhacks.afterburner.injection.Injector; import com.airhacks.afterburner.views.ViewLoader; import jakarta.inject.Inject; +import static org.jabref.model.entry.field.StandardField.DOI; +import static org.jabref.model.entry.field.StandardField.EPRINT; +import static org.jabref.model.entry.field.StandardField.ISBN; + public class IdentifierEditor extends HBox implements FieldEditorFX { @FXML private BaseIdentifierEditorViewModel viewModel; @@ -53,14 +56,18 @@ public IdentifierEditor(Field field, // but we need the injected vars to create the viewmodels. Injector.registerExistingAndInject(this); - if (StandardField.DOI == field) { - this.viewModel = new DoiIdentifierEditorViewModel(suggestionProvider, fieldCheckers, dialogService, taskExecutor, preferencesService, undoManager, stateManager); - } else if (StandardField.ISBN == field) { - this.viewModel = new ISBNIdentifierEditorViewModel(suggestionProvider, fieldCheckers, dialogService, taskExecutor, preferencesService, undoManager, stateManager); - } else if (StandardField.EPRINT == field) { - this.viewModel = new EprintIdentifierEditorViewModel(suggestionProvider, fieldCheckers, dialogService, taskExecutor, preferencesService, undoManager); - } else { - throw new IllegalStateException(String.format("Unable to instantiate a view model for identifier field editor '%s'", field.getDisplayName())); + switch (field) { + case DOI -> + this.viewModel = new DoiIdentifierEditorViewModel(suggestionProvider, fieldCheckers, dialogService, taskExecutor, preferencesService, undoManager, stateManager); + case ISBN -> + this.viewModel = new ISBNIdentifierEditorViewModel(suggestionProvider, fieldCheckers, dialogService, taskExecutor, preferencesService, undoManager, stateManager); + case EPRINT -> + this.viewModel = new EprintIdentifierEditorViewModel(suggestionProvider, fieldCheckers, dialogService, taskExecutor, preferencesService, undoManager); + + case null, default -> { + assert field != null; + throw new IllegalStateException(String.format("Unable to instantiate a view model for identifier field editor '%s'", field.getDisplayName())); + } } ViewLoader.view(this) @@ -74,7 +81,7 @@ public IdentifierEditor(Field field, lookupIdentifierButton.setTooltip( new Tooltip(Localization.lang("Look up %0", field.getDisplayName()))); - if (field.equals(StandardField.DOI)) { + if (field.equals(DOI)) { textArea.initContextMenu(EditorMenus.getDOIMenu(textArea, dialogService, preferencesService)); } else { textArea.initContextMenu(new DefaultMenu(textArea)); @@ -89,7 +96,6 @@ public BaseIdentifierEditorViewModel getViewModel() { @Override public void bindToEntry(BibEntry entry) { - this.entry = Optional.of(entry); viewModel.bindToEntry(entry); } diff --git a/src/main/java/org/jabref/logic/importer/WebFetchers.java b/src/main/java/org/jabref/logic/importer/WebFetchers.java index 6a7b0f7d07d..344fa6399b3 100644 --- a/src/main/java/org/jabref/logic/importer/WebFetchers.java +++ b/src/main/java/org/jabref/logic/importer/WebFetchers.java @@ -28,6 +28,7 @@ import org.jabref.logic.importer.fetcher.IEEE; import org.jabref.logic.importer.fetcher.INSPIREFetcher; import org.jabref.logic.importer.fetcher.IacrEprintFetcher; +import org.jabref.logic.importer.fetcher.IssnFetcher; import org.jabref.logic.importer.fetcher.LOBIDFetcher; import org.jabref.logic.importer.fetcher.LibraryOfCongress; import org.jabref.logic.importer.fetcher.MathSciNet; @@ -51,8 +52,10 @@ import org.jabref.model.entry.identifier.Identifier; import org.jabref.preferences.FilePreferences; +import static org.jabref.model.entry.field.StandardField.DOI; import static org.jabref.model.entry.field.StandardField.EPRINT; import static org.jabref.model.entry.field.StandardField.ISBN; +import static org.jabref.model.entry.field.StandardField.ISSN; public class WebFetchers { @@ -62,16 +65,18 @@ private WebFetchers() { public static Optional getIdBasedFetcherForField(Field field, ImportFormatPreferences importFormatPreferences) { IdBasedFetcher fetcher; - if (field == StandardField.DOI) { - fetcher = new DoiFetcher(importFormatPreferences); - } else if (field == ISBN) { - fetcher = new IsbnFetcher(importFormatPreferences); - // .addRetryFetcher(new EbookDeIsbnFetcher(importFormatPreferences)); - // .addRetryFetcher(new DoiToBibtexConverterComIsbnFetcher(importFormatPreferences)); - } else if (field == EPRINT) { - fetcher = new ArXivFetcher(importFormatPreferences); - } else { - return Optional.empty(); + switch (field) { + case DOI -> + fetcher = new DoiFetcher(importFormatPreferences); + case ISBN -> + fetcher = new IsbnFetcher(importFormatPreferences); + case EPRINT -> + fetcher = new ArXivFetcher(importFormatPreferences); + case ISSN -> + fetcher = new IssnFetcher(); + case null, default -> { + return Optional.empty(); + } } return Optional.of(fetcher); } @@ -162,7 +167,8 @@ public static SortedSet getEntryBasedFetchers(ImporterPrefere set.add(new AstrophysicsDataSystem(importFormatPreferences, importerPreferences)); set.add(new DoiFetcher(importFormatPreferences)); set.add(new IsbnFetcher(importFormatPreferences)); - // .addRetryFetcher(new EbookDeIsbnFetcher(importFormatPreferences))); + set.add(new IssnFetcher()); + // .addRetryFetcher(new EbookDeIsbnFetcher(importFormatPreferences))); // .addRetryFetcher(new DoiToBibtexConverterComIsbnFetcher(importFormatPreferences))); set.add(new MathSciNet(importFormatPreferences)); set.add(new CrossRef()); diff --git a/src/main/java/org/jabref/logic/importer/fetcher/DOAJFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/DOAJFetcher.java index 815996d311f..8898c730253 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/DOAJFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/DOAJFetcher.java @@ -55,10 +55,10 @@ public DOAJFetcher(ImportFormatPreferences preferences) { */ public static BibEntry parseBibJSONtoBibtex(JSONObject bibJsonEntry, Character keywordSeparator) { // Fields that are directly accessible at the top level BibJson object - Field[] singleFields = {StandardField.YEAR, StandardField.TITLE, StandardField.ABSTRACT, StandardField.MONTH}; + List singleFields = List.of(StandardField.YEAR, StandardField.TITLE, StandardField.ABSTRACT, StandardField.MONTH); // Fields that are accessible in the journal part of the BibJson object - Field[] journalSingleFields = {StandardField.PUBLISHER, StandardField.NUMBER, StandardField.VOLUME}; + List journalSingleFields = List.of(StandardField.PUBLISHER, StandardField.NUMBER, StandardField.VOLUME); BibEntry entry = new BibEntry(StandardEntryType.Article); @@ -155,13 +155,10 @@ public static BibEntry parseBibJSONtoBibtex(JSONObject bibJsonEntry, Character k return entry; } - public static URIBuilder addPath(URIBuilder base, String subPath) { + public static void addPath(URIBuilder base, String subPath) { // slightly altered version based on https://gist.github.com/enginer/230e2dc2f1d213a825d5 - if (StringUtil.isBlank(subPath) || "/".equals(subPath)) { - return base; - } else { + if (!StringUtil.isBlank(subPath) && !"/".equals(subPath)) { base.setPath(appendSegmentToPath(base.getPath(), subPath)); - return base; } } diff --git a/src/main/java/org/jabref/logic/importer/fetcher/IssnFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/IssnFetcher.java new file mode 100644 index 00000000000..11f85d12304 --- /dev/null +++ b/src/main/java/org/jabref/logic/importer/fetcher/IssnFetcher.java @@ -0,0 +1,52 @@ +package org.jabref.logic.importer.fetcher; + +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +import org.jabref.logic.importer.EntryBasedFetcher; +import org.jabref.logic.importer.FetcherException; +import org.jabref.logic.importer.IdBasedFetcher; +import org.jabref.logic.journals.JournalInformation; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.StandardField; + +/** + * Fetcher to generate the BibTex entry from an ISSN. + * As an ISSN ist just a journal identifier, so we only return journal title and publisher + * The idea is to use the {@link JournalInformationFetcher} to do a request for a given ISSN. + */ + +public class IssnFetcher implements EntryBasedFetcher, IdBasedFetcher { + + private final JournalInformationFetcher journalInformationFetcher; + + public IssnFetcher() { + this.journalInformationFetcher = new JournalInformationFetcher(); + } + + @Override + public List performSearch(BibEntry entry) throws FetcherException { + Optional issn = entry.getField(StandardField.ISSN); + if (issn.isPresent()) { + Optional journalInformation = journalInformationFetcher.getJournalInformation(issn.get(), ""); + return journalInformation.map(journalInfo -> journalInformationToBibEntry(journalInfo, issn.get())).stream().toList(); + } + return Collections.emptyList(); + } + + @Override + public String getName() { + return "ISSN"; + } + + @Override + public Optional performSearchById(String identifier) throws FetcherException { + Optional journalInformation = journalInformationFetcher.getJournalInformation(identifier, ""); + return journalInformation.map(journalInfo -> journalInformationToBibEntry(journalInfo, identifier)); + } + + private BibEntry journalInformationToBibEntry(JournalInformation journalInfo, String issn) { + return new BibEntry().withField(StandardField.JOURNALTITLE, journalInfo.title()).withField(StandardField.PUBLISHER, journalInfo.publisher()).withField(StandardField.ISSN, issn); + } +} diff --git a/src/main/java/org/jabref/logic/importer/fetcher/JournalInformationFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/JournalInformationFetcher.java index 7d12875b7c9..279edc6594a 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/JournalInformationFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/JournalInformationFetcher.java @@ -31,6 +31,7 @@ public class JournalInformationFetcher implements WebFetcher { public static final String NAME = "Journal Information"; private static final Logger LOGGER = LoggerFactory.getLogger(JournalInformationFetcher.class); + // Uses JabRef Online APIs private static final String API_URL = "https://jabref.org/api"; private static final Pattern QUOTES_BRACKET_PATTERN = Pattern.compile("[\"\\[\\]]"); @@ -90,7 +91,7 @@ private JournalInformation parseResponse(JSONObject responseJsonObject) throws F try { if (responseJsonObject.has("errors")) { JSONArray errors = responseJsonObject.optJSONArray("errors"); - if (errors != null && errors.length() > 0) { + if (errors != null && !errors.isEmpty()) { JSONObject error = errors.getJSONObject(0); String errorMessage = error.optString("message", ""); LOGGER.error("Error accessing catalog: {}", errorMessage); diff --git a/src/main/java/org/jabref/logic/importer/fetcher/isbntobibtex/IsbnFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/isbntobibtex/IsbnFetcher.java index 23344ddbba9..c449320075d 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/isbntobibtex/IsbnFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/isbntobibtex/IsbnFetcher.java @@ -34,13 +34,12 @@ public class IsbnFetcher implements EntryBasedFetcher, IdBasedFetcher { private static final Logger LOGGER = LoggerFactory.getLogger(IsbnFetcher.class); private static final Pattern NEWLINE_SPACE_PATTERN = Pattern.compile("\\n|\\r\\n|\\s"); protected final ImportFormatPreferences importFormatPreferences; - private final OpenLibraryIsbnFetcher openLibraryIsbnFetcher; private final List retryIsbnFetcher; private final GvkFetcher gvkIbsnFetcher; public IsbnFetcher(ImportFormatPreferences importFormatPreferences) { this.importFormatPreferences = importFormatPreferences; - this.openLibraryIsbnFetcher = new OpenLibraryIsbnFetcher(importFormatPreferences); + OpenLibraryIsbnFetcher openLibraryIsbnFetcher = new OpenLibraryIsbnFetcher(importFormatPreferences); this.gvkIbsnFetcher = new GvkFetcher(importFormatPreferences); this.retryIsbnFetcher = new ArrayList<>(); this.addRetryFetcher(openLibraryIsbnFetcher); diff --git a/src/main/java/org/jabref/logic/integrity/ISSNChecker.java b/src/main/java/org/jabref/logic/integrity/ISSNChecker.java index 23502ec9e8a..f7205d195b5 100644 --- a/src/main/java/org/jabref/logic/integrity/ISSNChecker.java +++ b/src/main/java/org/jabref/logic/integrity/ISSNChecker.java @@ -22,10 +22,9 @@ public Optional checkValue(String value) { return Optional.of(Localization.lang("incorrect format")); } - if (issn.isValidChecksum()) { - return Optional.empty(); - } else { + if (!issn.isValidChecksum()) { return Optional.of(Localization.lang("incorrect control digit")); } + return Optional.empty(); } } diff --git a/src/main/java/org/jabref/model/entry/field/FieldProperty.java b/src/main/java/org/jabref/model/entry/field/FieldProperty.java index cba4a76714b..19356f4dccb 100644 --- a/src/main/java/org/jabref/model/entry/field/FieldProperty.java +++ b/src/main/java/org/jabref/model/entry/field/FieldProperty.java @@ -10,6 +10,7 @@ public enum FieldProperty { FILE_EDITOR, GENDER, ISBN, + ISSN, JOURNAL_NAME, LANGUAGE, MONTH, diff --git a/src/main/java/org/jabref/model/entry/field/StandardField.java b/src/main/java/org/jabref/model/entry/field/StandardField.java index 0e568838fb5..c286ca6ea3c 100644 --- a/src/main/java/org/jabref/model/entry/field/StandardField.java +++ b/src/main/java/org/jabref/model/entry/field/StandardField.java @@ -66,7 +66,7 @@ public enum StandardField implements Field { INTRODUCTION("introduction", FieldProperty.PERSON_NAMES), ISBN("isbn", "ISBN", FieldProperty.ISBN, FieldProperty.VERBATIM), ISRN("isrn", "ISRN", FieldProperty.VERBATIM), - ISSN("issn", "ISSN", FieldProperty.VERBATIM), + ISSN("issn", "ISSN", FieldProperty.ISSN, FieldProperty.VERBATIM), ISSUE("issue"), ISSUETITLE("issuetitle"), ISSUESUBTITLE("issuesubtitle"), diff --git a/src/main/java/org/jabref/model/entry/identifier/ISSN.java b/src/main/java/org/jabref/model/entry/identifier/ISSN.java index 5063536eda9..7050a74687c 100644 --- a/src/main/java/org/jabref/model/entry/identifier/ISSN.java +++ b/src/main/java/org/jabref/model/entry/identifier/ISSN.java @@ -1,10 +1,15 @@ package org.jabref.model.entry.identifier; +import java.net.URI; import java.util.Objects; +import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; -public class ISSN { +import org.jabref.model.entry.field.Field; +import org.jabref.model.entry.field.StandardField; + +public class ISSN implements Identifier { private static final Pattern ISSN_PATTERN = Pattern.compile("^\\d{4}-\\d{3}[\\dxX]$"); private static final Pattern ISSN_PATTERN_NODASH = Pattern.compile("^(\\d{4})(\\d{3}[\\dxX])$"); @@ -48,4 +53,19 @@ public boolean isValidChecksum() { } return ((((sum % 11) + control) - '0') == 11) || ((sum % 11) == 0); } + + @Override + public String getNormalized() { + return issnString; + } + + @Override + public Field getDefaultField() { + return StandardField.ISSN; + } + + @Override + public Optional getExternalURI() { + return Optional.empty(); + } } diff --git a/src/test/java/org/jabref/logic/importer/WebFetchersTest.java b/src/test/java/org/jabref/logic/importer/WebFetchersTest.java index ffa6314fff7..cf9b302c15d 100644 --- a/src/test/java/org/jabref/logic/importer/WebFetchersTest.java +++ b/src/test/java/org/jabref/logic/importer/WebFetchersTest.java @@ -11,6 +11,7 @@ import org.jabref.logic.importer.fetcher.GoogleScholar; import org.jabref.logic.importer.fetcher.GrobidCitationFetcher; import org.jabref.logic.importer.fetcher.GvkFetcher; +import org.jabref.logic.importer.fetcher.IssnFetcher; import org.jabref.logic.importer.fetcher.JstorFetcher; import org.jabref.logic.importer.fetcher.MrDLibFetcher; import org.jabref.logic.importer.fetcher.isbntobibtex.DoiToBibtexConverterComIsbnFetcher; @@ -78,6 +79,8 @@ void getIdBasedFetchersReturnsAllFetcherDerivingFromIdBasedFetcher() { expected.remove(EbookDeIsbnFetcher.class); expected.remove(GvkFetcher.class); expected.remove(DoiToBibtexConverterComIsbnFetcher.class); + // Remove special ISSN fetcher only suitable for journal lookup + expected.remove(IssnFetcher.class); // Remove the following, because they don't work at the moment expected.remove(JstorFetcher.class); expected.remove(GoogleScholar.class); diff --git a/src/test/java/org/jabref/logic/importer/fetcher/IssnFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/IssnFetcherTest.java new file mode 100644 index 00000000000..684e01ecc63 --- /dev/null +++ b/src/test/java/org/jabref/logic/importer/fetcher/IssnFetcherTest.java @@ -0,0 +1,56 @@ +package org.jabref.logic.importer.fetcher; + +import java.util.List; +import java.util.Optional; + +import org.jabref.logic.importer.FetcherException; +import org.jabref.logic.importer.ImportFormatPreferences; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.StandardField; +import org.jabref.preferences.BibEntryPreferences; +import org.jabref.testutils.category.FetcherTest; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +@FetcherTest +class IssnFetcherTest { + + private IssnFetcher fetcher; + private BibEntry bibEntry; + + @BeforeEach + void setUp() { + ImportFormatPreferences importPrefs = mock(ImportFormatPreferences.class); + BibEntryPreferences bibEntryPrefs = mock(BibEntryPreferences.class); + when(importPrefs.bibEntryPreferences()).thenReturn(bibEntryPrefs); + + fetcher = new IssnFetcher(); + + bibEntry = new BibEntry() + .withField(StandardField.ISSN, "15454509") + .withField(StandardField.JOURNALTITLE, "Annual Review of Biochemistry") + .withField(StandardField.PUBLISHER, "Annual Reviews Inc."); + } + + @Test + void performSearchByEntry() throws FetcherException { + List fetchedEntry = fetcher.performSearch(bibEntry); + assertEquals(List.of(bibEntry), fetchedEntry); + } + + @Test + void performSearchById() throws FetcherException { + Optional fetchedEntry = fetcher.performSearchById("15454509"); + assertEquals(Optional.of(bibEntry), fetchedEntry); + } + + @Test + void getName() { + assertEquals("ISSN", fetcher.getName()); + } +}