Search in sources :

Example 1 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 2 with OtherNameEntity

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

the class JpaJaxbOtherNameAdapterTest method fromOtherNameToOtherNameEntityTest.

@Test
public void fromOtherNameToOtherNameEntityTest() throws JAXBException {
    OtherName otherName = getOtherName();
    OtherNameEntity otherNameEntity = adapter.toOtherNameEntity(otherName);
    assertNotNull(otherNameEntity);
    assertNotNull(otherNameEntity.getDateCreated());
    assertNotNull(otherNameEntity.getLastModified());
    assertEquals("Other Name #1", otherNameEntity.getDisplayName());
    // Source
    assertNull(otherNameEntity.getSourceId());
    assertNull(otherNameEntity.getClientSourceId());
    assertNull(otherNameEntity.getElementSourceId());
}
Also used : OtherName(org.orcid.jaxb.model.record_v2.OtherName) OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) Test(org.junit.Test)

Example 3 with OtherNameEntity

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

the class ProfileEntityManagerImplTest method testClaimChangingVisibility.

@Test
@Transactional
public void testClaimChangingVisibility() {
    Claim claim = new Claim();
    claim.setActivitiesVisibilityDefault(org.orcid.pojo.ajaxForm.Visibility.valueOf(Visibility.PRIVATE));
    claim.setPassword(Text.valueOf("passwordTest1"));
    claim.setPasswordConfirm(Text.valueOf("passwordTest1"));
    Checkbox checked = new Checkbox();
    checked.setValue(true);
    claim.setSendChangeNotifications(checked);
    claim.setSendOrcidNews(checked);
    claim.setTermsOfUse(checked);
    assertTrue(profileEntityManager.claimProfileAndUpdatePreferences("0000-0000-0000-0001", "public_0000-0000-0000-0001@test.orcid.org", Locale.EN, claim));
    ProfileEntity profile = profileEntityManager.findByOrcid("0000-0000-0000-0001");
    assertNotNull(profile);
    assertNotNull(profile.getBiographyEntity());
    assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, profile.getBiographyEntity().getVisibility());
    assertNotNull(profile.getAddresses());
    assertEquals(3, profile.getAddresses().size());
    for (AddressEntity a : profile.getAddresses()) {
        assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, a.getVisibility());
    }
    assertNotNull(profile.getExternalIdentifiers());
    assertEquals(3, profile.getExternalIdentifiers().size());
    for (ExternalIdentifierEntity e : profile.getExternalIdentifiers()) {
        assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, e.getVisibility());
    }
    assertNotNull(profile.getKeywords());
    assertEquals(3, profile.getKeywords().size());
    for (ProfileKeywordEntity k : profile.getKeywords()) {
        assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, k.getVisibility());
    }
    assertNotNull(profile.getOtherNames());
    assertEquals(3, profile.getOtherNames().size());
    for (OtherNameEntity o : profile.getOtherNames()) {
        assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, o.getVisibility());
    }
    assertNotNull(profile.getResearcherUrls());
    assertEquals(3, profile.getResearcherUrls().size());
    for (ResearcherUrlEntity r : profile.getResearcherUrls()) {
        assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, r.getVisibility());
    }
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) Checkbox(org.orcid.pojo.ajaxForm.Checkbox) ResearcherUrlEntity(org.orcid.persistence.jpa.entities.ResearcherUrlEntity) ExternalIdentifierEntity(org.orcid.persistence.jpa.entities.ExternalIdentifierEntity) OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) Claim(org.orcid.pojo.ajaxForm.Claim) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) AddressEntity(org.orcid.persistence.jpa.entities.AddressEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 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 5 with OtherNameEntity

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

the class Jaxb2JpaAdapterImpl method setOtherNames.

private void setOtherNames(ProfileEntity profileEntity, OtherNames otherNames) {
    String sourceId = getSourceId();
    SortedSet<OtherNameEntity> existingOtherNameEntities = profileEntity.getOtherNames();
    Iterator<OtherNameEntity> existingIt = null;
    if (existingOtherNameEntities != null) {
        existingIt = existingOtherNameEntities.iterator();
    }
    // Iterate over the list of existing elements, to see which ones still exists but preserving all the ones where the calling client is not the source of
    if (existingIt != null) {
        while (existingIt.hasNext()) {
            OtherNameEntity existing = existingIt.next();
            String existingElementSource = existing.getElementSourceId();
            if (sourceId != null && !sourceId.equals(existingElementSource)) {
            // If am not the source of this element, do nothing
            } else {
                // If am the source, check if the element exists in the list of incoming elements
                String value = existing.getDisplayName();
                boolean found = false;
                if (otherNames != null && otherNames.getOtherName() != null) {
                    for (OtherName newOtherName : otherNames.getOtherName()) {
                        if (Objects.equals(value, newOtherName.getContent())) {
                            found = true;
                            break;
                        }
                    }
                }
                // If it doesn't exists, remove it from the existing elements
                if (!found) {
                    existingIt.remove();
                }
            }
        }
    }
    // Iterate over the list of all new ones and add the ones that doesn't exists yet
    if (otherNames != null && otherNames.getOtherName() != null) {
        for (OtherName newOtherName : otherNames.getOtherName()) {
            boolean exists = false;
            if (existingOtherNameEntities != null) {
                for (OtherNameEntity existingEntity : existingOtherNameEntities) {
                    if (Objects.equals(newOtherName.getContent(), existingEntity.getDisplayName())) {
                        exists = true;
                        // If the profile is not claimed, you can update the visibility
                        if (profileEntity.getClaimed() == null || !profileEntity.getClaimed()) {
                            // Update the visibility of existing elements if the profile is not claimed
                            String existingVisibilityValue = existingEntity.getVisibility() == null ? null : existingEntity.getVisibility().value();
                            String listVisibilityValue = otherNames.getVisibility() == null ? null : otherNames.getVisibility().value();
                            if (listVisibilityValue != null && !Objects.equals(existingVisibilityValue, listVisibilityValue)) {
                                existingEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(listVisibilityValue));
                            }
                        }
                        break;
                    }
                }
            }
            if (!exists) {
                if (existingOtherNameEntities == null) {
                    existingOtherNameEntities = new TreeSet<OtherNameEntity>();
                    profileEntity.setOtherNames(existingOtherNameEntities);
                }
                OtherNameEntity newEntity = new OtherNameEntity();
                newEntity.setProfile(profileEntity);
                // Set source
                SourceEntity source = sourceManager.retrieveSourceEntity();
                setSource(source, newEntity);
                newEntity.setDisplayName(newOtherName.getContent());
                newEntity.setVisibility(getDefaultVisibility(profileEntity, otherNames.getVisibility(), OrcidVisibilityDefaults.OTHER_NAMES_DEFAULT));
                newEntity.setDisplayIndex(0L);
                for (OtherNameEntity tempEntity : existingOtherNameEntities) tempEntity.setDisplayIndex(tempEntity.getDisplayIndex() + 1);
                existingOtherNameEntities.add(newEntity);
            }
        }
    }
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OtherName(org.orcid.jaxb.model.message.OtherName) OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity)

Aggregations

OtherNameEntity (org.orcid.persistence.jpa.entities.OtherNameEntity)27 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)13 Date (java.util.Date)12 Transactional (org.springframework.transaction.annotation.Transactional)11 Test (org.junit.Test)10 ExternalIdentifierEntity (org.orcid.persistence.jpa.entities.ExternalIdentifierEntity)7 ProfileKeywordEntity (org.orcid.persistence.jpa.entities.ProfileKeywordEntity)7 ResearcherUrlEntity (org.orcid.persistence.jpa.entities.ResearcherUrlEntity)7 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)7 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)6 AddressEntity (org.orcid.persistence.jpa.entities.AddressEntity)6 DBUnitTest (org.orcid.test.DBUnitTest)6 HashMap (java.util.HashMap)4 OtherName (org.orcid.jaxb.model.record_v2.OtherName)4 OtherName (org.orcid.jaxb.model.v3.dev1.record.OtherName)4 ApplicationException (org.orcid.core.exception.ApplicationException)3 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)3 ProfileFundingEntity (org.orcid.persistence.jpa.entities.ProfileFundingEntity)3 InvalidParameterException (java.security.InvalidParameterException)2 MapperFactory (ma.glasnost.orika.MapperFactory)2