Search in sources :

Example 16 with OrcidError

use of org.orcid.jaxb.model.v3.dev1.error.OrcidError 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)

Example 17 with OrcidError

use of org.orcid.jaxb.model.v3.dev1.error.OrcidError in project ORCID-Source by ORCID.

the class OrcidSecurityManager_WorkBulkTest method testPrivateWorkBulkReadLimitedTokenMixedSources.

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

Example 18 with OrcidError

use of org.orcid.jaxb.model.v3.dev1.error.OrcidError in project ORCID-Source by ORCID.

the class OrcidSecurityManager_WorkBulkTest method testPrivateWorkBulkReadLimitedToken.

@Test
public void testPrivateWorkBulkReadLimitedToken() {
    WorkBulk workBulk = new WorkBulk();
    workBulk.setBulk(Arrays.asList(createWork(Visibility.PRIVATE, CLIENT_2)));
    SecurityContextTestUtils.setUpSecurityContext(ORCID_1, CLIENT_1, ScopePathType.READ_LIMITED);
    orcidSecurityManager.checkAndFilter(ORCID_1, workBulk, ScopePathType.ORCID_WORKS_READ_LIMITED);
    assertNotNull(workBulk);
    assertEquals(1, workBulk.getBulk().size());
    assertTrue(workBulk.getBulk().get(0) instanceof OrcidError);
}
Also used : OrcidError(org.orcid.jaxb.model.v3.dev1.error.OrcidError) WorkBulk(org.orcid.jaxb.model.v3.dev1.record.WorkBulk) Test(org.junit.Test)

Example 19 with OrcidError

use of org.orcid.jaxb.model.v3.dev1.error.OrcidError in project ORCID-Source by ORCID.

the class OrcidSecurityManager_WorkBulkTest method testMixedPublicAndLimitedWorkBulkReadPublicToken.

@Test
public void testMixedPublicAndLimitedWorkBulkReadPublicToken() {
    WorkBulk workBulk = new WorkBulk();
    workBulk.setBulk(Arrays.asList(createWork(Visibility.PUBLIC, CLIENT_2), 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)

Example 20 with OrcidError

use of org.orcid.jaxb.model.v3.dev1.error.OrcidError in project ORCID-Source by ORCID.

the class OrcidSecurityManager_WorkBulkTest method testPrivateWorkBulkReadLimitedTokenNoSource.

@Test
public void testPrivateWorkBulkReadLimitedTokenNoSource() {
    WorkBulk workBulk = new WorkBulk();
    workBulk.setBulk(Arrays.asList(createWork(Visibility.PRIVATE, null)));
    SecurityContextTestUtils.setUpSecurityContext(ORCID_1, CLIENT_2, ScopePathType.READ_LIMITED);
    orcidSecurityManager.checkAndFilter(ORCID_1, workBulk, ScopePathType.ORCID_WORKS_READ_LIMITED);
    assertNotNull(workBulk);
    assertEquals(1, workBulk.getBulk().size());
    assertTrue(workBulk.getBulk().get(0) instanceof OrcidError);
}
Also used : OrcidError(org.orcid.jaxb.model.v3.dev1.error.OrcidError) WorkBulk(org.orcid.jaxb.model.v3.dev1.record.WorkBulk) Test(org.junit.Test)

Aggregations

OrcidError (org.orcid.jaxb.model.v3.dev1.error.OrcidError)33 Test (org.junit.Test)30 Work (org.orcid.jaxb.model.v3.dev1.record.Work)18 WorkBulk (org.orcid.jaxb.model.v3.dev1.record.WorkBulk)18 ClientResponse (com.sun.jersey.api.client.ClientResponse)15 Visibility (org.orcid.jaxb.model.v3.dev1.common.Visibility)11 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)9 BulkElement (org.orcid.jaxb.model.record.bulk.BulkElement)7 BaseTest (org.orcid.core.BaseTest)5 Url (org.orcid.jaxb.model.v3.dev1.common.Url)5 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)5 Response (javax.ws.rs.core.Response)4 Title (org.orcid.jaxb.model.v3.dev1.common.Title)4 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)4 WorkTitle (org.orcid.jaxb.model.v3.dev1.record.WorkTitle)4 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)4 DBUnitTest (org.orcid.test.DBUnitTest)4 ArrayList (java.util.ArrayList)3 AccessControlException (java.security.AccessControlException)1 Date (java.util.Date)1