1616import javax .xml .parsers .DocumentBuilderFactory ;
1717import javax .xml .parsers .ParserConfigurationException ;
1818
19- import org .jabref .logic .cleanup .CleanupJob ;
2019import org .jabref .logic .cleanup .EprintCleanup ;
2120import org .jabref .logic .help .HelpFile ;
2221import org .jabref .logic .importer .FetcherException ;
@@ -80,7 +79,6 @@ public Optional<URL> findFullText(BibEntry entry) throws IOException {
8079 .map (Optional ::get )
8180 .findFirst ();
8281 pdfUrl .ifPresent (url -> LOGGER .info ("Fulltext PDF found @ arXiv." ));
83-
8482 return pdfUrl ;
8583 } catch (FetcherException e ) {
8684 LOGGER .warn ("arXiv API request failed" , e );
@@ -117,11 +115,12 @@ private Optional<ArXivEntry> searchForEntryById(String id) throws FetcherExcepti
117115 }
118116 }
119117
120- private List <ArXivEntry > searchForEntries (BibEntry entry ) throws FetcherException {
121- entry = (BibEntry ) entry .clone ();
122- CleanupJob cleanupJob = new EprintCleanup ();
123- cleanupJob .cleanup (entry );
124- // 1. Eprint
118+ private List <ArXivEntry > searchForEntries (BibEntry originalEntry ) throws FetcherException {
119+ // We need to clone the entry, because we modify it by a cleanup job.
120+ final BibEntry entry = (BibEntry ) originalEntry .clone ();
121+
122+ // 1. Check for Eprint
123+ new EprintCleanup ().cleanup (entry );
125124 Optional <String > identifier = entry .getField (StandardField .EPRINT );
126125 if (StringUtil .isNotBlank (identifier )) {
127126 try {
@@ -133,26 +132,21 @@ private List<ArXivEntry> searchForEntries(BibEntry entry) throws FetcherExceptio
133132 }
134133
135134 // 2. DOI and other fields
136- String query ;
137-
138- Optional <String > doi = entry .getField (StandardField .DOI ).flatMap (DOI ::parse ).map (DOI ::getNormalized );
139- if (doi .isPresent ()) {
140- // Search for an entry in the ArXiv which is linked to the doi
141- query = "doi:" + doi .get ();
142- } else {
143- Optional <String > authorQuery = entry .getField (StandardField .AUTHOR ).map (author -> "au:" + author );
144- Optional <String > titleQuery = entry .getField (StandardField .TITLE ).map (title -> "ti:" + StringUtil .ignoreCurlyBracket (title ));
145- query = OptionalUtil .toList (authorQuery , titleQuery ).stream ().collect (Collectors .joining ("+AND+" ));
146- }
147-
135+ String query = entry .getField (StandardField .DOI )
136+ .flatMap (DOI ::parse )
137+ .map (DOI ::getNormalized )
138+ .map (doiString -> "doi:" + doiString )
139+ .orElseGet (() -> {
140+ Optional <String > authorQuery = entry .getField (StandardField .AUTHOR ).map (author -> "au:" + author );
141+ Optional <String > titleQuery = entry .getField (StandardField .TITLE ).map (title -> "ti:" + StringUtil .ignoreCurlyBracket (title ));
142+ return String .join ("+AND+" , OptionalUtil .toList (authorQuery , titleQuery ));
143+ });
148144 Optional <ArXivEntry > arxivEntry = searchForEntry (query );
149-
150145 if (arxivEntry .isPresent ()) {
151146 // Check if entry is a match
152147 StringSimilarity match = new StringSimilarity ();
153148 String arxivTitle = arxivEntry .get ().title .orElse ("" );
154149 String entryTitle = StringUtil .ignoreCurlyBracket (entry .getField (StandardField .TITLE ).orElse ("" ));
155-
156150 if (match .isSimilar (arxivTitle , entryTitle )) {
157151 return OptionalUtil .toList (arxivEntry );
158152 }
@@ -175,7 +169,7 @@ private List<ArXivEntry> queryApi(String searchQuery, List<ArXivIdentifier> ids,
175169
176170 /**
177171 * Queries the API.
178- *
172+ * <p>
179173 * If only {@code searchQuery} is given, then the API will return results for each article that matches the query.
180174 * If only {@code ids} is given, then the API will return results for each article in the list.
181175 * If both {@code searchQuery} and {@code ids} are given, then the API will return each article in
0 commit comments