Search in sources :

Example 1 with WorkBulk

use of org.orcid.jaxb.model.v3.dev1.record.WorkBulk in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegatorImpl method viewBulkWorks.

@Override
public Response viewBulkWorks(String orcid, String putCodes) {
    ProfileEntity profileEntity = profileEntityManager.findByOrcid(orcid);
    if (profileEntity == null) {
        throw new OrcidNoResultException("No such profile: " + orcid);
    }
    WorkBulk workBulk = workManagerReadOnly.findWorkBulk(orcid, putCodes);
    orcidSecurityManager.checkAndFilter(orcid, workBulk, ScopePathType.ORCID_WORKS_READ_LIMITED);
    contributorUtils.filterContributorPrivateData(workBulk);
    ActivityUtils.cleanEmptyFields(workBulk);
    sourceUtils.setSourceName(workBulk);
    return Response.ok(workBulk).build();
}
Also used : OrcidNoResultException(org.orcid.core.exception.OrcidNoResultException) WorkBulk(org.orcid.jaxb.model.v3.dev1.record.WorkBulk) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 2 with WorkBulk

use of org.orcid.jaxb.model.v3.dev1.record.WorkBulk in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_WorksTest method testViewBulkWorksWithBadPutCode.

@Test
public void testViewBulkWorksWithBadPutCode() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
    Response response = serviceDelegator.viewBulkWorks(ORCID, "11,12,13,bad");
    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 Work);
    // private work
    assertTrue(workBulk.getBulk().get(2) instanceof Work);
    // bad put code
    assertTrue(workBulk.getBulk().get(3) instanceof OrcidError);
}
Also used : Response(javax.ws.rs.core.Response) OrcidError(org.orcid.jaxb.model.v3.dev1.error.OrcidError) WorkBulk(org.orcid.jaxb.model.v3.dev1.record.WorkBulk) Work(org.orcid.jaxb.model.v3.dev1.record.Work) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 3 with WorkBulk

use of org.orcid.jaxb.model.v3.dev1.record.WorkBulk in project ORCID-Source by ORCID.

the class PublicV3ApiServiceDelegatorTest method testViewBulkWorks.

@Test
public void testViewBulkWorks() {
    Response response = serviceDelegator.viewBulkWorks(ORCID, "11,12,13");
    assertNotNull(response);
    WorkBulk workBulk = (WorkBulk) response.getEntity();
    assertNotNull(workBulk);
    assertNotNull(workBulk.getBulk());
    assertEquals(3, workBulk.getBulk().size());
    assertTrue(workBulk.getBulk().get(0) instanceof Work);
    assertTrue(workBulk.getBulk().get(1) instanceof OrcidError);
    assertTrue(workBulk.getBulk().get(2) instanceof OrcidError);
    Work work = (Work) workBulk.getBulk().get(0);
    assertNotNull(work);
    assertNotNull(work.getLastModifiedDate());
    assertNotNull(work.getLastModifiedDate().getValue());
    assertNotNull(work.getWorkTitle());
    assertNotNull(work.getWorkTitle().getTitle());
    assertEquals("PUBLIC", work.getWorkTitle().getTitle().getContent());
    assertEquals(Long.valueOf(11), work.getPutCode());
    assertEquals("/0000-0000-0000-0003/work/11", work.getPath());
    assertEquals(WorkType.JOURNAL_ARTICLE, work.getWorkType());
    assertEquals("APP-5555555555555555", work.getSource().retrieveSourcePath());
    assertNotNull(work.getWorkContributors());
    assertNotNull(work.getWorkContributors().getContributor());
    assertEquals(1, work.getWorkContributors().getContributor().size());
    assertNotNull(work.getWorkContributors().getContributor().get(0).getContributorOrcid());
    assertEquals("0000-0000-0000-0000", work.getWorkContributors().getContributor().get(0).getContributorOrcid().getPath());
    assertNull(work.getWorkContributors().getContributor().get(0).getCreditName());
}
Also used : Response(javax.ws.rs.core.Response) OrcidError(org.orcid.jaxb.model.v3.dev1.error.OrcidError) WorkBulk(org.orcid.jaxb.model.v3.dev1.record.WorkBulk) Work(org.orcid.jaxb.model.v3.dev1.record.Work) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 4 with WorkBulk

use of org.orcid.jaxb.model.v3.dev1.record.WorkBulk in project ORCID-Source by ORCID.

the class WorkManagerReadOnlyImpl method findWorkBulk.

@Override
public WorkBulk findWorkBulk(String orcid, String putCodesAsString) {
    List<BulkElement> works = new ArrayList<>();
    String[] putCodes = getPutCodeArray(putCodesAsString);
    for (String putCode : putCodes) {
        try {
            Long id = Long.valueOf(putCode);
            WorkEntity workEntity = workEntityCacheManager.retrieveFullWork(orcid, id, getLastModified(orcid));
            works.add(jpaJaxbWorkAdapter.toWork(workEntity));
        } catch (Exception e) {
            works.add(orcidCoreExceptionMapper.getV3OrcidError(new PutCodeFormatException("'" + putCode + "' is not a valid put code")));
        }
    }
    WorkBulk bulk = new WorkBulk();
    bulk.setBulk(works);
    return bulk;
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) MinimizedWorkEntity(org.orcid.persistence.jpa.entities.MinimizedWorkEntity) PutCodeFormatException(org.orcid.core.exception.PutCodeFormatException) BulkElement(org.orcid.jaxb.model.record.bulk.BulkElement) WorkBulk(org.orcid.jaxb.model.v3.dev1.record.WorkBulk) ArrayList(java.util.ArrayList) ExceedMaxNumberOfPutCodesException(org.orcid.core.exception.ExceedMaxNumberOfPutCodesException) PutCodeFormatException(org.orcid.core.exception.PutCodeFormatException)

Example 5 with WorkBulk

use of org.orcid.jaxb.model.v3.dev1.record.WorkBulk in project ORCID-Source by ORCID.

the class WorksTest method testCantAddMoreThan1000WorksAtATime.

@Test
public void testCantAddMoreThan1000WorksAtATime() throws InterruptedException, JSONException {
    String accessToken = getAccessToken();
    WorkBulk bulk = createBulk(1001, null);
    ClientResponse postResponse = memberV3Dev1ApiClient.createWorksJson(this.getUser1OrcidId(), bulk, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), postResponse.getStatus());
    OrcidError error = postResponse.getEntity(OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9006), error.getErrorCode());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.v3.dev1.error.OrcidError) WorkBulk(org.orcid.jaxb.model.v3.dev1.record.WorkBulk) Test(org.junit.Test)

Aggregations

WorkBulk (org.orcid.jaxb.model.v3.dev1.record.WorkBulk)33 Test (org.junit.Test)29 Work (org.orcid.jaxb.model.v3.dev1.record.Work)23 OrcidError (org.orcid.jaxb.model.v3.dev1.error.OrcidError)22 BulkElement (org.orcid.jaxb.model.record.bulk.BulkElement)9 BaseTest (org.orcid.core.BaseTest)8 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)8 Title (org.orcid.jaxb.model.v3.dev1.common.Title)7 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)7 WorkTitle (org.orcid.jaxb.model.v3.dev1.record.WorkTitle)7 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)7 Url (org.orcid.jaxb.model.v3.dev1.common.Url)6 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)6 Response (javax.ws.rs.core.Response)5 DBUnitTest (org.orcid.test.DBUnitTest)5 ClientResponse (com.sun.jersey.api.client.ClientResponse)4 ArrayList (java.util.ArrayList)4 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)3 OrcidNoResultException (org.orcid.core.exception.OrcidNoResultException)2 TranslatedTitle (org.orcid.jaxb.model.v3.dev1.common.TranslatedTitle)2