Search in sources :

Example 36 with Url

use of org.orcid.jaxb.model.v3.dev1.common.Url in project ORCID-Source by ORCID.

the class JSONWorkExternalIdentifiersConverterV3 method convertFrom.

@Override
public ExternalIDs convertFrom(String source, Type<ExternalIDs> destinationType) {
    JSONWorkExternalIdentifiers workExternalIdentifiers = JsonUtils.readObjectFromJsonString(source, JSONWorkExternalIdentifiers.class);
    ExternalIDs externalIDs = new ExternalIDs();
    for (JSONWorkExternalIdentifier workExternalIdentifier : workExternalIdentifiers.getWorkExternalIdentifier()) {
        ExternalID id = new ExternalID();
        if (workExternalIdentifier.getWorkExternalIdentifierType() == null) {
            id.setType(WorkExternalIdentifierType.OTHER_ID.value());
        } else {
            id.setType(conv.convertFrom(workExternalIdentifier.getWorkExternalIdentifierType(), null));
        }
        if (workExternalIdentifier.getWorkExternalIdentifierId() != null) {
            id.setValue(workExternalIdentifier.getWorkExternalIdentifierId().content);
            // note, uses API type name.
            id.setNormalized(new TransientNonEmptyString(norm.normalise(id.getType(), workExternalIdentifier.getWorkExternalIdentifierId().content)));
            if (StringUtils.isEmpty(id.getNormalized().getValue())) {
                id.setNormalizedError(new TransientError(localeManager.resolveMessage("transientError.normalization_failed.code"), localeManager.resolveMessage("transientError.normalization_failed.message", id.getType(), workExternalIdentifier.getWorkExternalIdentifierId().content)));
            }
        }
        if (workExternalIdentifier.getUrl() != null) {
            id.setUrl(new Url(workExternalIdentifier.getUrl().getValue()));
        }
        if (workExternalIdentifier.getRelationship() != null) {
            id.setRelationship(Relationship.fromValue(conv.convertFrom(workExternalIdentifier.getRelationship(), null)));
        }
        externalIDs.getExternalIdentifier().add(id);
    }
    return externalIDs;
}
Also used : ExternalIDs(org.orcid.jaxb.model.v3.dev1.record.ExternalIDs) JSONWorkExternalIdentifiers(org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifiers) TransientError(org.orcid.jaxb.model.v3.dev1.common.TransientError) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) JSONWorkExternalIdentifier(org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifier) TransientNonEmptyString(org.orcid.jaxb.model.v3.dev1.common.TransientNonEmptyString) JSONUrl(org.orcid.core.adapter.jsonidentifier.JSONUrl) Url(org.orcid.jaxb.model.v3.dev1.common.Url)

Example 37 with Url

use of org.orcid.jaxb.model.v3.dev1.common.Url in project ORCID-Source by ORCID.

the class WorkManagerTest method testCreateWorkWithBulk_TwoSelf_DupError.

@Test
public void testCreateWorkWithBulk_TwoSelf_DupError() {
    String orcid = "0000-0000-0000-0003";
    Long time = System.currentTimeMillis();
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    WorkBulk bulk = new WorkBulk();
    // Work # 1
    Work work1 = new Work();
    WorkTitle title1 = new WorkTitle();
    title1.setTitle(new Title("Work # 1"));
    work1.setWorkTitle(title1);
    ExternalIDs extIds1 = new ExternalIDs();
    ExternalID extId1 = new ExternalID();
    extId1.setRelationship(Relationship.SELF);
    extId1.setType("isbn");
    extId1.setUrl(new Url("http://isbn/1/" + time));
    extId1.setValue("isbn-1");
    extIds1.getExternalIdentifier().add(extId1);
    work1.setWorkExternalIdentifiers(extIds1);
    work1.setWorkType(WorkType.BOOK);
    bulk.getBulk().add(work1);
    // Work # 2
    Work work2 = new Work();
    WorkTitle title2 = new WorkTitle();
    title2.setTitle(new Title("Work # 2"));
    work2.setWorkTitle(title2);
    ExternalIDs extIds2 = new ExternalIDs();
    ExternalID extId2 = new ExternalID();
    extId2.setRelationship(Relationship.SELF);
    extId2.setType("isbn");
    extId2.setUrl(new Url("http://isbn/1/" + time));
    extId2.setValue("isbn-1");
    extIds2.getExternalIdentifier().add(extId2);
    work2.setWorkExternalIdentifiers(extIds2);
    work2.setWorkType(WorkType.BOOK);
    bulk.getBulk().add(work2);
    WorkBulk updatedBulk = workManager.createWorks(orcid, bulk);
    assertNotNull(updatedBulk);
    assertEquals(2, updatedBulk.getBulk().size());
    assertTrue(updatedBulk.getBulk().get(0) instanceof Work);
    assertNotNull(((Work) updatedBulk.getBulk().get(0)).getPutCode());
    assertEquals(Relationship.SELF, ((Work) updatedBulk.getBulk().get(0)).getExternalIdentifiers().getExternalIdentifier().get(0).getRelationship());
    assertEquals("isbn-1", ((Work) updatedBulk.getBulk().get(0)).getExternalIdentifiers().getExternalIdentifier().get(0).getValue());
    assertTrue(updatedBulk.getBulk().get(1) instanceof OrcidError);
    assertEquals(Integer.valueOf(9021), ((OrcidError) updatedBulk.getBulk().get(1)).getErrorCode());
    assertEquals("409 Conflict: You have already added this activity (matched by external identifiers.) If you are trying to edit the item, please use PUT instead of POST.", ((OrcidError) updatedBulk.getBulk().get(1)).getDeveloperMessage());
    workManager.removeWorks(orcid, Arrays.asList(((Work) updatedBulk.getBulk().get(0)).getPutCode()));
}
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) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) WorkBulk(org.orcid.jaxb.model.v3.dev1.record.WorkBulk) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) 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) Url(org.orcid.jaxb.model.v3.dev1.common.Url) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 38 with Url

use of org.orcid.jaxb.model.v3.dev1.common.Url in project ORCID-Source by ORCID.

the class WorkManagerTest method testCreateWorkWithBulk_TwoSelf_DupError_CaseSensitive.

@Test
public void testCreateWorkWithBulk_TwoSelf_DupError_CaseSensitive() {
    String orcid = "0000-0000-0000-0003";
    Long time = System.currentTimeMillis();
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    WorkBulk bulk = new WorkBulk();
    // Work # 1
    Work work1 = new Work();
    WorkTitle title1 = new WorkTitle();
    title1.setTitle(new Title("Work # 1"));
    work1.setWorkTitle(title1);
    ExternalIDs extIds1 = new ExternalIDs();
    ExternalID extId1 = new ExternalID();
    extId1.setRelationship(Relationship.SELF);
    extId1.setType("doi");
    extId1.setUrl(new Url("http://doi.org/10.1/CASE" + time));
    extId1.setValue("10.1/CASE");
    extIds1.getExternalIdentifier().add(extId1);
    work1.setWorkExternalIdentifiers(extIds1);
    work1.setWorkType(WorkType.JOURNAL_ARTICLE);
    bulk.getBulk().add(work1);
    // Work # 2
    Work work2 = new Work();
    WorkTitle title2 = new WorkTitle();
    title2.setTitle(new Title("Work # 2"));
    work2.setWorkTitle(title2);
    ExternalIDs extIds2 = new ExternalIDs();
    ExternalID extId2 = new ExternalID();
    extId2.setRelationship(Relationship.SELF);
    extId2.setType("doi");
    extId2.setUrl(new Url("http://doi.org/10.1/case" + time));
    // this should fail as dois are not case sensitive
    extId2.setValue("10.1/case");
    extIds2.getExternalIdentifier().add(extId2);
    work2.setWorkExternalIdentifiers(extIds2);
    work2.setWorkType(WorkType.JOURNAL_ARTICLE);
    bulk.getBulk().add(work2);
    WorkBulk updatedBulk = workManager.createWorks(orcid, bulk);
    assertNotNull(updatedBulk);
    assertEquals(2, updatedBulk.getBulk().size());
    assertTrue(updatedBulk.getBulk().get(0) instanceof Work);
    assertNotNull(((Work) updatedBulk.getBulk().get(0)).getPutCode());
    assertEquals(Relationship.SELF, ((Work) updatedBulk.getBulk().get(0)).getExternalIdentifiers().getExternalIdentifier().get(0).getRelationship());
    assertEquals("10.1/CASE", ((Work) updatedBulk.getBulk().get(0)).getExternalIdentifiers().getExternalIdentifier().get(0).getValue());
    assertEquals("10.1/case", ((Work) updatedBulk.getBulk().get(0)).getExternalIdentifiers().getExternalIdentifier().get(0).getNormalized().getValue());
    assertTrue(updatedBulk.getBulk().get(1) instanceof OrcidError);
    assertEquals(Integer.valueOf(9021), ((OrcidError) updatedBulk.getBulk().get(1)).getErrorCode());
    assertEquals("409 Conflict: You have already added this activity (matched by external identifiers.) If you are trying to edit the item, please use PUT instead of POST.", ((OrcidError) updatedBulk.getBulk().get(1)).getDeveloperMessage());
    workManager.removeWorks(orcid, Arrays.asList(((Work) updatedBulk.getBulk().get(0)).getPutCode()));
}
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) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) WorkBulk(org.orcid.jaxb.model.v3.dev1.record.WorkBulk) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) 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) Url(org.orcid.jaxb.model.v3.dev1.common.Url) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 39 with Url

use of org.orcid.jaxb.model.v3.dev1.common.Url 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.v3.dev1.record.summary.WorkSummary) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) Works(org.orcid.jaxb.model.v3.dev1.record.summary.Works) Url(org.orcid.jaxb.model.v3.dev1.common.Url) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 40 with Url

use of org.orcid.jaxb.model.v3.dev1.common.Url in project ORCID-Source by ORCID.

the class ActivityValidatorTest method getExternalID.

public ExternalID getExternalID() {
    ExternalID id1 = new ExternalID();
    id1.setRelationship(Relationship.SELF);
    id1.setType("doi");
    id1.setValue("value1");
    id1.setUrl(new Url("http://value1.com"));
    return id1;
}
Also used : ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) Url(org.orcid.jaxb.model.v3.dev1.common.Url)

Aggregations

Url (org.orcid.jaxb.model.v3.dev1.common.Url)85 Test (org.junit.Test)76 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)68 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)50 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)42 Response (javax.ws.rs.core.Response)28 DBUnitTest (org.orcid.test.DBUnitTest)28 Title (org.orcid.jaxb.model.v3.dev1.common.Title)23 Work (org.orcid.jaxb.model.v3.dev1.record.Work)23 WorkTitle (org.orcid.jaxb.model.v3.dev1.record.WorkTitle)19 List (java.util.List)16 PeerReview (org.orcid.jaxb.model.v3.dev1.record.PeerReview)13 PersonExternalIdentifier (org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier)13 Funding (org.orcid.jaxb.model.v3.dev1.record.Funding)12 ClientResponse (com.sun.jersey.api.client.ClientResponse)10 DisambiguatedOrganization (org.orcid.jaxb.model.v3.dev1.common.DisambiguatedOrganization)8 TranslatedTitle (org.orcid.jaxb.model.v3.dev1.common.TranslatedTitle)8 WorkSummary (org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary)8 BaseTest (org.orcid.core.BaseTest)7 Organization (org.orcid.jaxb.model.v3.dev1.common.Organization)6