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;
}
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);
}
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;
}
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()));
}
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()));
}
Aggregations