Search in sources :

Example 26 with WorkBulk

use of org.orcid.jaxb.model.v3.dev1.record.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);
    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.v3.dev1.error.OrcidError) WorkBulk(org.orcid.jaxb.model.v3.dev1.record.WorkBulk) Work(org.orcid.jaxb.model.v3.dev1.record.Work) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 27 with WorkBulk

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

the class WorkManagerTest method testCreateWorksWithBulkAllOK.

@Test
public void testCreateWorksWithBulkAllOK() {
    String orcid = "0000-0000-0000-0003";
    Long time = System.currentTimeMillis();
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    WorkBulk bulk = new WorkBulk();
    for (int i = 0; i < 5; i++) {
        Work work = new Work();
        WorkTitle title = new WorkTitle();
        title.setTitle(new Title("Bulk work " + i + " " + time));
        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);
    }
    bulk = workManager.createWorks(orcid, bulk);
    assertNotNull(bulk);
    assertEquals(5, bulk.getBulk().size());
    for (int i = 0; i < 5; i++) {
        assertTrue(Work.class.isAssignableFrom(bulk.getBulk().get(i).getClass()));
        Work w = (Work) bulk.getBulk().get(i);
        assertNotNull(w.getPutCode());
        assertTrue(0L < w.getPutCode());
        assertEquals("Bulk work " + i + " " + time, w.getWorkTitle().getTitle().getContent());
        assertNotNull(w.getExternalIdentifiers().getExternalIdentifier());
        assertEquals("doi-" + i + "-" + time, w.getExternalIdentifiers().getExternalIdentifier().get(0).getValue());
        Work w1 = workManager.getWork(orcid, w.getPutCode());
        assertNotNull(w1);
        assertEquals("Bulk work " + i + " " + time, w1.getWorkTitle().getTitle().getContent());
        // Delete the work
        assertTrue(workManager.checkSourceAndRemoveWork(orcid, w1.getPutCode()));
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ExternalIDs(org.orcid.jaxb.model.v3.dev1.record.ExternalIDs) WorkTitle(org.orcid.jaxb.model.v3.dev1.record.WorkTitle) 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) Title(org.orcid.jaxb.model.v3.dev1.common.Title) WorkTitle(org.orcid.jaxb.model.v3.dev1.record.WorkTitle) Url(org.orcid.jaxb.model.v3.dev1.common.Url) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 28 with WorkBulk

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

the class WorkManagerTest method testCreateWorksWithBulk_OneSelfOnePartOf_NoDupError.

@Test
public void testCreateWorksWithBulk_OneSelfOnePartOf_NoDupError() {
    String orcid = "0000-0000-0000-0003";
    Long time = System.currentTimeMillis();
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    WorkBulk bulk = new WorkBulk();
    // Work # 1
    Work work1 = new Work();
    WorkTitle title1 = new WorkTitle();
    title1.setTitle(new Title("Work # 1"));
    work1.setWorkTitle(title1);
    ExternalIDs extIds1 = new ExternalIDs();
    ExternalID extId1 = new ExternalID();
    extId1.setRelationship(Relationship.SELF);
    extId1.setType("isbn");
    extId1.setUrl(new Url("http://isbn/1/" + time));
    extId1.setValue("isbn-1");
    extIds1.getExternalIdentifier().add(extId1);
    work1.setWorkExternalIdentifiers(extIds1);
    work1.setWorkType(WorkType.BOOK);
    bulk.getBulk().add(work1);
    // Work # 2
    Work work2 = new Work();
    WorkTitle title2 = new WorkTitle();
    title2.setTitle(new Title("Work # 2"));
    work2.setWorkTitle(title2);
    ExternalIDs extIds2 = new ExternalIDs();
    ExternalID extId2 = new ExternalID();
    extId2.setRelationship(Relationship.PART_OF);
    extId2.setType("isbn");
    extId2.setUrl(new Url("http://isbn/1/" + time));
    extId2.setValue("isbn-1");
    extIds2.getExternalIdentifier().add(extId2);
    work2.setWorkExternalIdentifiers(extIds2);
    work2.setWorkType(WorkType.BOOK);
    bulk.getBulk().add(work2);
    WorkBulk updatedBulk = workManager.createWorks(orcid, bulk);
    assertNotNull(updatedBulk);
    assertEquals(2, updatedBulk.getBulk().size());
    assertTrue(updatedBulk.getBulk().get(0) instanceof Work);
    assertNotNull(((Work) updatedBulk.getBulk().get(0)).getPutCode());
    assertEquals(Relationship.SELF, ((Work) updatedBulk.getBulk().get(0)).getExternalIdentifiers().getExternalIdentifier().get(0).getRelationship());
    assertEquals("isbn-1", ((Work) updatedBulk.getBulk().get(0)).getExternalIdentifiers().getExternalIdentifier().get(0).getValue());
    assertTrue(updatedBulk.getBulk().get(1) instanceof Work);
    assertNotNull(((Work) updatedBulk.getBulk().get(1)).getPutCode());
    assertEquals(Relationship.PART_OF, ((Work) updatedBulk.getBulk().get(1)).getExternalIdentifiers().getExternalIdentifier().get(0).getRelationship());
    assertEquals("isbn-1", ((Work) updatedBulk.getBulk().get(1)).getExternalIdentifiers().getExternalIdentifier().get(0).getValue());
    workManager.removeWorks(orcid, Arrays.asList(((Work) updatedBulk.getBulk().get(0)).getPutCode(), ((Work) updatedBulk.getBulk().get(1)).getPutCode()));
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ExternalIDs(org.orcid.jaxb.model.v3.dev1.record.ExternalIDs) WorkTitle(org.orcid.jaxb.model.v3.dev1.record.WorkTitle) 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) Title(org.orcid.jaxb.model.v3.dev1.common.Title) WorkTitle(org.orcid.jaxb.model.v3.dev1.record.WorkTitle) Url(org.orcid.jaxb.model.v3.dev1.common.Url) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 29 with WorkBulk

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

the class WorkManagerTest method testFindWorkBulk.

@Test
public void testFindWorkBulk() {
    String putCodes = "11,12,13";
    WorkBulk workBulk = workManager.findWorkBulk("0000-0000-0000-0003", putCodes);
    assertNotNull(workBulk);
    assertNotNull(workBulk.getBulk());
    assertEquals(3, workBulk.getBulk().size());
    assertTrue(workBulk.getBulk().get(0) instanceof Work);
    assertTrue(workBulk.getBulk().get(1) instanceof Work);
    assertTrue(workBulk.getBulk().get(2) instanceof Work);
}
Also used : WorkBulk(org.orcid.jaxb.model.v3.dev1.record.WorkBulk) Work(org.orcid.jaxb.model.v3.dev1.record.Work) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 30 with WorkBulk

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

the class OrcidSecurityManager_WorkBulkTest method testLimitedWorkBulkReadPublicTokenMixedSources.

@Test
public void testLimitedWorkBulkReadPublicTokenMixedSources() {
    WorkBulk workBulk = new WorkBulk();
    workBulk.setBulk(Arrays.asList(createWork(Visibility.PUBLIC, CLIENT_1), createWork(Visibility.LIMITED, CLIENT_2)));
    SecurityContextTestUtils.setUpSecurityContext(ORCID_1, CLIENT_1, ScopePathType.READ_PUBLIC);
    orcidSecurityManager.checkAndFilter(ORCID_1, workBulk, ScopePathType.ORCID_WORKS_READ_LIMITED);
    assertNotNull(workBulk);
    assertEquals(2, workBulk.getBulk().size());
    assertTrue(workBulk.getBulk().get(0) instanceof Work);
    assertTrue(workBulk.getBulk().get(1) instanceof OrcidError);
}
Also used : 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) 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