use of org.orcid.jaxb.model.v3.dev1.record.ExternalIDs in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_ServicesTest method testAddServicesDuplicateExternalIDs.
@Test(expected = OrcidDuplicatedActivityException.class)
public void testAddServicesDuplicateExternalIDs() {
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
ExternalID e1 = new ExternalID();
e1.setRelationship(Relationship.SELF);
e1.setType("erm");
e1.setUrl(new Url("https://orcid.org"));
e1.setValue("err");
ExternalID e2 = new ExternalID();
e2.setRelationship(Relationship.SELF);
e2.setType("err");
e2.setUrl(new Url("http://bbc.co.uk"));
e2.setValue("erm");
ExternalIDs externalIDs = new ExternalIDs();
externalIDs.getExternalIdentifier().add(e1);
externalIDs.getExternalIdentifier().add(e2);
Service service = (Service) Utils.getAffiliation(AffiliationType.SERVICE);
service.setExternalIDs(externalIDs);
Response response = serviceDelegator.createService(ORCID, service);
assertNotNull(response);
assertEquals(HttpStatus.SC_CREATED, response.getStatus());
Map<?, ?> map = response.getMetadata();
assertNotNull(map);
assertTrue(map.containsKey("Location"));
List<?> resultWithPutCode = (List<?>) map.get("Location");
Long putCode = Long.valueOf(String.valueOf(resultWithPutCode.get(0)));
try {
Service duplicate = (Service) Utils.getAffiliation(AffiliationType.SERVICE);
duplicate.setExternalIDs(externalIDs);
serviceDelegator.createService(ORCID, duplicate);
} finally {
serviceDelegator.deleteAffiliation(ORCID, putCode);
}
}
use of org.orcid.jaxb.model.v3.dev1.record.ExternalIDs in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_WorksTest method testUpdateWorkYouAreNotTheSourceOf.
@Test(expected = WrongSourceException.class)
public void testUpdateWorkYouAreNotTheSourceOf() {
SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4443", ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Response response = serviceDelegator.viewWork("4444-4444-4444-4443", 2L);
assertNotNull(response);
Work work = (Work) response.getEntity();
assertNotNull(work);
Utils.verifyLastModified(work.getLastModifiedDate());
assertEquals(Long.valueOf(2), work.getPutCode());
assertNotNull(work.getWorkTitle());
assertNotNull(work.getWorkTitle().getTitle());
assertEquals("Another day in the life", work.getWorkTitle().getTitle().getContent());
assertEquals(WorkType.BOOK, work.getWorkType());
work.setWorkType(WorkType.EDITED_BOOK);
work.getWorkTitle().getTitle().setContent("Updated work title");
ExternalIDs extIds = new ExternalIDs();
ExternalID extId = new ExternalID();
extId.setRelationship(Relationship.PART_OF);
extId.setType(WorkExternalIdentifierType.AGR.value());
extId.setValue("ext-id-" + System.currentTimeMillis());
extId.setUrl(new Url("http://thisIsANewUrl.com"));
extIds.getExternalIdentifier().add(extId);
work.setWorkExternalIdentifiers(extIds);
serviceDelegator.updateWork("4444-4444-4444-4443", 2L, work);
fail();
}
use of org.orcid.jaxb.model.v3.dev1.record.ExternalIDs in project ORCID-Source by ORCID.
the class ActivityValidator method checkExternalIdentifiersForDuplicates.
public void checkExternalIdentifiersForDuplicates(ExternalIDs newExtIds, ExternalIDs existingExtIds, Source existingSource, SourceEntity sourceEntity) {
if (existingExtIds != null && newExtIds != null) {
for (ExternalID existingId : existingExtIds.getExternalIdentifier()) {
for (ExternalID newId : newExtIds.getExternalIdentifier()) {
// normalize the ids before checking equality
newId.setNormalized(new TransientNonEmptyString(norm.normalise(newId.getType(), newId.getValue())));
if (existingId.getNormalized() == null)
existingId.setNormalized(new TransientNonEmptyString(norm.normalise(existingId.getType(), existingId.getValue())));
if (areRelationshipsSameButNotBothPartOf(existingId.getRelationship(), newId.getRelationship()) && newId.equals(existingId) && sourceEntity.getSourceId().equals(getExistingSource(existingSource))) {
Map<String, String> params = new HashMap<String, String>();
params.put("clientName", sourceEntity.getSourceName());
throw new OrcidDuplicatedActivityException(params);
}
}
}
}
}
use of org.orcid.jaxb.model.v3.dev1.record.ExternalIDs in project ORCID-Source by ORCID.
the class WorksTest method getWork.
private Work getWork(String title, boolean randomExtId, String extIdValue) {
Long time = System.currentTimeMillis();
Work work = new Work();
WorkTitle workTitle = new WorkTitle();
Title wTitle = new Title(title);
workTitle.setTranslatedTitle(new TranslatedTitle(title, "en"));
workTitle.setTitle(wTitle);
work.setWorkTitle(workTitle);
work.setWorkType(WorkType.BOOK);
ExternalID extId = new ExternalID();
extId.setRelationship(Relationship.SELF);
if (randomExtId) {
extId.setValue("work-ext-id-" + (Math.random() * 1000) + "-" + time);
} else {
extId.setValue("work-ext-id-" + extIdValue);
}
extId.setType("doi");
ExternalIDs extIds = new ExternalIDs();
extIds.getExternalIdentifier().add(extId);
work.setWorkExternalIdentifiers(extIds);
return work;
}
use of org.orcid.jaxb.model.v3.dev1.record.ExternalIDs in project ORCID-Source by ORCID.
the class JSONFundingExternalIdentifiersConverterV3Test method testConvertFrom.
@Test
public void testConvertFrom() {
ProfileFundingEntity funding = getProfileFundingEntity();
ExternalIDs externalIDs = converter.convertFrom(funding.getExternalIdentifiersJson(), null);
assertNotNull(externalIDs);
assertEquals(2, externalIDs.getExternalIdentifier().size());
ExternalID externalID = externalIDs.getExternalIdentifier().get(0);
assertEquals("grant_number", externalID.getType());
assertEquals("12345", externalID.getValue());
assertEquals("http://tempuri.org", externalID.getUrl().getValue());
externalID = externalIDs.getExternalIdentifier().get(1);
assertEquals("grant_number", externalID.getType());
assertEquals("67890", externalID.getValue());
assertEquals("http://tempuri.org/2", externalID.getUrl().getValue());
}
Aggregations