Search in sources :

Example 1 with RecordNameEntity

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

the class OrcidClientGroupManagerImpl method updateGroup.

/**
     * Updates an existing group profile. If the group doesnt exists it will
     * throw a OrcidClientGroupManagementException
     * 
     * @param orcidClientGroup
     *            The group to be updated
     */
@Transactional
public void updateGroup(OrcidClientGroup orcidClientGroup) {
    String groupOrcid = orcidClientGroup.getGroupOrcid();
    // If the incoming client group ORCID is not null, then lookup the
    // existing client group.
    ProfileEntity groupProfileEntity = profileDao.find(groupOrcid);
    if (groupProfileEntity == null) {
        // then raise an error.
        throw new OrcidClientGroupManagementException("Group ORCID was specified but does not yet exist: " + groupOrcid);
    } else {
        boolean updateClientScopes = false;
        // profile DAO
        if (!orcidClientGroup.getEmail().equals(groupProfileEntity.getPrimaryEmail().getId())) {
            EmailEntity primaryEmailEntity = new EmailEntity();
            primaryEmailEntity.setId(orcidClientGroup.getEmail().toLowerCase().trim());
            primaryEmailEntity.setCurrent(true);
            primaryEmailEntity.setVerified(true);
            primaryEmailEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
            groupProfileEntity.setPrimaryEmail(primaryEmailEntity);
        }
        if (groupProfileEntity.getRecordNameEntity() == null) {
            groupProfileEntity.setRecordNameEntity(new RecordNameEntity());
            groupProfileEntity.getRecordNameEntity().setProfile(groupProfileEntity);
        }
        // Set the record name entity table
        groupProfileEntity.getRecordNameEntity().setCreditName(orcidClientGroup.getGroupName());
        groupProfileEntity.getRecordNameEntity().setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
        groupProfileEntity.setSalesforeId(orcidClientGroup.getSalesforceId());
        // If group type changed
        if (!groupProfileEntity.getGroupType().equals(orcidClientGroup.getType())) {
            // Update the group type
            groupProfileEntity.setGroupType(orcidClientGroup.getType());
            // Set the flag to update the client scopes
            updateClientScopes = true;
        }
        // Merge changes
        profileDao.merge(groupProfileEntity);
        profileEntityManager.updateLastModifed(groupOrcid);
        // Update client types and scopes
        if (updateClientScopes)
            updateClientTypeDueGroupTypeUpdate(groupProfileEntity);
    }
}
Also used : OrcidClientGroupManagementException(org.orcid.core.exception.OrcidClientGroupManagementException) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with RecordNameEntity

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

the class Jaxb2JpaAdapterImpl method setFamilyName.

private void setFamilyName(ProfileEntity profileEntity, FamilyName familyName) {
    if (familyName != null && StringUtils.isNotBlank(familyName.getContent())) {
        if (profileEntity.getRecordNameEntity() == null) {
            profileEntity.setRecordNameEntity(new RecordNameEntity());
            profileEntity.getRecordNameEntity().setProfile(profileEntity);
        }
        profileEntity.getRecordNameEntity().setFamilyName(familyName.getContent());
    }
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity)

Example 3 with RecordNameEntity

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

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

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

RecordNameEntity (org.orcid.persistence.jpa.entities.RecordNameEntity)66 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)35 Test (org.junit.Test)26 DBUnitTest (org.orcid.test.DBUnitTest)13 Date (java.util.Date)11 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)10 HashSet (java.util.HashSet)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5 Before (org.junit.Before)4 Name (org.orcid.jaxb.model.v3.dev1.record.Name)4 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 Query (javax.persistence.Query)3 TypedQuery (javax.persistence.TypedQuery)3 Locale (org.orcid.jaxb.model.common_v2.Locale)3 Visibility (org.orcid.jaxb.model.common_v2.Visibility)3 Email (org.orcid.jaxb.model.record_v2.Email)3 Name (org.orcid.jaxb.model.record_v2.Name)3 Email (org.orcid.jaxb.model.v3.dev1.record.Email)3