use of org.orcid.jaxb.model.v3.dev1.record.Service in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegatorImpl method createService.
@Override
public Response createService(String orcid, Service service) {
orcidSecurityManager.checkClientAccessAndScopes(orcid, ScopePathType.AFFILIATIONS_CREATE, ScopePathType.AFFILIATIONS_UPDATE);
clearSource(service);
Service e = affiliationsManager.createServiceAffiliation(orcid, service, 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.Service in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegatorImpl method updateService.
@Override
public Response updateService(String orcid, Long putCode, Service service) {
orcidSecurityManager.checkClientAccessAndScopes(orcid, ScopePathType.AFFILIATIONS_UPDATE);
if (!putCode.equals(service.getPutCode())) {
Map<String, String> params = new HashMap<String, String>();
params.put("urlPutCode", String.valueOf(putCode));
params.put("bodyPutCode", String.valueOf(service.getPutCode()));
throw new MismatchedPutCodeException(params);
}
clearSource(service);
Service e = affiliationsManager.updateServiceAffiliation(orcid, service, true);
sourceUtils.setSourceName(e);
return Response.ok(e).build();
}
use of org.orcid.jaxb.model.v3.dev1.record.Service in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_ServicesTest method testUpdateServiceYouAreNotTheSourceOf.
@Test(expected = WrongSourceException.class)
public void testUpdateServiceYouAreNotTheSourceOf() {
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Response response = serviceDelegator.viewService(ORCID, 50L);
assertNotNull(response);
Service service = (Service) response.getEntity();
assertNotNull(service);
service.setDepartmentName("Updated department name");
service.setRoleTitle("The updated role title");
serviceDelegator.updateService(ORCID, 50L, service);
fail();
}
use of org.orcid.jaxb.model.v3.dev1.record.Service in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_ServicesTest method testAddService.
@Test
public void testAddService() {
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Response response = serviceDelegator.viewActivities(ORCID);
assertNotNull(response);
ActivitiesSummary originalSummary = (ActivitiesSummary) response.getEntity();
assertNotNull(originalSummary);
Utils.verifyLastModified(originalSummary.getLastModifiedDate());
assertNotNull(originalSummary.getServices());
Utils.verifyLastModified(originalSummary.getServices().getLastModifiedDate());
assertNotNull(originalSummary.getServices().getSummaries());
assertNotNull(originalSummary.getServices().getSummaries().get(0));
Utils.verifyLastModified(originalSummary.getServices().getSummaries().get(0).getLastModifiedDate());
assertEquals(4, originalSummary.getServices().getSummaries().size());
response = serviceDelegator.createService(ORCID, (Service) Utils.getAffiliation(AffiliationType.SERVICE));
assertNotNull(response);
assertEquals(Response.Status.CREATED.getStatusCode(), 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)));
response = serviceDelegator.viewActivities(ORCID);
assertNotNull(response);
ActivitiesSummary summaryWithNewElement = (ActivitiesSummary) response.getEntity();
assertNotNull(summaryWithNewElement);
Utils.verifyLastModified(summaryWithNewElement.getLastModifiedDate());
assertNotNull(summaryWithNewElement.getServices());
Utils.verifyLastModified(summaryWithNewElement.getServices().getLastModifiedDate());
assertNotNull(summaryWithNewElement.getServices().getSummaries());
assertEquals(5, summaryWithNewElement.getServices().getSummaries().size());
boolean haveNew = false;
for (ServiceSummary serviceSummary : summaryWithNewElement.getServices().getSummaries()) {
assertNotNull(serviceSummary.getPutCode());
Utils.verifyLastModified(serviceSummary.getLastModifiedDate());
if (serviceSummary.getPutCode().equals(putCode)) {
assertEquals("My department name", serviceSummary.getDepartmentName());
haveNew = true;
} else {
assertTrue(originalSummary.getServices().getSummaries().contains(serviceSummary));
}
}
assertTrue(haveNew);
// Remove new element
serviceDelegator.deleteAffiliation(ORCID, putCode);
}
use of org.orcid.jaxb.model.v3.dev1.record.Service in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_ServicesTest method testViewServiceSummaryReadPublic.
@Test
public void testViewServiceSummaryReadPublic() {
SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_PUBLIC);
Response r = serviceDelegator.viewServiceSummary(ORCID, 47L);
ServiceSummary element = (ServiceSummary) r.getEntity();
assertNotNull(element);
assertEquals("/0000-0000-0000-0003/service/47", element.getPath());
Utils.assertIsPublicOrSource(element, "APP-5555555555555555");
}
Aggregations