Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AstroPhysicsFetcher #7867

Merged
merged 3 commits into from
Jul 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,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
koppor marked this conversation as resolved.
Show resolved Hide resolved
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