Search in sources :

Example 21 with Source

use of org.orcid.jaxb.model.common_v2.Source in project ORCID-Source by ORCID.

the class ExternalIdentifierManagerImpl method updateExternalIdentifier.

@Override
public PersonExternalIdentifier updateExternalIdentifier(String orcid, PersonExternalIdentifier externalIdentifier, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    ExternalIdentifierEntity updatedExternalIdentifierEntity = externalIdentifierDao.getExternalIdentifierEntity(orcid, externalIdentifier.getPutCode());
    //Save the original source
    String existingSourceId = updatedExternalIdentifierEntity.getSourceId();
    String existingClientSourceId = updatedExternalIdentifierEntity.getClientSourceId();
    Visibility originalVisibility = Visibility.fromValue(updatedExternalIdentifierEntity.getVisibility().value());
    // Validate external identifier
    PersonValidator.validateExternalIdentifier(externalIdentifier, sourceEntity, false, isApiRequest, originalVisibility, requireRelationshipOnExternalIdentifier);
    // Validate it is not duplicated
    List<ExternalIdentifierEntity> existingExternalIdentifiers = externalIdentifierDao.getExternalIdentifiers(orcid, getLastModified(orcid));
    for (ExternalIdentifierEntity existing : existingExternalIdentifiers) {
        if (isDuplicated(existing, externalIdentifier, sourceEntity)) {
            Map<String, String> params = new HashMap<String, String>();
            params.put("type", "external-identifier");
            params.put("value", externalIdentifier.getUrl().getValue());
            throw new OrcidDuplicatedElementException(params);
        }
    }
    orcidSecurityManager.checkSource(updatedExternalIdentifierEntity);
    jpaJaxbExternalIdentifierAdapter.toExternalIdentifierEntity(externalIdentifier, updatedExternalIdentifierEntity);
    updatedExternalIdentifierEntity.setLastModified(new Date());
    //Set source
    updatedExternalIdentifierEntity.setSourceId(existingSourceId);
    updatedExternalIdentifierEntity.setClientSourceId(existingClientSourceId);
    externalIdentifierDao.merge(updatedExternalIdentifierEntity);
    return jpaJaxbExternalIdentifierAdapter.toExternalIdentifier(updatedExternalIdentifierEntity);
}
Also used : HashMap(java.util.HashMap) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ExternalIdentifierEntity(org.orcid.persistence.jpa.entities.ExternalIdentifierEntity) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Date(java.util.Date)

Example 22 with Source

use of org.orcid.jaxb.model.common_v2.Source in project ORCID-Source by ORCID.

the class AffiliationsManagerImpl method updateEmploymentAffiliation.

/**
     * Updates a employment that belongs to the given user
     * 
     * @param orcid
     *            The user
     * @param employment
     *            The employment to update
     * @return the updated employment
     * */
@Override
public Employment updateEmploymentAffiliation(String orcid, Employment employment, boolean isApiRequest) {
    OrgAffiliationRelationEntity employmentEntity = orgAffiliationRelationDao.getOrgAffiliationRelation(orcid, employment.getPutCode());
    Visibility originalVisibility = employmentEntity.getVisibility();
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    //Save the original source
    String existingSourceId = employmentEntity.getSourceId();
    String existingClientSourceId = employmentEntity.getClientSourceId();
    orcidSecurityManager.checkSource(employmentEntity);
    activityValidator.validateEmployment(employment, sourceEntity, false, isApiRequest, originalVisibility);
    jpaJaxbEmploymentAdapter.toOrgAffiliationRelationEntity(employment, employmentEntity);
    employmentEntity.setVisibility(originalVisibility);
    //Be sure it doesn't overwrite the source
    employmentEntity.setSourceId(existingSourceId);
    employmentEntity.setClientSourceId(existingClientSourceId);
    // Updates the give organization with the latest organization from
    // database, or, create a new one
    OrgEntity updatedOrganization = orgManager.getOrgEntity(employment);
    employmentEntity.setOrg(updatedOrganization);
    employmentEntity.setAffiliationType(AffiliationType.EMPLOYMENT);
    employmentEntity = orgAffiliationRelationDao.merge(employmentEntity);
    orgAffiliationRelationDao.flush();
    notificationManager.sendAmendEmail(orcid, AmendedSection.EMPLOYMENT, createItem(employmentEntity));
    return jpaJaxbEmploymentAdapter.toEmployment(employmentEntity);
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Visibility(org.orcid.jaxb.model.common_v2.Visibility) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 23 with Source

use of org.orcid.jaxb.model.common_v2.Source in project ORCID-Source by ORCID.

the class AffiliationsManagerImpl method updateEducationAffiliation.

/**
     * Updates a education that belongs to the given user
     * 
     * @param orcid
     *            The user
     * @param education
     *            The education to update
     * @return the updated education
     * */
@Override
public Education updateEducationAffiliation(String orcid, Education education, boolean isApiRequest) {
    OrgAffiliationRelationEntity educationEntity = orgAffiliationRelationDao.getOrgAffiliationRelation(orcid, education.getPutCode());
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    //Save the original source
    String existingSourceId = educationEntity.getSourceId();
    String existingClientSourceId = educationEntity.getClientSourceId();
    Visibility originalVisibility = educationEntity.getVisibility();
    orcidSecurityManager.checkSource(educationEntity);
    activityValidator.validateEducation(education, sourceEntity, false, isApiRequest, originalVisibility);
    jpaJaxbEducationAdapter.toOrgAffiliationRelationEntity(education, educationEntity);
    educationEntity.setVisibility(originalVisibility);
    //Be sure it doesn't overwrite the source
    educationEntity.setSourceId(existingSourceId);
    educationEntity.setClientSourceId(existingClientSourceId);
    // Updates the give organization with the latest organization from
    // database, or, create a new one
    OrgEntity updatedOrganization = orgManager.getOrgEntity(education);
    educationEntity.setOrg(updatedOrganization);
    educationEntity.setAffiliationType(AffiliationType.EDUCATION);
    educationEntity = orgAffiliationRelationDao.merge(educationEntity);
    orgAffiliationRelationDao.flush();
    notificationManager.sendAmendEmail(orcid, AmendedSection.EDUCATION, createItem(educationEntity));
    return jpaJaxbEducationAdapter.toEducation(educationEntity);
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Visibility(org.orcid.jaxb.model.common_v2.Visibility) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 24 with Source

use of org.orcid.jaxb.model.common_v2.Source 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 25 with Source

use of org.orcid.jaxb.model.common_v2.Source 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)

Aggregations

Test (org.junit.Test)25 Source (org.orcid.jaxb.model.common_v2.Source)16 Source (hex.glm.GLM2.Source)11 Url (org.orcid.jaxb.model.common_v2.Url)11 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)11 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)11 Visibility (org.orcid.jaxb.model.common_v2.Visibility)10 SourceClientId (org.orcid.jaxb.model.common_v2.SourceClientId)7 Items (org.orcid.jaxb.model.notification.permission_v2.Items)6 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)6 Date (java.util.Date)5 HashMap (java.util.HashMap)5 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)5 Item (org.orcid.jaxb.model.notification.permission_v2.Item)5 CreatedDate (org.orcid.jaxb.model.common_v2.CreatedDate)4 LastModifiedDate (org.orcid.jaxb.model.common_v2.LastModifiedDate)4 SourceName (org.orcid.jaxb.model.common_v2.SourceName)4 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)4 SourceOrcid (org.orcid.jaxb.model.common_v2.SourceOrcid)3 NotificationPermission (org.orcid.jaxb.model.notification.permission_v2.NotificationPermission)3