[CST-5799] Changes after community feedbacks

This commit is contained in:
Luca Giamminonni
2022-06-10 18:23:36 +02:00
parent b0bca4a055
commit 8f1aa722c5
8 changed files with 64 additions and 12 deletions

View File

@@ -68,10 +68,10 @@ import org.springframework.beans.factory.annotation.Autowired;
/** /**
* Implementation of {@link ExternalDataProvider} that search for all the works * Implementation of {@link ExternalDataProvider} that search for all the works
* of the profile with the given orcid id that hava a source other than * of the profile with the given orcid id that hava a source other than DSpace.
* DSpaceCris. The id of the external data objects returned by the methods of * The id of the external data objects returned by the methods of this class is
* this class is the concatenation of the orcid id and the put code associated * the concatenation of the orcid id and the put code associated with the
* with the publication, separated by :: * publication, separated by :: (example 0000-0000-0123-4567::123456)
* *
* @author Luca Giamminonni (luca.giamminonni at 4science.it) * @author Luca Giamminonni (luca.giamminonni at 4science.it)
* *
@@ -131,11 +131,29 @@ public class OrcidPublicationDataProvider extends AbstractExternalDataProvider {
return StringUtils.isBlank(id) || id.split("::").length != 2; return StringUtils.isBlank(id) || id.split("::").length != 2;
} }
/**
* Returns all the works related to the given ORCID in the range from start and
* limit.
*
* @param orcid the ORCID ID of the author to search for works
* @param start the start index
* @param limit the limit index
* @return the list of the works
*/
private List<Work> findWorks(String orcid, int start, int limit) { private List<Work> findWorks(String orcid, int start, int limit) {
List<WorkSummary> workSummaries = findWorkSummaries(orcid, start, limit); List<WorkSummary> workSummaries = findWorkSummaries(orcid, start, limit);
return findWorks(orcid, workSummaries); return findWorks(orcid, workSummaries);
} }
/**
* Returns all the works summaries related to the given ORCID in the range from
* start and limit.
*
* @param orcid the ORCID ID of the author to search for works summaries
* @param start the start index
* @param limit the limit index
* @return the list of the works summaries
*/
private List<WorkSummary> findWorkSummaries(String orcid, int start, int limit) { private List<WorkSummary> findWorkSummaries(String orcid, int start, int limit) {
return getWorks(orcid).getWorkGroup().stream() return getWorks(orcid).getWorkGroup().stream()
.filter(workGroup -> allWorkSummariesHaveDifferentSourceClientId(workGroup)) .filter(workGroup -> allWorkSummariesHaveDifferentSourceClientId(workGroup))
@@ -146,6 +164,14 @@ public class OrcidPublicationDataProvider extends AbstractExternalDataProvider {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
/**
* Returns all the works related to the given ORCID ID and work summaries (a
* work has more details than a work summary).
*
* @param orcid the ORCID id of the author to search for works
* @param workSummaries the work summaries used to search the related works
* @return the list of the works
*/
private List<Work> findWorks(String orcid, List<WorkSummary> workSummaries) { private List<Work> findWorks(String orcid, List<WorkSummary> workSummaries) {
List<String> workPutCodes = getPutCodes(workSummaries); List<String> workPutCodes = getPutCodes(workSummaries);
@@ -164,6 +190,14 @@ public class OrcidPublicationDataProvider extends AbstractExternalDataProvider {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
/**
* Search a work by ORCID id and putcode, using API or PUBLIC urls based on
* whether the ORCID API keys are configured or not.
*
* @param orcid the ORCID ID
* @param putCode the work's identifier on ORCID
* @return the work, if any
*/
private Optional<Work> getWork(String orcid, String putCode) { private Optional<Work> getWork(String orcid, String putCode) {
if (orcidConfiguration.isApiConfigured()) { if (orcidConfiguration.isApiConfigured()) {
String accessToken = getAccessToken(orcid); String accessToken = getAccessToken(orcid);
@@ -173,6 +207,12 @@ public class OrcidPublicationDataProvider extends AbstractExternalDataProvider {
} }
} }
/**
* Returns all the works related to the given ORCID.
*
* @param orcid the ORCID ID of the author to search for works
* @return the list of the works
*/
private Works getWorks(String orcid) { private Works getWorks(String orcid) {
if (orcidConfiguration.isApiConfigured()) { if (orcidConfiguration.isApiConfigured()) {
String accessToken = getAccessToken(orcid); String accessToken = getAccessToken(orcid);
@@ -182,6 +222,13 @@ public class OrcidPublicationDataProvider extends AbstractExternalDataProvider {
} }
} }
/**
* Returns all the works related to the given ORCID by the given putCodes.
*
* @param orcid the ORCID ID of the author to search for works
* @param putCodes the work's put codes to search
* @return the list of the works
*/
private WorkBulk getWorkBulk(String orcid, List<String> putCodes) { private WorkBulk getWorkBulk(String orcid, List<String> putCodes) {
if (orcidConfiguration.isApiConfigured()) { if (orcidConfiguration.isApiConfigured()) {
String accessToken = getAccessToken(orcid); String accessToken = getAccessToken(orcid);

View File

@@ -21,6 +21,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.io.File; import java.io.File;
import java.net.URL;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.function.Predicate; import java.util.function.Predicate;
@@ -57,7 +58,7 @@ import org.orcid.jaxb.model.v3.release.record.summary.Works;
*/ */
public class OrcidPublicationDataProviderIT extends AbstractIntegrationTestWithDatabase { public class OrcidPublicationDataProviderIT extends AbstractIntegrationTestWithDatabase {
private static final String BASE_XML_DIR_PATH = "./target/testing/dspace/assetstore/orcid-works/"; private static final String BASE_XML_DIR_PATH = "org/dspace/app/orcid-works/";
private static final String ACCESS_TOKEN = "32c83ccb-c6d5-4981-b6ea-6a34a36de8ab"; private static final String ACCESS_TOKEN = "32c83ccb-c6d5-4981-b6ea-6a34a36de8ab";
@@ -103,8 +104,8 @@ public class OrcidPublicationDataProviderIT extends AbstractIntegrationTestWithD
dataProvider.setOrcidClient(orcidClientMock); dataProvider.setOrcidClient(orcidClientMock);
originalClientId = orcidConfiguration.getClientId(); originalClientId = orcidConfiguration.getClientId();
orcidConfiguration.setClientId("DSPACE-CRIS-CLIENT-ID"); orcidConfiguration.setClientId("DSPACE-CLIENT-ID");
orcidConfiguration.setClientSecret("DSPACE-CRIS-CLIENT-SECRET"); orcidConfiguration.setClientSecret("DSPACE-CLIENT-SECRET");
when(orcidClientMock.getReadPublicAccessToken()).thenReturn(buildTokenResponse(ACCESS_TOKEN)); when(orcidClientMock.getReadPublicAccessToken()).thenReturn(buildTokenResponse(ACCESS_TOKEN));
@@ -387,7 +388,11 @@ public class OrcidPublicationDataProviderIT extends AbstractIntegrationTestWithD
private <T> T unmarshall(String fileName, Class<T> clazz) throws Exception { private <T> T unmarshall(String fileName, Class<T> clazz) throws Exception {
JAXBContext jaxbContext = JAXBContext.newInstance(clazz); JAXBContext jaxbContext = JAXBContext.newInstance(clazz);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
return (T) unmarshaller.unmarshal(new File(BASE_XML_DIR_PATH, fileName)); URL resource = getClass().getClassLoader().getResource(BASE_XML_DIR_PATH + fileName);
if (resource == null) {
throw new IllegalStateException("No resource found named " + BASE_XML_DIR_PATH + fileName);
}
return (T) unmarshaller.unmarshal(new File(resource.getFile()));
} }
} }

View File

@@ -39,8 +39,8 @@
<common:last-modified-date>2015-06-19T19:14:26.339Z</common:last-modified-date> <common:last-modified-date>2015-06-19T19:14:26.339Z</common:last-modified-date>
<common:source> <common:source>
<common:source-client-id> <common:source-client-id>
<common:uri>https://sandbox.orcid.org/client/DSPACE-CRIS-CLIENT-ID</common:uri> <common:uri>https://sandbox.orcid.org/client/DSPACE-CLIENT-ID</common:uri>
<common:path>DSPACE-CRIS-CLIENT-ID</common:path> <common:path>DSPACE-CLIENT-ID</common:path>
<common:host>sandbox.orcid.org</common:host> <common:host>sandbox.orcid.org</common:host>
</common:source-client-id> </common:source-client-id>
<common:source-name>DSPACE-CRIS</common:source-name> <common:source-name>DSPACE-CRIS</common:source-name>
@@ -120,8 +120,8 @@
<common:host>sandbox.orcid.org</common:host> <common:host>sandbox.orcid.org</common:host>
</common:source-orcid> </common:source-orcid>
<common:source-client-id> <common:source-client-id>
<common:uri>https://sandbox.orcid.org/client/DSPACE-CRIS-CLIENT-ID</common:uri> <common:uri>https://sandbox.orcid.org/client/DSPACE-CLIENT-ID</common:uri>
<common:path>DSPACE-CRIS-CLIENT-ID</common:path> <common:path>DSPACE-CLIENT-ID</common:path>
<common:host>sandbox.orcid.org</common:host> <common:host>sandbox.orcid.org</common:host>
</common:source-client-id> </common:source-client-id>
<common:source-name>DSPACE-CRIS</common:source-name> <common:source-name>DSPACE-CRIS</common:source-name>