Search in sources :

Example 46 with Visibility

use of org.orcid.jaxb.model.common_rc1.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(Visibility.valueOf(claim.getActivitiesVisibilityDefault().getVisibility().name()));
    }
    // 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 47 with Visibility

use of org.orcid.jaxb.model.common_rc1.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 48 with Visibility

use of org.orcid.jaxb.model.common_rc1.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, 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(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, createItemList(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 49 with Visibility

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

the class WorkManagerImpl method updateWork.

@Override
@Transactional
public Work updateWork(String orcid, Work work, boolean isApiRequest) {
    WorkEntity workEntity = workDao.getWork(orcid, work.getPutCode());
    Visibility originalVisibility = workEntity.getVisibility();
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    // Save the original source
    String existingSourceId = workEntity.getSourceId();
    String existingClientSourceId = workEntity.getClientSourceId();
    if (isApiRequest) {
        activityValidator.validateWork(work, sourceEntity, false, isApiRequest, workEntity.getVisibility());
        List<Work> existingWorks = this.findWorks(orcid);
        for (Work existing : existingWorks) {
            // Dont compare the updated peer review with the DB version
            if (!existing.getPutCode().equals(work.getPutCode())) {
                activityValidator.checkExternalIdentifiersForDuplicates(work.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceEntity);
            }
        }
    } else {
        // validate external ID vocab
        externalIDValidator.validateWorkOrPeerReview(work.getExternalIdentifiers());
    }
    orcidSecurityManager.checkSource(workEntity);
    jpaJaxbWorkAdapter.toWorkEntity(work, workEntity);
    workEntity.setVisibility(originalVisibility);
    // Be sure it doesn't overwrite the source
    workEntity.setSourceId(existingSourceId);
    workEntity.setClientSourceId(existingClientSourceId);
    workDao.merge(workEntity);
    workDao.flush();
    notificationManager.sendAmendEmail(orcid, AmendedSection.WORK, createItemList(workEntity));
    return jpaJaxbWorkAdapter.toWork(workEntity);
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Work(org.orcid.jaxb.model.record_v2.Work) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Transactional(org.springframework.transaction.annotation.Transactional)

Example 50 with Visibility

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

the class AddressManagerImpl method updateAddress.

@Override
@Transactional
public Address updateAddress(String orcid, Long putCode, Address address, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    AddressEntity updatedEntity = addressDao.getAddress(orcid, putCode);
    Visibility originalVisibility = Visibility.fromValue(updatedEntity.getVisibility().value());
    // Save the original source
    String existingSourceId = updatedEntity.getSourceId();
    String existingClientSourceId = updatedEntity.getClientSourceId();
    // If it is an update from the API, check the source and preserve the original visibility
    if (isApiRequest) {
        orcidSecurityManager.checkSource(updatedEntity);
    }
    // Validate the address
    PersonValidator.validateAddress(address, sourceEntity, false, isApiRequest, originalVisibility);
    // Validate it is not duplicated
    List<AddressEntity> existingAddresses = addressDao.getAddresses(orcid, getLastModified(orcid));
    for (AddressEntity existing : existingAddresses) {
        // If it is not the same element
        if (!existing.getId().equals(address.getPutCode())) {
            if (isDuplicated(existing, address, sourceEntity)) {
                Map<String, String> params = new HashMap<String, String>();
                params.put("type", "address");
                params.put("value", address.getCountry().getValue().value());
                throw new OrcidDuplicatedElementException(params);
            }
        }
    }
    adapter.toAddressEntity(address, updatedEntity);
    updatedEntity.setLastModified(new Date());
    // Be sure it doesn't overwrite the source
    updatedEntity.setSourceId(existingSourceId);
    updatedEntity.setClientSourceId(existingClientSourceId);
    addressDao.merge(updatedEntity);
    return adapter.toAddress(updatedEntity);
}
Also used : HashMap(java.util.HashMap) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) Visibility(org.orcid.jaxb.model.common_v2.Visibility) AddressEntity(org.orcid.persistence.jpa.entities.AddressEntity) Date(java.util.Date) Transactional(javax.transaction.Transactional)

Aggregations

Visibility (org.orcid.jaxb.model.common_v2.Visibility)55 ClientResponse (com.sun.jersey.api.client.ClientResponse)36 Test (org.junit.Test)36 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)12 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)11 HashMap (java.util.HashMap)10 OrcidError (org.orcid.jaxb.model.error_rc1.OrcidError)9 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)9 Visibility (org.orcid.jaxb.model.common_rc2.Visibility)8 Date (java.util.Date)7 Visibility (org.orcid.jaxb.model.common_rc1.Visibility)7 Visibility (org.orcid.jaxb.model.common_rc3.Visibility)6 Work (org.orcid.jaxb.model.record_v2.Work)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 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 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)4