Search in sources :

Example 61 with Visibility

use of org.orcid.jaxb.model.v3.dev1.common.Visibility in project ORCID-Source by ORCID.

the class PeerReviewManagerImpl method updatePeerReview.

@Override
public PeerReview updatePeerReview(String orcid, PeerReview peerReview, boolean isApiRequest) {
    PeerReviewEntity existingEntity = peerReviewDao.getPeerReview(orcid, peerReview.getPutCode());
    Visibility originalVisibility = Visibility.fromValue(existingEntity.getVisibility().value());
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    // Save the original source
    String existingSourceId = existingEntity.getSourceId();
    String existingClientSourceId = existingEntity.getClientSourceId();
    // If request comes from the API perform validations
    if (isApiRequest) {
        activityValidator.validatePeerReview(peerReview, sourceEntity, false, isApiRequest, originalVisibility);
        validateGroupId(peerReview);
        List<PeerReview> existingReviews = this.findPeerReviews(orcid);
        for (PeerReview existing : existingReviews) {
            // Dont compare the updated peer review with the DB version
            if (!existing.getPutCode().equals(peerReview.getPutCode())) {
                activityValidator.checkExternalIdentifiersForDuplicates(peerReview.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceManager.retrieveSourceEntity());
            }
        }
    } else {
        // check vocab of external identifiers
        externalIDValidator.validateWorkOrPeerReview(peerReview.getExternalIdentifiers());
        externalIDValidator.validateWorkOrPeerReview(peerReview.getSubjectExternalIdentifier());
    }
    PeerReviewEntity updatedEntity = new PeerReviewEntity();
    orcidSecurityManager.checkSource(existingEntity);
    jpaJaxbPeerReviewAdapter.toPeerReviewEntity(peerReview, updatedEntity);
    updatedEntity.setProfile(new ProfileEntity(orcid));
    updatedEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(originalVisibility.value()));
    // Be sure it doesn't overwrite the source
    updatedEntity.setSourceId(existingSourceId);
    updatedEntity.setClientSourceId(existingClientSourceId);
    OrgEntity updatedOrganization = orgManager.getOrgEntity(peerReview);
    updatedEntity.setOrg(updatedOrganization);
    updatedEntity = peerReviewDao.merge(updatedEntity);
    peerReviewDao.flush();
    notificationManager.sendAmendEmail(orcid, AmendedSection.PEER_REVIEW, createItemList(updatedEntity));
    return jpaJaxbPeerReviewAdapter.toPeerReview(updatedEntity);
}
Also used : PeerReviewEntity(org.orcid.persistence.jpa.entities.PeerReviewEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) PeerReview(org.orcid.jaxb.model.v3.dev1.record.PeerReview) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 62 with Visibility

use of org.orcid.jaxb.model.v3.dev1.common.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 = Visibility.fromValue(recordName.getVisibility().value());
    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.v3.dev1.common.Visibility)

Example 63 with Visibility

use of org.orcid.jaxb.model.v3.dev1.common.Visibility in project ORCID-Source by ORCID.

the class ProfileEntityManagerImpl method retrivePublicDisplayName.

@Override
public String retrivePublicDisplayName(String orcid) {
    String publicName = "";
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    if (profile != null) {
        RecordNameEntity recordName = profile.getRecordNameEntity();
        if (recordName != null) {
            Visibility namesVisibility = (recordName.getVisibility() != null) ? Visibility.fromValue(recordName.getVisibility().value()) : Visibility.fromValue(OrcidVisibilityDefaults.NAMES_DEFAULT.getVisibility().value());
            if (Visibility.PUBLIC.equals(namesVisibility)) {
                if (!PojoUtil.isEmpty(recordName.getCreditName())) {
                    publicName = recordName.getCreditName();
                } else {
                    publicName = PojoUtil.isEmpty(recordName.getGivenNames()) ? "" : recordName.getGivenNames();
                    publicName += PojoUtil.isEmpty(recordName.getFamilyName()) ? "" : " " + recordName.getFamilyName();
                }
            }
        }
    }
    return publicName;
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 64 with Visibility

use of org.orcid.jaxb.model.v3.dev1.common.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 = Visibility.fromValue(pfe.getVisibility().value());
    // 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, getLastModified(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(org.orcid.jaxb.model.common_v2.Visibility.fromValue(originalVisibility.value()));
    // 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, createItemList(pfe));
    }
    return jpaJaxbFundingAdapter.toFunding(pfe);
}
Also used : Funding(org.orcid.jaxb.model.v3.dev1.record.Funding) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 65 with Visibility

use of org.orcid.jaxb.model.v3.dev1.common.Visibility in project ORCID-Source by ORCID.

the class ResearcherUrlManagerImpl method updateResearcherUrl.

@Override
@Transactional
public ResearcherUrl updateResearcherUrl(String orcid, ResearcherUrl researcherUrl, boolean isApiRequest) {
    ResearcherUrlEntity updatedResearcherUrlEntity = researcherUrlDao.getResearcherUrl(orcid, researcherUrl.getPutCode());
    Visibility originalVisibility = Visibility.fromValue(updatedResearcherUrlEntity.getVisibility().value());
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    // Save the original source
    String existingSourceId = updatedResearcherUrlEntity.getSourceId();
    String existingClientSourceId = updatedResearcherUrlEntity.getClientSourceId();
    // Validate the researcher url
    PersonValidator.validateResearcherUrl(researcherUrl, sourceEntity, false, isApiRequest, originalVisibility);
    // Validate it is not duplicated
    List<ResearcherUrlEntity> existingResearcherUrls = researcherUrlDao.getResearcherUrls(orcid, getLastModified(orcid));
    for (ResearcherUrlEntity existing : existingResearcherUrls) {
        if (isDuplicated(existing, researcherUrl, sourceEntity)) {
            Map<String, String> params = new HashMap<String, String>();
            params.put("type", "researcher-url");
            params.put("value", researcherUrl.getUrlName());
            throw new OrcidDuplicatedElementException(params);
        }
    }
    orcidSecurityManager.checkSource(updatedResearcherUrlEntity);
    jpaJaxbResearcherUrlAdapter.toResearcherUrlEntity(researcherUrl, updatedResearcherUrlEntity);
    updatedResearcherUrlEntity.setLastModified(new Date());
    // Be sure it doesn't overwrite the source
    updatedResearcherUrlEntity.setSourceId(existingSourceId);
    updatedResearcherUrlEntity.setClientSourceId(existingClientSourceId);
    researcherUrlDao.merge(updatedResearcherUrlEntity);
    return jpaJaxbResearcherUrlAdapter.toResearcherUrl(updatedResearcherUrlEntity);
}
Also used : HashMap(java.util.HashMap) ResearcherUrlEntity(org.orcid.persistence.jpa.entities.ResearcherUrlEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Visibility (org.orcid.jaxb.model.v3.dev1.common.Visibility)44 ClientResponse (com.sun.jersey.api.client.ClientResponse)17 Test (org.junit.Test)17 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)12 Url (org.orcid.jaxb.model.v3.dev1.common.Url)11 OrcidError (org.orcid.jaxb.model.v3.dev1.error.OrcidError)11 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)11 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)11 HashMap (java.util.HashMap)10 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)10 Name (org.orcid.jaxb.model.v3.dev1.record.Name)7 OtherName (org.orcid.jaxb.model.v3.dev1.record.OtherName)7 Organization (org.orcid.jaxb.model.v3.dev1.common.Organization)6 Biography (org.orcid.jaxb.model.v3.dev1.record.Biography)6 Work (org.orcid.jaxb.model.v3.dev1.record.Work)6 EducationSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EducationSummary)6 Date (java.util.Date)5 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)5