From 419e8a9dcbf0f0765d795da3bc3bc0fb9da7a82b Mon Sep 17 00:00:00 2001 From: Luca Giamminonni Date: Fri, 6 Oct 2023 16:52:46 +0200 Subject: [PATCH] [DSC-1274] Implemented RorOrgUnitDataProvider --- .../provider/impl/RorOrgUnitDataProvider.java | 67 +++++++++++++++++++ .../config/spring/api/external-services.xml | 9 +++ 2 files changed, 76 insertions(+) create mode 100644 dspace-api/src/main/java/org/dspace/external/provider/impl/RorOrgUnitDataProvider.java diff --git a/dspace-api/src/main/java/org/dspace/external/provider/impl/RorOrgUnitDataProvider.java b/dspace-api/src/main/java/org/dspace/external/provider/impl/RorOrgUnitDataProvider.java new file mode 100644 index 000000000000..d37503b44bf3 --- /dev/null +++ b/dspace-api/src/main/java/org/dspace/external/provider/impl/RorOrgUnitDataProvider.java @@ -0,0 +1,67 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE and NOTICE files at the root of the source + * tree and available online at + * + * http://www.dspace.org/license/ + */ +package org.dspace.external.provider.impl; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +import org.apache.commons.lang3.StringUtils; +import org.dspace.external.model.ExternalDataObject; +import org.dspace.external.provider.AbstractExternalDataProvider; +import org.dspace.ror.ROROrgUnitDTO; +import org.dspace.ror.service.RORApiService; +import org.springframework.beans.factory.annotation.Autowired; + +public class RorOrgUnitDataProvider extends AbstractExternalDataProvider { + + @Autowired + private RORApiService rorApiService; + + private String sourceIdentifier; + + @Override + public Optional getExternalDataObject(String id) { + return rorApiService.getOrgUnit(id) + .map(this::convertToExternalDataObject); + } + + @Override + public List searchExternalDataObjects(String query, int start, int limit) { + return rorApiService.getOrgUnits(query).stream() + .map(this::convertToExternalDataObject) + .collect(Collectors.toList()); + } + + private ExternalDataObject convertToExternalDataObject(ROROrgUnitDTO orgUnit) { + ExternalDataObject object = new ExternalDataObject(sourceIdentifier); + object.setId(orgUnit.getId()); + object.setMetadata(rorApiService.getMetadataValues(orgUnit)); + return object; + } + + @Override + public boolean supports(String source) { + return StringUtils.equals(sourceIdentifier, source); + } + + @Override + public int getNumberOfResults(String query) { + return searchExternalDataObjects(query, 0, -1).size(); + } + + public void setSourceIdentifier(String sourceIdentifier) { + this.sourceIdentifier = sourceIdentifier; + } + + @Override + public String getSourceIdentifier() { + return sourceIdentifier; + } + +} diff --git a/dspace/config/spring/api/external-services.xml b/dspace/config/spring/api/external-services.xml index 43ceb79c4be7..1b521ae700c8 100644 --- a/dspace/config/spring/api/external-services.xml +++ b/dspace/config/spring/api/external-services.xml @@ -224,6 +224,15 @@ + + + + + + OrgUnit + + +