Search in sources :

Example 26 with ProfileEntity

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

the class OrcidProfileManagerReadOnlyImpl method doRetrieveFreshOrcidProfileInTransaction.

private OrcidProfile doRetrieveFreshOrcidProfileInTransaction(String orcid, LoadOptions loadOptions) {
    LOG.debug("About to obtain fresh profile: " + orcid);
    profileDao.flushWithoutTransactional();
    ProfileEntity profileEntity = profileDao.find(orcid);
    if (profileEntity != null) {
        OrcidProfile freshOrcidProfile = convertToOrcidProfile(profileEntity, loadOptions);
        return freshOrcidProfile;
    }
    return null;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 27 with ProfileEntity

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

the class ProfileEntityManagerImpl method reactivate.

@Override
public void reactivate(String orcid, String givenNames, String familyName, String password, Visibility defaultVisibility) {
    LOGGER.info("About to reactivate record, orcid={}", orcid);
    ProfileEntity profileEntity = profileEntityCacheManager.retrieve(orcid);
    profileEntity.setDeactivationDate(null);
    profileEntity.setClaimed(true);
    profileEntity.setEncryptedPassword(encryptionManager.hashForInternalUse(password));
    profileEntity.setActivitiesVisibilityDefault(defaultVisibility);
    RecordNameEntity recordNameEntity = profileEntity.getRecordNameEntity();
    recordNameEntity.setGivenNames(givenNames);
    recordNameEntity.setFamilyName(familyName);
    profileDao.merge(profileEntity);
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 28 with ProfileEntity

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

the class ProfileEntityManagerImpl method deprecateProfile.

/**
     * Deprecates a profile
     * 
     * @param deprecatedProfile
     *            The profile that want to be deprecated
     * @param primaryProfile
     *            The primary profile for the deprecated profile
     * @return true if the account was successfully deprecated, false otherwise
     */
@Override
@Transactional
public boolean deprecateProfile(String deprecatedOrcid, String primaryOrcid) {
    boolean wasDeprecated = profileDao.deprecateProfile(deprecatedOrcid, primaryOrcid);
    // If it was successfully deprecated
    if (wasDeprecated) {
        LOGGER.info("Account {} was deprecated to primary account: {}", deprecatedOrcid, primaryOrcid);
        ProfileEntity deprecated = profileDao.find(deprecatedOrcid);
        // Remove works
        workManager.removeAllWorks(deprecatedOrcid);
        // Remove funding
        if (deprecated.getProfileFunding() != null) {
            for (ProfileFundingEntity funding : deprecated.getProfileFunding()) {
                fundingManager.removeProfileFunding(funding.getProfile().getId(), funding.getId());
            }
        }
        // Remove affiliations
        if (deprecated.getOrgAffiliationRelations() != null) {
            for (OrgAffiliationRelationEntity affiliation : deprecated.getOrgAffiliationRelations()) {
                orgAffiliationRelationDao.removeOrgAffiliationRelation(affiliation.getProfile().getId(), affiliation.getId());
            }
        }
        // Remove external identifiers
        if (deprecated.getExternalIdentifiers() != null) {
            for (ExternalIdentifierEntity externalIdentifier : deprecated.getExternalIdentifiers()) {
                externalIdentifierManager.deleteExternalIdentifier(deprecated.getId(), externalIdentifier.getId(), false);
            }
        }
        // Remove researcher urls
        if (deprecated.getResearcherUrls() != null) {
            for (ResearcherUrlEntity rUrl : deprecated.getResearcherUrls()) {
                researcherUrlManager.deleteResearcherUrl(deprecatedOrcid, rUrl.getId(), false);
            }
        }
        // Remove other names
        if (deprecated.getOtherNames() != null) {
            for (OtherNameEntity otherName : deprecated.getOtherNames()) {
                otherNamesManager.deleteOtherName(deprecatedOrcid, otherName.getId(), false);
            }
        }
        // Remove keywords
        if (deprecated.getKeywords() != null) {
            for (ProfileKeywordEntity keyword : deprecated.getKeywords()) {
                profileKeywordManager.deleteKeyword(deprecatedOrcid, keyword.getId(), false);
            }
        }
        //Remove biography                        
        if (biographyManager.exists(deprecatedOrcid)) {
            Biography deprecatedBio = new Biography();
            deprecatedBio.setContent(null);
            deprecatedBio.setVisibility(Visibility.PRIVATE);
            biographyManager.updateBiography(deprecatedOrcid, deprecatedBio);
        }
        //Set the deactivated names
        if (recordNameManager.exists(deprecatedOrcid)) {
            Name name = new Name();
            name.setCreditName(new CreditName());
            name.setGivenNames(new GivenNames("Given Names Deactivated"));
            name.setFamilyName(new FamilyName("Family Name Deactivated"));
            name.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
            name.setPath(deprecatedOrcid);
            recordNameManager.updateRecordName(deprecatedOrcid, name);
        }
        userConnectionDao.deleteByOrcid(deprecatedOrcid);
        // Move all emails to the primary email
        Set<EmailEntity> deprecatedAccountEmails = deprecated.getEmails();
        if (deprecatedAccountEmails != null) {
            // For each email in the deprecated profile                            
            for (EmailEntity email : deprecatedAccountEmails) {
                // Delete each email from the deprecated
                // profile
                LOGGER.info("About to move email {} from profile {} to profile {}", new Object[] { email.getId(), deprecatedOrcid, primaryOrcid });
                emailManager.moveEmailToOtherAccount(email.getId(), deprecatedOrcid, primaryOrcid);
            }
        }
        return true;
    }
    return false;
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) FamilyName(org.orcid.jaxb.model.record_v2.FamilyName) ResearcherUrlEntity(org.orcid.persistence.jpa.entities.ResearcherUrlEntity) ExternalIdentifierEntity(org.orcid.persistence.jpa.entities.ExternalIdentifierEntity) CreditName(org.orcid.jaxb.model.record_v2.CreditName) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity) CreditName(org.orcid.jaxb.model.record_v2.CreditName) FamilyName(org.orcid.jaxb.model.record_v2.FamilyName) Name(org.orcid.jaxb.model.record_v2.Name) GivenNames(org.orcid.jaxb.model.record_v2.GivenNames) Biography(org.orcid.jaxb.model.record_v2.Biography) OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 29 with ProfileEntity

use of org.orcid.persistence.jpa.entities.ProfileEntity 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.common_v2.Visibility) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 30 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)

Aggregations

ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)374 Date (java.util.Date)107 Test (org.junit.Test)107 HashMap (java.util.HashMap)74 Transactional (org.springframework.transaction.annotation.Transactional)74 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)71 DBUnitTest (org.orcid.test.DBUnitTest)65 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)48 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)44 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)37 HashSet (java.util.HashSet)35 RecordNameEntity (org.orcid.persistence.jpa.entities.RecordNameEntity)35 Locale (java.util.Locale)34 Rollback (org.springframework.test.annotation.Rollback)27 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)26 ArrayList (java.util.ArrayList)25 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)21 Set (java.util.Set)17 Authentication (org.springframework.security.core.Authentication)17 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)16