Search in sources :

Example 6 with OrcidError

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

the class OrcidCoreExceptionMapper method getOrcidErrorV2Rc1.

private OrcidError getOrcidErrorV2Rc1(int errorCode, int status, Throwable t) {
    Locale locale = localeManager.getLocale();
    OrcidError orcidError = new OrcidError();
    orcidError.setResponseCode(status);
    orcidError.setErrorCode(errorCode);
    orcidError.setMoreInfo(messageSource.getMessage("apiError." + errorCode + ".moreInfo", null, locale));
    Map<String, String> params = null;
    if (t instanceof ApplicationException) {
        params = ((ApplicationException) t).getParams();
    }
    orcidError.setDeveloperMessage(getDeveloperMessage(errorCode, t, params));
    orcidError.setUserMessage(resolveMessage(messageSource.getMessage("apiError." + errorCode + ".userMessage", null, locale), params));
    return orcidError;
}
Also used : Locale(java.util.Locale) OrcidError(org.orcid.jaxb.model.error_rc1.OrcidError)

Example 7 with OrcidError

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

the class PublicV2Test method checkLimitedFunding.

public void checkLimitedFunding(String readPublicToken) throws JSONException, InterruptedException, URISyntaxException {
    changeDefaultUserVisibility(org.orcid.jaxb.model.common_v2.Visibility.LIMITED);
    Funding fundingToCreate = (Funding) unmarshallFromPath("/record_2.0_rc1/samples/funding-2.0_rc1.xml", Funding.class);
    fundingToCreate.setPutCode(null);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV2ApiClient.createFundingXml(getUser1OrcidId(), fundingToCreate, 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.viewFundingXml(getUser1OrcidId(), putCode, readPublicToken);
    } else {
        response = publicV2ApiClient.viewFundingXml(getUser1OrcidId(), putCode);
    }
    assertNotNull(response);
    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.viewFundingSummaryXml(getUser1OrcidId(), putCode, readPublicToken);
    } else {
        response = publicV2ApiClient.viewFundingSummaryXml(getUser1OrcidId(), putCode);
    }
    assertNotNull(response);
    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) Funding(org.orcid.jaxb.model.record_rc1.Funding)

Example 8 with OrcidError

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

the class PublicV2Test method checkLimitedEmployment.

public void checkLimitedEmployment(String readPublicToken) throws JSONException, InterruptedException, URISyntaxException {
    changeDefaultUserVisibility(org.orcid.jaxb.model.common_v2.Visibility.LIMITED);
    Employment employmentToCreate = (Employment) unmarshallFromPath("/record_2.0_rc1/samples/employment-2.0_rc1.xml", Employment.class);
    employmentToCreate.setPutCode(null);
    employmentToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV2ApiClient.createEmploymentXml(getUser1OrcidId(), employmentToCreate, 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 = publicV2ApiClient.viewEmploymentXml(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 = publicV2ApiClient.viewEmploymentSummaryXml(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) Employment(org.orcid.jaxb.model.record_rc1.Employment)

Example 9 with OrcidError

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

the class PublicV2Test method checkLimitedWork.

public void checkLimitedWork(String readPublicToken) throws JSONException, InterruptedException, URISyntaxException {
    changeDefaultUserVisibility(org.orcid.jaxb.model.common_v2.Visibility.LIMITED);
    Work workToCreate = (Work) unmarshallFromPath("/record_2.0_rc1/samples/work-2.0_rc1.xml", Work.class);
    workToCreate.setPutCode(null);
    workToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV2ApiClient.createWorkXml(getUser1OrcidId(), workToCreate, 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.viewWorkXml(getUser1OrcidId(), putCode, readPublicToken);
    } else {
        response = publicV2ApiClient.viewWorkXml(getUser1OrcidId(), putCode);
    }
    assertNotNull(response);
    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.viewWorkSummaryXml(getUser1OrcidId(), putCode, readPublicToken);
    } else {
        response = publicV2ApiClient.viewWorkSummaryXml(getUser1OrcidId(), putCode);
    }
    assertNotNull(response);
    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) Work(org.orcid.jaxb.model.record_rc1.Work)

Example 10 with OrcidError

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

the class VerifyOrcidBeforeFetchElementTest method testEmployment.

@Test
public void testEmployment() throws InterruptedException, JSONException, URISyntaxException {
    Employment employment = (Employment) unmarshallFromPath("/record_2.0_rc1/samples/employment-2.0_rc1.xml", Employment.class);
    employment.setPutCode(null);
    employment.setVisibility(Visibility.PUBLIC);
    String user1AccessToken = getAccessToken();
    // Create an employment
    ClientResponse postResponse = memberV2ApiClient.createEmploymentXml(getUser1OrcidId(), employment, 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() + "/employment/\\d+"));
    // Fetch it with the owner
    ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), user1AccessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    Employment gotEmployment = getResponse.getEntity(Employment.class);
    assertEquals("affiliation:department-name", gotEmployment.getDepartmentName());
    assertEquals("affiliation:role-title", gotEmployment.getRoleTitle());
    // 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.viewEmploymentXml(getUser2OrcidId(), gotEmployment.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.viewEmploymentXml(getUser2OrcidId(), String.valueOf(gotEmployment.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.deleteEducationXml(getUser1OrcidId(), gotEmployment.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) Employment(org.orcid.jaxb.model.record_rc1.Employment) Test(org.junit.Test)

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