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

Modify DOI service to not return entries without a URL #94

Merged
merged 1 commit into from
Oct 14, 2024
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
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
Loading