Search in sources :

Example 6 with ProfileKeywordEntity

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

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

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

the class ProfileKeywordDaoImpl method getProfileKeyword.

@Override
public ProfileKeywordEntity getProfileKeyword(String orcid, Long putCode) {
    Query query = entityManager.createQuery("FROM ProfileKeywordEntity WHERE profile.id=:orcid and id=:id");
    query.setParameter("orcid", orcid);
    query.setParameter("id", putCode);
    return (ProfileKeywordEntity) query.getSingleResult();
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) Query(javax.persistence.Query)

Example 9 with ProfileKeywordEntity

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

the class JpaJaxbKeywordAdapterTest method getProfileKeywordEntity.

private ProfileKeywordEntity getProfileKeywordEntity() {
    ProfileKeywordEntity entity = new ProfileKeywordEntity();
    entity.setDateCreated(new Date());
    entity.setLastModified(new Date());
    entity.setId(Long.valueOf(1));
    entity.setKeywordName("keyword-1");
    entity.setProfile(new ProfileEntity("0000-0000-0000-0000"));
    entity.setClientSourceId("APP-000000000000");
    entity.setVisibility(Visibility.LIMITED);
    return entity;
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) Date(java.util.Date) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 10 with ProfileKeywordEntity

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

the class JpaJaxbKeywordAdapterTest method fromProfileKeywordEntityToKeywordTest.

@Test
public void fromProfileKeywordEntityToKeywordTest() {
    ProfileKeywordEntity entity = getProfileKeywordEntity();
    Keyword keyword = adapter.toKeyword(entity);
    assertNotNull(keyword);
    assertEquals("keyword-1", keyword.getContent());
    assertNotNull(keyword.getCreatedDate());
    assertNotNull(keyword.getCreatedDate().getValue());
    assertNotNull(keyword.getLastModifiedDate());
    assertNotNull(keyword.getLastModifiedDate().getValue());
    assertEquals(Long.valueOf(1), keyword.getPutCode());
    assertNotNull(keyword.getSource());
    assertEquals("APP-000000000000", keyword.getSource().retrieveSourcePath());
    assertEquals(Visibility.LIMITED, keyword.getVisibility());
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) Keyword(org.orcid.jaxb.model.record_v2.Keyword) Test(org.junit.Test)

Aggregations

ProfileKeywordEntity (org.orcid.persistence.jpa.entities.ProfileKeywordEntity)17 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)9 Test (org.junit.Test)6 Date (java.util.Date)5 ExternalIdentifierEntity (org.orcid.persistence.jpa.entities.ExternalIdentifierEntity)5 OtherNameEntity (org.orcid.persistence.jpa.entities.OtherNameEntity)5 ResearcherUrlEntity (org.orcid.persistence.jpa.entities.ResearcherUrlEntity)5 Keyword (org.orcid.jaxb.model.record_v2.Keyword)4 AddressEntity (org.orcid.persistence.jpa.entities.AddressEntity)4 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)4 DBUnitTest (org.orcid.test.DBUnitTest)4 Transactional (org.springframework.transaction.annotation.Transactional)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 HashSet (java.util.HashSet)2 TreeSet (java.util.TreeSet)2 Transactional (javax.transaction.Transactional)2 ApplicationException (org.orcid.core.exception.ApplicationException)2