From 9f7e3ee8109810ba0f298f96d122ab11d69de52e Mon Sep 17 00:00:00 2001 From: Luca Giamminonni Date: Fri, 3 Nov 2023 17:49:25 +0100 Subject: [PATCH] [DSC-1319] Improved RorOrgUnitAuthority --- .../authority/RorOrgUnitAuthority.java | 50 ++++++++++++++++++- .../external/datamodel/ImportRecord.java | 7 +++ .../RorImportMetadataSourceServiceImpl.java | 29 +++++++++-- 3 files changed, 79 insertions(+), 7 deletions(-) diff --git a/dspace-api/src/main/java/org/dspace/content/authority/RorOrgUnitAuthority.java b/dspace-api/src/main/java/org/dspace/content/authority/RorOrgUnitAuthority.java index c733b95fc089..de2271901819 100644 --- a/dspace-api/src/main/java/org/dspace/content/authority/RorOrgUnitAuthority.java +++ b/dspace-api/src/main/java/org/dspace/content/authority/RorOrgUnitAuthority.java @@ -9,14 +9,16 @@ package org.dspace.content.authority; import java.util.Collection; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import org.apache.commons.lang3.StringUtils; import org.dspace.content.authority.factory.ItemAuthorityServiceFactory; import org.dspace.importer.external.datamodel.ImportRecord; import org.dspace.importer.external.exception.MetadataSourceException; +import org.dspace.importer.external.metadatamapping.MetadatumDTO; import org.dspace.importer.external.ror.service.RorImportMetadataSourceServiceImpl; import org.dspace.services.ConfigurationService; import org.dspace.services.factory.DSpaceServicesFactory; @@ -81,7 +83,51 @@ private String getName(ImportRecord orgUnit) { } private Map buildExtras(ImportRecord orgUnit) { - return new HashMap<>(); + + Map extras = new LinkedHashMap(); + + addExtra(extras, getIdentifier(orgUnit), "id"); + + orgUnit.getSingleValue("dc", "type", null) + .ifPresent(type -> addExtra(extras, type, "type")); + + String acronym = orgUnit.getValue("oairecerif", "acronym", null).stream() + .map(MetadatumDTO::getValue) + .collect(Collectors.joining(", ")); + + if (StringUtils.isNotBlank(acronym)) { + addExtra(extras, acronym, "acronym"); + } + + return extras; + } + + private void addExtra(Map extras, String value, String extraType) { + + String key = getKey(extraType); + + if (useAsData(extraType)) { + extras.put("data-" + key, value); + } + if (useForDisplaying(extraType)) { + extras.put(key, value); + } + + } + + private boolean useForDisplaying(String extraType) { + return configurationService.getBooleanProperty("cris.OrcidAuthority." + + getPluginInstanceName() + "." + extraType + ".display", true); + } + + private boolean useAsData(String extraType) { + return configurationService.getBooleanProperty("cris.OrcidAuthority." + + getPluginInstanceName() + "." + extraType + ".as-data", true); + } + + private String getKey(String extraType) { + return configurationService.getProperty("cris.OrcidAuthority." + + getPluginInstanceName() + "." + extraType + ".key", "ror_orgunit_" + extraType); } private String composeAuthorityValue(String rorId) { diff --git a/dspace-api/src/main/java/org/dspace/importer/external/datamodel/ImportRecord.java b/dspace-api/src/main/java/org/dspace/importer/external/datamodel/ImportRecord.java index e2cb24f4b578..06e05a30b302 100644 --- a/dspace-api/src/main/java/org/dspace/importer/external/datamodel/ImportRecord.java +++ b/dspace-api/src/main/java/org/dspace/importer/external/datamodel/ImportRecord.java @@ -11,6 +11,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Optional; import org.dspace.importer.external.metadatamapping.MetadatumDTO; @@ -94,6 +95,12 @@ public Collection getValue(String schema, String element, String q return values; } + public Optional getSingleValue(String schema, String element, String qualifier) { + return getValue(schema, element, qualifier).stream() + .map(MetadatumDTO::getValue) + .findFirst(); + } + /** * Add a value to the valueList * diff --git a/dspace-api/src/main/java/org/dspace/importer/external/ror/service/RorImportMetadataSourceServiceImpl.java b/dspace-api/src/main/java/org/dspace/importer/external/ror/service/RorImportMetadataSourceServiceImpl.java index ebc7caefb26d..650e939e3dd0 100644 --- a/dspace-api/src/main/java/org/dspace/importer/external/ror/service/RorImportMetadataSourceServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/importer/external/ror/service/RorImportMetadataSourceServiceImpl.java @@ -15,6 +15,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.Callable; +import java.util.stream.Collectors; import javax.el.MethodNotFoundException; import com.fasterxml.jackson.core.JsonProcessingException; @@ -69,7 +70,7 @@ public int getRecordsCount(Query query) throws MetadataSourceException { @Override public Collection getRecords(String query, int start, int count) throws MetadataSourceException { - return retry(new SearchByQueryCallable(query)); + return retry(new SearchByQueryCallable(query, start)); } @Override @@ -110,9 +111,10 @@ private class SearchByQueryCallable implements Callable> { private Query query; - private SearchByQueryCallable(String queryString) { + private SearchByQueryCallable(String queryString, int start) { query = new Query(); query.addParameter("query", queryString); + query.addParameter("start", start); } private SearchByQueryCallable(Query query) { @@ -121,7 +123,8 @@ private SearchByQueryCallable(Query query) { @Override public List call() throws Exception { - return search(query.getParameterAsClass("query", String.class)); + return search(query.getParameterAsClass("query", String.class), + query.getParameterAsClass("start", Integer.class)); } } @@ -220,13 +223,16 @@ private List searchById(String id) { return adsResults; } - private List search(String query) { + private List search(String query, Integer start) { List adsResults = new ArrayList<>(); try { Map> params = new HashMap>(); URIBuilder uriBuilder = new URIBuilder(this.url); uriBuilder.addParameter("query", query); + if (start != null) { + uriBuilder.addParameter("page", String.valueOf((start / 20) + 1)); + } String resp = liveImportClient.executeHttpGetRequest(timeout, uriBuilder.toString(), params); if (StringUtils.isEmpty(resp)) { @@ -247,7 +253,20 @@ private List search(String query) { } catch (URISyntaxException e) { e.printStackTrace(); } - return adsResults; + + if (start == null) { + return adsResults; + } + + if (start % 20 == 0) { + return adsResults.stream() + .limit(10) + .collect(Collectors.toList()); + } else { + return adsResults.stream() + .skip(10) + .collect(Collectors.toList()); + } } private JsonNode convertStringJsonToJsonNode(String json) {