Search in sources :

Example 11 with Visibility

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

the class ProfileEntityManagerImpl method claimProfileAndUpdatePreferences.

@Override
@Transactional
public boolean claimProfileAndUpdatePreferences(String orcid, String email, Locale locale, Claim claim) {
    //Verify the email
    boolean emailVerified = emailManager.verifySetCurrentAndPrimary(orcid, email);
    if (!emailVerified) {
        throw new InvalidParameterException("Unable to claim and verify email: " + email + " for user: " + orcid);
    }
    //Update the profile entity fields
    ProfileEntity profile = profileDao.find(orcid);
    profile.setLastModified(new Date());
    profile.setIndexingStatus(IndexingStatus.REINDEX);
    profile.setClaimed(true);
    profile.setCompletedDate(new Date());
    if (locale != null) {
        profile.setLocale(org.orcid.jaxb.model.common_v2.Locale.fromValue(locale.value()));
    }
    if (claim != null) {
        profile.setSendChangeNotifications(claim.getSendChangeNotifications().getValue());
        profile.setSendOrcidNews(claim.getSendOrcidNews().getValue());
        profile.setActivitiesVisibilityDefault(claim.getActivitiesVisibilityDefault().getVisibility());
    }
    //Update the visibility for every bio element to the visibility selected by the user
    //Update the bio
    org.orcid.jaxb.model.common_v2.Visibility defaultVisibility = org.orcid.jaxb.model.common_v2.Visibility.fromValue(claim.getActivitiesVisibilityDefault().getVisibility().value());
    if (profile.getBiographyEntity() != null) {
        profile.getBiographyEntity().setVisibility(defaultVisibility);
    }
    //Update address
    if (profile.getAddresses() != null) {
        for (AddressEntity a : profile.getAddresses()) {
            a.setVisibility(defaultVisibility);
        }
    }
    //Update the keywords
    if (profile.getKeywords() != null) {
        for (ProfileKeywordEntity k : profile.getKeywords()) {
            k.setVisibility(defaultVisibility);
        }
    }
    //Update the other names
    if (profile.getOtherNames() != null) {
        for (OtherNameEntity o : profile.getOtherNames()) {
            o.setVisibility(defaultVisibility);
        }
    }
    //Update the researcher urls
    if (profile.getResearcherUrls() != null) {
        for (ResearcherUrlEntity r : profile.getResearcherUrls()) {
            r.setVisibility(defaultVisibility);
        }
    }
    //Update the external identifiers
    if (profile.getExternalIdentifiers() != null) {
        for (ExternalIdentifierEntity e : profile.getExternalIdentifiers()) {
            e.setVisibility(defaultVisibility);
        }
    }
    profileDao.merge(profile);
    profileDao.flush();
    return true;
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) ResearcherUrlEntity(org.orcid.persistence.jpa.entities.ResearcherUrlEntity) ExternalIdentifierEntity(org.orcid.persistence.jpa.entities.ExternalIdentifierEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) InvalidParameterException(java.security.InvalidParameterException) Visibility(org.orcid.jaxb.model.common_v2.Visibility) OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) AddressEntity(org.orcid.persistence.jpa.entities.AddressEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with Visibility

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

the class ProfileEntityManagerImpl method getMemberDisplayName.

private String getMemberDisplayName(ProfileEntity member) {
    RecordNameEntity recordName = member.getRecordNameEntity();
    if (recordName == null) {
        return StringUtils.EMPTY;
    }
    //If it is a member, return the credit name
    if (OrcidType.GROUP.equals(member.getOrcidType())) {
        return recordName.getCreditName();
    }
    Visibility namesVisibilty = recordName.getVisibility();
    if (Visibility.PUBLIC.equals(namesVisibilty)) {
        if (!PojoUtil.isEmpty(recordName.getCreditName())) {
            return recordName.getCreditName();
        } else {
            String displayName = recordName.getGivenNames();
            String familyName = recordName.getFamilyName();
            if (StringUtils.isNotBlank(familyName)) {
                displayName += " " + familyName;
            }
            return displayName;
        }
    }
    return StringUtils.EMPTY;
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) Visibility(org.orcid.jaxb.model.common_v2.Visibility)

Example 13 with Visibility

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

the class ProfileFundingManagerImpl method updateFunding.

/**
     * Updates a funding that belongs to the given user
     * @param orcid
     *          The user
     * @param funding
     *          The funding to update
     * @return the updated funding                  
     * */
@Override
public Funding updateFunding(String orcid, Funding funding, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    ProfileFundingEntity pfe = profileFundingDao.getProfileFunding(orcid, funding.getPutCode());
    Visibility originalVisibility = pfe.getVisibility();
    //Save the original source
    String existingSourceId = pfe.getSourceId();
    String existingClientSourceId = pfe.getClientSourceId();
    activityValidator.validateFunding(funding, sourceEntity, false, isApiRequest, originalVisibility);
    if (!isApiRequest) {
        List<ProfileFundingEntity> existingFundings = profileFundingDao.getByUser(orcid);
        for (ProfileFundingEntity existingFunding : existingFundings) {
            Funding existing = jpaJaxbFundingAdapter.toFunding(existingFunding);
            if (!existing.getPutCode().equals(funding.getPutCode())) {
                activityValidator.checkFundingExternalIdentifiersForDuplicates(funding.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceEntity);
            }
        }
    }
    orcidSecurityManager.checkSource(pfe);
    jpaJaxbFundingAdapter.toProfileFundingEntity(funding, pfe);
    pfe.setVisibility(originalVisibility);
    //Be sure it doesn't overwrite the source
    pfe.setSourceId(existingSourceId);
    pfe.setClientSourceId(existingClientSourceId);
    //Updates the give organization with the latest organization from database, or, create a new one
    OrgEntity updatedOrganization = orgManager.getOrgEntity(funding);
    pfe.setOrg(updatedOrganization);
    pfe = profileFundingDao.merge(pfe);
    profileFundingDao.flush();
    if (!isApiRequest) {
        notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItem(pfe));
    }
    return jpaJaxbFundingAdapter.toFunding(pfe);
}
Also used : Funding(org.orcid.jaxb.model.record_v2.Funding) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Visibility(org.orcid.jaxb.model.common_v2.Visibility) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 14 with Visibility

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

the class ProfileKeywordManagerImpl method setIncomingPrivacy.

private void setIncomingPrivacy(ProfileKeywordEntity entity, ProfileEntity profile) {
    org.orcid.jaxb.model.common_v2.Visibility incomingKeywordVisibility = entity.getVisibility();
    org.orcid.jaxb.model.common_v2.Visibility defaultKeywordVisibility = (profile.getActivitiesVisibilityDefault() == null) ? org.orcid.jaxb.model.common_v2.Visibility.PRIVATE : org.orcid.jaxb.model.common_v2.Visibility.fromValue(profile.getActivitiesVisibilityDefault().value());
    if (profile.getClaimed() != null && profile.getClaimed()) {
        entity.setVisibility(defaultKeywordVisibility);
    } else if (incomingKeywordVisibility == null) {
        entity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
    }
}
Also used : Visibility(org.orcid.jaxb.model.common_v2.Visibility)

Example 15 with Visibility

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

the class OtherNameManagerImpl method updateOtherName.

@Override
@Transactional
public OtherName updateOtherName(String orcid, Long putCode, OtherName otherName, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    OtherNameEntity updatedOtherNameEntity = otherNameDao.getOtherName(orcid, putCode);
    Visibility originalVisibility = Visibility.fromValue(updatedOtherNameEntity.getVisibility().value());
    //Save the original source
    String existingSourceId = updatedOtherNameEntity.getSourceId();
    String existingClientSourceId = updatedOtherNameEntity.getClientSourceId();
    // Validate the other name
    PersonValidator.validateOtherName(otherName, sourceEntity, false, isApiRequest, originalVisibility);
    // Validate it is not duplicated
    List<OtherNameEntity> existingOtherNames = otherNameDao.getOtherNames(orcid, getLastModified(orcid));
    for (OtherNameEntity existing : existingOtherNames) {
        if (isDuplicated(existing, otherName, sourceEntity)) {
            Map<String, String> params = new HashMap<String, String>();
            params.put("type", "otherName");
            params.put("value", otherName.getContent());
            throw new OrcidDuplicatedElementException(params);
        }
    }
    orcidSecurityManager.checkSource(updatedOtherNameEntity);
    jpaJaxbOtherNameAdapter.toOtherNameEntity(otherName, updatedOtherNameEntity);
    updatedOtherNameEntity.setLastModified(new Date());
    //Be sure it doesn't overwrite the source
    updatedOtherNameEntity.setSourceId(existingSourceId);
    updatedOtherNameEntity.setClientSourceId(existingClientSourceId);
    otherNameDao.merge(updatedOtherNameEntity);
    return jpaJaxbOtherNameAdapter.toOtherName(updatedOtherNameEntity);
}
Also used : HashMap(java.util.HashMap) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Visibility (org.orcid.jaxb.model.common_v2.Visibility)55 Test (org.junit.Test)36 ClientResponse (com.sun.jersey.api.client.ClientResponse)35 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)12 HashMap (java.util.HashMap)10 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)10 OrcidError (org.orcid.jaxb.model.error_rc1.OrcidError)9 Visibility (org.orcid.jaxb.model.common_rc2.Visibility)8 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)8 Date (java.util.Date)7 Visibility (org.orcid.jaxb.model.common_rc1.Visibility)7 Visibility (org.orcid.jaxb.model.common_rc3.Visibility)6 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)5 Funding (org.orcid.jaxb.model.record_v2.Funding)5 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)5 Work (org.orcid.jaxb.model.record_v2.Work)5 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)5 Visibility (org.orcid.jaxb.model.common_rc4.Visibility)4 OrcidError (org.orcid.jaxb.model.error_rc3.OrcidError)4 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)4