Search in sources :

Example 6 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 7 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 8 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)

Example 9 with RecordNameEntity

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

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

Aggregations

RecordNameEntity (org.orcid.persistence.jpa.entities.RecordNameEntity)42 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)20 Test (org.junit.Test)15 DBUnitTest (org.orcid.test.DBUnitTest)8 Date (java.util.Date)7 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)6 HashSet (java.util.HashSet)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 Visibility (org.orcid.jaxb.model.common_v2.Visibility)4 Email (org.orcid.jaxb.model.record_v2.Email)4 Before (org.junit.Before)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 Name (org.orcid.jaxb.model.record_v2.Name)3 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)3 List (java.util.List)2 Query (javax.persistence.Query)2 TypedQuery (javax.persistence.TypedQuery)2 CreditName (org.orcid.jaxb.model.common_v2.CreditName)2 FamilyName (org.orcid.jaxb.model.record_v2.FamilyName)2 Transactional (org.springframework.transaction.annotation.Transactional)2