Search in sources :

Example 91 with PeerReview

use of org.orcid.jaxb.model.record_rc2.PeerReview in project ORCID-Source by ORCID.

the class MemberV2_1Test method createViewUpdateAndDeletePeerReview.

@Test
public void createViewUpdateAndDeletePeerReview() throws JSONException, InterruptedException, URISyntaxException {
    long time = System.currentTimeMillis();
    PeerReview peerReviewToCreate = (PeerReview) unmarshallFromPath("/record_2.1/samples/read_samples/peer-review-2.1.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 = memberV2_1ApiClient.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.1/" + this.getUser1OrcidId() + "/peer-review/\\d+"));
    ClientResponse getResponse = memberV2_1ApiClient.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 = memberV2_1ApiClient.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 = memberV2_1ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotPeerReview);
    assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV2_1ApiClient.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 = memberV2_1ApiClient.deletePeerReviewXml(this.getUser1OrcidId(), gotAfterUpdateWork.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Visibility(org.orcid.jaxb.model.common_v2.Visibility) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) Test(org.junit.Test)

Example 92 with PeerReview

use of org.orcid.jaxb.model.record_rc2.PeerReview in project ORCID-Source by ORCID.

the class MemberV2Test method testAddPeerReviewWithInvalidGroupingId.

@Test
public void testAddPeerReviewWithInvalidGroupingId() throws JSONException, InterruptedException, URISyntaxException {
    PeerReview peerReview = (PeerReview) unmarshallFromPath("/record_2.0_rc1/samples/peer-review-2.0_rc1.xml", PeerReview.class);
    peerReview.setPutCode(null);
    peerReview.setGroupId("Invalid group id " + System.currentTimeMillis());
    peerReview.getExternalIdentifiers().getExternalIdentifier().clear();
    WorkExternalIdentifier pExtId = new WorkExternalIdentifier();
    pExtId.setWorkExternalIdentifierId(new WorkExternalIdentifierId("Work Id " + System.currentTimeMillis()));
    pExtId.setWorkExternalIdentifierType(WorkExternalIdentifierType.AGR);
    pExtId.setRelationship(Relationship.SELF);
    peerReview.getExternalIdentifiers().getExternalIdentifier().add(pExtId);
    String accessToken = getAccessToken();
    // Pattern not valid
    ClientResponse postResponse = memberV2ApiClient.createPeerReviewXml(this.getUser1OrcidId(), peerReview, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), postResponse.getStatus());
    // Null group id
    peerReview.setGroupId(null);
    postResponse = memberV2ApiClient.createPeerReviewXml(this.getUser1OrcidId(), peerReview, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), postResponse.getStatus());
    // Empty group id
    peerReview.setGroupId("");
    postResponse = memberV2ApiClient.createPeerReviewXml(this.getUser1OrcidId(), peerReview, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), postResponse.getStatus());
    // Invalid group id
    peerReview.setGroupId("orcid-generated:" + peerReview.getGroupId());
    postResponse = memberV2ApiClient.createPeerReviewXml(this.getUser1OrcidId(), peerReview, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), postResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WorkExternalIdentifierId(org.orcid.jaxb.model.record_rc1.WorkExternalIdentifierId) WorkExternalIdentifier(org.orcid.jaxb.model.record_rc1.WorkExternalIdentifier) PeerReview(org.orcid.jaxb.model.record_rc1.PeerReview) Test(org.junit.Test)

Example 93 with PeerReview

use of org.orcid.jaxb.model.record_rc2.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());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.error_rc1.OrcidError) WorkExternalIdentifierId(org.orcid.jaxb.model.record_rc1.WorkExternalIdentifierId) WorkExternalIdentifier(org.orcid.jaxb.model.record_rc1.WorkExternalIdentifier) PeerReview(org.orcid.jaxb.model.record_rc1.PeerReview) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)72 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)66 ClientResponse (com.sun.jersey.api.client.ClientResponse)35 Response (javax.ws.rs.core.Response)17 DBUnitTest (org.orcid.test.DBUnitTest)17 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)16 Url (org.orcid.jaxb.model.common_v2.Url)10 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)10 PeerReview (org.orcid.jaxb.model.record_rc1.PeerReview)9 PeerReviewEntity (org.orcid.persistence.jpa.entities.PeerReviewEntity)8 ArrayList (java.util.ArrayList)7 BaseTest (org.orcid.core.BaseTest)6 WorkExternalIdentifier (org.orcid.jaxb.model.record_rc1.WorkExternalIdentifier)6 WorkExternalIdentifierId (org.orcid.jaxb.model.record_rc1.WorkExternalIdentifierId)6 PeerReview (org.orcid.jaxb.model.record_rc3.PeerReview)6 PeerReview (org.orcid.jaxb.model.record_rc4.PeerReview)6 Funding (org.orcid.jaxb.model.record_v2.Funding)6 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)6 Title (org.orcid.jaxb.model.common_v2.Title)5 Education (org.orcid.jaxb.model.record_v2.Education)5