use of org.orcid.jaxb.model.record_rc4.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_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 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_rc1/" + 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);
//TODO: response does not contain full external identifier or disambig org.
//Issue is that upgrading makes subject external identifier fail
//https://www.diffchecker.com/g5laoiou
//Note that this test does not hit disambiguated orgs (which are optional and also not being upgraded)
assertEquals("peer-review:url", gotPeerReview.getUrl().getValue());
assertEquals("peer-review:subject-name", gotPeerReview.getSubjectName().getTitle().getContent());
assertEquals(groupRecords.get(0).getGroupId(), gotPeerReview.getGroupId());
gotPeerReview.getSubjectName().getTitle().setContent("updated title");
//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);
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_rc4.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_rc1/samples/peer-review-2.0_rc1.xml", PeerReview.class);
peerReviewToCreate.setPutCode(null);
peerReviewToCreate.setGroupId(groupRecords.get(0).getGroupId());
peerReviewToCreate.setVisibility(Visibility.PUBLIC);
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().getWorkExternalIdentifier().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_rc1/" + 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_rc4.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/samples/read_samples/peer-review-2.0.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());
}
use of org.orcid.jaxb.model.record_rc4.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/samples/read_samples/peer-review-2.0.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/" + 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_rc4.PeerReview in project ORCID-Source by ORCID.
the class ValidateV2RC3Identifiers method testPeerReview.
/** Test both types of identifier here
*
* @throws SAXException
* @throws IOException
* @throws JAXBException
* @throws ParserConfigurationException
*/
@Test
public void testPeerReview() throws SAXException, IOException, JAXBException, ParserConfigurationException {
PeerReview peerReview = unmarshallFromPath("/record_2.0_rc3/samples/peer-review-2.0_rc3.xml", PeerReview.class);
ExternalID id = peerReview.getExternalIdentifiers().getExternalIdentifier().get(0);
assertEquals("source-work-id", id.getType());
assertEquals("work:external-identifier-id", id.getValue());
assertEquals(new Url("http://orcid.org"), id.getUrl());
assertEquals(Relationship.SELF, id.getRelationship());
ExternalID subjectid = peerReview.getSubjectExternalIdentifier();
assertEquals("doi", subjectid.getType());
assertEquals("peer-review:subject-external-identifier-id", subjectid.getValue());
assertEquals(new Url("http://orcid.org"), subjectid.getUrl());
assertEquals(Relationship.SELF, subjectid.getRelationship());
Validator validator = getValidator("peer-review");
validator.validate(marshall(PeerReview.class, peerReview));
validator.validate(marshallToDOM(PeerReview.class, peerReview));
//do the full record too
peerReview = unmarshallFromPath("/record_2.0_rc3/samples/peer-review-full-2.0_rc3.xml", PeerReview.class);
id = peerReview.getExternalIdentifiers().getExternalIdentifier().get(0);
assertEquals("source-work-id", id.getType());
assertEquals("work:external-identifier-id", id.getValue());
assertEquals(new Url("http://orcid.org"), id.getUrl());
assertEquals(Relationship.SELF, id.getRelationship());
subjectid = peerReview.getSubjectExternalIdentifier();
assertEquals("doi", subjectid.getType());
assertEquals("peer-review:subject-external-identifier-id", subjectid.getValue());
assertEquals(new Url("http://orcid.org"), subjectid.getUrl());
assertEquals(Relationship.SELF, subjectid.getRelationship());
}
Aggregations