Search in sources :

Example 51 with SourceEntity

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

the class WorkManagerImpl method updateWork.

@Override
@Transactional
public Work updateWork(String orcid, Work work, boolean isApiRequest) {
    WorkEntity workEntity = workDao.getWork(orcid, work.getPutCode());
    Visibility originalVisibility = workEntity.getVisibility();
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    //Save the original source
    String existingSourceId = workEntity.getSourceId();
    String existingClientSourceId = workEntity.getClientSourceId();
    if (isApiRequest) {
        activityValidator.validateWork(work, sourceEntity, false, isApiRequest, workEntity.getVisibility());
        long lastModifiedTime = getLastModified(orcid);
        List<Work> existingWorks = this.findWorks(orcid, lastModifiedTime);
        for (Work existing : existingWorks) {
            // Dont compare the updated peer review with the DB version
            if (!existing.getPutCode().equals(work.getPutCode())) {
                activityValidator.checkExternalIdentifiersForDuplicates(work.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceEntity);
            }
        }
    } else {
        //validate external ID vocab
        externalIDValidator.validateWorkOrPeerReview(work.getExternalIdentifiers());
    }
    orcidSecurityManager.checkSource(workEntity);
    jpaJaxbWorkAdapter.toWorkEntity(work, workEntity);
    workEntity.setVisibility(originalVisibility);
    //Be sure it doesn't overwrite the source
    workEntity.setSourceId(existingSourceId);
    workEntity.setClientSourceId(existingClientSourceId);
    workDao.merge(workEntity);
    workDao.flush();
    notificationManager.sendAmendEmail(orcid, AmendedSection.WORK, createItem(workEntity));
    return jpaJaxbWorkAdapter.toWork(workEntity);
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Work(org.orcid.jaxb.model.record_v2.Work) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Transactional(org.springframework.transaction.annotation.Transactional)

Example 52 with SourceEntity

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

the class WorkManagerImpl method createWork.

@Override
@Transactional
public Work createWork(String orcid, Work work, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    if (isApiRequest) {
        activityValidator.validateWork(work, sourceEntity, true, isApiRequest, null);
        // duplicates
        if (!sourceEntity.getSourceId().equals(orcid)) {
            long lastModifiedTime = getLastModified(orcid);
            List<Work> existingWorks = this.findWorks(orcid, lastModifiedTime);
            if (existingWorks != null) {
                for (Work existing : existingWorks) {
                    activityValidator.checkExternalIdentifiersForDuplicates(work.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceEntity);
                }
            }
        }
    } else {
        // validate external ID vocab
        externalIDValidator.validateWorkOrPeerReview(work.getExternalIdentifiers());
    }
    WorkEntity workEntity = jpaJaxbWorkAdapter.toWorkEntity(work);
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    workEntity.setProfile(profile);
    workEntity.setAddedToProfileDate(new Date());
    // Set source id 
    if (sourceEntity.getSourceProfile() != null) {
        workEntity.setSourceId(sourceEntity.getSourceProfile().getId());
    }
    if (sourceEntity.getSourceClient() != null) {
        workEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
    }
    setIncomingWorkPrivacy(workEntity, profile);
    DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(workEntity, isApiRequest);
    workDao.persist(workEntity);
    workDao.flush();
    notificationManager.sendAmendEmail(orcid, AmendedSection.WORK, createItem(workEntity));
    return jpaJaxbWorkAdapter.toWork(workEntity);
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Work(org.orcid.jaxb.model.record_v2.Work) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 53 with SourceEntity

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

the class ResearcherUrlManagerImpl method updateResearcherUrl.

@Override
@Transactional
public ResearcherUrl updateResearcherUrl(String orcid, ResearcherUrl researcherUrl, boolean isApiRequest) {
    ResearcherUrlEntity updatedResearcherUrlEntity = researcherUrlDao.getResearcherUrl(orcid, researcherUrl.getPutCode());
    Visibility originalVisibility = Visibility.fromValue(updatedResearcherUrlEntity.getVisibility().value());
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    //Save the original source
    String existingSourceId = updatedResearcherUrlEntity.getSourceId();
    String existingClientSourceId = updatedResearcherUrlEntity.getClientSourceId();
    // Validate the researcher url
    PersonValidator.validateResearcherUrl(researcherUrl, sourceEntity, false, isApiRequest, originalVisibility);
    // Validate it is not duplicated
    List<ResearcherUrlEntity> existingResearcherUrls = researcherUrlDao.getResearcherUrls(orcid, getLastModified(orcid));
    for (ResearcherUrlEntity existing : existingResearcherUrls) {
        if (isDuplicated(existing, researcherUrl, sourceEntity)) {
            Map<String, String> params = new HashMap<String, String>();
            params.put("type", "researcher-url");
            params.put("value", researcherUrl.getUrlName());
            throw new OrcidDuplicatedElementException(params);
        }
    }
    orcidSecurityManager.checkSource(updatedResearcherUrlEntity);
    jpaJaxbResearcherUrlAdapter.toResearcherUrlEntity(researcherUrl, updatedResearcherUrlEntity);
    updatedResearcherUrlEntity.setLastModified(new Date());
    //Be sure it doesn't overwrite the source
    updatedResearcherUrlEntity.setSourceId(existingSourceId);
    updatedResearcherUrlEntity.setClientSourceId(existingClientSourceId);
    researcherUrlDao.merge(updatedResearcherUrlEntity);
    return jpaJaxbResearcherUrlAdapter.toResearcherUrl(updatedResearcherUrlEntity);
}
Also used : HashMap(java.util.HashMap) ResearcherUrlEntity(org.orcid.persistence.jpa.entities.ResearcherUrlEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 54 with SourceEntity

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

the class ResearcherUrlManagerImpl method updateResearcherUrls.

/**
     * Update the researcher urls associated with a specific account
     * 
     * @param orcid
     * @param researcherUrls
     * */
@Override
@Transactional
public ResearcherUrls updateResearcherUrls(String orcid, ResearcherUrls researcherUrls) {
    List<ResearcherUrlEntity> existingEntities = researcherUrlDao.getResearcherUrls(orcid, getLastModified(orcid));
    //Delete the deleted ones
    for (ResearcherUrlEntity existingEntity : existingEntities) {
        boolean deleteMe = true;
        if (researcherUrls.getResearcherUrls() != null) {
            for (ResearcherUrl updatedOrNew : researcherUrls.getResearcherUrls()) {
                if (existingEntity.getId().equals(updatedOrNew.getPutCode())) {
                    deleteMe = false;
                    break;
                }
            }
        }
        if (deleteMe) {
            try {
                researcherUrlDao.deleteResearcherUrl(existingEntity.getProfile().getId(), existingEntity.getId());
            } catch (Exception e) {
                throw new ApplicationException("Unable to delete researcher url " + existingEntity.getId(), e);
            }
        }
    }
    // Update or create new
    if (researcherUrls != null && researcherUrls.getResearcherUrls() != null) {
        for (ResearcherUrl updatedOrNew : researcherUrls.getResearcherUrls()) {
            if (updatedOrNew.getPutCode() != null) {
                //Update the existing ones
                for (ResearcherUrlEntity existingEntity : existingEntities) {
                    if (existingEntity.getId().equals(updatedOrNew.getPutCode())) {
                        existingEntity.setLastModified(new Date());
                        existingEntity.setVisibility(updatedOrNew.getVisibility());
                        existingEntity.setUrl(updatedOrNew.getUrl().getValue());
                        existingEntity.setUrlName(updatedOrNew.getUrlName());
                        existingEntity.setDisplayIndex(updatedOrNew.getDisplayIndex());
                        researcherUrlDao.merge(existingEntity);
                    }
                }
            } else {
                //Add the new ones
                ResearcherUrlEntity newResearcherUrl = jpaJaxbResearcherUrlAdapter.toResearcherUrlEntity(updatedOrNew);
                SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
                ProfileEntity profile = new ProfileEntity(orcid);
                newResearcherUrl.setUser(profile);
                newResearcherUrl.setDateCreated(new Date());
                newResearcherUrl.setLastModified(new Date());
                if (sourceEntity.getSourceProfile() != null) {
                    newResearcherUrl.setSourceId(sourceEntity.getSourceProfile().getId());
                }
                if (sourceEntity.getSourceClient() != null) {
                    newResearcherUrl.setClientSourceId(sourceEntity.getSourceClient().getId());
                }
                newResearcherUrl.setVisibility(updatedOrNew.getVisibility());
                newResearcherUrl.setDisplayIndex(updatedOrNew.getDisplayIndex());
                researcherUrlDao.persist(newResearcherUrl);
            }
        }
    }
    return researcherUrls;
}
Also used : ApplicationException(org.orcid.core.exception.ApplicationException) ResearcherUrlEntity(org.orcid.persistence.jpa.entities.ResearcherUrlEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ResearcherUrl(org.orcid.jaxb.model.record_v2.ResearcherUrl) 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 55 with SourceEntity

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

the class ResearcherUrlManagerImpl method createResearcherUrl.

@Override
public ResearcherUrl createResearcherUrl(String orcid, ResearcherUrl researcherUrl, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    // Validate the researcher url
    PersonValidator.validateResearcherUrl(researcherUrl, sourceEntity, true, isApiRequest, null);
    // Validate it is not duplicated
    List<ResearcherUrlEntity> existingResearcherUrls = researcherUrlDao.getResearcherUrls(orcid, getLastModified(orcid));
    for (ResearcherUrlEntity existing : existingResearcherUrls) {
        if (isDuplicated(existing, researcherUrl, sourceEntity)) {
            Map<String, String> params = new HashMap<String, String>();
            params.put("type", "researcher-url");
            params.put("value", researcherUrl.getUrlName());
            throw new OrcidDuplicatedElementException(params);
        }
    }
    ResearcherUrlEntity newEntity = jpaJaxbResearcherUrlAdapter.toResearcherUrlEntity(researcherUrl);
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    newEntity.setUser(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);
    researcherUrlDao.persist(newEntity);
    return jpaJaxbResearcherUrlAdapter.toResearcherUrl(newEntity);
}
Also used : HashMap(java.util.HashMap) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ResearcherUrlEntity(org.orcid.persistence.jpa.entities.ResearcherUrlEntity) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date)

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