Skip to content

Commit

Permalink
Improve SpringerLink fetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-kolb committed Mar 15, 2020
1 parent 15c7981 commit 3eeb86c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/main/java/org/jabref/logic/importer/fetcher/SpringerLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,32 @@ public class SpringerLink implements FulltextFetcher {
@Override
public Optional<URL> findFullText(BibEntry entry) throws IOException {
Objects.requireNonNull(entry);
Optional<URL> pdfLink = Optional.empty();

// Try unique DOI first
Optional<DOI> doi = entry.getField(StandardField.DOI).flatMap(DOI::parse);

if (doi.isPresent()) {
// Available in catalog?
try {
HttpResponse<JsonNode> jsonResponse = Unirest.get(API_URL)
.queryString("api_key", API_KEY)
.queryString("q", String.format("doi:%s", doi.get().getDOI()))
.asJson();
if (jsonResponse.getBody() != null) {
JSONObject json = jsonResponse.getBody().getObject();
int results = json.getJSONArray("result").getJSONObject(0).getInt("total");
if (!doi.isPresent()) {
return Optional.empty();
}
// Available in catalog?
try {
HttpResponse<JsonNode> jsonResponse = Unirest.get(API_URL)
.queryString("api_key", API_KEY)
.queryString("q", String.format("doi:%s", doi.get().getDOI()))
.asJson();
if (jsonResponse.getBody() != null) {
JSONObject json = jsonResponse.getBody().getObject();
int results = json.getJSONArray("result").getJSONObject(0).getInt("total");

if (results > 0) {
LOGGER.info("Fulltext PDF found @ Springer.");
pdfLink = Optional.of(new URL("http", CONTENT_HOST, String.format("/content/pdf/%s.pdf", doi.get().getDOI())));
}
if (results > 0) {
LOGGER.info("Fulltext PDF found @ Springer.");
return Optional.of(new URL("http", CONTENT_HOST, String.format("/content/pdf/%s.pdf", doi.get().getDOI())));
}
} catch (UnirestException e) {
LOGGER.warn("SpringerLink API request failed", e);
}
} catch (UnirestException e) {
LOGGER.warn("SpringerLink API request failed", e);
}
return pdfLink;
return Optional.empty();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,14 @@ public void notFoundByDOI() throws IOException {

assertEquals(Optional.empty(), finder.findFullText(entry));
}

@Test
void entityWithoutDoi() throws IOException {
assertEquals(Optional.empty(), finder.findFullText(entry));
}

@Test
void trustLevel() {
assertEquals(TrustLevel.PUBLISHER, finder.getTrustLevel());
}
}

0 comments on commit 3eeb86c

Please sign in to comment.