use of org.orcid.jaxb.model.record_rc3.PeerReview in project ORCID-Source by ORCID.
the class MemberV2Test method createViewUpdateAndDeletePeerReview.
@Test
public void createViewUpdateAndDeletePeerReview() throws JSONException, InterruptedException, URISyntaxException {
long time = System.currentTimeMillis();
PeerReview peerReviewToCreate = (PeerReview) unmarshallFromPath("/record_2.0_rc3/samples/peer-review-2.0_rc3.xml", PeerReview.class);
peerReviewToCreate.setPutCode(null);
peerReviewToCreate.setGroupId(groupRecords.get(0).getGroupId());
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_rc3/" + 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:url", gotPeerReview.getUrl().getValue());
assertEquals("peer-review:subject-name", gotPeerReview.getSubjectName().getTitle().getContent());
assertEquals(groupRecords.get(0).getGroupId(), gotPeerReview.getGroupId());
//Save the original visibility
Visibility originalVisibility = gotPeerReview.getVisibility();
Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
//Verify you cant update the visibility
gotPeerReview.setVisibility(updatedVisibility);
ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotPeerReview);
assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
OrcidError error = putResponse.getEntity(OrcidError.class);
assertNotNull(error);
assertEquals(Integer.valueOf(9035), error.getErrorCode());
//Set the visibility again to the initial one
gotPeerReview.setVisibility(originalVisibility);
gotPeerReview.getSubjectName().getTitle().setContent("updated title");
putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotPeerReview);
assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
PeerReview gotAfterUpdateWork = getAfterUpdateResponse.getEntity(PeerReview.class);
assertEquals("updated title", gotAfterUpdateWork.getSubjectName().getTitle().getContent());
assertEquals(groupRecords.get(0).getGroupId(), gotAfterUpdateWork.getGroupId());
ClientResponse deleteResponse = memberV2ApiClient.deletePeerReviewXml(this.getUser1OrcidId(), gotAfterUpdateWork.getPutCode(), accessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
use of org.orcid.jaxb.model.record_rc3.PeerReview 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_rc3/samples/peer-review-2.0_rc3.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_rc3/" + 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());
}
use of org.orcid.jaxb.model.record_rc3.PeerReview in project ORCID-Source by ORCID.
the class VerifyOrcidBeforeFetchElementTest method testPeerReview.
@Test
public void testPeerReview() throws InterruptedException, JSONException, URISyntaxException {
long time = System.currentTimeMillis();
PeerReview peerReviewToCreate = (PeerReview) unmarshallFromPath("/record_2.0_rc1/samples/peer-review-2.0_rc1.xml", PeerReview.class);
peerReviewToCreate.setPutCode(null);
peerReviewToCreate.setGroupId(groupRecords.get(0).getGroupId());
peerReviewToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
WorkExternalIdentifier wExtId = new WorkExternalIdentifier();
wExtId.setWorkExternalIdentifierId(new WorkExternalIdentifierId("Work Id " + time));
wExtId.setWorkExternalIdentifierType(WorkExternalIdentifierType.AGR);
wExtId.setRelationship(Relationship.SELF);
peerReviewToCreate.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
String user1AccessToken = getAccessToken();
// Create an peer review
ClientResponse postResponse = memberV2ApiClient.createPeerReviewXml(getUser1OrcidId(), peerReviewToCreate, user1AccessToken);
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_rc1/" + getUser1OrcidId() + "/peer-review/\\d+"));
// Fetch it with the owner
ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), user1AccessToken);
assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
PeerReview gotPeerReview = getResponse.getEntity(PeerReview.class);
assertEquals("peer-review:url", gotPeerReview.getUrl().getValue());
assertEquals("peer-review:subject-name", gotPeerReview.getSubjectName().getTitle().getContent());
// Try to fetch it with other user orcid
// Using the members API
String user2AccessToken = getAccessToken(getUser2OrcidId(), getUser2Password(), getScopes(ScopePathType.ACTIVITIES_UPDATE), getClient1ClientId(), getClient1ClientSecret(), getClient1RedirectUri());
ClientResponse user2GetResponse = memberV2ApiClient.viewPeerReviewXml(getUser2OrcidId(), gotPeerReview.getPutCode(), user2AccessToken);
assertNotNull(user2GetResponse);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), user2GetResponse.getStatus());
OrcidError error = user2GetResponse.getEntity(OrcidError.class);
assertNotNull(error);
assertEquals(Integer.valueOf(9016), error.getErrorCode());
//Using the public API
user2GetResponse = publicV2ApiClient.viewPeerReviewXml(getUser2OrcidId(), String.valueOf(gotPeerReview.getPutCode()));
assertNotNull(user2GetResponse);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), user2GetResponse.getStatus());
error = user2GetResponse.getEntity(OrcidError.class);
assertNotNull(error);
assertEquals(Integer.valueOf(9016), error.getErrorCode());
// Delete it
ClientResponse deletedResponse = memberV2ApiClient.deletePeerReviewXml(getUser1OrcidId(), gotPeerReview.getPutCode(), user1AccessToken);
assertNotNull(deletedResponse);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deletedResponse.getStatus());
}
use of org.orcid.jaxb.model.record_rc3.PeerReview in project ORCID-Source by ORCID.
the class PublicV2Test method createActivities.
private void createActivities() throws JSONException, InterruptedException, URISyntaxException {
String accessToken = getAccessToken();
long time = System.currentTimeMillis();
Work workToCreate = (Work) unmarshallFromPath("/record_2.0_rc1/samples/work-2.0_rc1.xml", Work.class);
for (int i = 0; i < 4; i++) {
workToCreate.setPutCode(null);
workToCreate.getWorkTitle().getTitle().setContent("Work # " + i);
workToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
WorkExternalIdentifier wExtId = new WorkExternalIdentifier();
wExtId.setWorkExternalIdentifierId(new WorkExternalIdentifierId(time + " Work Id " + i));
wExtId.setWorkExternalIdentifierType(WorkExternalIdentifierType.AGR);
wExtId.setRelationship(Relationship.SELF);
workToCreate.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
if (i == 0 || i == 3)
workToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PUBLIC);
else if (i == 1)
workToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
else
workToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PRIVATE);
ClientResponse postResponse = memberV2ApiClient.createWorkXml(getUser1OrcidId(), workToCreate, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
}
Funding fundingToCreate = (Funding) unmarshallFromPath("/record_2.0_rc1/samples/funding-2.0_rc1.xml", Funding.class);
for (int i = 0; i < 4; i++) {
fundingToCreate.setPutCode(null);
fundingToCreate.getTitle().getTitle().setContent("Funding # " + i);
fundingToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
FundingExternalIdentifier fExtId = new FundingExternalIdentifier();
fExtId.setType(FundingExternalIdentifierType.GRANT_NUMBER);
fExtId.setValue(time + " funding Id " + i);
fExtId.setRelationship(Relationship.SELF);
fundingToCreate.getExternalIdentifiers().getExternalIdentifier().add(fExtId);
if (i == 0 || i == 3)
fundingToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PUBLIC);
else if (i == 1)
fundingToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
else
fundingToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PRIVATE);
ClientResponse postResponse = memberV2ApiClient.createFundingXml(getUser1OrcidId(), fundingToCreate, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
}
Employment employmentToCreate = (Employment) unmarshallFromPath("/record_2.0_rc1/samples/employment-2.0_rc1.xml", Employment.class);
for (int i = 0; i < 4; i++) {
employmentToCreate.setPutCode(null);
employmentToCreate.setRoleTitle("Employment # " + i);
if (i == 0 || i == 3)
employmentToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PUBLIC);
else if (i == 1)
employmentToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
else
employmentToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PRIVATE);
ClientResponse postResponse = memberV2ApiClient.createEmploymentXml(getUser1OrcidId(), employmentToCreate, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
}
Education educationToCreate = (Education) unmarshallFromPath("/record_2.0_rc1/samples/education-2.0_rc1.xml", Education.class);
for (int i = 0; i < 4; i++) {
educationToCreate.setPutCode(null);
educationToCreate.setRoleTitle("Education # " + i);
if (i == 0 || i == 3)
educationToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PUBLIC);
else if (i == 1)
educationToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
else
educationToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PRIVATE);
ClientResponse postResponse = memberV2ApiClient.createEducationXml(getUser1OrcidId(), educationToCreate, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
}
PeerReview peerReviewToCreate = (PeerReview) unmarshallFromPath("/record_2.0_rc1/samples/peer-review-2.0_rc1.xml", PeerReview.class);
for (int i = 0; i < 4; i++) {
peerReviewToCreate.setPutCode(null);
peerReviewToCreate.setGroupId(groupRecords.get(0).getGroupId());
peerReviewToCreate.getSubjectName().getTitle().setContent("PeerReview # " + i);
peerReviewToCreate.getCompletionDate().setDay(new Day(i + 1));
peerReviewToCreate.getCompletionDate().setMonth(new Month(i + 1));
peerReviewToCreate.getCompletionDate().setYear(new Year((i + 1) * 1000));
peerReviewToCreate.getExternalIdentifiers().getExternalIdentifier().get(0).getWorkExternalIdentifierId().setContent("extId-" + (i + 1));
if (i == 0 || i == 3) {
peerReviewToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PUBLIC);
} else if (i == 1) {
peerReviewToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
} else {
peerReviewToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PRIVATE);
}
ClientResponse postResponse = memberV2ApiClient.createPeerReviewXml(getUser1OrcidId(), peerReviewToCreate, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
}
}
use of org.orcid.jaxb.model.record_rc3.PeerReview in project ORCID-Source by ORCID.
the class MemberV2Test method testPeerReviewMustHaveAtLeastOneExtId.
@Test
public void testPeerReviewMustHaveAtLeastOneExtId() throws JSONException, InterruptedException, URISyntaxException {
PeerReview peerReview = (PeerReview) unmarshallFromPath("/record_2.0_rc2/samples/peer-review-2.0_rc2.xml", PeerReview.class);
peerReview.setPutCode(null);
peerReview.setGroupId(groupRecords.get(0).getGroupId());
peerReview.getExternalIdentifiers().getExternalIdentifier().clear();
String accessToken = getAccessToken();
ClientResponse postResponse = memberV2ApiClient.createPeerReviewXml(this.getUser1OrcidId(), peerReview, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), postResponse.getStatus());
}
Aggregations