Search in sources :

Example 31 with Membership

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

the class MemberV3ApiServiceDelegator_MembershipsTest method testUpdateMembership.

@Test
public void testUpdateMembership() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
    Response response = serviceDelegator.viewMembership(ORCID, 39L);
    assertNotNull(response);
    Membership membership = (Membership) response.getEntity();
    assertNotNull(membership);
    assertEquals("PRIVATE Department", membership.getDepartmentName());
    assertEquals("PRIVATE", membership.getRoleTitle());
    Utils.verifyLastModified(membership.getLastModifiedDate());
    LastModifiedDate before = membership.getLastModifiedDate();
    membership.setDepartmentName("Updated department name");
    membership.setRoleTitle("The updated role title");
    // disambiguated org is required in API v3
    DisambiguatedOrganization disambiguatedOrg = new DisambiguatedOrganization();
    disambiguatedOrg.setDisambiguatedOrganizationIdentifier("abc456");
    disambiguatedOrg.setDisambiguationSource("WDB");
    membership.getOrganization().setDisambiguatedOrganization(disambiguatedOrg);
    response = serviceDelegator.updateMembership(ORCID, 39L, membership);
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    response = serviceDelegator.viewMembership(ORCID, 39L);
    assertNotNull(response);
    membership = (Membership) response.getEntity();
    assertNotNull(membership);
    Utils.verifyLastModified(membership.getLastModifiedDate());
    assertTrue(membership.getLastModifiedDate().after(before));
    assertEquals("Updated department name", membership.getDepartmentName());
    assertEquals("The updated role title", membership.getRoleTitle());
    // Rollback changes
    membership.setDepartmentName("PRIVATE Department");
    membership.setRoleTitle("PRIVATE");
    response = serviceDelegator.updateMembership(ORCID, 39L, membership);
    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) Membership(org.orcid.jaxb.model.v3.dev1.record.Membership) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 32 with Membership

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

the class MemberV3ApiServiceDelegator_MembershipsTest method testAddMembership.

@Test
public void testAddMembership() {
    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.getMemberships());
    Utils.verifyLastModified(originalSummary.getMemberships().getLastModifiedDate());
    assertNotNull(originalSummary.getMemberships().getSummaries());
    assertNotNull(originalSummary.getMemberships().getSummaries().get(0));
    Utils.verifyLastModified(originalSummary.getMemberships().getSummaries().get(0).getLastModifiedDate());
    assertEquals(4, originalSummary.getMemberships().getSummaries().size());
    response = serviceDelegator.createMembership(ORCID, (Membership) Utils.getAffiliation(AffiliationType.MEMBERSHIP));
    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.getMemberships());
    Utils.verifyLastModified(summaryWithNewElement.getMemberships().getLastModifiedDate());
    assertNotNull(summaryWithNewElement.getMemberships().getSummaries());
    assertEquals(5, summaryWithNewElement.getMemberships().getSummaries().size());
    boolean haveNew = false;
    for (MembershipSummary membershipSummary : summaryWithNewElement.getMemberships().getSummaries()) {
        assertNotNull(membershipSummary.getPutCode());
        Utils.verifyLastModified(membershipSummary.getLastModifiedDate());
        if (membershipSummary.getPutCode().equals(putCode)) {
            assertEquals("My department name", membershipSummary.getDepartmentName());
            haveNew = true;
        } else {
            assertTrue(originalSummary.getMemberships().getSummaries().contains(membershipSummary));
        }
    }
    assertTrue(haveNew);
    // Remove new element
    serviceDelegator.deleteAffiliation(ORCID, putCode);
}
Also used : Response(javax.ws.rs.core.Response) Membership(org.orcid.jaxb.model.v3.dev1.record.Membership) List(java.util.List) MembershipSummary(org.orcid.jaxb.model.v3.dev1.record.summary.MembershipSummary) ActivitiesSummary(org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 33 with Membership

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

the class MemberV3ApiServiceDelegator_MembershipsTest method testUpdateMembershipDuplicateExternalIDs.

@Test(expected = OrcidDuplicatedActivityException.class)
public void testUpdateMembershipDuplicateExternalIDs() {
    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);
    Membership membership = (Membership) Utils.getAffiliation(AffiliationType.MEMBERSHIP);
    membership.setExternalIDs(externalIDs);
    Response response = serviceDelegator.createMembership(ORCID, membership);
    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 putCode1 = Long.valueOf(String.valueOf(resultWithPutCode.get(0)));
    Membership another = (Membership) Utils.getAffiliation(AffiliationType.MEMBERSHIP);
    response = serviceDelegator.createMembership(ORCID, another);
    map = response.getMetadata();
    assertNotNull(map);
    assertTrue(map.containsKey("Location"));
    resultWithPutCode = (List<?>) map.get("Location");
    Long putCode2 = Long.valueOf(String.valueOf(resultWithPutCode.get(0)));
    response = serviceDelegator.viewMembership(ORCID, putCode2);
    another = (Membership) response.getEntity();
    another.setExternalIDs(externalIDs);
    try {
        serviceDelegator.updateMembership(ORCID, putCode2, another);
    } finally {
        serviceDelegator.deleteAffiliation(ORCID, putCode1);
        serviceDelegator.deleteAffiliation(ORCID, putCode2);
    }
}
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) Membership(org.orcid.jaxb.model.v3.dev1.record.Membership) 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)

Example 34 with Membership

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

the class MemberV3ApiServiceDelegator_MembershipsTest method testViewLimitedMembership.

@Test
public void testViewLimitedMembership() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
    Response response = serviceDelegator.viewMembership(ORCID, 40L);
    assertNotNull(response);
    Membership membership = (Membership) response.getEntity();
    assertNotNull(membership);
    Utils.verifyLastModified(membership.getLastModifiedDate());
    assertEquals(Long.valueOf(40L), membership.getPutCode());
    assertEquals("/0000-0000-0000-0003/membership/40", membership.getPath());
    assertEquals("SELF LIMITED Department", membership.getDepartmentName());
    assertEquals(Visibility.LIMITED.value(), membership.getVisibility().value());
}
Also used : Response(javax.ws.rs.core.Response) Membership(org.orcid.jaxb.model.v3.dev1.record.Membership) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 35 with Membership

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

the class MemberV3ApiServiceDelegator_MembershipsTest method testUpdateMembershipLeavingVisibilityNullTest.

@Test
public void testUpdateMembershipLeavingVisibilityNullTest() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
    Response response = serviceDelegator.viewMembership(ORCID, 37L);
    assertNotNull(response);
    Membership membership = (Membership) response.getEntity();
    assertNotNull(membership);
    assertEquals(Visibility.PUBLIC, membership.getVisibility());
    membership.setVisibility(null);
    response = serviceDelegator.updateMembership(ORCID, 37L, membership);
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    membership = (Membership) response.getEntity();
    assertNotNull(membership);
    assertEquals(Visibility.PUBLIC, membership.getVisibility());
}
Also used : Response(javax.ws.rs.core.Response) Membership(org.orcid.jaxb.model.v3.dev1.record.Membership) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

Membership (org.orcid.jaxb.model.v3.dev1.record.Membership)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 Service (org.orcid.jaxb.model.v3.dev1.record.Service)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 MembershipSummary (org.orcid.jaxb.model.v3.dev1.record.summary.MembershipSummary)7 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)5 ActivitiesSummary (org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary)5 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Url (org.orcid.jaxb.model.v3.dev1.common.Url)4 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)4 Funding (org.orcid.jaxb.model.v3.dev1.record.Funding)4