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;
}
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());
}
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());
}
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());
}
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());
}
Aggregations