Search in sources :

Example 6 with Affiliation

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

the class OrcidProfileManagerImpl method persistAddedAffiliations.

private void persistAddedAffiliations(String orcid, List<Affiliation> updatedAffiliationsList) {
    ProfileEntity profileEntity = profileDao.find(orcid);
    for (Affiliation updatedAffiliation : updatedAffiliationsList) {
        OrgAffiliationRelationEntity orgAffiliationRelationEntity = jaxb2JpaAdapter.getNewOrgAffiliationRelationEntity(updatedAffiliation, profileEntity);
        orgAffiliationRelationDao.persist(orgAffiliationRelationEntity);
    }
    orcidProfileCacheManager.remove(orcid);
}
Also used : OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Affiliation(org.orcid.jaxb.model.message.Affiliation)

Example 7 with Affiliation

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

the class Api12MembersTest method activitiesReadLimitedTest.

@Test
public void activitiesReadLimitedTest() throws InterruptedException, JSONException {
    changeDefaultUserVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
    String clientId = getClient1ClientId();
    String clientRedirectUri = getClient1RedirectUri();
    String clientSecret = getClient1ClientSecret();
    String userId = getUser1OrcidId();
    String password = getUser1Password();
    String workTitle = "Work " + System.currentTimeMillis();
    String fundingTitle = "Funding " + System.currentTimeMillis();
    String orgName = "Org_" + System.currentTimeMillis();
    String accessToken = getAccessToken(userId, password, Arrays.asList("/read-limited", "/activities/update"), clientId, clientSecret, clientRedirectUri, true);
    Long workPutCode = null;
    Api12Helper.addWork(userId, accessToken, workTitle, t2OAuthClient_1_2);
    Long fundingPutCode = null;
    Api12Helper.addFunding(userId, accessToken, fundingTitle, t2OAuthClient_1_2);
    Long affiliationPutCode = null;
    Api12Helper.addAffiliation(userId, accessToken, orgName, t2OAuthClient_1_2);
    ClientResponse worksResponse = t2OAuthClient_1_2.viewWorksDetailsXml(userId, accessToken);
    assertNotNull(worksResponse);
    assertEquals(200, worksResponse.getStatus());
    assertEquals("application/vnd.orcid+xml; charset=UTF-8; qs=5", worksResponse.getType().toString());
    OrcidMessage orcidMessageWithNewWork = worksResponse.getEntity(OrcidMessage.class);
    assertNotNull(orcidMessageWithNewWork);
    assertNotNull(orcidMessageWithNewWork.getOrcidProfile());
    assertNotNull(orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities());
    assertNotNull(orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities().getOrcidWorks());
    assertNotNull(orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork());
    assertTrue(orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork().size() > 0);
    boolean workFound = false;
    for (OrcidWork work : orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork()) {
        if (workTitle.equals(work.getWorkTitle().getTitle().getContent())) {
            // Default user visibility should be public
            assertEquals(Visibility.PUBLIC, work.getVisibility());
            assertNotNull(work.getPutCode());
            workPutCode = Long.valueOf(work.getPutCode());
            workFound = true;
        }
    }
    assertTrue(workFound);
    ClientResponse fundingResponse = t2OAuthClient_1_2.viewFundingDetailsXml(userId, accessToken);
    assertNotNull(fundingResponse);
    assertEquals(200, fundingResponse.getStatus());
    assertEquals("application/vnd.orcid+xml; charset=UTF-8; qs=5", fundingResponse.getType().toString());
    OrcidMessage orcidMessageWithNewFunding = fundingResponse.getEntity(OrcidMessage.class);
    assertNotNull(orcidMessageWithNewFunding);
    assertNotNull(orcidMessageWithNewFunding.getOrcidProfile());
    assertNotNull(orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities());
    assertNotNull(orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities().getFundings());
    assertNotNull(orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities().getFundings().getFundings());
    assertTrue(orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities().getFundings().getFundings().size() > 0);
    boolean fundingFound = false;
    for (Funding funding : orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities().getFundings().getFundings()) {
        if (fundingTitle.equals(funding.getTitle().getTitle().getContent())) {
            // Default user visibility should be public
            assertEquals(Visibility.PUBLIC, funding.getVisibility());
            assertNotNull(funding.getPutCode());
            fundingPutCode = Long.valueOf(funding.getPutCode());
            fundingFound = true;
        }
    }
    assertTrue(fundingFound);
    ClientResponse affiliationResponse = t2OAuthClient_1_2.viewAffiliationDetailsXml(userId, accessToken);
    assertNotNull(affiliationResponse);
    assertEquals(200, affiliationResponse.getStatus());
    assertEquals("application/vnd.orcid+xml; charset=UTF-8; qs=5", affiliationResponse.getType().toString());
    OrcidMessage orcidMessageWithNewAffiliation = affiliationResponse.getEntity(OrcidMessage.class);
    assertNotNull(orcidMessageWithNewAffiliation);
    assertNotNull(orcidMessageWithNewAffiliation.getOrcidProfile());
    assertNotNull(orcidMessageWithNewAffiliation.getOrcidProfile().getOrcidActivities());
    assertNotNull(orcidMessageWithNewAffiliation.getOrcidProfile().getOrcidActivities().getAffiliations());
    assertNotNull(orcidMessageWithNewAffiliation.getOrcidProfile().getOrcidActivities().getAffiliations().getAffiliation());
    assertTrue(orcidMessageWithNewAffiliation.getOrcidProfile().getOrcidActivities().getAffiliations().getAffiliation().size() > 0);
    boolean affiliationFound = false;
    for (Affiliation affiliation : orcidMessageWithNewAffiliation.getOrcidProfile().getOrcidActivities().getAffiliations().getAffiliation()) {
        if (orgName.equals(affiliation.getOrganization().getName())) {
            // Default user visibility should be public
            assertEquals(Visibility.PUBLIC, affiliation.getVisibility());
            assertNotNull(affiliation.getPutCode());
            affiliationPutCode = Long.valueOf(affiliation.getPutCode());
            affiliationFound = true;
        }
    }
    assertTrue(affiliationFound);
    // Delete work
    ClientResponse deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), workPutCode, accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
    // Delete funding
    deleteResponse = memberV2ApiClient.deleteFundingXml(this.getUser1OrcidId(), fundingPutCode, accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
    // Delete affiliation
    deleteResponse = memberV2ApiClient.deleteEducationXml(this.getUser1OrcidId(), affiliationPutCode, accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Funding(org.orcid.jaxb.model.message.Funding) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) Affiliation(org.orcid.jaxb.model.message.Affiliation) Test(org.junit.Test)

Example 8 with Affiliation

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

the class T2OrcidApiServiceVersionedDelegatorTest method testCreateWithAffiliations.

@Test
public void testCreateWithAffiliations() throws JAXBException {
    setUpSecurityContextForClientOnly();
    OrcidMessage orcidMessage = getOrcidMessage("/orcid-message-for-create-latest.xml");
    Response createResponse = t2OrcidApiServiceDelegatorLatest.createProfile(mockedUriInfo, orcidMessage);
    assertNotNull(createResponse);
    assertEquals(HttpStatus.SC_CREATED, createResponse.getStatus());
    String location = ((URI) createResponse.getMetadata().getFirst("Location")).getPath();
    assertNotNull(location);
    String orcid = location.substring(1, 20);
    Response readResponse = t2OrcidApiServiceDelegatorLatest.findFullDetails(orcid);
    assertNotNull(readResponse);
    assertEquals(HttpStatus.SC_OK, readResponse.getStatus());
    OrcidMessage retrievedMessage = (OrcidMessage) readResponse.getEntity();
    OrcidProfile orcidProfile = retrievedMessage.getOrcidProfile();
    assertEquals(orcid, orcidProfile.getOrcidIdentifier().getPath());
    Affiliations affiliations = orcidProfile.retrieveAffiliations();
    assertNotNull(affiliations);
    assertEquals(1, affiliations.getAffiliation().size());
    Affiliation affiliation = affiliations.getAffiliation().get(0);
    assertEquals(Visibility.PRIVATE, affiliation.getVisibility());
    Source source = affiliation.getSource();
    assertNotNull(source);
    String sourceOrcid = source.retrieveSourcePath();
    assertNotNull(sourceOrcid);
    assertEquals("APP-5555555555555555", sourceOrcid);
}
Also used : Response(javax.ws.rs.core.Response) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Affiliations(org.orcid.jaxb.model.message.Affiliations) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) URI(java.net.URI) Source(org.orcid.jaxb.model.message.Source) Affiliation(org.orcid.jaxb.model.message.Affiliation) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 9 with Affiliation

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

the class T2OrcidApiServiceVersionedDelegatorTest method buildMessageWithAffiliation.

private OrcidMessage buildMessageWithAffiliation(AffiliationType type, String dept, String role, String orcid) {
    OrcidMessage orcidMessage = new OrcidMessage();
    orcidMessage.setMessageVersion("1.2");
    OrcidProfile orcidProfile = new OrcidProfile();
    orcidMessage.setOrcidProfile(orcidProfile);
    orcidProfile.setOrcidIdentifier(new OrcidIdentifier(orcid));
    OrcidActivities orcidActivities = new OrcidActivities();
    orcidProfile.setOrcidActivities(orcidActivities);
    Affiliations affiliations = new Affiliations();
    Affiliation affiliation = new Affiliation();
    affiliation.setStartDate(new FuzzyDate(2010, 01, 01));
    affiliation.setEndDate(new FuzzyDate(2015, 01, 01));
    affiliation.setDepartmentName(dept);
    affiliation.setRoleTitle(role);
    affiliation.setType(type);
    Organization organization = new Organization();
    organization.setName("My Org");
    OrganizationAddress add = new OrganizationAddress();
    add.setCity("My City");
    add.setCountry(Iso3166Country.US);
    organization.setAddress(add);
    DisambiguatedOrganization dorg = new DisambiguatedOrganization();
    dorg.setDisambiguatedOrganizationIdentifier("disambiguated org ID");
    dorg.setDisambiguationSource("THESOURCE");
    organization.setDisambiguatedOrganization(dorg);
    affiliation.setOrganization(organization);
    affiliations.getAffiliation().add(affiliation);
    orcidActivities.setAffiliations(affiliations);
    return orcidMessage;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) DisambiguatedOrganization(org.orcid.jaxb.model.message.DisambiguatedOrganization) Organization(org.orcid.jaxb.model.message.Organization) DisambiguatedOrganization(org.orcid.jaxb.model.message.DisambiguatedOrganization) 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) FuzzyDate(org.orcid.jaxb.model.message.FuzzyDate) OrcidActivities(org.orcid.jaxb.model.message.OrcidActivities) Affiliation(org.orcid.jaxb.model.message.Affiliation)

Example 10 with Affiliation

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

the class VisibilityFilterImpl method filter.

/**
 * Remove the elements that are not present in the list of set of
 * {@link org.orcid.jaxb.model.message .Visibility}s present in the array
 * passed in.
 *
 * @param messageToBeFiltered
 *            the {@link org.orcid.jaxb.model.message.OrcidMessage} that
 *            will be traversed looking for
 *            {@link org .orcid.jaxb.model.message.VisibilityType} elements.
 * @param source
 *            The orcid source that is executing the request
 * @param removeAttribute
 *            should all {@link org.orcid.jaxb.model.message.Visibility}
 *            elements be removed from the object graph. This has the effect
 *            that they will not be present in the resulting JAXB
 *            serialisation.
 * @param visibilities
 *            What {@link org.orcid.jaxb.model.message.Visibility} elements
 *            should be allowed.
 * @return the cleansed {@link org.orcid.jaxb.model.message.OrcidMessage}
 */
@Override
public OrcidMessage filter(OrcidMessage messageToBeFiltered, final String sourceId, final boolean allowPrivateWorks, final boolean allowPrivateFunding, final boolean allowPrivateAffiliations, Visibility... visibilities) {
    if (messageToBeFiltered == null || visibilities == null || visibilities.length == 0) {
        return null;
    }
    String messageIdForLog = getMessageIdForLog(messageToBeFiltered);
    LOGGER.debug("About to filter message: " + messageIdForLog);
    final Set<Visibility> visibilitySet = new HashSet<Visibility>(Arrays.asList(visibilities));
    if (visibilitySet.contains(Visibility.SYSTEM)) {
        return messageToBeFiltered;
    } else {
        TreeCleaner treeCleaner = new TreeCleaner();
        treeCleaner.clean(messageToBeFiltered, new TreeCleaningStrategy() {

            public TreeCleaningDecision needsStripping(Object obj) {
                TreeCleaningDecision decision = TreeCleaningDecision.DEFAULT;
                if (obj != null) {
                    Class<?> clazz = obj.getClass();
                    if (!PojoUtil.isEmpty(sourceId)) {
                        if (allowPrivateAffiliations && Affiliation.class.isAssignableFrom(clazz)) {
                            Affiliation affiliation = (Affiliation) obj;
                            Source source = affiliation.getSource();
                            if (source != null) {
                                String sourcePath = source.retrieveSourcePath();
                                if (sourcePath != null) {
                                    if (sourceId.equals(sourcePath)) {
                                        decision = TreeCleaningDecision.IGNORE;
                                    }
                                }
                            }
                        } else if (allowPrivateFunding && Funding.class.isAssignableFrom(clazz)) {
                            Funding funding = (Funding) obj;
                            Source source = funding.getSource();
                            if (source != null) {
                                String sourcePath = source.retrieveSourcePath();
                                if (sourcePath != null) {
                                    if (sourceId.equals(sourcePath)) {
                                        decision = TreeCleaningDecision.IGNORE;
                                    }
                                }
                            }
                        } else if (allowPrivateWorks && OrcidWork.class.isAssignableFrom(clazz)) {
                            OrcidWork work = (OrcidWork) obj;
                            Source source = work.getSource();
                            if (source != null) {
                                if (sourceId.equals(source.retrieveSourcePath())) {
                                    decision = TreeCleaningDecision.IGNORE;
                                }
                            }
                        }
                    }
                    // fields are inside the country element
                    if (Address.class.isAssignableFrom(clazz)) {
                        Address address = (Address) obj;
                        // Remove empty addresses
                        if (address.getCountry() == null) {
                            decision = TreeCleaningDecision.CLEANING_REQUIRED;
                        } else {
                            Country country = address.getCountry();
                            // Allow public addresses
                            if (Visibility.PUBLIC.equals(country.getVisibility())) {
                                decision = TreeCleaningDecision.IGNORE;
                            } else if (visibilitySet.contains(Visibility.LIMITED)) {
                                // Allow limited visibility when possible
                                if (Visibility.LIMITED.equals(country.getVisibility())) {
                                    decision = TreeCleaningDecision.IGNORE;
                                } else {
                                    // As last resource, check the source
                                    Source source = country.getSource();
                                    if (source != null && sourceId != null && sourceId.equals(source.retrieveSourcePath())) {
                                        decision = TreeCleaningDecision.IGNORE;
                                    } else {
                                        decision = TreeCleaningDecision.CLEANING_REQUIRED;
                                    }
                                }
                            }
                        }
                    }
                    if (Email.class.isAssignableFrom(clazz)) {
                        // include all emails if present
                        try {
                            Authentication authentication = getAuthentication();
                            if (authentication != null && messageToBeFiltered.getOrcidProfile() != null) {
                                permissionChecker.checkPermissions(getAuthentication(), ScopePathType.EMAIL_READ_PRIVATE, messageToBeFiltered.getOrcidProfile().retrieveOrcidPath());
                                decision = TreeCleaningDecision.IGNORE;
                            }
                        } catch (AccessControlException e) {
                        // private email can't be read, do nothing here
                        }
                    }
                    // that implements PrivateVisibleToSource
                    if (sourceId != null)
                        if (PrivateVisibleToSource.class.isAssignableFrom(clazz) && visibilitySet.contains(Visibility.LIMITED)) {
                            Source source = ((PrivateVisibleToSource) obj).getSource();
                            if (source != null) {
                                if (sourceId.equals(source.retrieveSourcePath())) {
                                    decision = TreeCleaningDecision.IGNORE;
                                }
                            }
                        }
                    if (TreeCleaningDecision.DEFAULT.equals(decision)) {
                        if (WorkContributors.class.isAssignableFrom(clazz)) {
                            decision = TreeCleaningDecision.IGNORE;
                        } else if (VisibilityType.class.isAssignableFrom(clazz)) {
                            VisibilityType visibilityType = (VisibilityType) obj;
                            if ((visibilityType.getVisibility() == null || !visibilitySet.contains(visibilityType.getVisibility()))) {
                                decision = TreeCleaningDecision.CLEANING_REQUIRED;
                            }
                        }
                    }
                }
                return decision;
            }
        });
        OrcidProfile orcidProfile = messageToBeFiltered.getOrcidProfile();
        if (orcidProfile != null) {
            orcidProfile.setOrcidInternal(null);
        }
        LOGGER.debug("Finished filtering message: " + messageIdForLog);
        return messageToBeFiltered;
    }
}
Also used : Email(org.orcid.jaxb.model.message.Email) Address(org.orcid.jaxb.model.message.Address) Funding(org.orcid.jaxb.model.message.Funding) WorkContributors(org.orcid.jaxb.model.message.WorkContributors) TreeCleaner(org.orcid.core.tree.TreeCleaner) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) AccessControlException(java.security.AccessControlException) PrivateVisibleToSource(org.orcid.jaxb.model.message.PrivateVisibleToSource) Source(org.orcid.jaxb.model.message.Source) TreeCleaningDecision(org.orcid.core.tree.TreeCleaningDecision) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) PrivateVisibleToSource(org.orcid.jaxb.model.message.PrivateVisibleToSource) VisibilityType(org.orcid.jaxb.model.message.VisibilityType) Authentication(org.springframework.security.core.Authentication) Country(org.orcid.jaxb.model.message.Country) Visibility(org.orcid.jaxb.model.message.Visibility) TreeCleaningStrategy(org.orcid.core.tree.TreeCleaningStrategy) HashSet(java.util.HashSet) Affiliation(org.orcid.jaxb.model.message.Affiliation)

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