diff --git a/CHANGELOG.md b/CHANGELOG.md index 407111ee185..5ef055fb511 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/docs/advanced-reading/fetchers.md b/docs/advanced-reading/fetchers.md index 9651ad9f282..a28445d66b9 100644 --- a/docs/advanced-reading/fetchers.md +++ b/docs/advanced-reading/fetchers.md @@ -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. diff --git a/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java b/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java index 2fff3084f95..c3dc605e7ef 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java @@ -171,7 +171,6 @@ public void doPostCleanup(BibEntry entry) { @Override public List performSearch(BibEntry entry) throws FetcherException { - if (entry.getFieldOrAlias(StandardField.TITLE).isEmpty() && entry.getFieldOrAlias(StandardField.AUTHOR).isEmpty()) { return Collections.emptyList(); } @@ -191,10 +190,8 @@ public List performSearch(BibEntry entry) throws FetcherException { * @return list of bibcodes matching the search request. May be empty */ private List 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"); @@ -275,17 +272,42 @@ private List performSearchByIds(Collection identifiers) throws } } + @Override + public List 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 bibCodes = fetchBibcodes(urlForQuery); + List results = performSearchByIds(bibCodes); + return results; + } + @Override public Page performSearchPaged(QueryNode luceneQuery, int pageNumber) throws FetcherException { + URL urlForQuery; try { - // This is currently just interpreting the complex query as a default string query - List bibcodes = fetchBibcodes(getURLForQuery(luceneQuery, pageNumber)); - Collection 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 bibCodes = fetchBibcodes(urlForQuery); + Collection 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; + } + } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java b/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java index 7f5c708047f..f7854d13f53 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java @@ -144,6 +144,7 @@ public void testGetName() { @Test public void searchByQueryFindsEntry() throws Exception { List fetchedEntries = fetcher.performSearch("Diez slice theorem Lie"); + assertFalse(fetchedEntries.isEmpty()); assertTrue(fetchedEntries.contains(diezSliceTheoremEntry)); } @@ -154,8 +155,10 @@ public void searchByEntryFindsEntry() throws Exception { searchEntry.setField(StandardField.AUTHOR, "Diez"); List 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