Search in sources :

Example 11 with Visibility

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

the class OrcidProfileManagerImpl method addAffiliations.

/**
     * Adds a new {@link List<org.orcid.jaxb.model.message.Affiliation<}
     * to the {@link} OrcidProfile} and returns the updated values
     * 
     * @param updatedOrcidProfile
     * @return
     */
@Override
@Transactional
public void addAffiliations(OrcidProfile updatedOrcidProfile) {
    String orcid = updatedOrcidProfile.getOrcidIdentifier().getPath();
    OrcidProfile existingProfile = retrieveOrcidProfile(orcid);
    if (existingProfile == null) {
        throw new IllegalArgumentException("No record found for " + orcid);
    }
    Affiliations existingAffiliations = existingProfile.retrieveAffiliations();
    Affiliations updatedAffiliations = updatedOrcidProfile.retrieveAffiliations();
    Visibility workVisibilityDefault = existingProfile.getOrcidInternal().getPreferences().getActivitiesVisibilityDefault().getValue();
    Boolean claimed = existingProfile.getOrcidHistory().isClaimed();
    setAffiliationPrivacy(updatedAffiliations, workVisibilityDefault, claimed == null ? false : claimed);
    updatedAffiliations = dedupeAffiliations(updatedAffiliations);
    String amenderOrcid = sourceManager.retrieveSourceOrcid();
    addSourceToAffiliations(updatedAffiliations, amenderOrcid);
    List<Affiliation> updatedAffiliationsList = updatedAffiliations.getAffiliation();
    checkAndUpdateDisambiguatedOrganization(updatedAffiliationsList);
    checkForAlreadyExistingAffiliations(existingAffiliations, updatedAffiliationsList);
    persistAddedAffiliations(orcid, updatedAffiliationsList);
    profileDao.flush();
    boolean notificationsEnabled = existingProfile.getOrcidInternal().getPreferences().getNotificationsEnabled();
    if (notificationsEnabled) {
        notificationManager.sendAmendEmail(existingProfile, AmendedSection.AFFILIATION);
    }
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Affiliations(org.orcid.jaxb.model.message.Affiliations) Visibility(org.orcid.jaxb.model.message.Visibility) Affiliation(org.orcid.jaxb.model.message.Affiliation) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with Visibility

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

the class OrcidProfileManagerImpl method addFundings.

/**
     * Adds a new {@link List&lt;org.orcid.jaxb.model.message.FundingList&lt;}
     * to the {@link} OrcidProfile} and returns the updated values
     * 
     * @param updatedOrcidProfile
     * @return
     */
@Override
@Transactional
public void addFundings(OrcidProfile updatedOrcidProfile) {
    String orcid = updatedOrcidProfile.getOrcidIdentifier().getPath();
    OrcidProfile existingProfile = retrieveOrcidProfile(orcid);
    if (existingProfile == null) {
        throw new IllegalArgumentException("No record found for " + orcid);
    }
    String amenderOrcid = sourceManager.retrieveSourceOrcid();
    FundingList existingFundingList = existingProfile.retrieveFundings();
    // updates the amount format to the right format according to the
    // current locale
    setFundingAmountsWithTheCorrectFormat(updatedOrcidProfile);
    FundingList updatedFundingList = updatedOrcidProfile.retrieveFundings();
    Visibility workVisibilityDefault = existingProfile.getOrcidInternal().getPreferences().getActivitiesVisibilityDefault().getValue();
    Boolean claimed = existingProfile.getOrcidHistory().isClaimed();
    setFundingPrivacy(updatedFundingList, workVisibilityDefault, claimed == null ? false : claimed);
    updatedFundingList = dedupeFundings(updatedFundingList);
    addSourceToFundings(updatedFundingList, amenderOrcid);
    List<Funding> updatedList = updatedFundingList.getFundings();
    checkForAlreadyExistingFundings(existingFundingList, updatedList);
    persistAddedFundings(orcid, updatedList);
    profileDao.flush();
    boolean notificationsEnabled = existingProfile.getOrcidInternal().getPreferences().getNotificationsEnabled();
    if (notificationsEnabled) {
        notificationManager.sendAmendEmail(existingProfile, AmendedSection.FUNDING);
    }
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) FundingList(org.orcid.jaxb.model.message.FundingList) Funding(org.orcid.jaxb.model.message.Funding) Visibility(org.orcid.jaxb.model.message.Visibility) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with Visibility

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

the class OrcidProfileManagerImpl method addDefaultVisibilityToBioItems.

private void addDefaultVisibilityToBioItems(OrcidProfile orcidProfile, Visibility defaultActivityVis, Boolean isClaimed) {
    if (defaultActivityVis == null) {
        defaultActivityVis = Visibility.PRIVATE;
    }
    if (isClaimed == null) {
        isClaimed = false;
    }
    if (orcidProfile.getOrcidBio() != null) {
        if (orcidProfile.getOrcidBio().getBiography() != null) {
            if (isClaimed) {
                orcidProfile.getOrcidBio().getBiography().setVisibility(defaultActivityVis);
            } else {
                Visibility visibility = orcidProfile.getOrcidBio().getBiography().getVisibility();
                orcidProfile.getOrcidBio().getBiography().setVisibility(visibility != null ? visibility : Visibility.PRIVATE);
            }
        }
        if (orcidProfile.getOrcidBio().getExternalIdentifiers() != null) {
            Visibility listVisibility = orcidProfile.getOrcidBio().getExternalIdentifiers().getVisibility();
            for (ExternalIdentifier x : orcidProfile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier()) {
                if (isClaimed) {
                    x.setVisibility(defaultActivityVis);
                } else {
                    x.setVisibility(listVisibility != null ? listVisibility : Visibility.PRIVATE);
                }
            }
        }
        if (orcidProfile.getOrcidBio().getKeywords() != null) {
            Visibility listVisibility = orcidProfile.getOrcidBio().getKeywords().getVisibility();
            for (Keyword x : orcidProfile.getOrcidBio().getKeywords().getKeyword()) {
                if (isClaimed) {
                    x.setVisibility(defaultActivityVis);
                } else {
                    x.setVisibility(listVisibility != null ? listVisibility : Visibility.PRIVATE);
                }
            }
        }
        if (orcidProfile.getOrcidBio().getResearcherUrls() != null) {
            Visibility listVisibility = orcidProfile.getOrcidBio().getResearcherUrls().getVisibility();
            for (ResearcherUrl x : orcidProfile.getOrcidBio().getResearcherUrls().getResearcherUrl()) {
                if (isClaimed) {
                    x.setVisibility(defaultActivityVis);
                } else {
                    x.setVisibility(listVisibility != null ? listVisibility : Visibility.PRIVATE);
                }
            }
        }
        if (orcidProfile.getOrcidBio().getPersonalDetails() != null && orcidProfile.getOrcidBio().getPersonalDetails().getOtherNames() != null) {
            Visibility listVisibility = orcidProfile.getOrcidBio().getPersonalDetails().getOtherNames().getVisibility();
            for (OtherName x : orcidProfile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName()) {
                if (isClaimed) {
                    x.setVisibility(defaultActivityVis);
                } else {
                    x.setVisibility(listVisibility != null ? listVisibility : Visibility.PRIVATE);
                }
            }
        }
        if (orcidProfile.getOrcidBio().getContactDetails() != null && orcidProfile.getOrcidBio().getContactDetails().getAddress() != null && orcidProfile.getOrcidBio().getContactDetails().getAddress().getCountry() != null) {
            Country country = orcidProfile.getOrcidBio().getContactDetails().getAddress().getCountry();
            if (isClaimed) {
                country.setVisibility(defaultActivityVis);
            } else {
                country.setVisibility(country.getVisibility() != null ? country.getVisibility() : Visibility.PRIVATE);
            }
        }
    }
}
Also used : Keyword(org.orcid.jaxb.model.message.Keyword) ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) OtherName(org.orcid.jaxb.model.message.OtherName) Country(org.orcid.jaxb.model.message.Country) Visibility(org.orcid.jaxb.model.message.Visibility) ResearcherUrl(org.orcid.jaxb.model.message.ResearcherUrl)

Example 14 with Visibility

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

the class DefaultPermissionChecker method getVisibilitiesForOauth2Authentication.

private Set<Visibility> getVisibilitiesForOauth2Authentication(OAuth2Authentication oAuth2Authentication, OrcidMessage orcidMessage, ScopePathType requiredScope) {
    Set<Visibility> visibilities = new HashSet<Visibility>();
    visibilities.add(Visibility.PUBLIC);
    String orcid = orcidMessage.getOrcidProfile().getOrcidIdentifier().getPath();
    // effectively means that the user can only see the public data
    try {
        checkScopes(oAuth2Authentication, requiredScope);
    } catch (AccessControlException e) {
        return visibilities;
    }
    // we can allow for access of protected data
    if (!oAuth2Authentication.isClientOnly() && oAuth2Authentication.getPrincipal() != null && ProfileEntity.class.isAssignableFrom(oAuth2Authentication.getPrincipal().getClass())) {
        ProfileEntity principal = (ProfileEntity) oAuth2Authentication.getPrincipal();
        visibilities.add(Visibility.REGISTERED_ONLY);
        if (principal != null && principal.getId().equals(orcid)) {
            Set<String> requestedScopes = oAuth2Authentication.getOAuth2Request().getScope();
            for (String scope : requestedScopes) {
                if (ScopePathType.hasStringScope(scope, requiredScope)) {
                    visibilities.add(Visibility.LIMITED);
                    break;
                }
            }
        }
    // This is a client credential authenticated client. If the profile
    // was created using this client and it
    // hasn't been claimed, it's theirs to read
    } else if (oAuth2Authentication.isClientOnly()) {
        OAuth2Request authorizationRequest = oAuth2Authentication.getOAuth2Request();
        String clientId = authorizationRequest.getClientId();
        String sponsorOrcid = getSponsorOrcid(orcidMessage);
        if (StringUtils.isNotBlank(sponsorOrcid) && clientId.equals(sponsorOrcid) && !orcidMessage.getOrcidProfile().getOrcidHistory().isClaimed()) {
            visibilities.add(Visibility.LIMITED);
            visibilities.add(Visibility.PRIVATE);
        }
    }
    return visibilities;
}
Also used : OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) AccessControlException(java.security.AccessControlException) Visibility(org.orcid.jaxb.model.message.Visibility) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) HashSet(java.util.HashSet)

Example 15 with Visibility

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

the class OrcidJaxbCopyManagerImpl method copyUpdatedKeywordsToExistingPreservingVisibility.

@Override
public void copyUpdatedKeywordsToExistingPreservingVisibility(OrcidBio existing, OrcidBio updated) {
    if (updated.getKeywords() == null) {
        return;
    }
    Visibility existingKeywordsVisibility = existing.getKeywords() != null && existing.getKeywords().getVisibility() != null ? existing.getKeywords().getVisibility() : OrcidVisibilityDefaults.KEYWORD_DEFAULT.getVisibility();
    Visibility updatedKeywordsVisibility = updated.getKeywords().getVisibility() != null ? updated.getKeywords().getVisibility() : existingKeywordsVisibility;
    Keywords updatedKeywords = updated.getKeywords();
    updatedKeywords.setVisibility(updatedKeywordsVisibility);
    existing.setKeywords(updatedKeywords);
}
Also used : Keywords(org.orcid.jaxb.model.message.Keywords) Visibility(org.orcid.jaxb.model.message.Visibility)

Aggregations

Visibility (org.orcid.jaxb.model.message.Visibility)17 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)6 Transactional (org.springframework.transaction.annotation.Transactional)6 HashSet (java.util.HashSet)4 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)4 AccessControlException (java.security.AccessControlException)2 Date (java.util.Date)2 OrcidOAuth2Authentication (org.orcid.core.oauth.OrcidOAuth2Authentication)2 Affiliation (org.orcid.jaxb.model.message.Affiliation)2 Country (org.orcid.jaxb.model.message.Country)2 ExternalIdentifiers (org.orcid.jaxb.model.message.ExternalIdentifiers)2 Funding (org.orcid.jaxb.model.message.Funding)2 Keywords (org.orcid.jaxb.model.message.Keywords)2 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)2 OtherNames (org.orcid.jaxb.model.message.OtherNames)2 ResearcherUrls (org.orcid.jaxb.model.message.ResearcherUrls)2 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)2 ArrayList (java.util.ArrayList)1 AfterReturning (org.aspectj.lang.annotation.AfterReturning)1 Test (org.junit.Test)1