diff --git a/src/main/java/org/jabref/logic/importer/WebFetchers.java b/src/main/java/org/jabref/logic/importer/WebFetchers.java index bbaf5d6e73fa..69b0dbb692df 100644 --- a/src/main/java/org/jabref/logic/importer/WebFetchers.java +++ b/src/main/java/org/jabref/logic/importer/WebFetchers.java @@ -28,9 +28,6 @@ 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.isbntobibtex.DoiToBibtexConverterComIsbnFetcher; -import org.jabref.logic.importer.fetcher.isbntobibtex.EbookDeIsbnFetcher; -import org.jabref.logic.importer.fetcher.isbntobibtex.IsbnFetcher; import org.jabref.logic.importer.fetcher.LibraryOfCongress; import org.jabref.logic.importer.fetcher.MathSciNet; import org.jabref.logic.importer.fetcher.MedlineFetcher; @@ -44,6 +41,9 @@ import org.jabref.logic.importer.fetcher.SpringerLink; import org.jabref.logic.importer.fetcher.TitleFetcher; import org.jabref.logic.importer.fetcher.ZbMATH; +import org.jabref.logic.importer.fetcher.isbntobibtex.DoiToBibtexConverterComIsbnFetcher; +import org.jabref.logic.importer.fetcher.isbntobibtex.EbookDeIsbnFetcher; +import org.jabref.logic.importer.fetcher.isbntobibtex.IsbnFetcher; import org.jabref.logic.importer.fileformat.PdfMergeMetadataImporter; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.field.Field; @@ -120,7 +120,7 @@ public static SortedSet getSearchBasedFetchers(ImportFormatP set.add(new SemanticScholar()); set.add(new ResearchGate(importFormatPreferences)); set.add(new BiodiversityLibrary(importerPreferences)); - return set; + return set; } /** diff --git a/src/main/java/org/jabref/logic/importer/fetcher/isbntobibtex/DoiToBibtexConverterComIsbnFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/isbntobibtex/DoiToBibtexConverterComIsbnFetcher.java index 58a2f5c2a576..cf3721eab658 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/isbntobibtex/DoiToBibtexConverterComIsbnFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/isbntobibtex/DoiToBibtexConverterComIsbnFetcher.java @@ -1,9 +1,13 @@ package org.jabref.logic.importer.fetcher.isbntobibtex; -import kong.unirest.json.JSONArray; -import kong.unirest.json.JSONException; -import kong.unirest.json.JSONObject; -import org.apache.http.client.utils.URIBuilder; +import java.net.MalformedURLException; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.Collections; +import java.util.List; +import java.util.stream.IntStream; +import java.util.stream.Stream; + import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.ParseException; @@ -15,16 +19,13 @@ import org.jabref.model.entry.types.StandardEntryType; import org.jabref.model.strings.StringUtil; -import java.net.MalformedURLException; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.Collections; -import java.util.List; -import java.util.stream.IntStream; -import java.util.stream.Stream; +import kong.unirest.json.JSONArray; +import kong.unirest.json.JSONException; +import kong.unirest.json.JSONObject; +import org.apache.http.client.utils.URIBuilder; /** - * Fetcher for ISBN using https://doi-to-bibtex-converter.herokuapp.com. + * Fetcher for ISBN using doi-to-bibtex-converter.herokuapp. */ public class DoiToBibtexConverterComIsbnFetcher extends AbstractIsbnFetcher { private static final String BASE_URL = "https://doi-to-bibtex-converter.herokuapp.com"; @@ -85,23 +86,24 @@ private BibEntry jsonItemToBibEntry(JSONObject item) throws ParseException { entry.setField(StandardField.MONTH, getElementFromJSONArrayByKey(data, "month")); entry.setField(StandardField.DAY, getElementFromJSONArrayByKey(data, "day")); return entry; - } catch (JSONException exception) { + } catch ( + JSONException exception) { throw new ParseException("CrossRef API JSON format has changed", exception); } } private String getElementFromJSONArrayByKey(JSONArray jsonArray, String key) { return IntStream.range(0, jsonArray.length()) - .mapToObj(jsonArray::getJSONObject) - .map(obj -> obj.getString(key)) - .findFirst() - .orElse(""); + .mapToObj(jsonArray::getJSONObject) + .map(obj -> obj.getString(key)) + .findFirst() + .orElse(""); } private StandardEntryType evaluateBibEntryTypeFromString(String type) { return Stream.of(StandardEntryType.values()) - .filter(entryType -> entryType.name().equalsIgnoreCase(type)) - .findAny() - .orElse(StandardEntryType.Book); + .filter(entryType -> entryType.name().equalsIgnoreCase(type)) + .findAny() + .orElse(StandardEntryType.Book); } } 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 02789d61b9d2..5de1b8086f43 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 @@ -1,5 +1,11 @@ package org.jabref.logic.importer.fetcher.isbntobibtex; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.regex.Pattern; + import org.jabref.logic.help.HelpFile; import org.jabref.logic.importer.EntryBasedFetcher; import org.jabref.logic.importer.FetcherException; @@ -10,15 +16,10 @@ import org.jabref.model.entry.field.StandardField; import org.jabref.model.strings.StringUtil; import org.jabref.model.util.OptionalUtil; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.regex.Pattern; - /** * Fetcher to generate the Bibtex entry from an ISBN. * The default fetcher is the {@link OpenLibraryIsbnFetcher}. @@ -60,7 +61,8 @@ public Optional performSearchById(String identifier) throws FetcherExc try { identifier = removeNewlinesAndSpacesFromIdentifier(identifier); bibEntry = openLibraryIsbnFetcher.performSearchById(identifier); - } catch (FetcherException ex) { + } catch ( + FetcherException ex) { LOGGER.debug("Got a fetcher exception for IBSN search", ex); } finally { while (bibEntry.isEmpty() && retryIsbnFetcher.iterator().hasNext()) { diff --git a/src/test/java/org/jabref/logic/importer/fetcher/isbntobibtex/DoiToBibtexConverterComIsbnFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/isbntobibtex/DoiToBibtexConverterComIsbnFetcherTest.java index 583aba5a63fe..8a19766feaa7 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/isbntobibtex/DoiToBibtexConverterComIsbnFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/isbntobibtex/DoiToBibtexConverterComIsbnFetcherTest.java @@ -1,10 +1,7 @@ package org.jabref.logic.importer.fetcher.isbntobibtex; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.mock; +import java.util.Optional; -import org.apache.commons.lang3.NotImplementedException; import org.jabref.logic.importer.FetcherClientException; import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportFormatPreferences; @@ -12,12 +9,15 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.types.StandardEntryType; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.mockito.Answers; -import java.util.Optional; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.mock; public class DoiToBibtexConverterComIsbnFetcherTest extends AbstractIsbnFetcherTest {