use of org.orcid.jaxb.model.record_rc3.ExternalID in project ORCID-Source by ORCID.
the class WorkManagerTest method getWork.
private Work getWork(String extIdValue) {
Work work = new Work();
WorkTitle title = new WorkTitle();
if (extIdValue == null) {
title.setTitle(new Title("Work title"));
} else {
title.setTitle(new Title("Work title " + extIdValue));
}
work.setWorkTitle(title);
work.setWorkType(WorkType.BOOK);
ExternalIDs extIds = new ExternalIDs();
ExternalID extId = new ExternalID();
extId.setRelationship(Relationship.SELF);
extId.setType("doi");
extId.setUrl(new Url("http://orcid.org"));
if (extIdValue == null) {
extId.setValue("ext-id-value");
} else {
extId.setValue("ext-id-value-" + extIdValue);
}
extIds.getExternalIdentifier().add(extId);
work.setWorkExternalIdentifiers(extIds);
work.setVisibility(Visibility.PUBLIC);
return work;
}
use of org.orcid.jaxb.model.record_rc3.ExternalID in project ORCID-Source by ORCID.
the class WorkManagerImpl method buildExistingExternalIdsSet.
/**
* Return the list of existing external identifiers for the given user where the source matches the given sourceId
*
* @param orcid
* The user we want to add the works to
* @param sourceId
* The client id we are evaluating
* @return A set of all the existing external identifiers that belongs to the given user and to the given source id
* */
private Set<ExternalID> buildExistingExternalIdsSet(String orcid, String sourceId) {
Set<ExternalID> existingExternalIds = new HashSet<ExternalID>();
long lastModifiedTime = getLastModified(orcid);
List<Work> existingWorks = this.findWorks(orcid, lastModifiedTime);
for (Work work : existingWorks) {
//If it is the same source
if (work.retrieveSourcePath().equals(sourceId)) {
if (work.getExternalIdentifiers() != null && work.getExternalIdentifiers().getExternalIdentifier() != null) {
for (ExternalID extId : work.getExternalIdentifiers().getExternalIdentifier()) {
//Don't include PART_OF external ids
if (!Relationship.PART_OF.equals(extId.getRelationship())) {
existingExternalIds.add(extId);
}
}
}
}
}
return existingExternalIds;
}
use of org.orcid.jaxb.model.record_rc3.ExternalID in project ORCID-Source by ORCID.
the class ExternalIDValidatorTest method testValidExtIdsWorksFine_flagOff.
@Test
public void testValidExtIdsWorksFine_flagOff() {
ExternalIDs extIds = new ExternalIDs();
ExternalID id1 = new ExternalID();
id1.setRelationship(null);
id1.setType("doi");
id1.setValue("value1");
id1.setUrl(new Url("http://value1.com"));
ExternalID id2 = new ExternalID();
id2.setRelationship(null);
id2.setType("doi");
id2.setValue("value1");
id2.setUrl(new Url("http://value1.com"));
ExternalID id3 = new ExternalID();
id3.setRelationship(null);
id3.setType("doi");
id3.setValue("value1");
id3.setUrl(new Url("http://value1.com"));
extIds.getExternalIdentifier().add(id1);
extIds.getExternalIdentifier().add(id2);
extIds.getExternalIdentifier().add(id3);
validator.validateWorkOrPeerReview(extIds);
}
use of org.orcid.jaxb.model.record_rc3.ExternalID in project ORCID-Source by ORCID.
the class WorksTest method testUpdateWorkWithProfileCreationTokenWhenClaimedAndNotSource.
@Test
public void testUpdateWorkWithProfileCreationTokenWhenClaimedAndNotSource() throws JSONException, InterruptedException, URISyntaxException {
long time = System.currentTimeMillis();
Work workToCreate = (Work) unmarshallFromPath("/record_2.0/samples/read_samples/work-2.0.xml", Work.class);
workToCreate.setPutCode(null);
workToCreate.setSource(null);
workToCreate.setVisibility(Visibility.PUBLIC);
workToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
ExternalID wExtId = new ExternalID();
wExtId.setValue("Work Id " + time);
wExtId.setType(WorkExternalIdentifierType.AGR.value());
wExtId.setRelationship(Relationship.SELF);
workToCreate.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
String accessToken = getAccessToken();
ClientResponse postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), workToCreate, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
String locationPath = postResponse.getLocation().getPath();
assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v2.0/" + this.getUser1OrcidId() + "/work/\\d+"));
ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
Work gotWork = getResponse.getEntity(Work.class);
assertEquals("common:title", gotWork.getWorkTitle().getTitle().getContent());
gotWork.getWorkTitle().getTitle().setContent("updated title");
String profileCreateToken = oauthHelper.getClientCredentialsAccessToken(this.getClient2ClientId(), this.getClient2ClientSecret(), ScopePathType.ORCID_PROFILE_CREATE);
ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), profileCreateToken, gotWork);
assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
Work gotAfterUpdateWork = getAfterUpdateResponse.getEntity(Work.class);
assertEquals("common:title", gotAfterUpdateWork.getWorkTitle().getTitle().getContent());
ClientResponse deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), gotWork.getPutCode(), accessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
use of org.orcid.jaxb.model.record_rc3.ExternalID in project ORCID-Source by ORCID.
the class MemberV2Test method testUpdatePeerReviewWithProfileCreationTokenWhenClaimedAndNotSource.
@Test
public void testUpdatePeerReviewWithProfileCreationTokenWhenClaimedAndNotSource() throws JSONException, InterruptedException, URISyntaxException {
long time = System.currentTimeMillis();
PeerReview peerReviewToCreate = (PeerReview) unmarshallFromPath("/record_2.0/samples/read_samples/peer-review-2.0.xml", PeerReview.class);
peerReviewToCreate.setPutCode(null);
peerReviewToCreate.setGroupId(groupRecords.get(0).getGroupId());
peerReviewToCreate.setVisibility(Visibility.PUBLIC);
peerReviewToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
ExternalID wExtId = new ExternalID();
wExtId.setValue("Work Id " + time);
wExtId.setType(WorkExternalIdentifierType.AGR.value());
wExtId.setRelationship(Relationship.SELF);
peerReviewToCreate.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
String accessToken = getAccessToken();
ClientResponse postResponse = memberV2ApiClient.createPeerReviewXml(this.getUser1OrcidId(), peerReviewToCreate, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
String locationPath = postResponse.getLocation().getPath();
assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v2.0/" + this.getUser1OrcidId() + "/peer-review/\\d+"));
ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
PeerReview gotPeerReview = getResponse.getEntity(PeerReview.class);
assertEquals("peer-review:subject-name", gotPeerReview.getSubjectName().getTitle().getContent());
gotPeerReview.getSubjectName().getTitle().setContent("updated title");
String profileCreateToken = oauthHelper.getClientCredentialsAccessToken(this.getClient2ClientId(), this.getClient2ClientSecret(), ScopePathType.ORCID_PROFILE_CREATE);
ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), profileCreateToken, gotPeerReview);
assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
PeerReview gotAfterUpdatePeerReview = getAfterUpdateResponse.getEntity(PeerReview.class);
assertEquals("peer-review:subject-name", gotAfterUpdatePeerReview.getSubjectName().getTitle().getContent());
ClientResponse deleteResponse = memberV2ApiClient.deletePeerReviewXml(this.getUser1OrcidId(), gotAfterUpdatePeerReview.getPutCode(), accessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Aggregations