Search in sources :

Example 1 with BulkElement

use of org.orcid.jaxb.model.record_v2.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 = memberV2_1ApiClient.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
            memberV2_1ApiClient.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 2 with BulkElement

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

the class WorksTest method testThreeWithInvalidTypeAllOthersAreFine.

@Test
public void testThreeWithInvalidTypeAllOthersAreFine() throws InterruptedException, JSONException {
    String accessToken = getAccessToken();
    WorkBulk bulk = createBulk(10, null);
    // Work 3: no type
    Work work3 = (Work) bulk.getBulk().get(3);
    work3.setWorkType(null);
    bulk.getBulk().set(3, work3);
    // Work 5: empty title
    Work work5 = (Work) bulk.getBulk().get(5);
    work5.getWorkTitle().getTitle().setContent(null);
    bulk.getBulk().set(5, work5);
    // Work 7: translated title language code empty
    Work work7 = (Work) bulk.getBulk().get(7);
    work7.getWorkTitle().getTranslatedTitle().setLanguageCode(null);
    bulk.getBulk().set(7, work7);
    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());
    for (int i = 0; i < bulk.getBulk().size(); i++) {
        BulkElement element = bulk.getBulk().get(i);
        if (i == 3 || i == 5 || i == 7) {
            assertTrue(OrcidError.class.isAssignableFrom(element.getClass()));
            OrcidError error = (OrcidError) element;
            switch(i) {
                case 3:
                    assertEquals(Integer.valueOf(9001), error.getErrorCode());
                    assertTrue(error.getDeveloperMessage().endsWith("\"http://www.orcid.org/ns/work\":type}' is expected.)"));
                    break;
                case 5:
                    assertEquals(Integer.valueOf(9001), error.getErrorCode());
                    assertTrue(error.getDeveloperMessage().contains("Object must have some value in its @XmlValue field: org.orcid.jaxb.model.common_v2.Title"));
                    break;
                case 7:
                    assertEquals(Integer.valueOf(9001), error.getErrorCode());
                    assertTrue(error.getDeveloperMessage().endsWith("Attribute 'language-code' must appear on element 'common:translated-title'.)"));
                    break;
            }
        } else {
            assertTrue(Work.class.isAssignableFrom(element.getClass()));
            Work work = (Work) element;
            assertNotNull(work.getPutCode());
            memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), work.getPutCode(), accessToken);
        }
    }
}
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 3 with BulkElement

use of org.orcid.jaxb.model.record_v2.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 4 with BulkElement

use of org.orcid.jaxb.model.record_v2.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 5 with BulkElement

use of org.orcid.jaxb.model.record_v2.BulkElement 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);
    ExternalID extId = new ExternalID();
    extId.setRelationship(Relationship.SELF);
    extId.setType("doi");
    extId.setUrl(new Url("http://doi/1"));
    extId.setValue("doi-1");
    work1.getExternalIdentifiers().getExternalIdentifier().clear();
    work1.getExternalIdentifiers().getExternalIdentifier().add(extId);
    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(extId);
    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.error_v2.OrcidError) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) ArrayList(java.util.ArrayList) Url(org.orcid.jaxb.model.common_v2.Url) BulkElement(org.orcid.jaxb.model.record.bulk.BulkElement) Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Aggregations

BulkElement (org.orcid.jaxb.model.record.bulk.BulkElement)11 Work (org.orcid.jaxb.model.record_v2.Work)10 WorkBulk (org.orcid.jaxb.model.record_v2.WorkBulk)10 Test (org.junit.Test)9 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)7 ClientResponse (com.sun.jersey.api.client.ClientResponse)6 ArrayList (java.util.ArrayList)3 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)3 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)3 WorkEntity (org.orcid.persistence.jpa.entities.WorkEntity)3 BaseTest (org.orcid.core.BaseTest)2 ExceedMaxNumberOfPutCodesException (org.orcid.core.exception.ExceedMaxNumberOfPutCodesException)2 PutCodeFormatException (org.orcid.core.exception.PutCodeFormatException)2 Url (org.orcid.jaxb.model.common_v2.Url)2 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)2 MinimizedWorkEntity (org.orcid.persistence.jpa.entities.MinimizedWorkEntity)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 ExceedMaxNumberOfElementsException (org.orcid.core.exception.ExceedMaxNumberOfElementsException)1