Search in sources :

Example 1 with OrgAffiliationRelationEntity

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

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

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

the class AffiliationsManagerImpl method checkSourceAndDelete.

/**
     * Deletes a given affiliation, if and only if, the client that requested
     * the delete is the source of the affiliation
     * 
     * @param orcid
     *            the affiliation owner
     * @param affiliationId
     *            The affiliation id
     * @return true if the affiliation was deleted, false otherwise
     * */
@Override
public boolean checkSourceAndDelete(String orcid, Long affiliationId) {
    OrgAffiliationRelationEntity affiliationEntity = orgAffiliationRelationDao.getOrgAffiliationRelation(orcid, affiliationId);
    orcidSecurityManager.checkSource(affiliationEntity);
    boolean result = orgAffiliationRelationDao.removeOrgAffiliationRelation(orcid, affiliationId);
    if (result)
        notificationManager.sendAmendEmail(orcid, AmendedSection.EMPLOYMENT, createItem(affiliationEntity));
    return result;
}
Also used : OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)

Example 4 with OrgAffiliationRelationEntity

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

the class AffiliationsManagerReadOnlyImpl method getAffiliations.

@Override
public List<Affiliation> getAffiliations(String orcid) {
    List<OrgAffiliationRelationEntity> affiliations = orgAffiliationRelationDao.getByUser(orcid);
    List<Affiliation> result = new ArrayList<Affiliation>();
    if (affiliations != null) {
        for (OrgAffiliationRelationEntity affiliation : affiliations) {
            if (AffiliationType.EDUCATION.equals(affiliation.getAffiliationType())) {
                result.add(jpaJaxbEducationAdapter.toEducation(affiliation));
            } else {
                result.add(jpaJaxbEmploymentAdapter.toEmployment(affiliation));
            }
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) Affiliation(org.orcid.jaxb.model.record_v2.Affiliation)

Example 5 with OrgAffiliationRelationEntity

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

the class Jaxb2JpaAdapterImpl method getOrgAffiliationRelationEntity.

private OrgAffiliationRelationEntity getOrgAffiliationRelationEntity(Affiliation affiliation, OrgAffiliationRelationEntity exisitingOrgAffiliationEntity) {
    if (affiliation != null) {
        // Get the org
        OrgEntity orgEntity = getOrgEntity(affiliation);
        OrgAffiliationRelationEntity orgRelationEntity = null;
        if (exisitingOrgAffiliationEntity == null) {
            String putCode = affiliation.getPutCode();
            if (StringUtils.isNotBlank(putCode) && !"-1".equals(putCode)) {
                throw new IllegalArgumentException("Invalid put-code was supplied for an affiliation: " + putCode);
            }
            orgRelationEntity = new OrgAffiliationRelationEntity();
        } else {
            orgRelationEntity = exisitingOrgAffiliationEntity;
            orgRelationEntity.clean();
        }
        FuzzyDate startDate = affiliation.getStartDate();
        FuzzyDate endDate = affiliation.getEndDate();
        if (affiliation.getType() != null) {
            orgRelationEntity.setAffiliationType(AffiliationType.fromValue(affiliation.getType().value()));
        }
        if (affiliation.getVisibility() != null) {
            orgRelationEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(affiliation.getVisibility().value()));
        } else {
            orgRelationEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
        }
        //Set source
        setSource(affiliation.getSource(), orgRelationEntity);
        orgRelationEntity.setDepartment(affiliation.getDepartmentName());
        orgRelationEntity.setEndDate(endDate != null ? new EndDateEntity(endDate) : null);
        orgRelationEntity.setOrg(orgEntity);
        orgRelationEntity.setTitle(affiliation.getRoleTitle());
        orgRelationEntity.setStartDate(startDate != null ? new StartDateEntity(startDate) : null);
        if (affiliation.getCreatedDate() != null && affiliation.getCreatedDate().getValue() != null)
            orgRelationEntity.setDateCreated(affiliation.getCreatedDate().getValue().toGregorianCalendar().getTime());
        if (affiliation.getLastModifiedDate() != null && affiliation.getLastModifiedDate().getValue() != null)
            orgRelationEntity.setLastModified(affiliation.getLastModifiedDate().getValue().toGregorianCalendar().getTime());
        return orgRelationEntity;
    }
    return null;
}
Also used : EndDateEntity(org.orcid.persistence.jpa.entities.EndDateEntity) StartDateEntity(org.orcid.persistence.jpa.entities.StartDateEntity) FuzzyDate(org.orcid.jaxb.model.message.FuzzyDate) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Aggregations

OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)28 Test (org.junit.Test)8 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)8 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)7 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)6 Education (org.orcid.jaxb.model.record_v2.Education)3 Employment (org.orcid.jaxb.model.record_v2.Employment)3 EndDateEntity (org.orcid.persistence.jpa.entities.EndDateEntity)3 ExternalIdentifierEntity (org.orcid.persistence.jpa.entities.ExternalIdentifierEntity)3 OtherNameEntity (org.orcid.persistence.jpa.entities.OtherNameEntity)3 ProfileFundingEntity (org.orcid.persistence.jpa.entities.ProfileFundingEntity)3 ProfileKeywordEntity (org.orcid.persistence.jpa.entities.ProfileKeywordEntity)3 ResearcherUrlEntity (org.orcid.persistence.jpa.entities.ResearcherUrlEntity)3 StartDateEntity (org.orcid.persistence.jpa.entities.StartDateEntity)3 TreeSet (java.util.TreeSet)2 MapperFactory (ma.glasnost.orika.MapperFactory)2 DefaultMapperFactory (ma.glasnost.orika.impl.DefaultMapperFactory)2 Visibility (org.orcid.jaxb.model.common_v2.Visibility)2 Affiliation (org.orcid.jaxb.model.message.Affiliation)2 EducationSummary (org.orcid.jaxb.model.record.summary_v2.EducationSummary)2