Search in sources :

Example 26 with OrcidError

use of org.orcid.jaxb.model.error_rc3.OrcidError in project ORCID-Source by ORCID.

the class WorksTest method testCreateBulkWithAllErrors.

@Test
public void testCreateBulkWithAllErrors() throws InterruptedException, JSONException {
    String accessToken = getAccessToken();
    WorkBulk bulk = createBulk(10, "existing-ext-id-" + System.currentTimeMillis());
    ClientResponse postResponse = memberV2ApiClient.createWorksJson(this.getUser1OrcidId(), bulk, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.OK.getStatusCode(), postResponse.getStatus());
    bulk = postResponse.getEntity(WorkBulk.class);
    assertNotNull(bulk);
    assertNotNull(bulk.getBulk());
    boolean first = true;
    // All elements might be ok
    for (BulkElement element : bulk.getBulk()) {
        if (first) {
            assertTrue(Work.class.isAssignableFrom(element.getClass()));
            Work work = (Work) element;
            // Remove the work
            memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), work.getPutCode(), accessToken);
            first = false;
        } else {
            assertTrue(OrcidError.class.isAssignableFrom(element.getClass()));
            OrcidError error = (OrcidError) element;
            assertEquals(Integer.valueOf(9021), error.getErrorCode());
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) BulkElement(org.orcid.jaxb.model.record.bulk.BulkElement) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test)

Example 27 with OrcidError

use of org.orcid.jaxb.model.error_rc3.OrcidError in project ORCID-Source by ORCID.

the class WorksTest method createViewUpdateAndDeleteWork.

@Test
public void createViewUpdateAndDeleteWork() throws JSONException, InterruptedException, URISyntaxException {
    showMyOrcidPage();
    changeDefaultUserVisibility(webDriver, org.orcid.jaxb.model.common_v2.Visibility.PUBLIC.name());
    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.getExternalIdentifiers().getExternalIdentifier().clear();
    ExternalID wExtId = new ExternalID();
    wExtId.setValue("Work Id " + time);
    wExtId.setType("agr");
    wExtId.setRelationship(Relationship.SELF);
    wExtId.setUrl(new Url("http://test.orcid.org/" + time));
    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());
    assertEquals("work:citation", gotWork.getWorkCitation().getCitation());
    assertEquals(CitationType.FORMATTED_UNSPECIFIED, gotWork.getWorkCitation().getWorkCitationType());
    gotWork.getWorkTitle().getTitle().setContent("updated title");
    // Save the original visibility
    Visibility originalVisibility = gotWork.getVisibility();
    Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
    // Verify you cant update the visibility
    gotWork.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotWork);
    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
    gotWork.setVisibility(originalVisibility);
    putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotWork);
    assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    Work gotAfterUpdateWork = getAfterUpdateResponse.getEntity(Work.class);
    assertEquals("updated title", gotAfterUpdateWork.getWorkTitle().getTitle().getContent());
    assertEquals("work:citation", gotAfterUpdateWork.getWorkCitation().getCitation());
    assertEquals(CitationType.FORMATTED_UNSPECIFIED, gotAfterUpdateWork.getWorkCitation().getWorkCitationType());
    ClientResponse deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), gotWork.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) Work(org.orcid.jaxb.model.record_v2.Work) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Url(org.orcid.jaxb.model.common_v2.Url) Test(org.junit.Test)

Example 28 with OrcidError

use of org.orcid.jaxb.model.error_rc3.OrcidError in project ORCID-Source by ORCID.

the class WorksTest method createViewUpdateAndDeleteWorkWithLegacyScope.

@Test
public void createViewUpdateAndDeleteWorkWithLegacyScope() throws JSONException, InterruptedException, URISyntaxException {
    showMyOrcidPage();
    changeDefaultUserVisibility(webDriver, org.orcid.jaxb.model.common_v2.Visibility.PUBLIC.name());
    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.getExternalIdentifiers().getExternalIdentifier().clear();
    ExternalID wExtId = new ExternalID();
    wExtId.setValue("Work Id " + time);
    wExtId.setType("agr");
    wExtId.setRelationship(Relationship.SELF);
    wExtId.setUrl(new Url("http://test.orcid.org/" + time));
    workToCreate.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
    String accessToken = getAccessToken(getScopes(ScopePathType.ORCID_WORKS_UPDATE));
    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());
    assertEquals("work:citation", gotWork.getWorkCitation().getCitation());
    assertEquals(CitationType.FORMATTED_UNSPECIFIED, gotWork.getWorkCitation().getWorkCitationType());
    gotWork.getWorkTitle().getTitle().setContent("updated title");
    // Save the original visibility
    Visibility originalVisibility = gotWork.getVisibility();
    Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
    // Verify you cant update the visibility
    gotWork.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotWork);
    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
    gotWork.setVisibility(originalVisibility);
    putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotWork);
    assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    Work gotAfterUpdateWork = getAfterUpdateResponse.getEntity(Work.class);
    assertEquals("updated title", gotAfterUpdateWork.getWorkTitle().getTitle().getContent());
    assertEquals("work:citation", gotAfterUpdateWork.getWorkCitation().getCitation());
    assertEquals(CitationType.FORMATTED_UNSPECIFIED, gotAfterUpdateWork.getWorkCitation().getWorkCitationType());
    ClientResponse deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), gotWork.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) Work(org.orcid.jaxb.model.record_v2.Work) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Url(org.orcid.jaxb.model.common_v2.Url) Test(org.junit.Test)

Example 29 with OrcidError

use of org.orcid.jaxb.model.error_rc3.OrcidError in project ORCID-Source by ORCID.

the class PublicV2Test method checkLimitedEducation.

public void checkLimitedEducation(String readPublicToken) throws JSONException, InterruptedException, URISyntaxException {
    // Change the default user visibility to public so we can create a limited work
    changeDefaultUserVisibility(org.orcid.jaxb.model.common_v2.Visibility.LIMITED);
    Education educationToCreate = (Education) unmarshallFromPath("/record_2.0_rc1/samples/education-2.0_rc1.xml", Education.class);
    educationToCreate.setPutCode(null);
    educationToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV2ApiClient.createEducationXml(getUser1OrcidId(), educationToCreate, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    String path = postResponse.getLocation().getPath();
    String putCode = path.substring(path.lastIndexOf('/') + 1, path.length());
    ClientResponse response = null;
    if (readPublicToken != null) {
        response = publicV2ApiClient.viewEducationXml(getUser1OrcidId(), putCode, readPublicToken);
    } else {
        response = publicV2ApiClient.viewEducationXml(getUser1OrcidId(), putCode);
    }
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), response.getStatus());
    OrcidError result = response.getEntity(OrcidError.class);
    assertNotNull(result);
    assertEquals(new Integer(9039), result.getErrorCode());
    assertEquals("403 Forbidden: The item is not public and cannot be accessed with the Public API.", result.getDeveloperMessage());
    response = null;
    if (readPublicToken != null) {
        response = publicV2ApiClient.viewEducationSummaryXml(getUser1OrcidId(), putCode, readPublicToken);
    } else {
        response = publicV2ApiClient.viewEducationSummaryXml(getUser1OrcidId(), putCode);
    }
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), response.getStatus());
    result = response.getEntity(OrcidError.class);
    assertNotNull(result);
    assertEquals(new Integer(9039), result.getErrorCode());
    assertEquals("403 Forbidden: The item is not public and cannot be accessed with the Public API.", result.getDeveloperMessage());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.error_rc1.OrcidError) Education(org.orcid.jaxb.model.record_rc1.Education)

Example 30 with OrcidError

use of org.orcid.jaxb.model.error_rc3.OrcidError in project ORCID-Source by ORCID.

the class PublicV2Test method checkLimitedPeerReview.

public void checkLimitedPeerReview(String readPublicToken) throws JSONException, InterruptedException, URISyntaxException {
    // Change the default user visibility to public so we can create a limited work
    changeDefaultUserVisibility(org.orcid.jaxb.model.common_v2.Visibility.LIMITED);
    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(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV2ApiClient.createPeerReviewXml(getUser1OrcidId(), peerReviewToCreate, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    String path = postResponse.getLocation().getPath();
    String putCode = path.substring(path.lastIndexOf('/') + 1, path.length());
    ClientResponse response = null;
    if (readPublicToken != null) {
        response = publicV2ApiClient.viewPeerReviewXml(getUser1OrcidId(), putCode, readPublicToken);
    } else {
        response = publicV2ApiClient.viewPeerReviewXml(getUser1OrcidId(), putCode);
    }
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), response.getStatus());
    OrcidError result = response.getEntity(OrcidError.class);
    assertNotNull(result);
    assertEquals(new Integer(9039), result.getErrorCode());
    assertEquals("403 Forbidden: The item is not public and cannot be accessed with the Public API.", result.getDeveloperMessage());
    response = null;
    if (readPublicToken != null) {
        response = publicV2ApiClient.viewPeerReviewSummaryXml(getUser1OrcidId(), putCode, readPublicToken);
    } else {
        response = publicV2ApiClient.viewPeerReviewSummaryXml(getUser1OrcidId(), putCode);
    }
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), response.getStatus());
    result = response.getEntity(OrcidError.class);
    assertNotNull(result);
    assertEquals(new Integer(9039), result.getErrorCode());
    assertEquals("403 Forbidden: The item is not public and cannot be accessed with the Public API.", result.getDeveloperMessage());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.error_rc1.OrcidError) PeerReview(org.orcid.jaxb.model.record_rc1.PeerReview)

Aggregations

Test (org.junit.Test)70 ClientResponse (com.sun.jersey.api.client.ClientResponse)56 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)51 OrcidError (org.orcid.jaxb.model.error_rc1.OrcidError)25 WorkBulk (org.orcid.jaxb.model.record_v2.WorkBulk)23 Work (org.orcid.jaxb.model.record_v2.Work)22 BulkElement (org.orcid.jaxb.model.record.bulk.BulkElement)13 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)12 Visibility (org.orcid.jaxb.model.common_v2.Visibility)11 Response (javax.ws.rs.core.Response)8 OrcidError (org.orcid.jaxb.model.error_rc3.OrcidError)8 OrcidError (org.orcid.jaxb.model.error_rc4.OrcidError)8 Url (org.orcid.jaxb.model.common_v2.Url)7 LockedRecordException (org.orcid.listener.exception.LockedRecordException)7 DBUnitTest (org.orcid.test.DBUnitTest)7 Locale (java.util.Locale)6 DeprecatedRecordException (org.orcid.listener.exception.DeprecatedRecordException)6 Visibility (org.orcid.jaxb.model.common_rc1.Visibility)5 Visibility (org.orcid.jaxb.model.common_rc2.Visibility)5 Visibility (org.orcid.jaxb.model.common_rc4.Visibility)5