use of org.orcid.jaxb.model.error_rc3.OrcidError in project ORCID-Source by ORCID.
the class InternalApiServiceDelegatorImpl method viewMemberInfo.
@Override
public Response viewMemberInfo(String memberIdOrName) {
Member member = memberManager.getMember(memberIdOrName);
if (member == null || (member.getErrors() != null && !member.getErrors().isEmpty())) {
OrcidError orcidError = new OrcidError();
orcidError.setResponseCode(404);
orcidError.setErrorCode(0);
orcidError.setMoreInfo("Unable to find member info for: " + memberIdOrName);
orcidError.setDeveloperMessage("Member id or name not found for: " + memberIdOrName);
orcidError.setUserMessage("Unable to find member info for: " + memberIdOrName);
return Response.status(Response.Status.NOT_FOUND).entity(orcidError).build();
}
MemberInfo memberInfo = MemberInfo.fromMember(member);
return Response.ok(memberInfo).build();
}
use of org.orcid.jaxb.model.error_rc3.OrcidError in project ORCID-Source by ORCID.
the class InternalApiServiceDelegatorTest method viewMemberInfo.
@Test
public void viewMemberInfo() {
String memberId = "5555-5555-5555-5558";
Response response = internalApiServiceDelegator.viewMemberInfo(memberId);
assertNotNull(response);
MemberInfo info = (MemberInfo) response.getEntity();
assertNotNull(info);
assertEquals(memberId, info.getId());
assertNotNull(info.getName());
assertNotNull(info.getClients());
assertFalse(info.getClients().isEmpty());
response = internalApiServiceDelegator.viewMemberInfo(info.getName());
assertNotNull(response);
MemberInfo infoByName = (MemberInfo) response.getEntity();
assertNotNull(infoByName);
assertEquals(memberId, infoByName.getId());
assertEquals(info, infoByName);
response = internalApiServiceDelegator.viewMemberInfo("invalid name");
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
OrcidError error = (OrcidError) response.getEntity();
assertNotNull(error);
assertEquals(new Integer(0), error.getErrorCode());
assertEquals("Member id or name not found for: invalid name", error.getDeveloperMessage());
}
use of org.orcid.jaxb.model.error_rc3.OrcidError in project ORCID-Source by ORCID.
the class Orcid20APIClient method fetchPublicProfile.
/**
* Fetches the profile from the ORCID public API v1.2
*
* @param orcid
* @return
*/
public Record fetchPublicProfile(String orcid) throws LockedRecordException, DeprecatedRecordException {
WebResource webResource = jerseyClient.resource(baseUri).path(orcid + "/record");
webResource.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false);
Builder builder = webResource.accept(MediaType.APPLICATION_XML).header("Authorization", "Bearer " + accessToken);
ClientResponse response = builder.get(ClientResponse.class);
if (response.getStatus() != 200) {
OrcidError orcidError = null;
switch(response.getStatus()) {
case 301:
orcidError = response.getEntity(OrcidError.class);
throw new DeprecatedRecordException(orcidError);
case 409:
orcidError = response.getEntity(OrcidError.class);
throw new LockedRecordException(orcidError);
default:
LOG.error("Unable to fetch public record " + orcid + " on API 2.0 HTTP error code: " + response.getStatus());
throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
}
}
return response.getEntity(Record.class);
}
use of org.orcid.jaxb.model.error_rc3.OrcidError in project ORCID-Source by ORCID.
the class PublicV2ApiServiceVersionedDelegatorTest method testViewBulkWorks.
@Test
public void testViewBulkWorks() {
Response response = serviceDelegator.viewBulkWorks("0000-0000-0000-0003", "11,12,13,16");
WorkBulk workBulk = (WorkBulk) response.getEntity();
assertNotNull(workBulk);
assertNotNull(workBulk.getBulk());
assertEquals(4, workBulk.getBulk().size());
assertTrue(workBulk.getBulk().get(0) instanceof Work);
assertTrue(workBulk.getBulk().get(1) instanceof OrcidError);
assertTrue(workBulk.getBulk().get(2) instanceof OrcidError);
assertTrue(workBulk.getBulk().get(3) instanceof OrcidError);
}
use of org.orcid.jaxb.model.error_rc3.OrcidError in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegator_WorksTest method testCreateBulkWorksWithBlankTitles.
@Test
public void testCreateBulkWorksWithBlankTitles() {
RequestAttributes previousAttrs = RequestContextHolder.getRequestAttributes();
RequestAttributes attrs = new ServletRequestAttributes(new MockHttpServletRequest());
attrs.setAttribute(ApiVersionFilter.API_VERSION_REQUEST_ATTRIBUTE_NAME, "2.0", RequestAttributes.SCOPE_REQUEST);
RequestContextHolder.setRequestAttributes(attrs);
Long time = System.currentTimeMillis();
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
WorkBulk bulk = new WorkBulk();
for (int i = 0; i < 5; i++) {
Work work = new Work();
WorkTitle title = new WorkTitle();
title.setTitle(i == 0 ? new Title(" ") : new Title("title " + i));
work.setWorkTitle(title);
ExternalIDs extIds = new ExternalIDs();
ExternalID extId = new ExternalID();
extId.setRelationship(Relationship.SELF);
extId.setType("doi");
extId.setUrl(new Url("http://doi/" + i + "/" + time));
extId.setValue("doi-" + i + "-" + time);
extIds.getExternalIdentifier().add(extId);
work.setWorkExternalIdentifiers(extIds);
work.setWorkType(WorkType.BOOK);
bulk.getBulk().add(work);
}
Response response = serviceDelegator.createWorks(ORCID, bulk);
assertNotNull(response);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
bulk = (WorkBulk) response.getEntity();
assertNotNull(bulk);
assertEquals(5, bulk.getBulk().size());
for (int i = 0; i < 5; i++) {
if (i == 0) {
assertTrue(bulk.getBulk().get(i) instanceof OrcidError);
} else {
assertTrue(bulk.getBulk().get(i) instanceof Work);
serviceDelegator.deleteWork(ORCID, ((Work) bulk.getBulk().get(i)).getPutCode());
}
}
RequestContextHolder.setRequestAttributes(previousAttrs);
}
Aggregations