Search in sources :

Example 11 with OtherNameEntity

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

the class JpaJaxbOtherNameAdapterTest method getOtherNameEntity.

private OtherNameEntity getOtherNameEntity() {
    OtherNameEntity result = new OtherNameEntity();
    result.setId(Long.valueOf(1));
    result.setDateCreated(new Date());
    result.setLastModified(new Date());
    result.setDisplayName("display-name");
    result.setProfile(new ProfileEntity("0000-0000-0000-0000"));
    result.setVisibility(Visibility.PUBLIC);
    result.setClientSourceId("APP-000000001");
    return result;
}
Also used : OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) Date(java.util.Date) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 12 with OtherNameEntity

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

the class SetUpClientsAndUsers method clearRegistry.

private boolean clearRegistry(OrcidProfile existingProfile, Map<String, String> params) {
    if (existingProfile != null) {
        String orcid = params.get(ORCID);
        String email = params.get(EMAIL);
        // exception
        if (existingProfile.getOrcidBio() == null || existingProfile.getOrcidBio().getContactDetails() == null || existingProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail() == null || !email.equals(existingProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue())) {
            throw new ApplicationException("User with email " + params.get(EMAIL) + " must have orcid id '" + orcid + "' but it is '" + existingProfile.getOrcidId() + "'");
        }
        // Check if the profile have the same password, if not, update the
        // password
        String encryptedPassword = encryptionManager.hashForInternalUse(params.get(PASSWORD));
        if (!encryptedPassword.equals(existingProfile.getPassword())) {
            existingProfile.setPassword(params.get(PASSWORD));
            orcidProfileManager.updatePasswordInformation(existingProfile);
        }
        // Set default names
        Name name = new Name();
        name.setCreditName(new CreditName(params.get(CREDIT_NAME)));
        name.setGivenNames(new GivenNames(params.get(GIVEN_NAMES)));
        name.setFamilyName(new FamilyName(params.get(FAMILY_NAMES)));
        name.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(OrcidVisibilityDefaults.NAMES_DEFAULT.getVisibility().value()));
        if (recordNameManager.exists(orcid)) {
            recordNameManager.updateRecordName(orcid, name);
        } else {
            recordNameManager.createRecordName(orcid, name);
        }
        profileDao.updatePreferences(orcid, true, true, true, true, org.orcid.jaxb.model.common_v2.Visibility.PUBLIC, true, 1f);
        // Set default bio
        org.orcid.jaxb.model.record_v2.Biography bio = biographyManager.getBiography(orcid, 0L);
        if (bio == null || bio.getContent() == null) {
            bio = new org.orcid.jaxb.model.record_v2.Biography(params.get(BIO));
            bio.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(OrcidVisibilityDefaults.BIOGRAPHY_DEFAULT.getVisibility().value()));
            biographyManager.createBiography(orcid, bio);
        } else {
            bio.setContent(params.get(BIO));
            bio.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(OrcidVisibilityDefaults.BIOGRAPHY_DEFAULT.getVisibility().value()));
            biographyManager.updateBiography(orcid, bio);
        }
        // Remove other names
        List<OtherNameEntity> otherNames = otherNameDao.getOtherNames(orcid, 0L);
        if (otherNames != null && !otherNames.isEmpty()) {
            for (OtherNameEntity otherName : otherNames) {
                otherNameDao.deleteOtherName(otherName);
            }
        }
        // Remove keywords
        List<ProfileKeywordEntity> keywords = profileKeywordDao.getProfileKeywors(orcid, 0L);
        if (keywords != null && !keywords.isEmpty()) {
            for (ProfileKeywordEntity keyword : keywords) {
                profileKeywordDao.deleteProfileKeyword(keyword);
            }
        }
        //Remove researcher urls
        List<ResearcherUrlEntity> rUrls = researcherUrlDao.getResearcherUrls(orcid, 0L);
        if (rUrls != null && !rUrls.isEmpty()) {
            for (ResearcherUrlEntity rUrl : rUrls) {
                researcherUrlDao.deleteResearcherUrl(orcid, rUrl.getId());
            }
        }
        // Remove external ids
        List<ExternalIdentifierEntity> extIds = externalIdentifierDao.getExternalIdentifiers(orcid, System.currentTimeMillis());
        if (extIds != null && !extIds.isEmpty()) {
            for (ExternalIdentifierEntity extId : extIds) {
                externalIdentifierDao.removeExternalIdentifier(orcid, extId.getId());
            }
        }
        // Remove addresses
        List<AddressEntity> addresses = addressDao.getAddresses(orcid, 0L);
        if (addresses != null && !addresses.isEmpty()) {
            for (AddressEntity address : addresses) {
                addressDao.deleteAddress(orcid, address.getId());
            }
        }
        // Remove emails
        List<EmailEntity> emails = emailDao.findByOrcid(orcid);
        if (emails != null && !emails.isEmpty()) {
            for (EmailEntity rc2Email : emails) {
                if (!params.get(EMAIL).equals(rc2Email.getId())) {
                    emailDao.removeEmail(orcid, rc2Email.getId());
                }
            }
        }
        // Remove notifications
        List<NotificationEntity> notifications = notificationDao.findByOrcid(orcid, true, 0, 10000);
        if (notifications != null && !notifications.isEmpty()) {
            for (NotificationEntity notification : notifications) {
                notificationDao.deleteNotificationItemByNotificationId(notification.getId());
                notificationDao.deleteNotificationWorkByNotificationId(notification.getId());
                notificationDao.deleteNotificationById(notification.getId());
            }
        }
        // Remove works
        List<MinimizedWorkEntity> works = workDao.findWorks(orcid, 0L);
        if (works != null && !works.isEmpty()) {
            for (MinimizedWorkEntity work : works) {
                workDao.removeWork(orcid, work.getId());
            }
        }
        // Remove affiliations
        List<OrgAffiliationRelationEntity> affiliations = orgAffiliationRelationDao.getByUser(orcid);
        if (affiliations != null && !affiliations.isEmpty()) {
            for (OrgAffiliationRelationEntity affiliation : affiliations) {
                orgAffiliationRelationDao.remove(affiliation.getId());
            }
        }
        // Remove fundings
        List<ProfileFundingEntity> fundings = profileFundingDao.getByUser(orcid);
        if (fundings != null && !fundings.isEmpty()) {
            for (ProfileFundingEntity funding : fundings) {
                profileFundingDao.removeProfileFunding(orcid, funding.getId());
            }
        }
        // Remove peer reviews
        List<PeerReviewEntity> peerReviews = peerReviewDao.getByUser(orcid);
        if (peerReviews != null && !peerReviews.isEmpty()) {
            for (PeerReviewEntity peerReview : peerReviews) {
                peerReviewDao.removePeerReview(orcid, peerReview.getId());
            }
        }
        // Remove 3d party links
        List<OrcidOauth2TokenDetail> tokenDetails = orcidOauth2TokenDetailDao.findByUserName(orcid);
        if (tokenDetails != null && !tokenDetails.isEmpty()) {
            for (OrcidOauth2TokenDetail token : tokenDetails) {
                orcidOauth2TokenDetailDao.remove(token.getId());
            }
        }
        //Unlock just in case it is locked
        profileDao.unlockProfile(orcid);
        return true;
    }
    return false;
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) FamilyName(org.orcid.jaxb.model.record_v2.FamilyName) ExternalIdentifierEntity(org.orcid.persistence.jpa.entities.ExternalIdentifierEntity) FamilyName(org.orcid.jaxb.model.record_v2.FamilyName) CreditName(org.orcid.jaxb.model.common_v2.CreditName) Name(org.orcid.jaxb.model.record_v2.Name) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity) GivenNames(org.orcid.jaxb.model.record_v2.GivenNames) MinimizedWorkEntity(org.orcid.persistence.jpa.entities.MinimizedWorkEntity) PeerReviewEntity(org.orcid.persistence.jpa.entities.PeerReviewEntity) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) AddressEntity(org.orcid.persistence.jpa.entities.AddressEntity) OrcidOauth2TokenDetail(org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail) ResearcherUrlEntity(org.orcid.persistence.jpa.entities.ResearcherUrlEntity) CreditName(org.orcid.jaxb.model.common_v2.CreditName) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) ApplicationException(org.orcid.core.exception.ApplicationException) OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)

Example 13 with OtherNameEntity

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

the class OtherNameDaoTest method testGetOtherName.

@Test
public void testGetOtherName() {
    OtherNameEntity otherName = otherNameDao.getOtherName("4444-4444-4444-4443", 2L);
    assertNotNull(otherName);
    assertEquals("Flibberdy Flabinah", otherName.getDisplayName());
    assertEquals(Visibility.PUBLIC, otherName.getVisibility());
}
Also used : OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest)

Example 14 with OtherNameEntity

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

the class OtherNameManagerImpl method createOtherName.

@Override
@Transactional
public OtherName createOtherName(String orcid, OtherName otherName, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    // Validate the otherName
    PersonValidator.validateOtherName(otherName, sourceEntity, true, isApiRequest, null);
    // 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", "other-name");
            params.put("value", otherName.getContent());
            throw new OrcidDuplicatedElementException(params);
        }
    }
    OtherNameEntity newEntity = jpaJaxbOtherNameAdapter.toOtherNameEntity(otherName);
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    newEntity.setProfile(profile);
    newEntity.setDateCreated(new Date());
    //Set the source
    if (sourceEntity.getSourceProfile() != null) {
        newEntity.setSourceId(sourceEntity.getSourceProfile().getId());
    }
    if (sourceEntity.getSourceClient() != null) {
        newEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
    }
    setIncomingPrivacy(newEntity, profile);
    DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(newEntity, isApiRequest);
    otherNameDao.persist(newEntity);
    return jpaJaxbOtherNameAdapter.toOtherName(newEntity);
}
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) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with OtherNameEntity

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

the class OtherNameManagerImpl method updateOtherNames.

@Override
@Transactional
public OtherNames updateOtherNames(String orcid, OtherNames otherNames) {
    List<OtherNameEntity> existingOtherNamesEntityList = otherNameDao.getOtherNames(orcid, getLastModified(orcid));
    //Delete the deleted ones
    for (OtherNameEntity existingOtherName : existingOtherNamesEntityList) {
        boolean deleteMe = true;
        if (otherNames.getOtherNames() != null) {
            for (OtherName updatedOrNew : otherNames.getOtherNames()) {
                if (existingOtherName.getId().equals(updatedOrNew.getPutCode())) {
                    deleteMe = false;
                    break;
                }
            }
        }
        if (deleteMe) {
            try {
                otherNameDao.deleteOtherName(existingOtherName);
            } catch (Exception e) {
                throw new ApplicationException("Unable to delete other name " + existingOtherName.getId(), e);
            }
        }
    }
    if (otherNames != null && otherNames.getOtherNames() != null) {
        for (OtherName updatedOrNew : otherNames.getOtherNames()) {
            if (updatedOrNew.getPutCode() != null) {
                //Update the existing ones
                for (OtherNameEntity existingOtherName : existingOtherNamesEntityList) {
                    if (existingOtherName.getId().equals(updatedOrNew.getPutCode())) {
                        existingOtherName.setLastModified(new Date());
                        existingOtherName.setVisibility(updatedOrNew.getVisibility());
                        existingOtherName.setDisplayName(updatedOrNew.getContent());
                        existingOtherName.setDisplayIndex(updatedOrNew.getDisplayIndex());
                        otherNameDao.merge(existingOtherName);
                    }
                }
            } else {
                //Add the new ones
                OtherNameEntity newOtherName = jpaJaxbOtherNameAdapter.toOtherNameEntity(updatedOrNew);
                SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
                ProfileEntity profile = new ProfileEntity(orcid);
                newOtherName.setProfile(profile);
                newOtherName.setDateCreated(new Date());
                //Set the source
                if (sourceEntity.getSourceProfile() != null) {
                    newOtherName.setSourceId(sourceEntity.getSourceProfile().getId());
                }
                if (sourceEntity.getSourceClient() != null) {
                    newOtherName.setClientSourceId(sourceEntity.getSourceClient().getId());
                }
                newOtherName.setVisibility(updatedOrNew.getVisibility());
                newOtherName.setDisplayIndex(updatedOrNew.getDisplayIndex());
                otherNameDao.persist(newOtherName);
            }
        }
    }
    return otherNames;
}
Also used : ApplicationException(org.orcid.core.exception.ApplicationException) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OtherName(org.orcid.jaxb.model.record_v2.OtherName) OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) ApplicationException(org.orcid.core.exception.ApplicationException) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) Date(java.util.Date) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Transactional(org.springframework.transaction.annotation.Transactional)

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