Search in sources :

Example 81 with SourceEntity

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

the class GroupIdRecordManagerImpl method updateGroupIdRecord.

@Override
public GroupIdRecord updateGroupIdRecord(Long putCode, GroupIdRecord groupIdRecord) {
    GroupIdRecordEntity existingEntity = groupIdRecordDao.find(putCode);
    if (existingEntity == null) {
        throw new GroupIdRecordNotFoundException();
    }
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    // Save the original source
    String existingSourceId = existingEntity.getSourceId();
    String existingClientSourceId = existingEntity.getClientSourceId();
    activityValidator.validateGroupIdRecord(groupIdRecord, false, sourceEntity);
    validateDuplicate(groupIdRecord);
    orcidSecurityManager.checkSource(existingEntity);
    GroupIdRecordEntity updatedEntity = jpaJaxbGroupIdRecordAdapter.toGroupIdRecordEntity(groupIdRecord);
    updatedEntity.setDateCreated(existingEntity.getDateCreated());
    // Be sure it doesn't overwrite the source
    updatedEntity.setSourceId(existingSourceId);
    updatedEntity.setClientSourceId(existingClientSourceId);
    updatedEntity = groupIdRecordDao.merge(updatedEntity);
    return jpaJaxbGroupIdRecordAdapter.toGroupIdRecord(updatedEntity);
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) GroupIdRecordEntity(org.orcid.persistence.jpa.entities.GroupIdRecordEntity) GroupIdRecordNotFoundException(org.orcid.core.exception.GroupIdRecordNotFoundException)

Example 82 with SourceEntity

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

the class IdentifierTypeManagerImpl method createIdentifierType.

@Override
@CacheEvict(value = { "identifier-types", "identifier-types-map" }, allEntries = true)
public IdentifierType createIdentifierType(IdentifierType id) {
    IdentifierTypeEntity entity = adapter.fromPojo(id);
    SourceEntity source = sourceManager.retrieveSourceEntity();
    entity.setSourceClient(source.getSourceClient());
    Date now = new Date();
    entity.setDateCreated(now);
    entity.setLastModified(now);
    entity = idTypeDao.addIdentifierType(entity);
    return adapter.fromEntity(entity);
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) IdentifierTypeEntity(org.orcid.persistence.jpa.entities.IdentifierTypeEntity) Date(java.util.Date) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 83 with SourceEntity

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

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

Example 85 with SourceEntity

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

the class ProfileKeywordManagerImpl method updateKeywords.

@Override
@Transactional
public Keywords updateKeywords(String orcid, Keywords keywords) {
    List<ProfileKeywordEntity> existingKeywordsList = profileKeywordDao.getProfileKeywors(orcid, getLastModified(orcid));
    // Delete the deleted ones
    for (ProfileKeywordEntity existing : existingKeywordsList) {
        boolean deleteMe = true;
        if (keywords.getKeywords() != null) {
            for (Keyword updatedOrNew : keywords.getKeywords()) {
                if (existing.getId().equals(updatedOrNew.getPutCode())) {
                    deleteMe = false;
                    break;
                }
            }
        }
        if (deleteMe) {
            try {
                profileKeywordDao.deleteProfileKeyword(existing);
            } catch (Exception e) {
                throw new ApplicationException("Unable to delete keyword " + existing.getId(), e);
            }
        }
    }
    if (keywords != null && keywords.getKeywords() != null) {
        for (Keyword updatedOrNew : keywords.getKeywords()) {
            if (updatedOrNew.getPutCode() != null) {
                // Update the existing ones
                for (ProfileKeywordEntity existingKeyword : existingKeywordsList) {
                    if (existingKeyword.getId().equals(updatedOrNew.getPutCode())) {
                        existingKeyword.setLastModified(new Date());
                        existingKeyword.setVisibility(updatedOrNew.getVisibility());
                        existingKeyword.setKeywordName(updatedOrNew.getContent());
                        existingKeyword.setDisplayIndex(updatedOrNew.getDisplayIndex());
                        profileKeywordDao.merge(existingKeyword);
                    }
                }
            } else {
                // Add the new ones
                ProfileKeywordEntity newKeyword = adapter.toProfileKeywordEntity(updatedOrNew);
                SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
                ProfileEntity profile = new ProfileEntity(orcid);
                newKeyword.setProfile(profile);
                newKeyword.setDateCreated(new Date());
                //Set the source
                if (sourceEntity.getSourceProfile() != null) {
                    newKeyword.setSourceId(sourceEntity.getSourceProfile().getId());
                }
                if (sourceEntity.getSourceClient() != null) {
                    newKeyword.setClientSourceId(sourceEntity.getSourceClient().getId());
                }
                newKeyword.setVisibility(updatedOrNew.getVisibility());
                newKeyword.setDisplayIndex(updatedOrNew.getDisplayIndex());
                profileKeywordDao.persist(newKeyword);
            }
        }
    }
    return keywords;
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) ApplicationException(org.orcid.core.exception.ApplicationException) Keyword(org.orcid.jaxb.model.record_v2.Keyword) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ApplicationException(org.orcid.core.exception.ApplicationException) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) Date(java.util.Date) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Transactional(javax.transaction.Transactional)

Aggregations

SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)111 Test (org.junit.Test)58 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)57 BaseTest (org.orcid.core.BaseTest)44 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)28 Date (java.util.Date)19 HashMap (java.util.HashMap)15 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)14 Work (org.orcid.jaxb.model.record_v2.Work)14 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)13 Visibility (org.orcid.jaxb.model.common_v2.Visibility)12 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)11 Transactional (org.springframework.transaction.annotation.Transactional)11 Funding (org.orcid.jaxb.model.record_v2.Funding)10 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)6 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)6 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)6 PeerReviewEntity (org.orcid.persistence.jpa.entities.PeerReviewEntity)6 WorkEntity (org.orcid.persistence.jpa.entities.WorkEntity)6 GroupIdRecord (org.orcid.jaxb.model.groupid_v2.GroupIdRecord)5