Search in sources :

Example 6 with BulkElement

use of org.orcid.jaxb.model.record.bulk.BulkElement 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.bulk.BulkElement) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test)

Example 7 with BulkElement

use of org.orcid.jaxb.model.record.bulk.BulkElement in project ORCID-Source by ORCID.

the class WorksTest method testCreateBulkWork.

@Test
public void testCreateBulkWork() throws InterruptedException, JSONException {
    String accessToken = getAccessToken();
    WorkBulk bulk = createBulk(10, null);
    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());
    // All elements might be ok
    for (BulkElement element : bulk.getBulk()) {
        assertTrue(Work.class.isAssignableFrom(element.getClass()));
        Work work = (Work) element;
        // Remove the work
        memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), work.getPutCode(), accessToken);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) BulkElement(org.orcid.jaxb.model.record.bulk.BulkElement) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test)

Example 8 with BulkElement

use of org.orcid.jaxb.model.record.bulk.BulkElement 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.bulk.BulkElement) WorkBulk(org.orcid.jaxb.model.record_rc4.WorkBulk) Work(org.orcid.jaxb.model.record_rc4.Work) Test(org.junit.Test)

Example 9 with BulkElement

use of org.orcid.jaxb.model.record.bulk.BulkElement 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_rc3.OrcidError) BulkElement(org.orcid.jaxb.model.record.bulk.BulkElement) WorkBulk(org.orcid.jaxb.model.record_rc3.WorkBulk) Work(org.orcid.jaxb.model.record_rc3.Work) Test(org.junit.Test)

Example 10 with BulkElement

use of org.orcid.jaxb.model.record.bulk.BulkElement 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)

Aggregations

BulkElement (org.orcid.jaxb.model.record.bulk.BulkElement)30 Test (org.junit.Test)21 ClientResponse (com.sun.jersey.api.client.ClientResponse)15 Work (org.orcid.jaxb.model.record_v2.Work)10 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)9 WorkBulk (org.orcid.jaxb.model.record_v2.WorkBulk)9 ArrayList (java.util.ArrayList)8 OrcidError (org.orcid.jaxb.model.v3.dev1.error.OrcidError)7 Work (org.orcid.jaxb.model.v3.dev1.record.Work)7 WorkBulk (org.orcid.jaxb.model.v3.dev1.record.WorkBulk)6 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)6 BaseTest (org.orcid.core.BaseTest)4 WorkEntity (org.orcid.persistence.jpa.entities.WorkEntity)4 HashMap (java.util.HashMap)3 Work (org.orcid.jaxb.model.record_rc3.Work)3 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)3 AccessControlException (java.security.AccessControlException)2 Date (java.util.Date)2 Locale (java.util.Locale)2 NoResultException (javax.persistence.NoResultException)2