Search in sources :

Example 1 with ResearcherUrlEntity

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

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

the class JpaJaxbResearcherUrlAdapterTest method getResearcherUrlEntity.

private ResearcherUrlEntity getResearcherUrlEntity() {
    ResearcherUrlEntity entity = new ResearcherUrlEntity();
    entity.setId(13579L);
    entity.setClientSourceId("APP-0001");
    entity.setUrl("http://orcid.org");
    entity.setUrlName("Orcid URL");
    entity.setVisibility(Visibility.LIMITED);
    return entity;
}
Also used : ResearcherUrlEntity(org.orcid.persistence.jpa.entities.ResearcherUrlEntity)

Example 3 with ResearcherUrlEntity

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

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

the class Jaxb2JpaAdapterImpl method setResearcherUrls.

private void setResearcherUrls(ProfileEntity profileEntity, ResearcherUrls researcherUrls) {
    String sourceId = getSourceId();
    SortedSet<ResearcherUrlEntity> existingResearcherUrlEntities = profileEntity.getResearcherUrls();
    Iterator<ResearcherUrlEntity> existingIt = null;
    if (existingResearcherUrlEntities != null) {
        existingIt = existingResearcherUrlEntities.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()) {
            ResearcherUrlEntity 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
                Pair<String, String> existingPair = createResearcherUrlPair(existing);
                boolean found = false;
                if (researcherUrls != null && researcherUrls.getResearcherUrl() != null) {
                    for (ResearcherUrl newResearcherUrl : researcherUrls.getResearcherUrl()) {
                        Pair<String, String> newResearcherUrlPair = createResearcherUrlPair(newResearcherUrl);
                        if (Objects.equals(existingPair, newResearcherUrlPair)) {
                            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 (researcherUrls != null && researcherUrls.getResearcherUrl() != null) {
        for (ResearcherUrl newResearcherUrl : researcherUrls.getResearcherUrl()) {
            boolean exists = false;
            Pair<String, String> newResearcherUrlPair = createResearcherUrlPair(newResearcherUrl);
            if (existingResearcherUrlEntities != null) {
                for (ResearcherUrlEntity existingEntity : existingResearcherUrlEntities) {
                    Pair<String, String> existingPair = createResearcherUrlPair(existingEntity);
                    if (Objects.equals(newResearcherUrlPair, existingPair)) {
                        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 = researcherUrls.getVisibility() == null ? null : researcherUrls.getVisibility().value();
                            if (listVisibilityValue != null && !Objects.equals(existingVisibilityValue, listVisibilityValue)) {
                                existingEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(listVisibilityValue));
                            }
                        }
                        break;
                    }
                }
            }
            if (!exists) {
                if (existingResearcherUrlEntities == null) {
                    existingResearcherUrlEntities = new TreeSet<ResearcherUrlEntity>();
                    profileEntity.setResearcherUrls(existingResearcherUrlEntities);
                }
                ResearcherUrlEntity newEntity = new ResearcherUrlEntity();
                newEntity.setUser(profileEntity);
                // Set source
                SourceEntity source = sourceManager.retrieveSourceEntity();
                setSource(source, newEntity);
                if (newResearcherUrl.getUrl() != null) {
                    newEntity.setUrl(newResearcherUrl.getUrl().getValue());
                }
                if (newResearcherUrl.getUrlName() != null) {
                    newEntity.setUrlName(newResearcherUrl.getUrlName().getContent());
                }
                newEntity.setVisibility(getDefaultVisibility(profileEntity, researcherUrls.getVisibility(), OrcidVisibilityDefaults.RESEARCHER_URLS_DEFAULT));
                newEntity.setDisplayIndex(0L);
                for (ResearcherUrlEntity tempEntity : existingResearcherUrlEntities) tempEntity.setDisplayIndex(tempEntity.getDisplayIndex() + 1);
                existingResearcherUrlEntities.add(newEntity);
            }
        }
    }
}
Also used : ResearcherUrlEntity(org.orcid.persistence.jpa.entities.ResearcherUrlEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ResearcherUrl(org.orcid.jaxb.model.message.ResearcherUrl)

Example 5 with ResearcherUrlEntity

use of org.orcid.persistence.jpa.entities.ResearcherUrlEntity 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(org.orcid.jaxb.model.common_v2.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)

Aggregations

ResearcherUrlEntity (org.orcid.persistence.jpa.entities.ResearcherUrlEntity)28 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)12 Transactional (org.springframework.transaction.annotation.Transactional)12 Date (java.util.Date)10 Test (org.junit.Test)10 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)8 ExternalIdentifierEntity (org.orcid.persistence.jpa.entities.ExternalIdentifierEntity)7 OtherNameEntity (org.orcid.persistence.jpa.entities.OtherNameEntity)7 ProfileKeywordEntity (org.orcid.persistence.jpa.entities.ProfileKeywordEntity)7 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)7 AddressEntity (org.orcid.persistence.jpa.entities.AddressEntity)6 DBUnitTest (org.orcid.test.DBUnitTest)6 ApplicationException (org.orcid.core.exception.ApplicationException)5 HashMap (java.util.HashMap)4 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)3 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)3 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)3 ProfileFundingEntity (org.orcid.persistence.jpa.entities.ProfileFundingEntity)3 Rollback (org.springframework.test.annotation.Rollback)3 InvalidParameterException (java.security.InvalidParameterException)2