use of org.orcid.jaxb.model.v3.dev1.record.Distinction in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegatorImpl method createDistinction.
@Override
public Response createDistinction(String orcid, Distinction distinction) {
orcidSecurityManager.checkClientAccessAndScopes(orcid, ScopePathType.AFFILIATIONS_CREATE, ScopePathType.AFFILIATIONS_UPDATE);
clearSource(distinction);
Distinction e = affiliationsManager.createDistinctionAffiliation(orcid, distinction, true);
sourceUtils.setSourceName(e);
try {
return Response.created(new URI(String.valueOf(e.getPutCode()))).build();
} catch (URISyntaxException ex) {
throw new RuntimeException(localeManager.resolveMessage("apiError.createdistinction_response.exception"), ex);
}
}
use of org.orcid.jaxb.model.v3.dev1.record.Distinction in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_DistinctionsTest method testUpdateDistinctionLeavingVisibilityNullTest.
@Test
public void testUpdateDistinctionLeavingVisibilityNullTest() {
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Response response = serviceDelegator.viewDistinction(ORCID, 27L);
assertNotNull(response);
Distinction distinction = (Distinction) response.getEntity();
assertNotNull(distinction);
assertEquals(Visibility.PUBLIC, distinction.getVisibility());
distinction.setVisibility(null);
response = serviceDelegator.updateDistinction(ORCID, 27L, distinction);
assertNotNull(response);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
distinction = (Distinction) response.getEntity();
assertNotNull(distinction);
assertEquals(Visibility.PUBLIC, distinction.getVisibility());
}
use of org.orcid.jaxb.model.v3.dev1.record.Distinction in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_DistinctionsTest method testViewDistinctionSummaryReadPublic.
@Test
public void testViewDistinctionSummaryReadPublic() {
SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_PUBLIC);
Response r = serviceDelegator.viewDistinctionSummary(ORCID, 27L);
DistinctionSummary element = (DistinctionSummary) r.getEntity();
assertNotNull(element);
assertEquals("/0000-0000-0000-0003/distinction/27", element.getPath());
Utils.assertIsPublicOrSource(element, "APP-5555555555555555");
}
use of org.orcid.jaxb.model.v3.dev1.record.Distinction in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_DistinctionsTest method testUpdateDistinction.
@Test
public void testUpdateDistinction() {
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Response response = serviceDelegator.viewDistinction(ORCID, 27L);
assertNotNull(response);
Distinction distinction = (Distinction) response.getEntity();
assertNotNull(distinction);
assertEquals("PUBLIC Department", distinction.getDepartmentName());
assertEquals("PUBLIC", distinction.getRoleTitle());
Utils.verifyLastModified(distinction.getLastModifiedDate());
LastModifiedDate before = distinction.getLastModifiedDate();
distinction.setDepartmentName("Updated department name");
distinction.setRoleTitle("The updated role title");
// disambiguated org is required in API v3
DisambiguatedOrganization disambiguatedOrg = new DisambiguatedOrganization();
disambiguatedOrg.setDisambiguatedOrganizationIdentifier("abc456");
disambiguatedOrg.setDisambiguationSource("WDB");
distinction.getOrganization().setDisambiguatedOrganization(disambiguatedOrg);
response = serviceDelegator.updateDistinction(ORCID, 27L, distinction);
assertNotNull(response);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
response = serviceDelegator.viewDistinction(ORCID, 27L);
assertNotNull(response);
distinction = (Distinction) response.getEntity();
assertNotNull(distinction);
Utils.verifyLastModified(distinction.getLastModifiedDate());
assertTrue(distinction.getLastModifiedDate().after(before));
assertEquals("Updated department name", distinction.getDepartmentName());
assertEquals("The updated role title", distinction.getRoleTitle());
// Rollback changes
distinction.setDepartmentName("PUBLIC Department");
distinction.setRoleTitle("PUBLIC");
response = serviceDelegator.updateDistinction(ORCID, 27L, distinction);
assertNotNull(response);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
}
use of org.orcid.jaxb.model.v3.dev1.record.Distinction in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_DistinctionsTest method testAddDistinctionsDuplicateExternalIDs.
@Test(expected = OrcidDuplicatedActivityException.class)
public void testAddDistinctionsDuplicateExternalIDs() {
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);
Distinction distinction = (Distinction) Utils.getAffiliation(AffiliationType.DISTINCTION);
distinction.setExternalIDs(externalIDs);
Response response = serviceDelegator.createDistinction(ORCID, distinction);
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 {
Distinction duplicate = (Distinction) Utils.getAffiliation(AffiliationType.DISTINCTION);
duplicate.setExternalIDs(externalIDs);
serviceDelegator.createDistinction(ORCID, duplicate);
} finally {
serviceDelegator.deleteAffiliation(ORCID, putCode);
}
}
Aggregations