Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

/**
* Utility class for trying to resolve URLs to full-text PDF for articles.
*
* Combines multiple {@link FulltextFetcher}s together. Each fetcher is invoked, the "best" result (sorted by the fetcher trust level) is returned.
*/
public class FulltextFetchers {
private static final Logger LOGGER = LoggerFactory.getLogger(FulltextFetchers.class);
Expand Down Expand Up @@ -59,7 +61,7 @@ public Optional<URL> findFullTextPDF(BibEntry entry) {
BibEntry clonedEntry = (BibEntry) entry.clone();
Optional<DOI> doi = clonedEntry.getField(StandardField.DOI).flatMap(DOI::parse);

if (!doi.isPresent()) {
if (doi.isEmpty()) {
findDoiForEntry(clonedEntry);
}

Expand Down
25 changes: 9 additions & 16 deletions src/test/java/org/jabref/logic/importer/FulltextFetchersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@

import org.jabref.logic.importer.fetcher.TrustLevel;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.StandardField;
import org.jabref.testutils.category.FetcherTest;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -20,17 +19,8 @@

@FetcherTest
public class FulltextFetchersTest {
private BibEntry entry;

@BeforeEach
public void setUp() {
entry = new BibEntry();
}

@AfterEach
public void tearDown() {
entry = null;
}
private BibEntry entry = new BibEntry();

@Test
public void acceptPdfUrls() throws MalformedURLException {
Expand Down Expand Up @@ -60,18 +50,21 @@ public void noTrustLevel() throws MalformedURLException {

@Test
public void higherTrustLevelWins() throws IOException, FetcherException {
final URL lowUrl = new URL("http://docs.oasis-open.org/opencsa/sca-bpel/sca-bpel-1.1-spec-cd-01.pdf");
FulltextFetcher finderHigh = mock(FulltextFetcher.class);
when(finderHigh.getTrustLevel()).thenReturn(TrustLevel.SOURCE);
final URL highUrl = new URL("http://docs.oasis-open.org/wsbpel/2.0/OS/wsbpel-v2.0-OS.pdf");
when(finderHigh.findFullText(entry)).thenReturn(Optional.of(highUrl));

FulltextFetcher finderHigh = mock(FulltextFetcher.class);
FulltextFetcher finderLow = mock(FulltextFetcher.class);
when(finderHigh.getTrustLevel()).thenReturn(TrustLevel.SOURCE);
when(finderLow.getTrustLevel()).thenReturn(TrustLevel.UNKNOWN);
when(finderHigh.findFullText(entry)).thenReturn(Optional.of(highUrl));
final URL lowUrl = new URL("http://docs.oasis-open.org/opencsa/sca-bpel/sca-bpel-1.1-spec-cd-01.pdf");
when(finderLow.findFullText(entry)).thenReturn(Optional.of(lowUrl));

FulltextFetchers fetcher = new FulltextFetchers(Set.of(finderLow, finderHigh));

// set an (arbitrary) DOI to the test entry to skip side effects inside the "findFullTextPDF" method
entry.setField(StandardField.DOI, "10.5220/0007903201120130");

assertEquals(Optional.of(highUrl), fetcher.findFullTextPDF(entry));
}
}