Skip to content

Commit 871e413

Browse files
author
colinhex
committed
optimize CompositeIdFetcher.java
1 parent 1ca0272 commit 871e413

File tree

2 files changed

+15
-27
lines changed

2 files changed

+15
-27
lines changed

Diff for: src/main/java/org/jabref/logic/importer/CompositeIdFetcher.java

+15-24
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
import org.jabref.logic.importer.fetcher.IacrEprintFetcher;
99
import org.jabref.logic.importer.fetcher.IsbnFetcher;
1010
import org.jabref.model.entry.BibEntry;
11+
import org.jabref.model.entry.identifier.ArXivIdentifier;
12+
import org.jabref.model.entry.identifier.DOI;
13+
import org.jabref.model.entry.identifier.Eprint;
14+
import org.jabref.model.entry.identifier.ISBN;
1115

1216
import org.slf4j.Logger;
1317
import org.slf4j.LoggerFactory;
1418

15-
public class CompositeIdFetcher implements IdBasedFetcher {
19+
public class CompositeIdFetcher {
1620

1721
private static final Logger LOGGER = LoggerFactory.getLogger(CompositeIdFetcher.class);
1822

@@ -22,51 +26,42 @@ public CompositeIdFetcher(ImportFormatPreferences importFormatPreferences) {
2226
this.importFormatPreferences = importFormatPreferences;
2327
}
2428

25-
@Override
2629
public Optional<BibEntry> performSearchById(String identifier) {
27-
28-
Optional<BibEntry> fetchedEntry;
29-
3030
try {
31-
fetchedEntry = new ArXiv(importFormatPreferences).performSearchById(identifier);
32-
if (fetchedEntry.isPresent()) {
33-
return fetchedEntry;
31+
if (ArXivIdentifier.parse(identifier).isPresent()) {
32+
return new ArXiv(importFormatPreferences).performSearchById(identifier);
3433
}
3534
} catch (FetcherException fetcherException) {
3635
LOGGER.debug(fetcherException.getMessage());
3736
}
3837

3938
try {
40-
fetchedEntry = new IsbnFetcher(importFormatPreferences).performSearchById(identifier);
41-
if (fetchedEntry.isPresent()) {
42-
return fetchedEntry;
39+
if (ISBN.parse(identifier).isPresent()) {
40+
return new IsbnFetcher(importFormatPreferences).performSearchById(identifier);
4341
}
4442
} catch (FetcherException fetcherException) {
4543
LOGGER.debug(fetcherException.getMessage());
4644
}
4745

4846
try {
49-
fetchedEntry = new DoiFetcher(importFormatPreferences).performSearchById(identifier);
50-
if (fetchedEntry.isPresent()) {
51-
return fetchedEntry;
47+
if (DOI.parse(identifier).isPresent()) {
48+
return new DoiFetcher(importFormatPreferences).performSearchById(identifier);
5249
}
5350
} catch (FetcherException fetcherException) {
5451
LOGGER.debug(fetcherException.getMessage());
5552
}
5653

5754
try {
58-
fetchedEntry = new IacrEprintFetcher(importFormatPreferences).performSearchById(identifier);
59-
if (fetchedEntry.isPresent()) {
60-
return fetchedEntry;
55+
if (DOI.parse(identifier).isPresent()) {
56+
return new CrossRef().performSearchById(identifier);
6157
}
6258
} catch (FetcherException fetcherException) {
6359
LOGGER.debug(fetcherException.getMessage());
6460
}
6561

6662
try {
67-
fetchedEntry = new CrossRef().performSearchById(identifier);
68-
if (fetchedEntry.isPresent()) {
69-
return fetchedEntry;
63+
if (Eprint.build(identifier).isPresent()) {
64+
return new IacrEprintFetcher(importFormatPreferences).performSearchById(identifier);
7065
}
7166
} catch (FetcherException fetcherException) {
7267
LOGGER.debug(fetcherException.getMessage());
@@ -76,8 +71,4 @@ public Optional<BibEntry> performSearchById(String identifier) {
7671

7772
}
7873

79-
@Override
80-
public String getName() {
81-
return "CompositeIdFetcher";
82-
}
8374
}

Diff for: src/test/java/org/jabref/logic/importer/WebFetchersTest.java

-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ void getIdBasedFetchersReturnsAllFetcherDerivingFromIdBasedFetcher() throws Exce
5959
expected.remove(JstorFetcher.class);
6060
expected.remove(GoogleScholar.class);
6161

62-
// Remove CompositeIdFetcher for now
63-
expected.remove(CompositeIdFetcher.class);
64-
6562
assertEquals(expected, getClasses(idFetchers));
6663
}
6764
}

0 commit comments

Comments
 (0)