use of org.orcid.jaxb.model.error_v2.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;
}
use of org.orcid.jaxb.model.error_v2.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;
}
use of org.orcid.jaxb.model.error_v2.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;
}
use of org.orcid.jaxb.model.error_v2.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());
}
use of org.orcid.jaxb.model.error_v2.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);
}
}
}
Aggregations