Search in sources :

Example 46 with ProfileEntity

use of org.orcid.persistence.jpa.entities.ProfileEntity 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 47 with ProfileEntity

use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.

the class ProfileEntityManagerImpl method deactivateRecord.

@Override
@Transactional
public boolean deactivateRecord(String orcid) {
    //Clear the record
    ProfileEntity toClear = profileDao.find(orcid);
    toClear.setLastModified(new Date());
    toClear.setDeactivationDate(new Date());
    toClear.setActivitiesVisibilityDefault(Visibility.PRIVATE);
    toClear.setIndexingStatus(IndexingStatus.REINDEX);
    // Remove works
    workManager.removeAllWorks(orcid);
    // Remove funding
    if (toClear.getProfileFunding() != null) {
        toClear.getProfileFunding().clear();
    }
    // Remove affiliations
    if (toClear.getOrgAffiliationRelations() != null) {
        toClear.getOrgAffiliationRelations().clear();
    }
    // Remove external identifiers
    if (toClear.getExternalIdentifiers() != null) {
        toClear.getExternalIdentifiers().clear();
    }
    // Remove researcher urls
    if (toClear.getResearcherUrls() != null) {
        toClear.getResearcherUrls().clear();
    }
    // Remove other names
    if (toClear.getOtherNames() != null) {
        toClear.getOtherNames().clear();
    }
    // Remove keywords
    if (toClear.getKeywords() != null) {
        toClear.getKeywords().clear();
    }
    // Remove address
    if (toClear.getAddresses() != null) {
        toClear.getAddresses().clear();
    }
    BiographyEntity bioEntity = toClear.getBiographyEntity();
    if (bioEntity != null) {
        bioEntity.setBiography("");
        bioEntity.setVisibility(Visibility.PRIVATE);
    }
    //Set the deactivated names
    RecordNameEntity recordName = toClear.getRecordNameEntity();
    if (recordName != null) {
        recordName.setCreditName(null);
        recordName.setGivenNames("Given Names Deactivated");
        recordName.setFamilyName("Family Name Deactivated");
        recordName.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
    }
    Set<EmailEntity> emails = toClear.getEmails();
    if (emails != null) {
        // For each email in the deprecated profile                            
        for (EmailEntity email : emails) {
            email.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
        }
    }
    profileDao.merge(toClear);
    profileDao.flush();
    //Delete all connections
    userConnectionDao.deleteByOrcid(orcid);
    notificationManager.sendAmendEmail(orcid, AmendedSection.UNKNOWN, null);
    return true;
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) BiographyEntity(org.orcid.persistence.jpa.entities.BiographyEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 48 with ProfileEntity

use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.

the class ProfileFundingManagerImpl method createFunding.

/**
     * Add a new funding to the given user
     * @param orcid
     *          The user to add the funding
     * @param funding
     *          The funding to add
     * @return the added funding                  
     * */
@Override
@Transactional
public Funding createFunding(String orcid, Funding funding, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    activityValidator.validateFunding(funding, sourceEntity, true, isApiRequest, null);
    //Check for duplicates
    List<ProfileFundingEntity> existingFundings = profileFundingDao.getByUser(orcid);
    List<Funding> fundings = jpaJaxbFundingAdapter.toFunding(existingFundings);
    if (fundings != null && isApiRequest) {
        for (Funding exstingFunding : fundings) {
            activityValidator.checkFundingExternalIdentifiersForDuplicates(funding.getExternalIdentifiers(), exstingFunding.getExternalIdentifiers(), exstingFunding.getSource(), sourceEntity);
        }
    }
    ProfileFundingEntity profileFundingEntity = jpaJaxbFundingAdapter.toProfileFundingEntity(funding);
    //Updates the give organization with the latest organization from database
    OrgEntity updatedOrganization = orgManager.getOrgEntity(funding);
    profileFundingEntity.setOrg(updatedOrganization);
    //Set the source
    if (sourceEntity.getSourceProfile() != null) {
        profileFundingEntity.setSourceId(sourceEntity.getSourceProfile().getId());
    }
    if (sourceEntity.getSourceClient() != null) {
        profileFundingEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
    }
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    profileFundingEntity.setProfile(profile);
    setIncomingWorkPrivacy(profileFundingEntity, profile);
    DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(profileFundingEntity, isApiRequest);
    profileFundingDao.persist(profileFundingEntity);
    profileFundingDao.flush();
    if (isApiRequest) {
        notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItem(profileFundingEntity));
    }
    return jpaJaxbFundingAdapter.toFunding(profileFundingEntity);
}
Also used : Funding(org.orcid.jaxb.model.record_v2.Funding) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 49 with ProfileEntity

use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.

the class RecordNameManagerImpl method updateRecordName.

@Override
public boolean updateRecordName(String orcid, Name name) {
    if (name == null) {
        return false;
    }
    RecordNameEntity entity = jpaJaxbNameAdapter.toRecordNameEntity(name);
    if (entity.getProfile() == null || PojoUtil.isEmpty(entity.getProfile().getId())) {
        entity.setProfile(new ProfileEntity(orcid));
    }
    entity.setLastModified(new Date());
    recordNameDao.updateRecordName(entity);
    // Evict the name in the source name manager
    sourceNameCacheManager.remove(orcid);
    return true;
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date)

Example 50 with ProfileEntity

use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.

the class PeerReviewManagerImpl method createPeerReview.

@Override
public PeerReview createPeerReview(String orcid, PeerReview peerReview, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    // If request comes from the API, perform the validations
    if (isApiRequest) {
        // Validate it have at least one ext id
        activityValidator.validatePeerReview(peerReview, sourceEntity, true, isApiRequest, null);
        List<PeerReviewEntity> peerReviews = peerReviewDao.getByUser(orcid);
        // duplicates
        if (!sourceEntity.getSourceId().equals(orcid)) {
            if (peerReviews != null) {
                for (PeerReviewEntity entity : peerReviews) {
                    PeerReview existing = jpaJaxbPeerReviewAdapter.toPeerReview(entity);
                    activityValidator.checkExternalIdentifiersForDuplicates(peerReview.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceEntity);
                }
            }
        } else {
            //check vocab of external identifiers
            externalIDValidator.validateWorkOrPeerReview(peerReview.getExternalIdentifiers());
            externalIDValidator.validateWorkOrPeerReview(peerReview.getSubjectExternalIdentifier());
        }
        validateGroupId(peerReview);
    }
    PeerReviewEntity entity = jpaJaxbPeerReviewAdapter.toPeerReviewEntity(peerReview);
    // Updates the give organization with the latest organization from
    // database
    OrgEntity updatedOrganization = orgManager.getOrgEntity(peerReview);
    entity.setOrg(updatedOrganization);
    //Set the source
    if (sourceEntity.getSourceProfile() != null) {
        entity.setSourceId(sourceEntity.getSourceProfile().getId());
    }
    if (sourceEntity.getSourceClient() != null) {
        entity.setClientSourceId(sourceEntity.getSourceClient().getId());
    }
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    entity.setProfile(profile);
    setIncomingPrivacy(entity, profile);
    DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(entity, isApiRequest);
    peerReviewDao.persist(entity);
    peerReviewDao.flush();
    notificationManager.sendAmendEmail(orcid, AmendedSection.PEER_REVIEW, createItem(entity));
    return jpaJaxbPeerReviewAdapter.toPeerReview(entity);
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) PeerReviewEntity(org.orcid.persistence.jpa.entities.PeerReviewEntity) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Aggregations

ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)231 Test (org.junit.Test)65 Date (java.util.Date)64 Transactional (org.springframework.transaction.annotation.Transactional)58 DBUnitTest (org.orcid.test.DBUnitTest)44 HashMap (java.util.HashMap)41 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)37 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)36 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)33 HashSet (java.util.HashSet)30 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)28 Rollback (org.springframework.test.annotation.Rollback)25 RecordNameEntity (org.orcid.persistence.jpa.entities.RecordNameEntity)20 Set (java.util.Set)16 ArrayList (java.util.ArrayList)15 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)14 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)14 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)13 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)13 Authentication (org.springframework.security.core.Authentication)12