Skip to content

Commit

Permalink
Improve ACS fetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-kolb committed Mar 15, 2020
1 parent a71959f commit de790f9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
25 changes: 13 additions & 12 deletions src/main/java/org/jabref/logic/importer/fetcher/ACS.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class ACS implements FulltextFetcher {

/**
* Tries to find a fulltext URL for a given BibTex entry.
*
* <p>
* Currently only uses the DOI if found.
*
* @param entry The Bibtex entry
Expand All @@ -37,23 +37,24 @@ public class ACS implements FulltextFetcher {
@Override
public Optional<URL> findFullText(BibEntry entry) throws IOException {
Objects.requireNonNull(entry);
Optional<URL> pdfLink = Optional.empty();

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

if (doi.isPresent()) {
String source = String.format(SOURCE, doi.get().getDOI());
// Retrieve PDF link
Document html = Jsoup.connect(source).ignoreHttpErrors(true).get();
Element link = html.select("a.button_primary").first();
if (!doi.isPresent()) {
return Optional.empty();
}

String source = String.format(SOURCE, doi.get().getDOI());
// Retrieve PDF link
Document html = Jsoup.connect(source).ignoreHttpErrors(true).get();
Element link = html.select("a.button_primary").first();

if (link != null) {
LOGGER.info("Fulltext PDF found @ ACS.");
pdfLink = Optional.of(new URL(source.replaceFirst("/abs/", "/pdf/")));
}
if (link != null) {
LOGGER.info("Fulltext PDF found @ ACS.");
return Optional.of(new URL(source.replaceFirst("/abs/", "/pdf/")));
}
return pdfLink;
return Optional.empty();
}

@Override
Expand Down
11 changes: 10 additions & 1 deletion src/test/java/org/jabref/logic/importer/fetcher/ACSTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

@FetcherTest
class ACSTest {

private ACS finder;
private BibEntry entry;

Expand Down Expand Up @@ -44,4 +43,14 @@ 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 de790f9

Please sign in to comment.