Search in sources :

Example 86 with ExternalID

use of org.orcid.jaxb.model.record_rc2.ExternalID in project ORCID-Source by ORCID.

the class WorkManagerTest method testGroupWorksWithDisplayIndex.

@Test
public void testGroupWorksWithDisplayIndex() {
    /**
         * @formatter:off
         * They should be grouped as
         * 
         * Group 1: Work 3
         * Group 2: Work 4 + Work 1
         * Group 3: Work 5 + Work 2
         * Group 4: Work 6
         * @formatter:on
         */
    WorkSummary s1 = getWorkSummary("Work 1", "ext-id-1", Visibility.PUBLIC, "0");
    WorkSummary s2 = getWorkSummary("Work 2", "ext-id-2", Visibility.LIMITED, "1");
    WorkSummary s3 = getWorkSummary("Work 3", "ext-id-3", Visibility.PRIVATE, "0");
    WorkSummary s4 = getWorkSummary("Work 4", "ext-id-1", Visibility.PRIVATE, "1");
    WorkSummary s5 = getWorkSummary("Work 5", "ext-id-2", Visibility.PUBLIC, "2");
    WorkSummary s6 = getWorkSummary("Work 6", "ext-id-4", Visibility.PRIVATE, "0");
    List<WorkSummary> workList1 = Arrays.asList(s1, s2, s3, s4, s5, s6);
    Works works1 = workManager.groupWorks(workList1, false);
    assertNotNull(works1);
    assertEquals(4, works1.getWorkGroup().size());
    // Group 1 have all with ext-id-3
    assertEquals(1, works1.getWorkGroup().get(0).getWorkSummary().size());
    assertEquals(1, works1.getWorkGroup().get(0).getIdentifiers().getExternalIdentifier().size());
    assertEquals("ext-id-3", works1.getWorkGroup().get(0).getIdentifiers().getExternalIdentifier().get(0).getValue());
    // Group 2 have all with ext-id-2
    assertEquals(2, works1.getWorkGroup().get(1).getWorkSummary().size());
    assertEquals(1, works1.getWorkGroup().get(1).getIdentifiers().getExternalIdentifier().size());
    assertEquals("ext-id-1", works1.getWorkGroup().get(1).getIdentifiers().getExternalIdentifier().get(0).getValue());
    // Group 3 have ext-id-3
    assertEquals(2, works1.getWorkGroup().get(2).getWorkSummary().size());
    assertEquals(1, works1.getWorkGroup().get(2).getIdentifiers().getExternalIdentifier().size());
    assertEquals("ext-id-2", works1.getWorkGroup().get(2).getIdentifiers().getExternalIdentifier().get(0).getValue());
    // Group 4 have ext-id-4
    assertEquals(1, works1.getWorkGroup().get(3).getWorkSummary().size());
    assertEquals(1, works1.getWorkGroup().get(3).getIdentifiers().getExternalIdentifier().size());
    assertEquals("ext-id-4", works1.getWorkGroup().get(3).getIdentifiers().getExternalIdentifier().get(0).getValue());
    WorkSummary s7 = getWorkSummary("Work 7", "ext-id-4", Visibility.PRIVATE, "0");
    // Add ext-id-3 to work 7, so, it join group 3 and group 4 in a single
    // group
    ExternalID extId = new ExternalID();
    extId.setRelationship(Relationship.SELF);
    extId.setType("doi");
    extId.setUrl(new Url("http://orcid.org"));
    extId.setValue("ext-id-3");
    s7.getExternalIdentifiers().getExternalIdentifier().add(extId);
    /**
         * @formatter:off
         * Now, they should be grouped as
         * 
         * 
         * Group 1: Work 3 + Work 6 + Work 7
         * Group 2: Work 4 + Work 1
         * Group 3: Work 5 + Work 2
         * @formatter:on
         */
    List<WorkSummary> workList2 = Arrays.asList(s1, s2, s3, s4, s5, s6, s7);
    Works works2 = workManager.groupWorks(workList2, false);
    assertNotNull(works2);
    assertEquals(3, works2.getWorkGroup().size());
    // Group 1 have all with ext-id-3 and ext-id-4
    assertEquals(3, works2.getWorkGroup().get(0).getWorkSummary().size());
    assertEquals(2, works2.getWorkGroup().get(0).getIdentifiers().getExternalIdentifier().size());
    assertThat(works2.getWorkGroup().get(0).getIdentifiers().getExternalIdentifier().get(0).getValue(), anyOf(is("ext-id-3"), is("ext-id-4")));
    assertThat(works2.getWorkGroup().get(0).getIdentifiers().getExternalIdentifier().get(1).getValue(), anyOf(is("ext-id-3"), is("ext-id-4")));
    // Group 2 have all with ext-id-1
    assertEquals(2, works2.getWorkGroup().get(1).getWorkSummary().size());
    assertEquals(1, works2.getWorkGroup().get(1).getIdentifiers().getExternalIdentifier().size());
    assertEquals("ext-id-1", works2.getWorkGroup().get(1).getIdentifiers().getExternalIdentifier().get(0).getValue());
    // Group 2 have all with ext-id-2
    assertEquals(2, works2.getWorkGroup().get(2).getWorkSummary().size());
    assertEquals(1, works2.getWorkGroup().get(2).getIdentifiers().getExternalIdentifier().size());
    assertEquals("ext-id-2", works2.getWorkGroup().get(2).getIdentifiers().getExternalIdentifier().get(0).getValue());
}
Also used : WorkSummary(org.orcid.jaxb.model.record.summary_v2.WorkSummary) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Works(org.orcid.jaxb.model.record.summary_v2.Works) Url(org.orcid.jaxb.model.common_v2.Url) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 87 with ExternalID

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

Example 88 with ExternalID

use of org.orcid.jaxb.model.record_rc2.ExternalID in project ORCID-Source by ORCID.

the class WorkManagerTest method getWork.

private Work getWork(String extIdValue) {
    Work work = new Work();
    WorkTitle title = new WorkTitle();
    if (extIdValue == null) {
        title.setTitle(new Title("Work title"));
    } else {
        title.setTitle(new Title("Work title " + extIdValue));
    }
    work.setWorkTitle(title);
    work.setWorkType(WorkType.BOOK);
    ExternalIDs extIds = new ExternalIDs();
    ExternalID extId = new ExternalID();
    extId.setRelationship(Relationship.SELF);
    extId.setType("doi");
    extId.setUrl(new Url("http://orcid.org"));
    if (extIdValue == null) {
        extId.setValue("ext-id-value");
    } else {
        extId.setValue("ext-id-value-" + extIdValue);
    }
    extIds.getExternalIdentifier().add(extId);
    work.setWorkExternalIdentifiers(extIds);
    work.setVisibility(Visibility.PUBLIC);
    return work;
}
Also used : ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Work(org.orcid.jaxb.model.record_v2.Work) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) Title(org.orcid.jaxb.model.common_v2.Title) Url(org.orcid.jaxb.model.common_v2.Url)

Example 89 with ExternalID

use of org.orcid.jaxb.model.record_rc2.ExternalID in project ORCID-Source by ORCID.

the class WorkManagerTest method testGroupWorks.

@Test
public void testGroupWorks() {
    /**
         * @formatter:off
         * They should be grouped as
         * 
         * Group 1: Work 1 + Work 4
         * Group 2: Work 2 + Work 5
         * Group 3: Work 3
         * Group 4: Work 6
         * @formatter:on
         */
    WorkSummary s1 = getWorkSummary("Work 1", "ext-id-1", Visibility.PUBLIC);
    WorkSummary s2 = getWorkSummary("Work 2", "ext-id-2", Visibility.LIMITED);
    WorkSummary s3 = getWorkSummary("Work 3", "ext-id-3", Visibility.PRIVATE);
    WorkSummary s4 = getWorkSummary("Work 4", "ext-id-1", Visibility.PRIVATE);
    WorkSummary s5 = getWorkSummary("Work 5", "ext-id-2", Visibility.PUBLIC);
    WorkSummary s6 = getWorkSummary("Work 6", "ext-id-4", Visibility.PRIVATE);
    List<WorkSummary> workList1 = Arrays.asList(s1, s2, s3, s4, s5, s6);
    Works works1 = workManager.groupWorks(workList1, false);
    assertNotNull(works1);
    assertEquals(4, works1.getWorkGroup().size());
    // Group 1 have all with ext-id-1
    assertEquals(2, works1.getWorkGroup().get(0).getWorkSummary().size());
    assertEquals(1, works1.getWorkGroup().get(0).getIdentifiers().getExternalIdentifier().size());
    assertEquals("ext-id-1", works1.getWorkGroup().get(0).getIdentifiers().getExternalIdentifier().get(0).getValue());
    // Group 2 have all with ext-id-2
    assertEquals(2, works1.getWorkGroup().get(1).getWorkSummary().size());
    assertEquals(1, works1.getWorkGroup().get(1).getIdentifiers().getExternalIdentifier().size());
    assertEquals("ext-id-2", works1.getWorkGroup().get(1).getIdentifiers().getExternalIdentifier().get(0).getValue());
    // Group 3 have ext-id-3
    assertEquals(1, works1.getWorkGroup().get(2).getWorkSummary().size());
    assertEquals(1, works1.getWorkGroup().get(2).getIdentifiers().getExternalIdentifier().size());
    assertEquals("ext-id-3", works1.getWorkGroup().get(2).getIdentifiers().getExternalIdentifier().get(0).getValue());
    // Group 4 have ext-id-4
    assertEquals(1, works1.getWorkGroup().get(3).getWorkSummary().size());
    assertEquals(1, works1.getWorkGroup().get(3).getIdentifiers().getExternalIdentifier().size());
    assertEquals("ext-id-4", works1.getWorkGroup().get(3).getIdentifiers().getExternalIdentifier().get(0).getValue());
    WorkSummary s7 = getWorkSummary("Work 7", "ext-id-4", Visibility.PRIVATE);
    // Add ext-id-3 to work 7, so, it join group 3 and group 4 in a single
    // group
    ExternalID extId = new ExternalID();
    extId.setRelationship(Relationship.SELF);
    extId.setType("doi");
    extId.setUrl(new Url("http://orcid.org"));
    extId.setValue("ext-id-3");
    s7.getExternalIdentifiers().getExternalIdentifier().add(extId);
    /**
         * @formatter:off
         * Now, they should be grouped as
         * 
         * Group 1: Work 1 + Work 4
         * Group 2: Work 2 + Work 5
         * Group 3: Work 3 + Work 6 + Work 7
         * @formatter:on
         */
    List<WorkSummary> workList2 = Arrays.asList(s1, s2, s3, s4, s5, s6, s7);
    Works works2 = workManager.groupWorks(workList2, false);
    assertNotNull(works2);
    assertEquals(3, works2.getWorkGroup().size());
    // Group 1 have all with ext-id-1
    assertEquals(2, works2.getWorkGroup().get(0).getWorkSummary().size());
    assertEquals(1, works2.getWorkGroup().get(0).getIdentifiers().getExternalIdentifier().size());
    assertEquals("ext-id-1", works2.getWorkGroup().get(0).getIdentifiers().getExternalIdentifier().get(0).getValue());
    // Group 2 have all with ext-id-2
    assertEquals(2, works2.getWorkGroup().get(1).getWorkSummary().size());
    assertEquals(1, works2.getWorkGroup().get(1).getIdentifiers().getExternalIdentifier().size());
    assertEquals("ext-id-2", works2.getWorkGroup().get(1).getIdentifiers().getExternalIdentifier().get(0).getValue());
    // Group 3 have all with ext-id-3 and ext-id-4
    assertEquals(3, works2.getWorkGroup().get(2).getWorkSummary().size());
    assertEquals(2, works2.getWorkGroup().get(2).getIdentifiers().getExternalIdentifier().size());
    assertThat(works2.getWorkGroup().get(2).getIdentifiers().getExternalIdentifier().get(0).getValue(), anyOf(is("ext-id-3"), is("ext-id-4")));
    assertThat(works2.getWorkGroup().get(2).getIdentifiers().getExternalIdentifier().get(1).getValue(), anyOf(is("ext-id-3"), is("ext-id-4")));
}
Also used : WorkSummary(org.orcid.jaxb.model.record.summary_v2.WorkSummary) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Works(org.orcid.jaxb.model.record.summary_v2.Works) Url(org.orcid.jaxb.model.common_v2.Url) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 90 with ExternalID

use of org.orcid.jaxb.model.record_rc2.ExternalID in project ORCID-Source by ORCID.

the class MemberV2PerformanceTest method createManyWorks.

@Test
public void createManyWorks() throws JSONException, InterruptedException, URISyntaxException {
    int numWorks = 1000;
    // Amount of linear increase allowed
    float scalingFactor = 1.5f;
    int numInitialSample = numWorks / 10;
    long initialSampleTime = 0;
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    for (int i = 1; i <= numWorks; i++) {
        StopWatch singleWorkStopWatch = new StopWatch();
        singleWorkStopWatch.start();
        long time = System.currentTimeMillis();
        Work workToCreate = (Work) unmarshallFromPath("/record_2.0/samples/work-2.0.xml", Work.class);
        workToCreate.setPutCode(null);
        workToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
        ExternalID wExtId = new ExternalID();
        wExtId.setValue("Work Id " + i + " " + time);
        wExtId.setType(WorkExternalIdentifierType.AGR.value());
        wExtId.setRelationship(Relationship.SELF);
        workToCreate.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
        String accessToken = getAccessToken();
        ClientResponse postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), workToCreate, accessToken);
        stopWatch.split();
        long splitTime = stopWatch.getSplitTime();
        System.out.println("Split time: " + splitTime);
        if (i == numInitialSample) {
            initialSampleTime = splitTime;
        } else if (i > numInitialSample) {
            float maxTime = (initialSampleTime / numInitialSample) * scalingFactor * i;
            System.out.println("Max time: " + maxTime);
            assertTrue("Split time = " + splitTime + ", but max allowed time = " + maxTime + ", when num added = " + i, splitTime <= maxTime);
        }
        assertNotNull(postResponse);
        assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
        String locationPath = postResponse.getLocation().getPath();
        assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v2.0/" + this.getUser1OrcidId() + "/work/\\d+"));
        ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
        assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
        Work gotWork = getResponse.getEntity(Work.class);
        assertEquals("common:title", gotWork.getWorkTitle().getTitle().getContent());
        System.out.println("Time for single work = " + singleWorkStopWatch);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Work(org.orcid.jaxb.model.record_v2.Work) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Aggregations

ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)110 Test (org.junit.Test)97 Url (org.orcid.jaxb.model.common_v2.Url)55 ClientResponse (com.sun.jersey.api.client.ClientResponse)52 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)50 Work (org.orcid.jaxb.model.record_v2.Work)32 Title (org.orcid.jaxb.model.common_v2.Title)28 WorkTitle (org.orcid.jaxb.model.record_v2.WorkTitle)22 Funding (org.orcid.jaxb.model.record_v2.Funding)16 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)16 WorkSummary (org.orcid.jaxb.model.record.summary_v2.WorkSummary)14 ArrayList (java.util.ArrayList)13 ExternalID (org.orcid.jaxb.model.record_rc3.ExternalID)13 ExternalID (org.orcid.jaxb.model.record_rc4.ExternalID)13 FundingTitle (org.orcid.jaxb.model.record_v2.FundingTitle)11 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)9 WorkGroup (org.orcid.jaxb.model.record.summary_v2.WorkGroup)8 ExternalID (org.orcid.jaxb.model.record_rc2.ExternalID)8 List (java.util.List)7 Validator (javax.xml.validation.Validator)7