From 5e055a7acd7571849e2134c84d26840c27236f04 Mon Sep 17 00:00:00 2001 From: Shafin Kamal Date: Mon, 10 Oct 2022 21:50:34 +1100 Subject: [PATCH] DOAB Fetcher now fetches ISBN field where possible This commit modifies the URL for DOAB query to include `BITSTREAM` data. The fetcher can then obtain the ISBN and add the field to the entry accordingly. fixes #8708. --- CHANGELOG.md | 1 + .../logic/importer/fetcher/DOABFetcher.java | 30 +++++++++++++++---- .../importer/fetcher/DOABFetcherTest.java | 1 + 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cdaae90658..19c154098f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We reworked the Define study parameters dialog. [#9123](https://github.com/JabRef/jabref/pull/9123) - We simplified the actions to fast-resolve duplicates to 'Keep Left', 'Keep Right', 'Keep Both' and 'Keep Merged'. [#9056](https://github.com/JabRef/jabref/issues/9056) - We fixed an issue where a message about changed metadata would occur on saving although nothing changed. [#9159](https://github.com/JabRef/jabref/issues/9159) +- We modified the Directory of Open Access Books (DOAB) fetcher so that it will now also fetch the ISBN when possible. [#8708](https://github.com/JabRef/jabref/issues/8708) ### Fixed diff --git a/src/main/java/org/jabref/logic/importer/fetcher/DOABFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/DOABFetcher.java index 6adbb920937..0b30145e2e5 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/DOABFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/DOABFetcher.java @@ -45,7 +45,8 @@ public URL getURLForQuery(QueryNode luceneQuery) throws URISyntaxException, Malf // without the quotation the results returned are not relevant to the query query = ("\"".concat(query)).concat("\""); builder.addParameter("query", query); - builder.addParameter("expand", "metadata"); + // bitstreams included in URL building to acquire ISBN's. + builder.addParameter("expand", "metadata,bitstreams"); return builder.build().toURL(); } @@ -64,24 +65,43 @@ public Parser getParser() { // the information used for bibtex entries are in an array inside the resulting jsonarray // see this query for reference https://directory.doabooks.org/rest/search?query="i open fire"&expand=metadata JSONArray metadataArray = response.getJSONObject(0).getJSONArray("metadata"); - BibEntry entry = jsonToBibEntry(metadataArray); + JSONArray bitstreamArray = response.getJSONObject(0).getJSONArray("bitstreams"); + BibEntry entry = jsonToBibEntry(metadataArray, bitstreamArray); return Collections.singletonList(entry); } List entries = new ArrayList<>(response.length()); for (int i = 0; i < response.length(); i++) { JSONArray metadataArray = response.getJSONObject(i).getJSONArray("metadata"); - BibEntry entry = jsonToBibEntry(metadataArray); + JSONArray bitstreamArray = response.getJSONObject(i).getJSONArray("bitstreams"); + BibEntry entry = jsonToBibEntry(metadataArray, bitstreamArray); entries.add(entry); } return entries; }; } - private BibEntry jsonToBibEntry(JSONArray metadataArray) { + private BibEntry jsonToBibEntry(JSONArray metadataArray, JSONArray bitstreamArray) { BibEntry entry = new BibEntry(); List authorsList = new ArrayList<>(); List editorsList = new ArrayList<>(); StringJoiner keywordJoiner = new StringJoiner(", "); + + // Get the ISBN within the BITSTREAM. See the link below: + // https://directory.doabooks.org/rest/search?query=handle:%2220.500.12854/26303%22&expand=metadata,bitstreams + // Note that in many cases, an ISBN cannot be obtained in the metadata, even in the BITSTREAM. See the link below: + // https://directory.doabooks.org/rest/search?query=%22i%20open%20fire%22&expand=metadata,bitstreams + for (int i = 0; i < bitstreamArray.length(); i++) { + JSONObject bitstreamObject = bitstreamArray.getJSONObject(i); + // Subcategorise each instance of the BITSTREAM by "metadata" key + JSONArray array = bitstreamObject.getJSONArray("metadata"); + for (int k = 0; k < array.length(); k++) { + JSONObject metadataInBitstreamObject = array.getJSONObject(k); + if (metadataInBitstreamObject.getString("key").equals("oapen.relation.isbn")) { + entry.setField(StandardField.ISBN, metadataInBitstreamObject.getString("value")); + } + } + } + for (int i = 0; i < metadataArray.length(); i++) { JSONObject dataObject = metadataArray.getJSONObject(i); switch (dataObject.getString("key")) { @@ -123,7 +143,7 @@ private BibEntry jsonToBibEntry(JSONArray metadataArray) { case "dc.contributor.editor" -> editorsList.add(toAuthor(dataObject.getString("value"))); case "oapen.volume" -> entry.setField(StandardField.VOLUME, dataObject.getString("value")); - case "oapen.relation.isbn" -> entry.setField(StandardField.ISBN, + case "oapen.relation.isbn", "dc.identifier.isbn" -> entry.setField(StandardField.ISBN, dataObject.getString("value")); case "dc.title.alternative" -> entry.setField(StandardField.SUBTITLE, dataObject.getString("value")); diff --git a/src/test/java/org/jabref/logic/importer/fetcher/DOABFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/DOABFetcherTest.java index 640c422bdbe..244f97867a1 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/DOABFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/DOABFetcherTest.java @@ -45,6 +45,7 @@ public static Stream testPerformSearch() { ), Arguments.of( new BibEntry(StandardEntryType.Book) + .withField(StandardField.ISBN, "9789085551201") .withField(StandardField.AUTHOR, "Ronald Snijder") .withField(StandardField.TITLE, "The deliverance of open access books") .withField(StandardField.SUBTITLE, "Examining usage and dissemination")