Search in sources :

Example 71 with OrcidError

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

the class OrcidCoreExceptionMapper method getOrcidErrorV2.

private org.orcid.jaxb.model.error_v2.OrcidError getOrcidErrorV2(int errorCode, int status, Throwable t) {
    Locale locale = localeManager.getLocale();
    org.orcid.jaxb.model.error_v2.OrcidError orcidError = new org.orcid.jaxb.model.error_v2.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 72 with OrcidError

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

the class OrcidCoreExceptionMapper method getOrcidErrorV2Rc2.

private org.orcid.jaxb.model.error_rc2.OrcidError getOrcidErrorV2Rc2(int errorCode, int status, Throwable t) {
    Locale locale = localeManager.getLocale();
    org.orcid.jaxb.model.error_rc2.OrcidError orcidError = new org.orcid.jaxb.model.error_rc2.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 73 with OrcidError

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

the class OrcidCoreExceptionMapper method getOrcidErrorV2Rc4.

private org.orcid.jaxb.model.error_rc4.OrcidError getOrcidErrorV2Rc4(int errorCode, int status, Throwable t) {
    Locale locale = localeManager.getLocale();
    org.orcid.jaxb.model.error_rc4.OrcidError orcidError = new org.orcid.jaxb.model.error_rc4.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 74 with OrcidError

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

the class MemberV2Test method createViewUpdateAndDeleteEmployment.

@Test
public void createViewUpdateAndDeleteEmployment() throws JSONException, InterruptedException, URISyntaxException {
    Employment employment = (Employment) unmarshallFromPath("/record_2.0_rc4/samples/employment-2.0_rc4.xml", Employment.class);
    employment.setPutCode(null);
    employment.setVisibility(Visibility.PUBLIC);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV2ApiClient.createEmploymentXml(this.getUser1OrcidId(), employment, 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_rc4/" + this.getUser1OrcidId() + "/employment/\\d+"));
    ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    Employment gotEmployment = getResponse.getEntity(Employment.class);
    assertEquals("employment:department-name", gotEmployment.getDepartmentName());
    assertEquals("employment:role-title", gotEmployment.getRoleTitle());
    //Save the original visibility
    Visibility originalVisibility = gotEmployment.getVisibility();
    Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
    //Verify you cant update the visibility
    gotEmployment.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotEmployment);
    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
    gotEmployment.setVisibility(originalVisibility);
    gotEmployment.setDepartmentName("updated dept. name");
    gotEmployment.setRoleTitle("updated role title");
    putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotEmployment);
    assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    Employment gotAfterUpdateEmployment = getAfterUpdateResponse.getEntity(Employment.class);
    assertEquals("updated dept. name", gotAfterUpdateEmployment.getDepartmentName());
    assertEquals("updated role title", gotAfterUpdateEmployment.getRoleTitle());
    ClientResponse deleteResponse = memberV2ApiClient.deleteEmploymentXml(this.getUser1OrcidId(), gotEmployment.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_rc4.OrcidError) Employment(org.orcid.jaxb.model.record_rc4.Employment) Visibility(org.orcid.jaxb.model.common_rc4.Visibility) Test(org.junit.Test)

Example 75 with OrcidError

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

the class WorksTest method testThreeWithInvalidTypeAllOthersAreFine.

@Test
public void testThreeWithInvalidTypeAllOthersAreFine() throws InterruptedException, JSONException {
    String accessToken = getAccessToken();
    WorkBulk bulk = createBulk(10, null);
    //Work 3: no type
    Work work3 = (Work) bulk.getBulk().get(3);
    work3.setWorkType(null);
    bulk.getBulk().set(3, work3);
    //Work 5: empty title
    Work work5 = (Work) bulk.getBulk().get(5);
    work5.getWorkTitle().getTitle().setContent(null);
    bulk.getBulk().set(5, work5);
    //Work 7: translated title language code empty
    Work work7 = (Work) bulk.getBulk().get(7);
    work7.getWorkTitle().getTranslatedTitle().setLanguageCode(null);
    bulk.getBulk().set(7, work7);
    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());
    for (int i = 0; i < bulk.getBulk().size(); i++) {
        BulkElement element = bulk.getBulk().get(i);
        if (i == 3 || i == 5 || i == 7) {
            assertTrue(OrcidError.class.isAssignableFrom(element.getClass()));
            OrcidError error = (OrcidError) element;
            switch(i) {
                case 3:
                    assertEquals(Integer.valueOf(9037), error.getErrorCode());
                    assertTrue(error.getDeveloperMessage().startsWith("Invalid work type"));
                    break;
                case 5:
                    assertEquals(Integer.valueOf(9022), error.getErrorCode());
                    break;
                case 7:
                    assertEquals(Integer.valueOf(9037), error.getErrorCode());
                    assertTrue(error.getDeveloperMessage().startsWith("Invalid translated title"));
                    break;
            }
        } else {
            assertTrue(Work.class.isAssignableFrom(element.getClass()));
            Work work = (Work) element;
            assertNotNull(work.getPutCode());
            memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), work.getPutCode(), accessToken);
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.error_rc4.OrcidError) BulkElement(org.orcid.jaxb.model.record_rc4.BulkElement) WorkBulk(org.orcid.jaxb.model.record_rc4.WorkBulk) Work(org.orcid.jaxb.model.record_rc4.Work) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)65 ClientResponse (com.sun.jersey.api.client.ClientResponse)54 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)43 OrcidError (org.orcid.jaxb.model.error_rc1.OrcidError)24 WorkBulk (org.orcid.jaxb.model.record_v2.WorkBulk)21 Work (org.orcid.jaxb.model.record_v2.Work)19 Visibility (org.orcid.jaxb.model.common_v2.Visibility)10 BulkElement (org.orcid.jaxb.model.record_v2.BulkElement)9 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)9 OrcidError (org.orcid.jaxb.model.error_rc3.OrcidError)8 OrcidError (org.orcid.jaxb.model.error_rc4.OrcidError)8 Response (javax.ws.rs.core.Response)7 Locale (java.util.Locale)6 DBUnitTest (org.orcid.test.DBUnitTest)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 Visibility (org.orcid.jaxb.model.common_rc3.Visibility)4 Url (org.orcid.jaxb.model.common_v2.Url)4 ArrayList (java.util.ArrayList)3