Search in sources :

Example 6 with OtherNameEntity

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

the class Jpa2JaxbAdapterImpl method getOtherNames.

private OtherNames getOtherNames(ProfileEntity profile) {
    OtherNames otherNames = new OtherNames();
    Visibility mostRestrictive = Visibility.PUBLIC;
    Set<OtherNameEntity> otherNamesEntitiy = profile.getOtherNames();
    if (otherNamesEntitiy != null && otherNamesEntitiy.size() > 0) {
        for (OtherNameEntity otherNameEntity : otherNamesEntitiy) {
            //will only be null if there's an issue with the data or you're using this layer directly
            Visibility vis = (otherNameEntity.getVisibility() != null) ? Visibility.fromValue(otherNameEntity.getVisibility().value()) : Visibility.PRIVATE;
            if (vis.isMoreRestrictiveThan(mostRestrictive))
                mostRestrictive = vis;
            OtherName otherName = new OtherName(otherNameEntity.getDisplayName(), vis);
            if (!PojoUtil.isEmpty(otherNameEntity.getElementSourceId())) {
                Source source = getSource(otherNameEntity);
                otherName.setSource(source);
            }
            otherNames.getOtherName().add(otherName);
        }
    }
    otherNames.setVisibility(mostRestrictive);
    return otherNames;
}
Also used : OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity)

Example 7 with OtherNameEntity

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

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

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

the class OtherNameManagerImpl method updateOtherName.

@Override
@Transactional
public OtherName updateOtherName(String orcid, Long putCode, OtherName otherName, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    OtherNameEntity updatedOtherNameEntity = otherNameDao.getOtherName(orcid, putCode);
    Visibility originalVisibility = Visibility.fromValue(updatedOtherNameEntity.getVisibility().value());
    //Save the original source
    String existingSourceId = updatedOtherNameEntity.getSourceId();
    String existingClientSourceId = updatedOtherNameEntity.getClientSourceId();
    // Validate the other name
    PersonValidator.validateOtherName(otherName, sourceEntity, false, isApiRequest, originalVisibility);
    // Validate it is not duplicated
    List<OtherNameEntity> existingOtherNames = otherNameDao.getOtherNames(orcid, getLastModified(orcid));
    for (OtherNameEntity existing : existingOtherNames) {
        if (isDuplicated(existing, otherName, sourceEntity)) {
            Map<String, String> params = new HashMap<String, String>();
            params.put("type", "otherName");
            params.put("value", otherName.getContent());
            throw new OrcidDuplicatedElementException(params);
        }
    }
    orcidSecurityManager.checkSource(updatedOtherNameEntity);
    jpaJaxbOtherNameAdapter.toOtherNameEntity(otherName, updatedOtherNameEntity);
    updatedOtherNameEntity.setLastModified(new Date());
    //Be sure it doesn't overwrite the source
    updatedOtherNameEntity.setSourceId(existingSourceId);
    updatedOtherNameEntity.setClientSourceId(existingClientSourceId);
    otherNameDao.merge(updatedOtherNameEntity);
    return jpaJaxbOtherNameAdapter.toOtherName(updatedOtherNameEntity);
}
Also used : HashMap(java.util.HashMap) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with OtherNameEntity

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

the class JpaJaxbOtherNameAdapterTest method fromOtherNameEntityToOtherNameTest.

@Test
public void fromOtherNameEntityToOtherNameTest() {
    OtherNameEntity entity = getOtherNameEntity();
    OtherName otherName = adapter.toOtherName(entity);
    assertNotNull(otherName);
    assertEquals("display-name", otherName.getContent());
    assertNotNull(otherName.getCreatedDate());
    assertNotNull(otherName.getLastModifiedDate());
    assertEquals(Long.valueOf(1), otherName.getPutCode());
    assertNotNull(otherName.getSource());
    assertEquals("APP-000000001", otherName.getSource().retrieveSourcePath());
    assertEquals(Visibility.PUBLIC, otherName.getVisibility());
}
Also used : OtherName(org.orcid.jaxb.model.record_v2.OtherName) OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) Test(org.junit.Test)

Aggregations

OtherNameEntity (org.orcid.persistence.jpa.entities.OtherNameEntity)18 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)8 Date (java.util.Date)7 Test (org.junit.Test)7 Transactional (org.springframework.transaction.annotation.Transactional)6 ExternalIdentifierEntity (org.orcid.persistence.jpa.entities.ExternalIdentifierEntity)5 ProfileKeywordEntity (org.orcid.persistence.jpa.entities.ProfileKeywordEntity)5 ResearcherUrlEntity (org.orcid.persistence.jpa.entities.ResearcherUrlEntity)5 DBUnitTest (org.orcid.test.DBUnitTest)5 OtherName (org.orcid.jaxb.model.record_v2.OtherName)4 AddressEntity (org.orcid.persistence.jpa.entities.AddressEntity)4 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)4 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)3 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)3 ProfileFundingEntity (org.orcid.persistence.jpa.entities.ProfileFundingEntity)3 HashMap (java.util.HashMap)2 ApplicationException (org.orcid.core.exception.ApplicationException)2 Visibility (org.orcid.jaxb.model.common_v2.Visibility)2 FamilyName (org.orcid.jaxb.model.record_v2.FamilyName)2 GivenNames (org.orcid.jaxb.model.record_v2.GivenNames)2