Skip to content

Commit

Permalink
[DSC-1274] Implemented RorOrgUnitDataProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaGiamminonni committed Oct 6, 2023
1 parent e477796 commit 419e8a9
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<ExternalDataObject> getExternalDataObject(String id) {
return rorApiService.getOrgUnit(id)
.map(this::convertToExternalDataObject);
}

@Override
public List<ExternalDataObject> 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;
}

}
9 changes: 9 additions & 0 deletions dspace/config/spring/api/external-services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@
</list>
</property>
</bean>

<bean id="rorDataProvider" class="org.dspace.external.provider.impl.RorOrgUnitDataProvider" >
<property name="sourceIdentifier" value="rorOrgUnits"/>
<property name="supportedEntityTypes">
<list>
<value>OrgUnit</value>
</list>
</property>
</bean>

<bean id="vufindLiveImportDataProvider" class="org.dspace.external.provider.impl.LiveImportDataProvider">
<property name="metadataSource" ref="vufindImportService"/>
Expand Down

0 comments on commit 419e8a9

Please sign in to comment.