Skip to content

Commit

Permalink
Fix AstroPhysicsFetcher (#7867)
Browse files Browse the repository at this point in the history
* Fix authorization issue at performSearch

Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com>
Co-authored-by: Benedikt Tutzer <btut@users.noreply.github.com>

* Fix ADS fetcher to also use the bibCode indirection

Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com>

* Add CHANGELOG entry

Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com>

Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com>
Co-authored-by: Benedikt Tutzer <btut@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 4, 2021
1 parent f0709b7 commit d3b329f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where duplicate files (both file names and contents are the same) is downloaded and add to linked files [#6197](https://github.com/JabRef/jabref/issues/6197)
- We fixed an issue where changing the appearance of the preview tab did not trigger a restart warning. [#5464](https://github.com/JabRef/jabref/issues/5464)
- We fixed an issue where editing "Custom preview style" triggers exception. [#7526](https://github.com/JabRef/jabref/issues/7526)
- We fixed the [SAO/NASA Astrophysics Data System](https://docs.jabref.org/collect/import-using-online-bibliographic-database#sao-nasa-astrophysics-data-system) fetcher. [#7867](https://github.com/JabRef/jabref/pull/7867)
- We fixed an issue where a title with multiple applied formattings in EndNote was not imported correctly [forum#2734](https://discourse.jabref.org/t/importing-endnote-label-field-to-jabref-from-xml-file/2734)
- We fixed an issue where a `report` in EndNote was imported as `article` [forum#2734](https://discourse.jabref.org/t/importing-endnote-label-field-to-jabref-from-xml-file/2734)
- We fixed an issue where the field `publisher` in EndNote was not imported in JabRef [forum#2734](https://discourse.jabref.org/t/importing-endnote-label-field-to-jabref-from-xml-file/2734)
Expand Down
6 changes: 3 additions & 3 deletions docs/advanced-reading/fetchers.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ Fetchers are the implementation of the [search using online services](https://do

| Service | Key Source | Environment Variable | Rate Limit |
| :--- | :--- | :--- | :--- |
| [IEEEXplore](https://docs.jabref.org/collect/import-using-online-bibliographic-database/ieeexplore) | [IEEE Xplore API portal](https://developer.ieee.org/) | `IEEEAPIKey` | 200 calls/day |
| [IEEEXplore](https://docs.jabref.org/collect/import-using-online-bibliographic-database#ieeexplore) | [IEEE Xplore API portal](https://developer.ieee.org/) | `IEEEAPIKey` | 200 calls/day |
| [MathSciNet](http://www.ams.org/mathscinet) | \(none\) | \(none\) | Depending on the current network |
| [SAO/NASA Astrophysics Data System](https://docs.jabref.org/collect/import-using-online-bibliographic-database/ads) | [ADS UI](https://ui.adsabs.harvard.edu/user/settings/token) | `AstrophysicsDataSystemAPIKey` | 5000 calls/day |
| [SAO/NASA Astrophysics Data System](https://docs.jabref.org/collect/import-using-online-bibliographic-database#sao-nasa-astrophysics-data-system) | [ADS UI](https://ui.adsabs.harvard.edu/user/settings/token) | `AstrophysicsDataSystemAPIKey` | 5000 calls/day |
| [ScienceDirect](https://www.sciencedirect.com/) | | `ScienceDirectApiKey` | |
| [Springer Nature](https://docs.jabref.org/collect/import-using-online-bibliographic-database/springer) | [Springer Nature API Portal](https://dev.springernature.com/) | `SpringerNatureAPIKey` | 5000 calls/day |
| [Springer Nature](https://docs.jabref.org/collect/import-using-online-bibliographic-database#springer) | [Springer Nature API Portal](https://dev.springernature.com/) | `SpringerNatureAPIKey` | 5000 calls/day |
| [Zentralblatt Math](https://www.zbmath.org/) | \(none\) | \(none\) | Depending on the current network |

"Depending on the current network" means that it depends whether your request is routed through a network having paid access. For instance, some universities have subscriptions to MathSciNet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ public void doPostCleanup(BibEntry entry) {

@Override
public List<BibEntry> performSearch(BibEntry entry) throws FetcherException {

if (entry.getFieldOrAlias(StandardField.TITLE).isEmpty() && entry.getFieldOrAlias(StandardField.AUTHOR).isEmpty()) {
return Collections.emptyList();
}
Expand All @@ -191,10 +190,8 @@ public List<BibEntry> performSearch(BibEntry entry) throws FetcherException {
* @return list of bibcodes matching the search request. May be empty
*/
private List<String> fetchBibcodes(URL url) throws FetcherException {

try {
URLDownload download = new URLDownload(url);
download.addHeader("Authorization", "Bearer " + API_KEY);
URLDownload download = getUrlDownload(url);
String content = download.asString();
JSONObject obj = new JSONObject(content);
JSONArray codes = obj.getJSONObject("response").getJSONArray("docs");
Expand Down Expand Up @@ -275,17 +272,42 @@ private List<BibEntry> performSearchByIds(Collection<String> identifiers) throws
}
}

@Override
public List<BibEntry> performSearch(QueryNode luceneQuery) throws FetcherException {
URL urlForQuery;
try {
urlForQuery = getURLForQuery(luceneQuery);
} catch (URISyntaxException e) {
throw new FetcherException("Search URI is malformed", e);
} catch (IOException e) {
throw new FetcherException("A network error occurred", e);
}
List<String> bibCodes = fetchBibcodes(urlForQuery);
List<BibEntry> results = performSearchByIds(bibCodes);
return results;
}

@Override
public Page<BibEntry> performSearchPaged(QueryNode luceneQuery, int pageNumber) throws FetcherException {
URL urlForQuery;
try {
// This is currently just interpreting the complex query as a default string query
List<String> bibcodes = fetchBibcodes(getURLForQuery(luceneQuery, pageNumber));
Collection<BibEntry> results = performSearchByIds(bibcodes);
return new Page<>(luceneQuery.toString(), pageNumber, results);
urlForQuery = getURLForQuery(luceneQuery, pageNumber);
} catch (URISyntaxException e) {
throw new FetcherException("Search URI is malformed", e);
} catch (IOException e) {
throw new FetcherException("A network error occurred", e);
}
// This is currently just interpreting the complex query as a default string query
List<String> bibCodes = fetchBibcodes(urlForQuery);
Collection<BibEntry> results = performSearchByIds(bibCodes);
return new Page<>(luceneQuery.toString(), pageNumber, results);
}

@Override
public URLDownload getUrlDownload(URL url) {
URLDownload urlDownload = new URLDownload(url);
urlDownload.addHeader("Authorization", "Bearer " + API_KEY);
return urlDownload;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public void testGetName() {
@Test
public void searchByQueryFindsEntry() throws Exception {
List<BibEntry> fetchedEntries = fetcher.performSearch("Diez slice theorem Lie");
assertFalse(fetchedEntries.isEmpty());
assertTrue(fetchedEntries.contains(diezSliceTheoremEntry));
}

Expand All @@ -154,8 +155,10 @@ public void searchByEntryFindsEntry() throws Exception {
searchEntry.setField(StandardField.AUTHOR, "Diez");

List<BibEntry> fetchedEntries = fetcher.performSearch(searchEntry);

// The list contains more than one element, thus we need to check in two steps and cannot use assertEquals(List.of(diezSliceTheoremEntry, fetchedEntries))
assertFalse(fetchedEntries.isEmpty());
assertEquals(diezSliceTheoremEntry, fetchedEntries.get(0));
assertTrue(fetchedEntries.contains(diezSliceTheoremEntry));
}

@Test
Expand Down

0 comments on commit d3b329f

Please sign in to comment.