Search in sources :

Example 16 with WorkBulk

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

the class WorksTest method testCreateBulkWithAllErrors.

@Test
public void testCreateBulkWithAllErrors() throws InterruptedException, JSONException {
    String accessToken = getAccessToken();
    WorkBulk bulk = createBulk(10, "existing-ext-id-" + System.currentTimeMillis());
    ClientResponse postResponse = memberV2ApiClient.createWorksJson(this.getUser1OrcidId(), bulk, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.OK.getStatusCode(), postResponse.getStatus());
    bulk = postResponse.getEntity(WorkBulk.class);
    assertNotNull(bulk);
    assertNotNull(bulk.getBulk());
    boolean first = true;
    //All elements might be ok
    for (BulkElement element : bulk.getBulk()) {
        if (first) {
            assertTrue(Work.class.isAssignableFrom(element.getClass()));
            Work work = (Work) element;
            //Remove the work
            memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), work.getPutCode(), accessToken);
            first = false;
        } else {
            assertTrue(OrcidError.class.isAssignableFrom(element.getClass()));
            OrcidError error = (OrcidError) element;
            assertEquals(Integer.valueOf(9021), error.getErrorCode());
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) BulkElement(org.orcid.jaxb.model.record_v2.BulkElement) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test)

Example 17 with WorkBulk

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

the class WorksTest method createBulk.

private WorkBulk createBulk(int size, String extId) {
    WorkBulk bulk = new WorkBulk();
    Long time = System.currentTimeMillis();
    for (int i = 0; i < size; i++) {
        if (extId == null) {
            bulk.getBulk().add(getWork("Work title #" + i + "-" + time, true, null));
        } else {
            bulk.getBulk().add(getWork("Work title #" + i + "-" + time, false, String.valueOf(time)));
        }
    }
    return bulk;
}
Also used : WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk)

Example 18 with WorkBulk

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

the class WorksTest method testCreateBulkWithAllErrors.

@Test
public void testCreateBulkWithAllErrors() throws InterruptedException, JSONException {
    String accessToken = getAccessToken();
    WorkBulk bulk = createBulk(10, "existing-ext-id-" + System.currentTimeMillis());
    ClientResponse postResponse = memberV2ApiClient.createWorksJson(this.getUser1OrcidId(), bulk, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.OK.getStatusCode(), postResponse.getStatus());
    bulk = postResponse.getEntity(WorkBulk.class);
    assertNotNull(bulk);
    assertNotNull(bulk.getBulk());
    boolean first = true;
    //All elements might be ok
    for (BulkElement element : bulk.getBulk()) {
        if (first) {
            assertTrue(Work.class.isAssignableFrom(element.getClass()));
            Work work = (Work) element;
            //Remove the work
            memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), work.getPutCode(), accessToken);
            first = false;
        } else {
            assertTrue(OrcidError.class.isAssignableFrom(element.getClass()));
            OrcidError error = (OrcidError) element;
            assertEquals(Integer.valueOf(9021), error.getErrorCode());
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.error_rc4.OrcidError) BulkElement(org.orcid.jaxb.model.record_rc4.BulkElement) WorkBulk(org.orcid.jaxb.model.record_rc4.WorkBulk) Work(org.orcid.jaxb.model.record_rc4.Work) Test(org.junit.Test)

Example 19 with WorkBulk

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

the class PublicV2ApiServiceVersionedDelegatorTest method testViewBulkWorks.

@Test
public void testViewBulkWorks() {
    Response response = serviceDelegator.viewBulkWorks("0000-0000-0000-0003", "11,12,13,16");
    WorkBulk workBulk = (WorkBulk) response.getEntity();
    assertNotNull(workBulk);
    assertNotNull(workBulk.getBulk());
    assertEquals(4, workBulk.getBulk().size());
    assertTrue(workBulk.getBulk().get(0) instanceof Work);
    assertTrue(workBulk.getBulk().get(1) instanceof OrcidError);
    assertTrue(workBulk.getBulk().get(2) instanceof OrcidError);
    assertTrue(workBulk.getBulk().get(3) instanceof OrcidError);
}
Also used : Response(javax.ws.rs.core.Response) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) Work(org.orcid.jaxb.model.record_v2.Work) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 20 with WorkBulk

use of org.orcid.jaxb.model.record_v2.WorkBulk 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.getOrcidError(e);
            filteredElements.add(error);
        }
    }
    workBulk.setBulk(filteredElements);
}
Also used : OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) BulkElement(org.orcid.jaxb.model.record_v2.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)

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