Search in sources :

Example 26 with ExternalIDs

use of org.orcid.jaxb.model.v3.dev1.record.ExternalIDs in project ORCID-Source by ORCID.

the class JSONExternalIdentifiersConverterV3 method convertFrom.

@Override
public ExternalIDs convertFrom(String source, Type<ExternalIDs> destinationType) {
    JSONExternalIdentifiers externalIdentifiers = JsonUtils.readObjectFromJsonString(source, JSONExternalIdentifiers.class);
    ExternalIDs externalIDs = new ExternalIDs();
    for (JSONExternalIdentifier externalIdentifier : externalIdentifiers.getExternalIdentifier()) {
        ExternalID id = new ExternalID();
        if (externalIdentifier.getType() == null) {
            id.setType(FundingExternalIdentifierType.GRANT_NUMBER.value());
        } else {
            id.setType(externalIdentifier.getType().toLowerCase());
        }
        if (externalIdentifier.getUrl() != null && !PojoUtil.isEmpty(externalIdentifier.getUrl().getValue())) {
            Url url = new Url(externalIdentifier.getUrl().getValue());
            id.setUrl(url);
        }
        if (!PojoUtil.isEmpty(externalIdentifier.getValue())) {
            id.setValue(externalIdentifier.getValue());
        }
        if (externalIdentifier.getRelationship() != null) {
            id.setRelationship(Relationship.fromValue(conv.convertFrom(externalIdentifier.getRelationship(), null)));
        }
        externalIDs.getExternalIdentifier().add(id);
    }
    return externalIDs;
}
Also used : JSONExternalIdentifier(org.orcid.core.adapter.jsonidentifier.JSONExternalIdentifier) ExternalIDs(org.orcid.jaxb.model.v3.dev1.record.ExternalIDs) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) JSONUrl(org.orcid.core.adapter.jsonidentifier.JSONUrl) Url(org.orcid.jaxb.model.v3.dev1.common.Url) JSONExternalIdentifiers(org.orcid.core.adapter.jsonidentifier.JSONExternalIdentifiers)

Example 27 with ExternalIDs

use of org.orcid.jaxb.model.v3.dev1.record.ExternalIDs in project ORCID-Source by ORCID.

the class JSONWorkExternalIdentifiersConverterV3 method convertTo.

@Override
public String convertTo(ExternalIDs source, Type<String> destinationType) {
    JSONWorkExternalIdentifiers jsonWorkExternalIdentifiers = new JSONWorkExternalIdentifiers();
    for (ExternalID externalID : source.getExternalIdentifier()) {
        JSONWorkExternalIdentifier jsonWorkExternalIdentifier = new JSONWorkExternalIdentifier();
        if (externalID.getType() != null) {
            jsonWorkExternalIdentifier.setWorkExternalIdentifierType(conv.convertTo(externalID.getType(), null));
        }
        if (externalID.getUrl() != null) {
            jsonWorkExternalIdentifier.setUrl(new JSONUrl(externalID.getUrl().getValue()));
        }
        if (!PojoUtil.isEmpty(externalID.getValue())) {
            jsonWorkExternalIdentifier.setWorkExternalIdentifierId(new WorkExternalIdentifierId(externalID.getValue()));
        }
        if (externalID.getRelationship() != null) {
            jsonWorkExternalIdentifier.setRelationship(conv.convertTo(externalID.getRelationship().value(), null));
        }
        jsonWorkExternalIdentifiers.getWorkExternalIdentifier().add(jsonWorkExternalIdentifier);
    }
    return JsonUtils.convertToJsonString(jsonWorkExternalIdentifiers);
}
Also used : JSONWorkExternalIdentifiers(org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifiers) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) WorkExternalIdentifierId(org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifier.WorkExternalIdentifierId) JSONUrl(org.orcid.core.adapter.jsonidentifier.JSONUrl) JSONWorkExternalIdentifier(org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifier)

Example 28 with ExternalIDs

use of org.orcid.jaxb.model.v3.dev1.record.ExternalIDs 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 29 with ExternalIDs

use of org.orcid.jaxb.model.v3.dev1.record.ExternalIDs 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 30 with ExternalIDs

use of org.orcid.jaxb.model.v3.dev1.record.ExternalIDs 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)

Aggregations

ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)75 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)72 Url (org.orcid.jaxb.model.v3.dev1.common.Url)49 Test (org.junit.Test)45 Title (org.orcid.jaxb.model.v3.dev1.common.Title)23 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)22 Response (javax.ws.rs.core.Response)20 DBUnitTest (org.orcid.test.DBUnitTest)20 WorkTitle (org.orcid.jaxb.model.v3.dev1.record.WorkTitle)19 List (java.util.List)15 Work (org.orcid.jaxb.model.v3.dev1.record.Work)14 TransientNonEmptyString (org.orcid.jaxb.model.v3.dev1.common.TransientNonEmptyString)8 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)8 WorkBulk (org.orcid.jaxb.model.v3.dev1.record.WorkBulk)7 BaseTest (org.orcid.core.BaseTest)6 JSONUrl (org.orcid.core.adapter.jsonidentifier.JSONUrl)6 DisambiguatedOrganization (org.orcid.jaxb.model.v3.dev1.common.DisambiguatedOrganization)6 Organization (org.orcid.jaxb.model.v3.dev1.common.Organization)6 OrganizationAddress (org.orcid.jaxb.model.v3.dev1.common.OrganizationAddress)6 FundingTitle (org.orcid.jaxb.model.v3.dev1.record.FundingTitle)6