Search in sources :

Example 26 with WorkBulk

use of org.orcid.jaxb.model.record_v2.WorkBulk in project ORCID-Source by ORCID.

the class WorkManagerTest method testFindWorkBulkInvalidPutCodes.

@Test
public void testFindWorkBulkInvalidPutCodes() {
    String putCodes = "11,12,13,invalid";
    WorkBulk workBulk = workManager.findWorkBulk("0000-0000-0000-0003", putCodes, System.currentTimeMillis());
    assertNotNull(workBulk);
    assertNotNull(workBulk.getBulk());
    assertEquals(4, workBulk.getBulk().size());
    assertTrue(workBulk.getBulk().get(0) instanceof Work);
    assertTrue(workBulk.getBulk().get(1) instanceof Work);
    assertTrue(workBulk.getBulk().get(2) instanceof Work);
    assertTrue(workBulk.getBulk().get(3) instanceof OrcidError);
}
Also used : OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 27 with WorkBulk

use of org.orcid.jaxb.model.record_v2.WorkBulk in project ORCID-Source by ORCID.

the class WorkManagerTest method testCreateWorksWithBulkAllErrors.

@Test
public void testCreateWorksWithBulkAllErrors() {
    String orcid = "0000-0000-0000-0003";
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    //Set up data: 
    //Create one work with a DOI doi-1 so we can create a duplicate
    Work work = new Work();
    WorkTitle workTitle = new WorkTitle();
    workTitle.setTitle(new Title("work #1"));
    work.setWorkTitle(workTitle);
    ExternalIDs extIds = new ExternalIDs();
    ExternalID extId = new ExternalID();
    extId.setRelationship(Relationship.SELF);
    extId.setType("doi");
    extId.setUrl(new Url("http://doi/1"));
    extId.setValue("doi-1");
    extIds.getExternalIdentifier().add(extId);
    work.setWorkExternalIdentifiers(extIds);
    work.setWorkType(WorkType.BOOK);
    Work newWork = workManager.createWork(orcid, work, true);
    Long putCode = newWork.getPutCode();
    WorkBulk bulk = new WorkBulk();
    //Work # 1: No ext ids
    Work work1 = getWork("work # 1 " + System.currentTimeMillis());
    work1.getExternalIdentifiers().getExternalIdentifier().clear();
    //Work # 2: No title
    Work work2 = getWork("work # 2 " + System.currentTimeMillis());
    work2.getWorkTitle().getTitle().setContent(null);
    //Work # 3: No work type
    Work work3 = getWork("work # 3 " + System.currentTimeMillis());
    work3.setWorkType(null);
    //Work # 4: Ext id already exists
    Work work4 = getWork("work # 4 " + System.currentTimeMillis());
    work4.getExternalIdentifiers().getExternalIdentifier().add(extId);
    bulk.getBulk().add(work1);
    bulk.getBulk().add(work2);
    bulk.getBulk().add(work3);
    bulk.getBulk().add(work4);
    bulk = workManager.createWorks(orcid, bulk);
    assertNotNull(bulk);
    assertEquals(4, bulk.getBulk().size());
    for (int i = 0; i < bulk.getBulk().size(); i++) {
        BulkElement element = bulk.getBulk().get(i);
        assertTrue(OrcidError.class.isAssignableFrom(element.getClass()));
        OrcidError error = (OrcidError) element;
        switch(i) {
            case 0:
                assertEquals(Integer.valueOf(9023), error.getErrorCode());
                break;
            case 1:
                assertEquals(Integer.valueOf(9022), error.getErrorCode());
                break;
            case 2:
                assertEquals(Integer.valueOf(9037), error.getErrorCode());
                break;
            case 3:
                assertEquals(Integer.valueOf(9021), error.getErrorCode());
                break;
        }
    }
    //Delete the work
    assertTrue(workManager.checkSourceAndRemoveWork(orcid, putCode));
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) Title(org.orcid.jaxb.model.common_v2.Title) Url(org.orcid.jaxb.model.common_v2.Url) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) BulkElement(org.orcid.jaxb.model.record_v2.BulkElement) Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 28 with WorkBulk

use of org.orcid.jaxb.model.record_v2.WorkBulk in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegatorImpl 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, profileEntity.getLastModified().getTime());
    orcidSecurityManager.checkAndFilter(orcid, workBulk, ScopePathType.ORCID_WORKS_READ_LIMITED);
    ActivityUtils.cleanEmptyFields(workBulk);
    sourceUtils.setSourceName(workBulk);
    return Response.ok(workBulk).build();
}
Also used : OrcidNoResultException(org.orcid.core.exception.OrcidNoResultException) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 29 with WorkBulk

use of org.orcid.jaxb.model.record_v2.WorkBulk in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegatorImpl method createWorks.

@Override
public Response createWorks(String orcid, WorkBulk works) {
    orcidSecurityManager.checkClientAccessAndScopes(orcid, ScopePathType.ORCID_WORKS_CREATE);
    if (works != null) {
        for (BulkElement b : works.getBulk()) {
            if (Work.class.isAssignableFrom(b.getClass())) {
                clearSource((Work) b);
            }
        }
    }
    works = workManager.createWorks(orcid, works);
    sourceUtils.setSourceName(works);
    return Response.ok(works).build();
}
Also used : BulkElement(org.orcid.jaxb.model.record_v2.BulkElement)

Example 30 with WorkBulk

use of org.orcid.jaxb.model.record_v2.WorkBulk in project ORCID-Source by ORCID.

the class WorkManagerReadOnlyImpl method findWorkBulk.

@Override
public WorkBulk findWorkBulk(String orcid, String putCodesAsString, long profileLastModified) {
    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, profileLastModified);
            works.add(jpaJaxbWorkAdapter.toWork(workEntity));
        } catch (Exception e) {
            works.add(orcidCoreExceptionMapper.getOrcidError(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_v2.BulkElement) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) ArrayList(java.util.ArrayList) ExceedMaxNumberOfPutCodesException(org.orcid.core.exception.ExceedMaxNumberOfPutCodesException) PutCodeFormatException(org.orcid.core.exception.PutCodeFormatException)

Aggregations

Test (org.junit.Test)39 WorkBulk (org.orcid.jaxb.model.record_v2.WorkBulk)36 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)24 Work (org.orcid.jaxb.model.record_v2.Work)23 ClientResponse (com.sun.jersey.api.client.ClientResponse)16 BulkElement (org.orcid.jaxb.model.record_v2.BulkElement)13 Response (javax.ws.rs.core.Response)7 DBUnitTest (org.orcid.test.DBUnitTest)7 BaseTest (org.orcid.core.BaseTest)5 WorkBulk (org.orcid.jaxb.model.record_rc3.WorkBulk)5 WorkBulk (org.orcid.jaxb.model.record_rc4.WorkBulk)5 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)5 ArrayList (java.util.ArrayList)4 Url (org.orcid.jaxb.model.common_v2.Url)4 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)4 Title (org.orcid.jaxb.model.common_v2.Title)3 OrcidError (org.orcid.jaxb.model.error_rc3.OrcidError)3 OrcidError (org.orcid.jaxb.model.error_rc4.OrcidError)3 BulkElement (org.orcid.jaxb.model.record_rc3.BulkElement)3 Work (org.orcid.jaxb.model.record_rc3.Work)3