use of org.orcid.jaxb.model.record_v2.ExternalIDs in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegator_FundingTest method testUpdateFunding.
@Test
public void testUpdateFunding() {
SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4447", ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Response response = serviceDelegator.viewFunding("4444-4444-4444-4447", 6L);
assertNotNull(response);
Funding funding = (Funding) response.getEntity();
assertNotNull(funding);
assertEquals("Public Funding # 1", funding.getTitle().getTitle().getContent());
assertEquals("This is the description for funding with id 6", funding.getDescription());
LastModifiedDate before = funding.getLastModifiedDate();
funding.getTitle().getTitle().setContent("Updated funding title");
funding.setDescription("This is an updated description");
ExternalID fExtId = new ExternalID();
fExtId.setRelationship(Relationship.PART_OF);
fExtId.setType(FundingExternalIdentifierType.GRANT_NUMBER.value());
fExtId.setUrl(new Url("http://fundingExtId.com"));
fExtId.setValue("new-funding-ext-id");
ExternalIDs fExtIds = new ExternalIDs();
fExtIds.getExternalIdentifier().add(fExtId);
funding.setExternalIdentifiers(fExtIds);
response = serviceDelegator.updateFunding("4444-4444-4444-4447", 6L, funding);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
response = serviceDelegator.viewFunding("4444-4444-4444-4447", 6L);
assertNotNull(response);
funding = (Funding) response.getEntity();
assertNotNull(funding);
Utils.verifyLastModified(funding.getLastModifiedDate());
assertTrue(funding.getLastModifiedDate().after(before));
assertEquals("Updated funding title", funding.getTitle().getTitle().getContent());
assertEquals("This is an updated description", funding.getDescription());
// Rollback changes
funding.getTitle().getTitle().setContent("Public Funding # 1");
funding.setDescription("This is the description for funding with id 6");
response = serviceDelegator.updateFunding("4444-4444-4444-4447", 6L, funding);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
}
use of org.orcid.jaxb.model.record_v2.ExternalIDs in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegator_FundingTest method testUpdateFundingYouAreNotTheSourceOf.
@Test(expected = WrongSourceException.class)
public void testUpdateFundingYouAreNotTheSourceOf() {
SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4446", ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Response response = serviceDelegator.viewFunding("4444-4444-4444-4446", 5L);
assertNotNull(response);
Funding funding = (Funding) response.getEntity();
assertNotNull(funding);
funding.getTitle().getTitle().setContent("Updated funding title");
ExternalID fExtId = new ExternalID();
fExtId.setRelationship(Relationship.PART_OF);
fExtId.setType(FundingExternalIdentifierType.GRANT_NUMBER.value());
fExtId.setUrl(new Url("http://fundingExtId.com"));
fExtId.setValue("new-funding-ext-id");
ExternalIDs fExtIds = new ExternalIDs();
fExtIds.getExternalIdentifier().add(fExtId);
funding.setExternalIdentifiers(fExtIds);
serviceDelegator.updateFunding("4444-4444-4444-4446", 5L, funding);
fail();
}
use of org.orcid.jaxb.model.record_v2.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()) {
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.record_v2.ExternalIDs in project ORCID-Source by ORCID.
the class ExternalIDValidator method validateFunding.
public void validateFunding(ExternalIDs ids) {
if (// urgh
ids == null)
return;
List<String> errors = Lists.newArrayList();
for (ExternalID id : ids.getExternalIdentifier()) {
if (id.getType() == null || !identifierTypeManager.fetchIdentifierTypesByAPITypeName(null).containsKey(id.getType())) {
errors.add(id.getType());
}
if (PojoUtil.isEmpty(id.getValue())) {
errors.add("value");
}
if (requireRelationshipOnExternalIdentifier) {
if (id.getRelationship() == null) {
errors.add("relationship");
}
}
}
checkAndThrow(errors);
}
use of org.orcid.jaxb.model.record_v2.ExternalIDs in project ORCID-Source by ORCID.
the class ActivityValidator method checkFundingExternalIdentifiersForDuplicates.
public void checkFundingExternalIdentifiersForDuplicates(ExternalIDs newExtIds, ExternalIDs existingExtIds, Source existingSource, SourceEntity sourceEntity) {
if (existingExtIds != null && newExtIds != null) {
for (ExternalID existingId : existingExtIds.getExternalIdentifier()) {
for (ExternalID newId : newExtIds.getExternalIdentifier()) {
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);
}
}
}
}
}
Aggregations