Search in sources :

Example 11 with Organization

use of org.orcid.jaxb.model.v3.dev1.common.Organization in project ORCID-Source by ORCID.

the class ProfileFundingManagerImpl method updateFunding.

/**
 * Updates a funding that belongs to the given user
 * @param orcid
 *          The user
 * @param funding
 *          The funding to update
 * @return the updated funding
 */
@Override
public Funding updateFunding(String orcid, Funding funding, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    ProfileFundingEntity pfe = profileFundingDao.getProfileFunding(orcid, funding.getPutCode());
    Visibility originalVisibility = Visibility.fromValue(pfe.getVisibility().value());
    // Save the original source
    String existingSourceId = pfe.getSourceId();
    String existingClientSourceId = pfe.getClientSourceId();
    activityValidator.validateFunding(funding, sourceEntity, false, isApiRequest, originalVisibility);
    if (!isApiRequest) {
        List<ProfileFundingEntity> existingFundings = profileFundingDao.getByUser(orcid, getLastModified(orcid));
        for (ProfileFundingEntity existingFunding : existingFundings) {
            Funding existing = jpaJaxbFundingAdapter.toFunding(existingFunding);
            if (!existing.getPutCode().equals(funding.getPutCode())) {
                activityValidator.checkFundingExternalIdentifiersForDuplicates(funding.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceEntity);
            }
        }
    }
    orcidSecurityManager.checkSource(pfe);
    jpaJaxbFundingAdapter.toProfileFundingEntity(funding, pfe);
    pfe.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(originalVisibility.value()));
    // Be sure it doesn't overwrite the source
    pfe.setSourceId(existingSourceId);
    pfe.setClientSourceId(existingClientSourceId);
    // Updates the give organization with the latest organization from database, or, create a new one
    OrgEntity updatedOrganization = orgManager.getOrgEntity(funding);
    pfe.setOrg(updatedOrganization);
    pfe = profileFundingDao.merge(pfe);
    profileFundingDao.flush();
    if (!isApiRequest) {
        notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItemList(pfe));
    }
    return jpaJaxbFundingAdapter.toFunding(pfe);
}
Also used : Funding(org.orcid.jaxb.model.v3.dev1.record.Funding) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 12 with Organization

use of org.orcid.jaxb.model.v3.dev1.common.Organization in project ORCID-Source by ORCID.

the class ProfileFundingManagerImpl method createFunding.

/**
 * Add a new funding to the given user
 * @param orcid
 *          The user to add the funding
 * @param funding
 *          The funding to add
 * @return the added funding
 */
@Override
@Transactional
public Funding createFunding(String orcid, Funding funding, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    activityValidator.validateFunding(funding, sourceEntity, true, isApiRequest, null);
    // Check for duplicates
    List<ProfileFundingEntity> existingFundings = profileFundingDao.getByUser(orcid, getLastModified(orcid));
    List<Funding> fundings = jpaJaxbFundingAdapter.toFunding(existingFundings);
    if (fundings != null && isApiRequest) {
        for (Funding exstingFunding : fundings) {
            activityValidator.checkFundingExternalIdentifiersForDuplicates(funding.getExternalIdentifiers(), exstingFunding.getExternalIdentifiers(), exstingFunding.getSource(), sourceEntity);
        }
    }
    ProfileFundingEntity profileFundingEntity = jpaJaxbFundingAdapter.toProfileFundingEntity(funding);
    // Updates the give organization with the latest organization from database
    OrgEntity updatedOrganization = orgManager.getOrgEntity(funding);
    profileFundingEntity.setOrg(updatedOrganization);
    // Set the source
    if (sourceEntity.getSourceProfile() != null) {
        profileFundingEntity.setSourceId(sourceEntity.getSourceProfile().getId());
    }
    if (sourceEntity.getSourceClient() != null) {
        profileFundingEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
    }
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    profileFundingEntity.setProfile(profile);
    setIncomingWorkPrivacy(profileFundingEntity, profile);
    DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(profileFundingEntity, isApiRequest);
    profileFundingDao.persist(profileFundingEntity);
    profileFundingDao.flush();
    if (isApiRequest) {
        notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItemList(profileFundingEntity));
    }
    return jpaJaxbFundingAdapter.toFunding(profileFundingEntity);
}
Also used : Funding(org.orcid.jaxb.model.v3.dev1.record.Funding) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with Organization

use of org.orcid.jaxb.model.v3.dev1.common.Organization in project ORCID-Source by ORCID.

the class AffiliationsManagerImpl method createAffiliation.

private Affiliation createAffiliation(String orcid, Affiliation affiliation, boolean isApiRequest, AffiliationType type) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    activityValidator.validateAffiliation(affiliation, sourceEntity, true, isApiRequest, null);
    if (isApiRequest) {
        checkAffiliationExternalIDsForDuplicates(orcid, affiliation, sourceEntity);
    }
    OrgAffiliationRelationEntity entity = null;
    switch(type) {
        case DISTINCTION:
            entity = jpaJaxbDistinctionAdapter.toOrgAffiliationRelationEntity((Distinction) affiliation);
            break;
        case EDUCATION:
            entity = jpaJaxbEducationAdapter.toOrgAffiliationRelationEntity((Education) affiliation);
            break;
        case EMPLOYMENT:
            entity = jpaJaxbEmploymentAdapter.toOrgAffiliationRelationEntity((Employment) affiliation);
            break;
        case INVITED_POSITION:
            entity = jpaJaxbInvitedPositionAdapter.toOrgAffiliationRelationEntity((InvitedPosition) affiliation);
            break;
        case MEMBERSHIP:
            entity = jpaJaxbMembershipAdapter.toOrgAffiliationRelationEntity((Membership) affiliation);
            break;
        case QUALIFICATION:
            entity = jpaJaxbQualificationAdapter.toOrgAffiliationRelationEntity((Qualification) affiliation);
            break;
        case SERVICE:
            entity = jpaJaxbServiceAdapter.toOrgAffiliationRelationEntity((Service) affiliation);
            break;
    }
    // Updates the give organization with the latest organization from
    // database
    OrgEntity updatedOrganization = orgManager.getOrgEntity(affiliation);
    entity.setOrg(updatedOrganization);
    // Set source id
    if (sourceEntity.getSourceProfile() != null) {
        entity.setSourceId(sourceEntity.getSourceProfile().getId());
    }
    if (sourceEntity.getSourceClient() != null) {
        entity.setClientSourceId(sourceEntity.getSourceClient().getId());
    }
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    entity.setProfile(profile);
    setIncomingWorkPrivacy(entity, profile);
    entity.setAffiliationType(type);
    orgAffiliationRelationDao.persist(entity);
    orgAffiliationRelationDao.flush();
    Affiliation result = null;
    switch(type) {
        case DISTINCTION:
            notificationManager.sendAmendEmail(orcid, AmendedSection.DISTINCTION, createItemList(entity));
            result = jpaJaxbDistinctionAdapter.toDistinction(entity);
            break;
        case EDUCATION:
            notificationManager.sendAmendEmail(orcid, AmendedSection.EDUCATION, createItemList(entity));
            result = jpaJaxbEducationAdapter.toEducation(entity);
            break;
        case EMPLOYMENT:
            notificationManager.sendAmendEmail(orcid, AmendedSection.EMPLOYMENT, createItemList(entity));
            result = jpaJaxbEmploymentAdapter.toEmployment(entity);
            break;
        case INVITED_POSITION:
            notificationManager.sendAmendEmail(orcid, AmendedSection.INVITED_POSITION, createItemList(entity));
            result = jpaJaxbInvitedPositionAdapter.toInvitedPosition(entity);
            break;
        case MEMBERSHIP:
            notificationManager.sendAmendEmail(orcid, AmendedSection.MEMBERSHIP, createItemList(entity));
            result = jpaJaxbMembershipAdapter.toMembership(entity);
            break;
        case QUALIFICATION:
            notificationManager.sendAmendEmail(orcid, AmendedSection.QUALIFICATION, createItemList(entity));
            result = jpaJaxbQualificationAdapter.toQualification(entity);
            break;
        case SERVICE:
            notificationManager.sendAmendEmail(orcid, AmendedSection.SERVICE, createItemList(entity));
            result = jpaJaxbServiceAdapter.toService(entity);
            break;
    }
    return result;
}
Also used : Qualification(org.orcid.jaxb.model.v3.dev1.record.Qualification) Education(org.orcid.jaxb.model.v3.dev1.record.Education) Employment(org.orcid.jaxb.model.v3.dev1.record.Employment) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) InvitedPosition(org.orcid.jaxb.model.v3.dev1.record.InvitedPosition) Membership(org.orcid.jaxb.model.v3.dev1.record.Membership) Service(org.orcid.jaxb.model.v3.dev1.record.Service) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) Distinction(org.orcid.jaxb.model.v3.dev1.record.Distinction) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity) Affiliation(org.orcid.jaxb.model.v3.dev1.record.Affiliation)

Example 14 with Organization

use of org.orcid.jaxb.model.v3.dev1.common.Organization in project ORCID-Source by ORCID.

the class GetMyDataControllerTest method setOrg.

private void setOrg(OrganizationHolder oh) {
    OrganizationAddress address = new OrganizationAddress();
    address.setCity("city");
    address.setCountry(Iso3166Country.US);
    Organization org = new Organization();
    org.setName("Organization");
    org.setAddress(address);
    oh.setOrganization(org);
}
Also used : Organization(org.orcid.jaxb.model.v3.dev1.common.Organization) OrganizationAddress(org.orcid.jaxb.model.v3.dev1.common.OrganizationAddress)

Example 15 with Organization

use of org.orcid.jaxb.model.v3.dev1.common.Organization in project ORCID-Source by ORCID.

the class AffiliationsManagerTest method fillAffiliation.

private void fillAffiliation(Affiliation aff) {
    Organization org = new Organization();
    org.setName("org-name");
    OrganizationAddress address = new OrganizationAddress();
    address.setCity("city");
    address.setCountry(Iso3166Country.US);
    org.setAddress(address);
    DisambiguatedOrganization disambiguatedOrg = new DisambiguatedOrganization();
    disambiguatedOrg.setDisambiguatedOrganizationIdentifier("def456");
    disambiguatedOrg.setDisambiguationSource("WDB");
    org.setDisambiguatedOrganization(disambiguatedOrg);
    aff.setOrganization(org);
    aff.setStartDate(new FuzzyDate(new Year(2016), new Month(3), new Day(29)));
    aff.setVisibility(Visibility.PUBLIC);
}
Also used : Month(org.orcid.jaxb.model.v3.dev1.common.Month) Organization(org.orcid.jaxb.model.v3.dev1.common.Organization) DisambiguatedOrganization(org.orcid.jaxb.model.v3.dev1.common.DisambiguatedOrganization) DisambiguatedOrganization(org.orcid.jaxb.model.v3.dev1.common.DisambiguatedOrganization) Year(org.orcid.jaxb.model.v3.dev1.common.Year) OrganizationAddress(org.orcid.jaxb.model.v3.dev1.common.OrganizationAddress) FuzzyDate(org.orcid.jaxb.model.v3.dev1.common.FuzzyDate) Day(org.orcid.jaxb.model.v3.dev1.common.Day)

Aggregations

Organization (org.orcid.jaxb.model.v3.dev1.common.Organization)12 OrganizationAddress (org.orcid.jaxb.model.v3.dev1.common.OrganizationAddress)12 DisambiguatedOrganization (org.orcid.jaxb.model.v3.dev1.common.DisambiguatedOrganization)11 Url (org.orcid.jaxb.model.v3.dev1.common.Url)6 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)6 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)6 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)5 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)5 Title (org.orcid.jaxb.model.v3.dev1.common.Title)4 Funding (org.orcid.jaxb.model.v3.dev1.record.Funding)4 FuzzyDate (org.orcid.jaxb.model.v3.dev1.common.FuzzyDate)3 Affiliation (org.orcid.jaxb.model.v3.dev1.record.Affiliation)3 Distinction (org.orcid.jaxb.model.v3.dev1.record.Distinction)3 Education (org.orcid.jaxb.model.v3.dev1.record.Education)3 Employment (org.orcid.jaxb.model.v3.dev1.record.Employment)3 InvitedPosition (org.orcid.jaxb.model.v3.dev1.record.InvitedPosition)3 Membership (org.orcid.jaxb.model.v3.dev1.record.Membership)3 PeerReview (org.orcid.jaxb.model.v3.dev1.record.PeerReview)3 Qualification (org.orcid.jaxb.model.v3.dev1.record.Qualification)3 Service (org.orcid.jaxb.model.v3.dev1.record.Service)3