Skip to content

Commit

Permalink
Modify DOI service to not return entries without a URL and tighten up…
Browse files Browse the repository at this point in the history
… the filename parsing.
  • Loading branch information
markpatton committed Oct 14, 2024
1 parent dfe0b06 commit cebfa1c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
package org.eclipse.pass.doi.service;

import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import javax.json.Json;
import javax.json.JsonArray;
Expand Down Expand Up @@ -57,6 +60,20 @@ public HashMap<String, String> headerMap() {
return null;
}

private String get_filename(String url) {
try {
URI uri = new URI(url);

if (uri.getPath() == null) {
return null;
}

return new File(uri.getPath()).getName();
} catch (URISyntaxException e) {
return null;
}
}

@Override
public JsonObject processObject(JsonObject object) {
JsonArray locations = object.getJsonArray("oa_locations");
Expand All @@ -67,14 +84,13 @@ public JsonObject processObject(JsonObject object) {
JsonValue urlForPdf = manuscript.getValue("/url_for_pdf");
JsonValue isBest = manuscript.getValue("/is_best");

JsonValue filename;
if ( urlForPdf == JsonValue.NULL ) {
filename = JsonValue.NULL;
} else {
String urlForPdfString = urlForPdf.toString().replaceAll("\"","");
filename = Json.createValue (urlForPdfString.substring(urlForPdfString.lastIndexOf('/') + 1));
continue;
}

String name = get_filename(manuscript.getString("url_for_pdf"));
JsonValue filename = name == null ? JsonValue.NULL : Json.createValue(name);

JsonValue repoInst = manuscript.getValue("/repository_institution");

JsonObject manuscriptObject = Json.createObjectBuilder().add("url", urlForPdf)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ public class UnpaywallDoiServiceTest {
"\"repositoryLabel\":null,\"type\":\"application/pdf\",\"source\":\"Unpaywall\"," +
"\"name\":\"CMC.S38446\",\"isBest\":true},{\"url\":\"https://europepmc.org/articles/pmc5072460?pdf=render\"," +
"\"repositoryLabel\":\"PubMed Central - Europe PMC\",\"type\":\"application/pdf\"," +
"\"source\":\"Unpaywall\",\"name\":\"pmc5072460?pdf=render\",\"isBest\":false}," +
"{\"url\":null,\"repositoryLabel\":null,\"type\":\"application/pdf\"," +
"\"source\":\"Unpaywall\",\"name\":null,\"isBest\":false}]}";
"\"source\":\"Unpaywall\",\"name\":\"pmc5072460\",\"isBest\":false}" +
"]}";

@Test
public void testProcessObject() {
Expand Down

0 comments on commit cebfa1c

Please sign in to comment.