Search in sources :

Example 1 with Service

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);
    }
}
Also used : Service(org.orcid.jaxb.model.v3.dev1.record.Service) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 2 with Service

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();
}
Also used : HashMap(java.util.HashMap) Service(org.orcid.jaxb.model.v3.dev1.record.Service) MismatchedPutCodeException(org.orcid.core.exception.MismatchedPutCodeException)

Example 3 with Service

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();
}
Also used : Response(javax.ws.rs.core.Response) Service(org.orcid.jaxb.model.v3.dev1.record.Service) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 4 with Service

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);
}
Also used : Response(javax.ws.rs.core.Response) Service(org.orcid.jaxb.model.v3.dev1.record.Service) List(java.util.List) ServiceSummary(org.orcid.jaxb.model.v3.dev1.record.summary.ServiceSummary) ActivitiesSummary(org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 5 with Service

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");
}
Also used : Response(javax.ws.rs.core.Response) ServiceSummary(org.orcid.jaxb.model.v3.dev1.record.summary.ServiceSummary) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

Service (org.orcid.jaxb.model.v3.dev1.record.Service)41 Test (org.junit.Test)31 DBUnitTest (org.orcid.test.DBUnitTest)18 Response (javax.ws.rs.core.Response)17 Distinction (org.orcid.jaxb.model.v3.dev1.record.Distinction)11 Education (org.orcid.jaxb.model.v3.dev1.record.Education)11 Membership (org.orcid.jaxb.model.v3.dev1.record.Membership)11 Employment (org.orcid.jaxb.model.v3.dev1.record.Employment)10 InvitedPosition (org.orcid.jaxb.model.v3.dev1.record.InvitedPosition)10 Qualification (org.orcid.jaxb.model.v3.dev1.record.Qualification)10 Affiliation (org.orcid.jaxb.model.v3.dev1.record.Affiliation)8 ServiceSummary (org.orcid.jaxb.model.v3.dev1.record.summary.ServiceSummary)7 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)6 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Funding (org.orcid.jaxb.model.v3.dev1.record.Funding)4 Work (org.orcid.jaxb.model.v3.dev1.record.Work)4 ActivitiesSummary (org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary)4 Services (org.orcid.jaxb.model.v3.dev1.record.summary.Services)4