-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
IsbnFetcher.java
70 lines (57 loc) · 2.32 KB
/
IsbnFetcher.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package org.jabref.logic.importer.fetcher;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import org.jabref.logic.help.HelpFile;
import org.jabref.logic.importer.EntryBasedFetcher;
import org.jabref.logic.importer.FetcherException;
import org.jabref.logic.importer.IdBasedFetcher;
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.FieldName;
import org.jabref.model.strings.StringUtil;
import org.jabref.model.util.OptionalUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Fetcher for ISBN trying ebook.de first and then chimbori.com
*/
public class IsbnFetcher implements EntryBasedFetcher, IdBasedFetcher {
private static final Logger LOGGER = LoggerFactory.getLogger(IsbnFetcher.class);
protected final ImportFormatPreferences importFormatPreferences;
public IsbnFetcher(ImportFormatPreferences importFormatPreferences) {
this.importFormatPreferences = importFormatPreferences;
}
@Override
public String getName() {
return "ISBN";
}
@Override
public Optional<HelpFile> getHelpPage() {
return Optional.of(HelpFile.FETCHER_ISBN);
}
@Override
public Optional<BibEntry> performSearchById(String identifier) throws FetcherException {
if (StringUtil.isBlank(identifier)) {
return Optional.empty();
}
IsbnViaEbookDeFetcher isbnViaEbookDeFetcher = new IsbnViaEbookDeFetcher(importFormatPreferences);
Optional<BibEntry> bibEntry = isbnViaEbookDeFetcher.performSearchById(identifier);
// nothing found at ebook.de, try chimbori.com
if (!bibEntry.isPresent()) {
LOGGER.debug("No entry found at ebook.de try chimbori.com");
IsbnViaChimboriFetcher isbnViaChimboriFetcher = new IsbnViaChimboriFetcher(importFormatPreferences);
bibEntry = isbnViaChimboriFetcher.performSearchById(identifier);
}
return bibEntry;
}
@Override
public List<BibEntry> performSearch(BibEntry entry) throws FetcherException {
Optional<String> isbn = entry.getField(FieldName.ISBN);
if (isbn.isPresent()) {
return OptionalUtil.toList(performSearchById(isbn.get()));
} else {
return Collections.emptyList();
}
}
}