Search in sources :

Example 11 with Affiliation

use of org.orcid.jaxb.model.message.Affiliation in project ORCID-Source by ORCID.

the class Api12MembersTest method addAffiliationTest.

@Test
public void addAffiliationTest() throws InterruptedException, JSONException {
    String clientId = getClient1ClientId();
    String clientRedirectUri = getClient1RedirectUri();
    String clientSecret = getClient1ClientSecret();
    String userId = getUser1OrcidId();
    String password = getUser1Password();
    String accessToken = getAccessToken(userId, password, Arrays.asList("/affiliations/read-limited", "/activities/update"), clientId, clientSecret, clientRedirectUri, true);
    String orgName = "Org_" + System.currentTimeMillis();
    Long putCode = null;
    Api12Helper.addAffiliation(userId, accessToken, orgName, t2OAuthClient_1_2);
    ClientResponse response = t2OAuthClient_1_2.viewAffiliationDetailsXml(userId, accessToken);
    assertNotNull(response);
    assertEquals(200, response.getStatus());
    assertEquals("application/vnd.orcid+xml; charset=UTF-8; qs=5", response.getType().toString());
    OrcidMessage orcidMessage = response.getEntity(OrcidMessage.class);
    assertNotNull(orcidMessage);
    assertNotNull(orcidMessage.getOrcidProfile());
    assertNotNull(orcidMessage.getOrcidProfile().getOrcidActivities());
    assertNotNull(orcidMessage.getOrcidProfile().getOrcidActivities().getAffiliations());
    assertNotNull(orcidMessage.getOrcidProfile().getOrcidActivities().getAffiliations().getAffiliation());
    boolean found = false;
    for (Affiliation affiliation : orcidMessage.getOrcidProfile().getOrcidActivities().getAffiliations().getAffiliation()) {
        if (orgName.equals(affiliation.getOrganization().getName())) {
            assertNotNull(affiliation.getPutCode());
            putCode = Long.valueOf(affiliation.getPutCode());
            found = true;
        }
    }
    assertTrue(found);
    // Delete it
    ClientResponse deleteResponse = memberV2ApiClient.deleteEducationXml(this.getUser1OrcidId(), putCode, accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) Affiliation(org.orcid.jaxb.model.message.Affiliation) Test(org.junit.Test)

Example 12 with Affiliation

use of org.orcid.jaxb.model.message.Affiliation in project ORCID-Source by ORCID.

the class T2OrcidApiServiceDelegatorTest method testAddAffiliationToDeprecatedAccount.

@Test(expected = OrcidDeprecatedException.class)
public void testAddAffiliationToDeprecatedAccount() {
    SecurityContextTestUtils.setUpSecurityContext();
    OrcidMessage orcidMessage = new OrcidMessage();
    orcidMessage.setMessageVersion("1.2_rc6");
    OrcidProfile orcidProfile = new OrcidProfile();
    orcidMessage.setOrcidProfile(orcidProfile);
    orcidProfile.setOrcidIdentifier(new OrcidIdentifier("4444-4444-4444-444X"));
    OrcidActivities orcidActivities = new OrcidActivities();
    orcidProfile.setOrcidActivities(orcidActivities);
    OrganizationAddress address = new OrganizationAddress();
    address.setCity("City");
    address.setCountry(Iso3166Country.US);
    Organization org = new Organization();
    org.setAddress(address);
    org.setName("Testing org name");
    Affiliations affiliations = new Affiliations();
    Affiliation affiliation = new Affiliation();
    affiliation.setDepartmentName("Dept name");
    affiliation.setOrganization(org);
    affiliation.setType(AffiliationType.EMPLOYMENT);
    affiliations.getAffiliation().add(affiliation);
    orcidActivities.setAffiliations(affiliations);
    t2OrcidApiServiceDelegator.addAffiliations(mockedUriInfo, "4444-4444-4444-444X", orcidMessage);
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Organization(org.orcid.jaxb.model.message.Organization) Affiliations(org.orcid.jaxb.model.message.Affiliations) OrcidIdentifier(org.orcid.jaxb.model.message.OrcidIdentifier) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrganizationAddress(org.orcid.jaxb.model.message.OrganizationAddress) OrcidActivities(org.orcid.jaxb.model.message.OrcidActivities) Affiliation(org.orcid.jaxb.model.message.Affiliation) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 13 with Affiliation

use of org.orcid.jaxb.model.message.Affiliation in project ORCID-Source by ORCID.

the class T2OrcidApiServiceDelegatorTest method testUpdateExistingNonPrivateAffiliation.

@Test
@Transactional
public void testUpdateExistingNonPrivateAffiliation() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4443", ScopePathType.AFFILIATIONS_UPDATE);
    OrcidMessage orcidMessage = new OrcidMessage();
    orcidMessage.setMessageVersion("1.2_rc6");
    OrcidProfile orcidProfile = new OrcidProfile();
    orcidMessage.setOrcidProfile(orcidProfile);
    orcidProfile.setOrcidIdentifier(new OrcidIdentifier("4444-4444-4444-4443"));
    OrcidActivities orcidActivities = new OrcidActivities();
    orcidProfile.setOrcidActivities(orcidActivities);
    Affiliations affiliations = new Affiliations();
    orcidActivities.setAffiliations(affiliations);
    Affiliation affiliation1 = new Affiliation();
    affiliations.getAffiliation().add(affiliation1);
    affiliation1.setPutCode("3");
    affiliation1.setType(AffiliationType.EDUCATION);
    Organization organization1 = new Organization();
    affiliation1.setOrganization(organization1);
    organization1.setName("Different org");
    OrganizationAddress organizationAddress = new OrganizationAddress();
    organization1.setAddress(organizationAddress);
    organizationAddress.setCity("Edinburgh");
    organizationAddress.setCountry(Iso3166Country.GB);
    Response response = t2OrcidApiServiceDelegator.updateAffiliations(mockedUriInfo, "4444-4444-4444-4443", orcidMessage);
    assertNotNull(response);
    OrcidProfile retrievedProfile = orcidProfileManager.retrieveOrcidProfile("4444-4444-4444-4443");
    List<Affiliation> retreivedAffiliationsList = retrievedProfile.getOrcidActivities().getAffiliations().getAffiliation();
    assertEquals(3, retreivedAffiliationsList.size());
    Affiliation updatedAffiliation = retreivedAffiliationsList.get(0);
    assertEquals("Different org", updatedAffiliation.getOrganization().getName());
    assertEquals("APP-5555555555555555", updatedAffiliation.getSource().retrieveSourcePath());
    Affiliation existingAffiliation = retreivedAffiliationsList.get(1);
    assertEquals(Visibility.PRIVATE, existingAffiliation.getVisibility());
    assertEquals("Eine Institution", existingAffiliation.getOrganization().getName());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Response(javax.ws.rs.core.Response) Organization(org.orcid.jaxb.model.message.Organization) Affiliations(org.orcid.jaxb.model.message.Affiliations) OrcidIdentifier(org.orcid.jaxb.model.message.OrcidIdentifier) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrganizationAddress(org.orcid.jaxb.model.message.OrganizationAddress) OrcidActivities(org.orcid.jaxb.model.message.OrcidActivities) Affiliation(org.orcid.jaxb.model.message.Affiliation) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with Affiliation

use of org.orcid.jaxb.model.message.Affiliation in project ORCID-Source by ORCID.

the class OrcidProfileManagerImpl method dedupeAffiliations.

private Affiliations dedupeAffiliations(Affiliations affiliations) {
    Set<Affiliation> affiliationSet = new LinkedHashSet<Affiliation>();
    for (Affiliation affiliation : affiliations.getAffiliation()) {
        orcidProfileCleaner.clean(affiliation);
        affiliationSet.add(affiliation);
    }
    Affiliations dedupedAffiliations = new Affiliations();
    dedupedAffiliations.getAffiliation().addAll(affiliationSet);
    return dedupedAffiliations;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Affiliations(org.orcid.jaxb.model.message.Affiliations) Affiliation(org.orcid.jaxb.model.message.Affiliation)

Example 15 with Affiliation

use of org.orcid.jaxb.model.message.Affiliation in project ORCID-Source by ORCID.

the class OrcidProfileManagerImpl method checkAndUpdateDisambiguatedOrganization.

private void checkAndUpdateDisambiguatedOrganization(List<Affiliation> affiliations) {
    if (affiliations != null && !affiliations.isEmpty()) {
        for (Affiliation affiliation : affiliations) {
            Organization org = affiliation.getOrganization();
            OrgEntity orgEntity = orgManager.getOrgEntity(org);
            // If the org exists
            if (orgEntity != null) {
                // And it have a disambiguated org
                if (orgEntity.getOrgDisambiguated() != null) {
                    // Update the desambiguated org
                    org.setDisambiguatedOrganization(adapter.getDisambiguatedOrganization(orgEntity.getOrgDisambiguated()));
                } else {
                    // Null the disambiguated organization
                    org.setDisambiguatedOrganization(null);
                }
            }
        }
    }
}
Also used : Organization(org.orcid.jaxb.model.message.Organization) Affiliation(org.orcid.jaxb.model.message.Affiliation) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Aggregations

Affiliation (org.orcid.jaxb.model.message.Affiliation)29 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)18 Affiliations (org.orcid.jaxb.model.message.Affiliations)16 Test (org.junit.Test)14 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)13 Organization (org.orcid.jaxb.model.message.Organization)12 OrcidActivities (org.orcid.jaxb.model.message.OrcidActivities)11 OrganizationAddress (org.orcid.jaxb.model.message.OrganizationAddress)10 DBUnitTest (org.orcid.test.DBUnitTest)8 OrcidIdentifier (org.orcid.jaxb.model.message.OrcidIdentifier)7 Transactional (org.springframework.transaction.annotation.Transactional)7 Response (javax.ws.rs.core.Response)5 ClientResponse (com.sun.jersey.api.client.ClientResponse)4 Funding (org.orcid.jaxb.model.message.Funding)4 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)4 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)4 DisambiguatedOrganization (org.orcid.jaxb.model.message.DisambiguatedOrganization)3 FuzzyDate (org.orcid.jaxb.model.message.FuzzyDate)3 PersonalDetails (org.orcid.jaxb.model.message.PersonalDetails)3 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)3