Search in sources :

Example 6 with Service

use of org.orcid.jaxb.model.v3.dev1.record.Service in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_ServicesTest method testUpdateService.

@Test
public void testUpdateService() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
    Response response = serviceDelegator.viewService(ORCID, 47L);
    assertNotNull(response);
    Service service = (Service) response.getEntity();
    assertNotNull(service);
    assertEquals("PUBLIC Department", service.getDepartmentName());
    assertEquals("PUBLIC", service.getRoleTitle());
    Utils.verifyLastModified(service.getLastModifiedDate());
    LastModifiedDate before = service.getLastModifiedDate();
    service.setDepartmentName("Updated department name");
    service.setRoleTitle("The updated role title");
    // disambiguated org is required in API v3
    DisambiguatedOrganization disambiguatedOrg = new DisambiguatedOrganization();
    disambiguatedOrg.setDisambiguatedOrganizationIdentifier("abc456");
    disambiguatedOrg.setDisambiguationSource("WDB");
    service.getOrganization().setDisambiguatedOrganization(disambiguatedOrg);
    response = serviceDelegator.updateService(ORCID, 47L, service);
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    response = serviceDelegator.viewService(ORCID, 47L);
    assertNotNull(response);
    service = (Service) response.getEntity();
    assertNotNull(service);
    Utils.verifyLastModified(service.getLastModifiedDate());
    assertTrue(service.getLastModifiedDate().after(before));
    assertEquals("Updated department name", service.getDepartmentName());
    assertEquals("The updated role title", service.getRoleTitle());
    // Rollback changes
    service.setDepartmentName("PUBLIC Department");
    service.setRoleTitle("PUBLIC");
    response = serviceDelegator.updateService(ORCID, 47L, service);
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) LastModifiedDate(org.orcid.jaxb.model.v3.dev1.common.LastModifiedDate) DisambiguatedOrganization(org.orcid.jaxb.model.v3.dev1.common.DisambiguatedOrganization) Service(org.orcid.jaxb.model.v3.dev1.record.Service) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 7 with Service

use of org.orcid.jaxb.model.v3.dev1.record.Service in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_ServicesTest method testUpdateServiceLeavingVisibilityNullTest.

@Test
public void testUpdateServiceLeavingVisibilityNullTest() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
    Response response = serviceDelegator.viewService(ORCID, 47L);
    assertNotNull(response);
    Service service = (Service) response.getEntity();
    assertNotNull(service);
    assertEquals(Visibility.PUBLIC, service.getVisibility());
    service.setVisibility(null);
    response = serviceDelegator.updateService(ORCID, 47L, service);
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    service = (Service) response.getEntity();
    assertNotNull(service);
    assertEquals(Visibility.PUBLIC, service.getVisibility());
}
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 8 with Service

use of org.orcid.jaxb.model.v3.dev1.record.Service in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_ServicesTest method testUpdateServiceChangingVisibilityTest.

@Test(expected = VisibilityMismatchException.class)
public void testUpdateServiceChangingVisibilityTest() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
    Response response = serviceDelegator.viewService(ORCID, 47L);
    assertNotNull(response);
    Service service = (Service) response.getEntity();
    assertNotNull(service);
    assertEquals(Visibility.PUBLIC, service.getVisibility());
    service.setVisibility(Visibility.PRIVATE);
    response = serviceDelegator.updateService(ORCID, 47L, 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 9 with Service

use of org.orcid.jaxb.model.v3.dev1.record.Service in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_ServicesTest method testDeleteService.

@Test
public void testDeleteService() {
    SecurityContextTestUtils.setUpSecurityContext("0000-0000-0000-0002", ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
    Response response = serviceDelegator.viewService("0000-0000-0000-0002", 1006L);
    assertNotNull(response);
    Service service = (Service) response.getEntity();
    assertNotNull(service);
    response = serviceDelegator.deleteAffiliation("0000-0000-0000-0002", 1006L);
    assertNotNull(response);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
    try {
        serviceDelegator.viewService("0000-0000-0000-0002", 1006L);
        fail();
    } catch (NoResultException nre) {
    } catch (Exception e) {
        fail();
    }
}
Also used : Response(javax.ws.rs.core.Response) Service(org.orcid.jaxb.model.v3.dev1.record.Service) NoResultException(javax.persistence.NoResultException) NoResultException(javax.persistence.NoResultException) VisibilityMismatchException(org.orcid.core.exception.VisibilityMismatchException) WrongSourceException(org.orcid.core.exception.WrongSourceException) OrcidDuplicatedActivityException(org.orcid.core.exception.OrcidDuplicatedActivityException) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) OrcidVisibilityException(org.orcid.core.exception.OrcidVisibilityException) OrcidUnauthorizedException(org.orcid.core.exception.OrcidUnauthorizedException) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 10 with Service

use of org.orcid.jaxb.model.v3.dev1.record.Service 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);
    }
}
Also used : Response(javax.ws.rs.core.Response) ExternalIDs(org.orcid.jaxb.model.v3.dev1.record.ExternalIDs) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) Service(org.orcid.jaxb.model.v3.dev1.record.Service) List(java.util.List) ResearcherUrl(org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl) Url(org.orcid.jaxb.model.v3.dev1.common.Url) 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