Search in sources :

Example 56 with Work

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

the class WorkManagerTest method testGetAll.

@Test
public void testGetAll() {
    List<Work> elements = workManager.findWorks("0000-0000-0000-0003");
    assertNotNull(elements);
    assertEquals(6, elements.size());
    boolean found1 = false, found2 = false, found3 = false, found4 = false, found5 = false, found6 = false;
    for (Work element : elements) {
        if (11 == element.getPutCode()) {
            found1 = true;
        } else if (12 == element.getPutCode()) {
            found2 = true;
        } else if (13 == element.getPutCode()) {
            found3 = true;
        } else if (14 == element.getPutCode()) {
            found4 = true;
        } else if (15 == element.getPutCode()) {
            found5 = true;
        } else if (16 == element.getPutCode()) {
            found6 = true;
        } else {
            fail("Invalid element found: " + element.getPutCode());
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(found3);
    assertTrue(found4);
    assertTrue(found5);
}
Also used : Work(org.orcid.jaxb.model.v3.dev1.record.Work) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 57 with Work

use of org.orcid.jaxb.model.v3.dev1.record.Work 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();
    extIds.getExternalIdentifier().add(getDuplicateExternalId());
    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(getDuplicateExternalId());
    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.v3.dev1.error.OrcidError) ExternalIDs(org.orcid.jaxb.model.v3.dev1.record.ExternalIDs) WorkTitle(org.orcid.jaxb.model.v3.dev1.record.WorkTitle) BulkElement(org.orcid.jaxb.model.record.bulk.BulkElement) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) WorkBulk(org.orcid.jaxb.model.v3.dev1.record.WorkBulk) Work(org.orcid.jaxb.model.v3.dev1.record.Work) Title(org.orcid.jaxb.model.v3.dev1.common.Title) WorkTitle(org.orcid.jaxb.model.v3.dev1.record.WorkTitle) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 58 with Work

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

the class WorkManagerTest method testGroupWorks.

@Test
public void testGroupWorks() {
    /**
     * @formatter:off
     * They should be grouped as
     *
     * Group 1: Work 1 + Work 4
     * Group 2: Work 2 + Work 5
     * Group 3: Work 3
     * Group 4: Work 6
     * @formatter:on
     */
    WorkSummary s1 = getWorkSummary("Work 1", "ext-id-1", Visibility.PUBLIC);
    WorkSummary s2 = getWorkSummary("Work 2", "ext-id-2", Visibility.LIMITED);
    WorkSummary s3 = getWorkSummary("Work 3", "ext-id-3", Visibility.PRIVATE);
    WorkSummary s4 = getWorkSummary("Work 4", "ext-id-1", Visibility.PRIVATE);
    WorkSummary s5 = getWorkSummary("Work 5", "ext-id-2", Visibility.PUBLIC);
    WorkSummary s6 = getWorkSummary("Work 6", "ext-id-4", Visibility.PRIVATE);
    List<WorkSummary> workList1 = Arrays.asList(s1, s2, s3, s4, s5, s6);
    Works works1 = workManager.groupWorks(workList1, false);
    assertNotNull(works1);
    assertEquals(4, works1.getWorkGroup().size());
    // Group 1 have all with ext-id-1
    assertEquals(2, works1.getWorkGroup().get(0).getWorkSummary().size());
    assertEquals(1, works1.getWorkGroup().get(0).getIdentifiers().getExternalIdentifier().size());
    assertEquals("ext-id-1", works1.getWorkGroup().get(0).getIdentifiers().getExternalIdentifier().get(0).getValue());
    // Group 2 have all with ext-id-2
    assertEquals(2, works1.getWorkGroup().get(1).getWorkSummary().size());
    assertEquals(1, works1.getWorkGroup().get(1).getIdentifiers().getExternalIdentifier().size());
    assertEquals("ext-id-2", works1.getWorkGroup().get(1).getIdentifiers().getExternalIdentifier().get(0).getValue());
    // Group 3 have ext-id-3
    assertEquals(1, works1.getWorkGroup().get(2).getWorkSummary().size());
    assertEquals(1, works1.getWorkGroup().get(2).getIdentifiers().getExternalIdentifier().size());
    assertEquals("ext-id-3", works1.getWorkGroup().get(2).getIdentifiers().getExternalIdentifier().get(0).getValue());
    // Group 4 have ext-id-4
    assertEquals(1, works1.getWorkGroup().get(3).getWorkSummary().size());
    assertEquals(1, works1.getWorkGroup().get(3).getIdentifiers().getExternalIdentifier().size());
    assertEquals("ext-id-4", works1.getWorkGroup().get(3).getIdentifiers().getExternalIdentifier().get(0).getValue());
    WorkSummary s7 = getWorkSummary("Work 7", "ext-id-4", Visibility.PRIVATE);
    // Add ext-id-3 to work 7, so, it join group 3 and group 4 in a single
    // group
    ExternalID extId = new ExternalID();
    extId.setRelationship(Relationship.SELF);
    extId.setType("doi");
    extId.setUrl(new Url("http://orcid.org"));
    extId.setValue("ext-id-3");
    s7.getExternalIdentifiers().getExternalIdentifier().add(extId);
    /**
     * @formatter:off
     * Now, they should be grouped as
     *
     * Group 1: Work 1 + Work 4
     * Group 2: Work 2 + Work 5
     * Group 3: Work 3 + Work 6 + Work 7
     * @formatter:on
     */
    List<WorkSummary> workList2 = Arrays.asList(s1, s2, s3, s4, s5, s6, s7);
    Works works2 = workManager.groupWorks(workList2, false);
    assertNotNull(works2);
    assertEquals(3, works2.getWorkGroup().size());
    // Group 1 have all with ext-id-1
    assertEquals(2, works2.getWorkGroup().get(0).getWorkSummary().size());
    assertEquals(1, works2.getWorkGroup().get(0).getIdentifiers().getExternalIdentifier().size());
    assertEquals("ext-id-1", works2.getWorkGroup().get(0).getIdentifiers().getExternalIdentifier().get(0).getValue());
    // Group 2 have all with ext-id-2
    assertEquals(2, works2.getWorkGroup().get(1).getWorkSummary().size());
    assertEquals(1, works2.getWorkGroup().get(1).getIdentifiers().getExternalIdentifier().size());
    assertEquals("ext-id-2", works2.getWorkGroup().get(1).getIdentifiers().getExternalIdentifier().get(0).getValue());
    // Group 3 have all with ext-id-3 and ext-id-4
    assertEquals(3, works2.getWorkGroup().get(2).getWorkSummary().size());
    assertEquals(2, works2.getWorkGroup().get(2).getIdentifiers().getExternalIdentifier().size());
    assertThat(works2.getWorkGroup().get(2).getIdentifiers().getExternalIdentifier().get(0).getValue(), anyOf(is("ext-id-3"), is("ext-id-4")));
    assertThat(works2.getWorkGroup().get(2).getIdentifiers().getExternalIdentifier().get(1).getValue(), anyOf(is("ext-id-3"), is("ext-id-4")));
}
Also used : WorkSummary(org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) Works(org.orcid.jaxb.model.v3.dev1.record.summary.Works) Url(org.orcid.jaxb.model.v3.dev1.common.Url) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 59 with Work

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

the class WorkManagerTest method displayIndexIsSetTo_0_FromAPI.

@Test
public void displayIndexIsSetTo_0_FromAPI() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    Work w1 = getWork("fromAPI-1");
    w1 = workManager.createWork(claimedOrcid, w1, true);
    WorkEntity w = workDao.find(w1.getPutCode());
    assertNotNull(w1);
    assertEquals(Long.valueOf(0), w.getDisplayIndex());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) MinimizedWorkEntity(org.orcid.persistence.jpa.entities.MinimizedWorkEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Work(org.orcid.jaxb.model.v3.dev1.record.Work) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 60 with Work

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

the class WorkManagerTest method testCreateWorksWithBulkSomeOKSomeErrors.

@Test
public void testCreateWorksWithBulkSomeOKSomeErrors() {
    String orcid = "0000-0000-0000-0003";
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_2_ID)));
    // Lets send a bulk of 6 works
    WorkBulk bulk = new WorkBulk();
    // Work # 1 - Fine
    Work work1 = getWork(null);
    work1.getExternalIdentifiers().getExternalIdentifier().clear();
    work1.getExternalIdentifiers().getExternalIdentifier().add(getDuplicateExternalId());
    work1.getWorkTitle().getTitle().setContent("Work # 1");
    bulk.getBulk().add(work1);
    // Work # 2 - Fine
    Work work2 = getWork(null);
    work2.getWorkTitle().getTitle().setContent("Work # 2");
    bulk.getBulk().add(work2);
    // Work # 3 - Duplicated of Work # 1
    Work work3 = getWork(null);
    work3.getExternalIdentifiers().getExternalIdentifier().clear();
    work3.getExternalIdentifiers().getExternalIdentifier().add(getDuplicateExternalId());
    work3.getWorkTitle().getTitle().setContent("Work # 3");
    bulk.getBulk().add(work3);
    // Work # 4 - Fine
    Work work4 = getWork("new-ext-id-" + System.currentTimeMillis());
    work4.getWorkTitle().getTitle().setContent("Work # 4");
    bulk.getBulk().add(work4);
    // Work # 5 - Duplicated of existing work
    Work work5 = getWork(null);
    ExternalID dupExtId = new ExternalID();
    dupExtId.setRelationship(Relationship.SELF);
    dupExtId.setType("doi");
    dupExtId.setValue("1");
    work5.getExternalIdentifiers().getExternalIdentifier().clear();
    work5.getExternalIdentifiers().getExternalIdentifier().add(dupExtId);
    work5.getWorkTitle().getTitle().setContent("Work # 5");
    bulk.getBulk().add(work5);
    // Work # 6 - No title specified
    Work work6 = getWork(null);
    work6.getWorkTitle().getTitle().setContent(null);
    bulk.getBulk().add(work6);
    bulk = workManager.createWorks(orcid, bulk);
    assertNotNull(bulk);
    assertEquals(6, bulk.getBulk().size());
    List<Long> worksToDelete = new ArrayList<Long>();
    for (int i = 0; i < bulk.getBulk().size(); i++) {
        BulkElement element = bulk.getBulk().get(i);
        switch(i) {
            case 0:
            case 1:
            case 3:
                assertTrue(Work.class.isAssignableFrom(element.getClass()));
                Work work = (Work) element;
                assertNotNull(work);
                assertNotNull(work.getPutCode());
                if (i == 0) {
                    assertEquals("Work # 1", work.getWorkTitle().getTitle().getContent());
                } else if (i == 1) {
                    assertEquals("Work # 2", work.getWorkTitle().getTitle().getContent());
                } else {
                    assertEquals("Work # 4", work.getWorkTitle().getTitle().getContent());
                }
                worksToDelete.add(work.getPutCode());
                break;
            case 2:
            case 4:
            case 5:
                assertTrue("Error on id: " + i, OrcidError.class.isAssignableFrom(element.getClass()));
                OrcidError error = (OrcidError) element;
                if (i == 2) {
                    assertEquals(Integer.valueOf(9021), error.getErrorCode());
                } else if (i == 4) {
                    assertEquals(Integer.valueOf(9021), error.getErrorCode());
                } else {
                    assertEquals(Integer.valueOf(9022), error.getErrorCode());
                }
                break;
        }
    }
    // Delete new works
    for (Long putCode : worksToDelete) {
        assertTrue(workManager.checkSourceAndRemoveWork(orcid, putCode));
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OrcidError(org.orcid.jaxb.model.v3.dev1.error.OrcidError) BulkElement(org.orcid.jaxb.model.record.bulk.BulkElement) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) WorkBulk(org.orcid.jaxb.model.v3.dev1.record.WorkBulk) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) Work(org.orcid.jaxb.model.v3.dev1.record.Work) ArrayList(java.util.ArrayList) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Aggregations

Test (org.junit.Test)154 Work (org.orcid.jaxb.model.v3.dev1.record.Work)141 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)46 DBUnitTest (org.orcid.test.DBUnitTest)41 Response (javax.ws.rs.core.Response)39 Title (org.orcid.jaxb.model.v3.dev1.common.Title)29 WorkTitle (org.orcid.jaxb.model.v3.dev1.record.WorkTitle)29 WorkSummary (org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary)29 Url (org.orcid.jaxb.model.v3.dev1.common.Url)28 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)24 WorkBulk (org.orcid.jaxb.model.v3.dev1.record.WorkBulk)22 OrcidError (org.orcid.jaxb.model.v3.dev1.error.OrcidError)21 BaseTest (org.orcid.core.BaseTest)20 NoResultException (javax.persistence.NoResultException)17 OrcidAccessControlException (org.orcid.core.exception.OrcidAccessControlException)17 OrcidUnauthorizedException (org.orcid.core.exception.OrcidUnauthorizedException)17 OrcidVisibilityException (org.orcid.core.exception.OrcidVisibilityException)17 VisibilityMismatchException (org.orcid.core.exception.VisibilityMismatchException)17 WrongSourceException (org.orcid.core.exception.WrongSourceException)17 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)15