Skip to content

Commit

Permalink
ISSUE-262: Fix checkstyle issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ezienecker committed Oct 7, 2022
1 parent c00ff96 commit e419c81
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 36 deletions.
8 changes: 4 additions & 4 deletions src/main/java/org/jabref/logic/importer/WebFetchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -120,7 +120,7 @@ public static SortedSet<SearchBasedFetcher> getSearchBasedFetchers(ImportFormatP
set.add(new SemanticScholar());
set.add(new ResearchGate(importFormatPreferences));
set.add(new BiodiversityLibrary(importerPreferences));
return set;
return set;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 <a href="https://doi-to-bibtex-converter.herokuapp.com">https://doi-to-bibtex-converter.herokuapp.com</a>.
* Fetcher for ISBN using <a href="https://doi-to-bibtex-converter.herokuapp.com">doi-to-bibtex-converter.herokuapp</a>.
*/
public class DoiToBibtexConverterComIsbnFetcher extends AbstractIsbnFetcher {
private static final String BASE_URL = "https://doi-to-bibtex-converter.herokuapp.com";
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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}.
Expand Down Expand Up @@ -60,7 +61,8 @@ public Optional<BibEntry> 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()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
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;
import org.jabref.logic.importer.fetcher.AbstractIsbnFetcherTest;
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 {

Expand Down

0 comments on commit e419c81

Please sign in to comment.