Search in sources :

Example 16 with OrcidError

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();
}
Also used : OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) MemberInfo(org.orcid.internal.util.MemberInfo) Member(org.orcid.pojo.ajaxForm.Member)

Example 17 with OrcidError

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());
}
Also used : LastModifiedResponse(org.orcid.internal.util.LastModifiedResponse) Response(javax.ws.rs.core.Response) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) MemberInfo(org.orcid.internal.util.MemberInfo) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest)

Example 18 with OrcidError

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);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) LockedRecordException(org.orcid.listener.exception.LockedRecordException) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) Builder(com.sun.jersey.api.client.WebResource.Builder) WebResource(com.sun.jersey.api.client.WebResource)

Example 19 with OrcidError

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);
}
Also used : Response(javax.ws.rs.core.Response) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) Work(org.orcid.jaxb.model.record_v2.Work) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 20 with 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);
}
Also used : OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) TranslatedTitle(org.orcid.jaxb.model.common_v2.TranslatedTitle) Title(org.orcid.jaxb.model.common_v2.Title) RequestAttributes(org.springframework.web.context.request.RequestAttributes) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) Url(org.orcid.jaxb.model.common_v2.Url) ResearcherUrl(org.orcid.jaxb.model.record_v2.ResearcherUrl) Response(javax.ws.rs.core.Response) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) Work(org.orcid.jaxb.model.record_v2.Work) DBUnitTest(org.orcid.test.DBUnitTest) 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