Search in sources :

Example 16 with Affiliation

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

the class OrcidMessageUtil method setSourceName.

public void setSourceName(OrcidProfile orcidProfile) {
    if (orcidProfile != null) {
        if (orcidProfile.getOrcidActivities() != null) {
            OrcidActivities orcidActivities = orcidProfile.getOrcidActivities();
            if (orcidActivities.getAffiliations() != null) {
                Affiliations affs = orcidActivities.getAffiliations();
                List<Affiliation> affList = affs.getAffiliation();
                if (affList != null) {
                    for (Affiliation aff : affList) {
                        setSourceName(aff);
                    }
                }
            }
            if (orcidActivities.getFundings() != null) {
                FundingList fundingList = orcidActivities.getFundings();
                List<Funding> fundings = fundingList.getFundings();
                if (fundings != null) {
                    for (Funding funding : fundings) {
                        setSourceName(funding);
                    }
                }
            }
            if (orcidActivities.getOrcidWorks() != null) {
                OrcidWorks orcidWorks = orcidActivities.getOrcidWorks();
                List<OrcidWork> works = orcidWorks.getOrcidWork();
                if (works != null) {
                    for (OrcidWork work : works) {
                        setSourceName(work);
                    }
                }
            }
        }
        if (orcidProfile.getOrcidBio() != null) {
            OrcidBio orcidBio = orcidProfile.getOrcidBio();
            if (orcidBio.getContactDetails() != null) {
                Address address = orcidBio.getContactDetails().getAddress();
                if (address != null) {
                    setSourceName(address);
                }
            }
            if (orcidBio.getExternalIdentifiers() != null) {
                ExternalIdentifiers extIds = orcidBio.getExternalIdentifiers();
                List<ExternalIdentifier> extIdsList = extIds.getExternalIdentifier();
                if (extIdsList != null) {
                    for (ExternalIdentifier extId : extIdsList) {
                        setSourceName(extId);
                    }
                }
            }
            if (orcidBio.getKeywords() != null) {
                Keywords keywords = orcidBio.getKeywords();
                List<Keyword> keywordList = keywords.getKeyword();
                if (keywordList != null) {
                    for (Keyword keyword : keywordList) {
                        setSourceName(keyword);
                    }
                }
            }
            if (orcidBio.getPersonalDetails() != null) {
                OtherNames otherNames = orcidBio.getPersonalDetails().getOtherNames();
                if (otherNames != null) {
                    List<OtherName> otherNameList = otherNames.getOtherName();
                    if (otherNameList != null) {
                        for (OtherName otherName : otherNameList) {
                            setSourceName(otherName);
                        }
                    }
                }
            }
            if (orcidBio.getResearcherUrls() != null) {
                ResearcherUrls rUrls = orcidBio.getResearcherUrls();
                List<ResearcherUrl> rUrlList = rUrls.getResearcherUrl();
                if (rUrlList != null) {
                    for (ResearcherUrl rUrl : rUrlList) {
                        setSourceName(rUrl);
                    }
                }
            }
        }
    }
}
Also used : Keywords(org.orcid.jaxb.model.message.Keywords) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) Address(org.orcid.jaxb.model.message.Address) Keyword(org.orcid.jaxb.model.message.Keyword) Funding(org.orcid.jaxb.model.message.Funding) ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) OtherNames(org.orcid.jaxb.model.message.OtherNames) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) OtherName(org.orcid.jaxb.model.message.OtherName) OrcidActivities(org.orcid.jaxb.model.message.OrcidActivities) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks) FundingList(org.orcid.jaxb.model.message.FundingList) Affiliations(org.orcid.jaxb.model.message.Affiliations) ResearcherUrls(org.orcid.jaxb.model.message.ResearcherUrls) ResearcherUrl(org.orcid.jaxb.model.message.ResearcherUrl) ExternalIdentifiers(org.orcid.jaxb.model.message.ExternalIdentifiers) Affiliation(org.orcid.jaxb.model.message.Affiliation)

Example 17 with Affiliation

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

the class Api12Helper method addAffiliation.

protected static void addAffiliation(String userOrcid, String token, String orgName, T2OAuthAPIService<ClientResponse> oauthT2Client) {
    OrcidMessage orcidMessage = new OrcidMessage();
    orcidMessage.setMessageVersion(OrcidMessage.DEFAULT_VERSION);
    OrcidProfile orcidProfile = new OrcidProfile();
    orcidMessage.setOrcidProfile(orcidProfile);
    OrcidActivities orcidActivities = new OrcidActivities();
    orcidProfile.setOrcidActivities(orcidActivities);
    Affiliations affiliations = new Affiliations();
    orcidActivities.setAffiliations(affiliations);
    Affiliation affiliation = new Affiliation();
    affiliation.setVisibility(Visibility.LIMITED);
    affiliations.getAffiliation().add(affiliation);
    affiliation.setType(AffiliationType.EDUCATION);
    Organization organization = new Organization();
    affiliation.setOrganization(organization);
    organization.setName(orgName);
    OrganizationAddress organizationAddress = new OrganizationAddress();
    organization.setAddress(organizationAddress);
    organizationAddress.setCity("Edinburgh");
    organizationAddress.setCountry(Iso3166Country.GB);
    ClientResponse clientResponse = oauthT2Client.addAffiliationsXml(userOrcid, orcidMessage, token);
    assertEquals(201, clientResponse.getStatus());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) ClientResponse(com.sun.jersey.api.client.ClientResponse) Organization(org.orcid.jaxb.model.message.Organization) Affiliations(org.orcid.jaxb.model.message.Affiliations) 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)

Example 18 with Affiliation

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

the class Api12MembersTest method viewOwnPrivateAffiliationsTest.

@Test
public void viewOwnPrivateAffiliationsTest() throws InterruptedException, JSONException {
    changeDefaultUserVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
    String client1Id = getClient1ClientId();
    String client1RedirectUri = getClient1RedirectUri();
    String client1Secret = getClient1ClientSecret();
    String client2Id = getClient2ClientId();
    String client2RedirectUri = getClient2RedirectUri();
    String client2Secret = getClient2ClientSecret();
    String userId = getUser1OrcidId();
    String password = getUser1Password();
    String client1AccessToken = getAccessToken(userId, password, Arrays.asList("/activities/read-limited", "/activities/update"), client1Id, client1Secret, client1RedirectUri, true);
    String client2AccessToken = getAccessToken(userId, password, Arrays.asList("/activities/read-limited", "/activities/update"), client2Id, client2Secret, client2RedirectUri, true);
    String orgName1 = "Client 1 - Education " + System.currentTimeMillis();
    String orgName2 = "Client 2 - Education " + System.currentTimeMillis();
    Api12Helper.addAffiliation(userId, client1AccessToken, orgName1, t2OAuthClient_1_2);
    Api12Helper.addAffiliation(userId, client2AccessToken, orgName2, t2OAuthClient_1_2);
    Long putCode1 = 0L;
    Long putCode2 = 0L;
    // Fetch with client 1 and verify it can only see his private affiliations
    ClientResponse client1Response = t2OAuthClient_1_2.viewAffiliationDetailsXml(userId, client1AccessToken);
    assertNotNull(client1Response);
    assertEquals(200, client1Response.getStatus());
    OrcidMessage orcidMessageWithNewFunding = client1Response.getEntity(OrcidMessage.class);
    assertNotNull(orcidMessageWithNewFunding);
    assertNotNull(orcidMessageWithNewFunding.getOrcidProfile());
    assertNotNull(orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities());
    assertNotNull(orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities().getAffiliations());
    assertNotNull(orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities().getAffiliations().getAffiliation());
    boolean found = false;
    for (Affiliation affiliation : orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities().getAffiliations().getAffiliation()) {
        if (orgName2.equals(affiliation.getOrganization().getName())) {
            fail("I found affiliation for client # 2, which is wrong since it is private");
        }
        if (orgName1.equals(affiliation.getOrganization().getName())) {
            assertEquals(Visibility.PRIVATE, affiliation.getVisibility());
            putCode1 = Long.valueOf(affiliation.getPutCode());
            found = true;
        }
    }
    assertTrue(found);
    // Fetch with client 2 and verify it can only see his private affiliations
    ClientResponse client2Response = t2OAuthClient_1_2.viewAffiliationDetailsXml(userId, client2AccessToken);
    assertNotNull(client2Response);
    assertEquals(200, client2Response.getStatus());
    orcidMessageWithNewFunding = client2Response.getEntity(OrcidMessage.class);
    assertNotNull(orcidMessageWithNewFunding);
    assertNotNull(orcidMessageWithNewFunding.getOrcidProfile());
    assertNotNull(orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities());
    assertNotNull(orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities().getAffiliations());
    assertNotNull(orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities().getAffiliations().getAffiliation());
    found = false;
    for (Affiliation affiliation : orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities().getAffiliations().getAffiliation()) {
        if (orgName1.equals(affiliation.getOrganization().getName())) {
            fail("I found funding for client # 1, which is wrong since it is private");
        }
        if (orgName2.equals(affiliation.getOrganization().getName())) {
            assertEquals(Visibility.PRIVATE, affiliation.getVisibility());
            putCode2 = Long.valueOf(affiliation.getPutCode());
            found = true;
        }
    }
    assertTrue(found);
    // Delete both affiliations before finishing
    ClientResponse deleteResponse = memberV2ApiClient.deleteEducationXml(this.getUser1OrcidId(), putCode1, client1AccessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
    deleteResponse = memberV2ApiClient.deleteEducationXml(this.getUser1OrcidId(), putCode2, client2AccessToken);
    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 19 with Affiliation

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

the class JpaJaxbEntityAdapterToOrcidProfileTest method checkAffiliations.

private void checkAffiliations(List<Affiliation> affiliations) {
    assertNotNull(affiliations);
    assertEquals(3, affiliations.size());
    Affiliation affiliation = affiliations.get(2);
    assertEquals(Visibility.LIMITED, affiliation.getVisibility());
    assertEquals("An institution", affiliation.getOrganization().getName());
    assertEquals("A Department", affiliation.getDepartmentName());
    assertEquals("2010-07-02", affiliation.getStartDate().toString());
    assertEquals("2011-07-02", affiliation.getEndDate().toString());
    assertEquals("Primary Researcher", affiliation.getRoleTitle());
    DisambiguatedOrganization disambiguatedAffiliation = affiliation.getOrganization().getDisambiguatedOrganization();
    assertNotNull(disambiguatedAffiliation);
    assertEquals("abc456", disambiguatedAffiliation.getDisambiguatedOrganizationIdentifier());
    assertEquals("WDB", disambiguatedAffiliation.getDisambiguationSource());
    checkAddress(affiliation.getOrganization().getAddress());
}
Also used : DisambiguatedOrganization(org.orcid.jaxb.model.message.DisambiguatedOrganization) Affiliation(org.orcid.jaxb.model.message.Affiliation)

Example 20 with Affiliation

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

the class OrcidProfileManagerImplTest method testOrgReuse.

@Test
@Transactional
@Rollback(true)
public void testOrgReuse() {
    OrcidProfile profile1 = createBasicProfile();
    OrcidHistory history = new OrcidHistory();
    history.setSubmissionDate(new SubmissionDate(DateUtils.convertToXMLGregorianCalendar(new Date())));
    profile1.setOrcidHistory(history);
    history.setClaimed(new Claimed(true));
    OrcidActivities orcidActivities = profile1.getOrcidActivities();
    Affiliations affiliations = new Affiliations();
    orcidActivities.setAffiliations(affiliations);
    Affiliation affiliation = new Affiliation();
    affiliations.getAffiliation().add(affiliation);
    Organization organization = new Organization();
    affiliation.setOrganization(organization);
    organization.setName("New College");
    OrganizationAddress organizationAddress = new OrganizationAddress();
    organization.setAddress(organizationAddress);
    organizationAddress.setCity("Edinburgh");
    organizationAddress.setCountry(Iso3166Country.GB);
    orcidProfileManager.createOrcidProfile(profile1, false, false);
    ProfileEntity profileEntity = profileDao.find(TEST_ORCID);
    assertEquals(1, profileEntity.getOrgAffiliationRelations().size());
    OrgEntity orgEntity = profileEntity.getOrgAffiliationRelations().iterator().next().getOrg();
    assertNotNull(orgEntity);
    // Now create another profile with the same affiliation and check that
    // the org is reused;
    String otherOrcid = "4444-4444-4444-4448";
    OrcidProfile profile2 = createBasicProfile();
    profile2.setOrcidIdentifier(otherOrcid);
    List<Email> emailList2 = profile2.getOrcidBio().getContactDetails().getEmail();
    emailList2.clear();
    emailList2.add(new Email("another@semantico.com"));
    profile2.getOrcidActivities().setAffiliations(affiliations);
    orcidProfileManager.createOrcidProfile(profile2, false, false);
    ProfileEntity profileEntity2 = profileDao.find(otherOrcid);
    assertEquals(1, profileEntity2.getOrgAffiliationRelations().size());
    OrgEntity orgEntity2 = profileEntity2.getOrgAffiliationRelations().iterator().next().getOrg();
    assertNotNull(orgEntity);
    assertEquals(orgEntity.getId(), orgEntity2.getId());
}
Also used : Organization(org.orcid.jaxb.model.message.Organization) Email(org.orcid.jaxb.model.message.Email) OrganizationAddress(org.orcid.jaxb.model.message.OrganizationAddress) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) OrcidActivities(org.orcid.jaxb.model.message.OrcidActivities) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Date(java.util.Date) ApprovalDate(org.orcid.jaxb.model.message.ApprovalDate) Claimed(org.orcid.jaxb.model.message.Claimed) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Affiliations(org.orcid.jaxb.model.message.Affiliations) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) Affiliation(org.orcid.jaxb.model.message.Affiliation) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

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