forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DSC-1274] Implemented RorOrgUnitDataProvider
- Loading branch information
1 parent
e477796
commit 419e8a9
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
dspace-api/src/main/java/org/dspace/external/provider/impl/RorOrgUnitDataProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters