Search in sources :

Example 26 with OrcidError

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

the class OrcidSecurityManagerImpl method checkAndFilter.

@Override
public void checkAndFilter(String orcid, WorkBulk workBulk, ScopePathType scopePathType) {
    isMyToken(orcid);
    List<BulkElement> bulkElements = workBulk.getBulk();
    List<BulkElement> filteredElements = new ArrayList<>();
    for (int i = 0; i < bulkElements.size(); i++) {
        BulkElement element = bulkElements.get(i);
        if (element instanceof OrcidError) {
            filteredElements.add(element);
            continue;
        }
        try {
            checkAndFilter(orcid, (Work) element, scopePathType, true);
            filteredElements.add(element);
        } catch (Exception e) {
            if (e instanceof OrcidUnauthorizedException) {
                throw e;
            }
            OrcidError error = orcidCoreExceptionMapper.getV3OrcidError(e);
            filteredElements.add(error);
        }
    }
    workBulk.setBulk(filteredElements);
}
Also used : OrcidError(org.orcid.jaxb.model.v3.dev1.error.OrcidError) BulkElement(org.orcid.jaxb.model.record.bulk.BulkElement) OrcidUnauthorizedException(org.orcid.core.exception.OrcidUnauthorizedException) ArrayList(java.util.ArrayList) NoResultException(javax.persistence.NoResultException) OrcidNotClaimedException(org.orcid.core.exception.OrcidNotClaimedException) OrcidDeprecatedException(org.orcid.core.exception.OrcidDeprecatedException) WrongSourceException(org.orcid.core.exception.WrongSourceException) LockedException(org.orcid.core.security.aop.LockedException) AccessControlException(java.security.AccessControlException) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) OrcidVisibilityException(org.orcid.core.exception.OrcidVisibilityException) OrcidUnauthorizedException(org.orcid.core.exception.OrcidUnauthorizedException) DeactivatedException(org.orcid.core.exception.DeactivatedException)

Example 27 with OrcidError

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

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

Example 29 with OrcidError

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

the class OrcidSecurityManager_WorkBulkTest method testLimitedWorkBulkReadPublicTokenNoSource.

@Test
public void testLimitedWorkBulkReadPublicTokenNoSource() {
    WorkBulk workBulk = new WorkBulk();
    workBulk.setBulk(Arrays.asList(createWork(Visibility.LIMITED, null), createWork(Visibility.LIMITED, null)));
    SecurityContextTestUtils.setUpSecurityContext(ORCID_1, CLIENT_2, 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 OrcidError);
    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) Test(org.junit.Test)

Example 30 with OrcidError

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

the class MemberV3ApiServiceDelegatorImpl method createWorks.

@Override
public Response createWorks(String orcid, WorkBulk works) {
    orcidSecurityManager.checkClientAccessAndScopes(orcid, ScopePathType.ORCID_WORKS_CREATE, ScopePathType.ORCID_WORKS_UPDATE);
    if (works != null) {
        for (int i = 0; i < works.getBulk().size(); i++) {
            if (Work.class.isAssignableFrom(works.getBulk().get(i).getClass())) {
                Work work = (Work) works.getBulk().get(i);
                try {
                    schemaValidator.validate(work);
                    clearSource(work);
                } catch (WebApplicationException e) {
                    OrcidError error = orcidCoreExceptionMapper.getOrcidErrorV3Dev1(9001, 400, e);
                    works.getBulk().remove(i);
                    works.getBulk().add(i, error);
                }
            }
        }
    }
    works = workManager.createWorks(orcid, works);
    sourceUtils.setSourceName(works);
    return Response.ok(works).build();
}
Also used : OrcidError(org.orcid.jaxb.model.v3.dev1.error.OrcidError) WebApplicationException(javax.ws.rs.WebApplicationException) Work(org.orcid.jaxb.model.v3.dev1.record.Work)

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