Search in sources :

Example 31 with Visibility

use of org.orcid.jaxb.model.common_rc2.Visibility 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 32 with Visibility

use of org.orcid.jaxb.model.common_rc2.Visibility 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 33 with Visibility

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

the class AffiliationsManagerImpl method setIncomingWorkPrivacy.

private void setIncomingWorkPrivacy(OrgAffiliationRelationEntity orgAffiliationRelationEntity, ProfileEntity profile) {
    Visibility incomingElementVisibility = orgAffiliationRelationEntity.getVisibility();
    Visibility defaultElementVisibility = profile.getActivitiesVisibilityDefault();
    if (profile.getClaimed()) {
        orgAffiliationRelationEntity.setVisibility(defaultElementVisibility);
    } else if (incomingElementVisibility == null) {
        orgAffiliationRelationEntity.setVisibility(Visibility.PRIVATE);
    }
}
Also used : Visibility(org.orcid.jaxb.model.common_v2.Visibility)

Example 34 with Visibility

use of org.orcid.jaxb.model.common_rc2.Visibility 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 35 with Visibility

use of org.orcid.jaxb.model.common_rc2.Visibility 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

Visibility (org.orcid.jaxb.model.common_v2.Visibility)55 ClientResponse (com.sun.jersey.api.client.ClientResponse)35 Test (org.junit.Test)35 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)12 HashMap (java.util.HashMap)10 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)10 OrcidError (org.orcid.jaxb.model.error_rc1.OrcidError)9 Visibility (org.orcid.jaxb.model.common_rc2.Visibility)8 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)8 Date (java.util.Date)7 Visibility (org.orcid.jaxb.model.common_rc1.Visibility)7 Visibility (org.orcid.jaxb.model.common_rc3.Visibility)6 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)5 Funding (org.orcid.jaxb.model.record_v2.Funding)5 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)5 Work (org.orcid.jaxb.model.record_v2.Work)5 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)5 Visibility (org.orcid.jaxb.model.common_rc4.Visibility)4 OrcidError (org.orcid.jaxb.model.error_rc3.OrcidError)4 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)4