Skip to content

Commit

Permalink
Extract method
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed Sep 29, 2024
1 parent 654616c commit d1c33d9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.Date;
import org.jabref.model.entry.LinkedFile;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.types.StandardEntryType;
import org.jabref.model.strings.StringUtil;
Expand Down Expand Up @@ -381,17 +382,7 @@ private void putDoi(BibEntry bibEntry, Element datafield) {

if ("e".equals(ind1) && StringUtil.isNotBlank("u") && StringUtil.isNotBlank(resource)) { // DOI
String fulltext = getSubfield("3", datafield);

if ("Volltext".equals(fulltext)) {
try {
LinkedFile linkedFile = new LinkedFile(URI.create(resource).toURL(), "PDF");
bibEntry.setField(StandardField.FILE, linkedFile.toString());
} catch (MalformedURLException e) {
LOGGER.info("Malformed URL: {}", resource);
}
} else {
bibEntry.setField(StandardField.DOI, resource);
}
handleVolltext(bibEntry, fulltext, resource, StandardField.DOI);
}
}

Expand All @@ -403,17 +394,20 @@ private void putElectronicLocation(BibEntry bibEntry, Element datafield) {
if ("4".equals(ind1) && "0".equals(ind2)) {
String fulltext = getSubfield("3", datafield);
String resource = getSubfield("u", datafield);
handleVolltext(bibEntry, fulltext, resource, StandardField.URL);
}
}

if ("Volltext".equals(fulltext) && StringUtil.isNotBlank(resource)) {
try {
LinkedFile linkedFile = new LinkedFile("", URI.create(resource).toURL(), StandardFileType.PDF.getName());
bibEntry.setFiles(List.of(linkedFile));
} catch (MalformedURLException | IllegalArgumentException e) {
LOGGER.info("Malformed URL: {}", resource);
}
} else {
bibEntry.setField(StandardField.URL, resource);
private static void handleVolltext(BibEntry bibEntry, String fieldName, String resource, Field fallBackField) {
if ("Volltext".equals(fieldName) && StringUtil.isNotBlank(resource)) {
try {
LinkedFile linkedFile = new LinkedFile("", URI.create(resource).toURL(), StandardFileType.PDF.getName());
bibEntry.setFiles(List.of(linkedFile));
} catch (MalformedURLException | IllegalArgumentException e) {
LOGGER.info("Malformed URL: {}", resource);
}
} else {
bibEntry.setField(fallBackField, resource);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void complexSearchQueryURLCorrect() throws Exception {
@Test
void performSearchMatchingMultipleEntries() throws FetcherException {
List<BibEntry> searchResult = fetcher.performSearch("effective java bloch");
assertEquals(List.of(bibEntryISBN9783960886402, bibEntryISBN0134685997), searchResult.subList(0, 1));
assertEquals(List.of(bibEntryISBN9783960886402, bibEntryISBN0134685997), searchResult.subList(0, 2));
}

@Test
Expand Down

0 comments on commit d1c33d9

Please sign in to comment.