Search in sources :

Example 1 with EmailEntity

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

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

the class EmailManagerReadOnlyImpl method getEmails.

private Emails getEmails(String orcid, Visibility visibility) {
    List<EmailEntity> entities = new ArrayList<EmailEntity>();
    if (visibility == null) {
        entities = emailDao.findByOrcid(orcid);
    } else {
        entities = emailDao.findByOrcid(orcid, Visibility.PUBLIC);
    }
    List<org.orcid.jaxb.model.record_v2.Email> emailList = jpaJaxbEmailAdapter.toEmailList(entities);
    Emails emails = new Emails();
    emails.setEmails(emailList);
    return emails;
}
Also used : Email(org.orcid.jaxb.model.record_v2.Email) ArrayList(java.util.ArrayList) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) Emails(org.orcid.jaxb.model.record_v2.Emails)

Example 3 with EmailEntity

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

the class Jaxb2JpaAdapterImpl method setEmails.

private void setEmails(ProfileEntity profileEntity, ContactDetails contactDetails) {
    Set<EmailEntity> existingEmailEntities = profileEntity.getEmails();
    Map<String, EmailEntity> existingEmailEntitiesMap = createEmailEntitiesMap(existingEmailEntities);
    Set<EmailEntity> emailEntities = null;
    if (existingEmailEntities == null) {
        emailEntities = new HashSet<>();
    } else {
        // To allow for orphan deletion
        existingEmailEntities.clear();
        emailEntities = existingEmailEntities;
    }
    for (Email email : contactDetails.getEmail()) {
        String emailId = email.getValue().trim();
        EmailEntity emailEntity = null;
        EmailEntity existingEmailEntity = existingEmailEntitiesMap.get(emailId);
        if (existingEmailEntity == null) {
            emailEntity = new EmailEntity();
            emailEntity.setId(emailId);
            emailEntity.setProfile(profileEntity);
            emailEntity.setSourceId(email.getSource());
            emailEntity.setClientSourceId(email.getSourceClientId());
        } else {
            existingEmailEntity.clean();
            emailEntity = existingEmailEntity;
        }
        emailEntity.setPrimary(email.isPrimary());
        emailEntity.setCurrent(email.isCurrent());
        emailEntity.setVerified(email.isVerified());
        if (email.getVisibility() == null) {
            emailEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
        } else {
            emailEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(email.getVisibility().value()));
        }
        emailEntities.add(emailEntity);
    }
    profileEntity.setEmails(emailEntities);
}
Also used : Email(org.orcid.jaxb.model.message.Email) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity)

Example 4 with EmailEntity

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

the class Jpa2JaxbAdapterImpl method getOrcidHistory.

private OrcidHistory getOrcidHistory(ProfileEntity profileEntity) {
    OrcidHistory history = new OrcidHistory();
    if (profileEntity.getCompletedDate() != null) {
        history.setCompletionDate(new CompletionDate(toXMLGregorianCalendar(profileEntity.getCompletedDate())));
    }
    Boolean confirmed = profileEntity.getClaimed() != null ? profileEntity.getClaimed() : Boolean.FALSE;
    history.setClaimed(new Claimed(confirmed));
    String creationMethod = profileEntity.getCreationMethod();
    history.setCreationMethod(CreationMethod.isValid(creationMethod) ? CreationMethod.fromValue(creationMethod) : CreationMethod.WEBSITE);
    history.setSource(getSponsor(profileEntity));
    if (profileEntity.getSubmissionDate() != null) {
        history.setSubmissionDate(new SubmissionDate(toXMLGregorianCalendar(profileEntity.getSubmissionDate())));
    }
    if (profileEntity.getDeactivationDate() != null) {
        history.setDeactivationDate(new DeactivationDate(toXMLGregorianCalendar(profileEntity.getDeactivationDate())));
    }
    if (profileEntity.getLastModified() != null) {
        history.setLastModifiedDate(new LastModifiedDate(toXMLGregorianCalendar(profileEntity.getLastModified())));
    }
    boolean verfiedEmail = false;
    boolean verfiedPrimaryEmail = false;
    if (profileEntity.getEmails() != null) {
        for (EmailEntity emailEntity : profileEntity.getEmails()) {
            if (emailEntity != null && emailEntity.getVerified()) {
                verfiedEmail = true;
                if (emailEntity.getPrimary()) {
                    verfiedPrimaryEmail = true;
                    break;
                }
            }
        }
    }
    history.setVerifiedEmail(new VerifiedEmail(verfiedEmail));
    history.setVerifiedPrimaryEmail(new VerifiedPrimaryEmail(verfiedPrimaryEmail));
    return history;
}
Also used : EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity)

Example 5 with EmailEntity

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

Aggregations

EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)45 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)21 Date (java.util.Date)14 Test (org.junit.Test)14 HashSet (java.util.HashSet)11 RecordNameEntity (org.orcid.persistence.jpa.entities.RecordNameEntity)10 DBUnitTest (org.orcid.test.DBUnitTest)7 InvocationOnMock (org.mockito.invocation.InvocationOnMock)6 Email (org.orcid.jaxb.model.v3.dev1.record.Email)6 Transactional (org.springframework.transaction.annotation.Transactional)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 Set (java.util.Set)4 Email (org.orcid.jaxb.model.record_v2.Email)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2