Search in sources :

Example 51 with OrgEntity

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

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

the class Jaxb2JpaAdapterImpl method getOrgEntity.

/**
 * Get an OrgEntity object based on the provided orcidGrant
 *
 * @param orcidGrant
 * @return a OrgEntity based on the provided OrcidGrant
 */
private OrgEntity getOrgEntity(Funding orcidFunding) {
    if (orcidFunding != null) {
        OrgEntity orgEntity = new OrgEntity();
        Organization organization = orcidFunding.getOrganization();
        orgEntity.setName(organization.getName());
        OrganizationAddress address = organization.getAddress();
        orgEntity.setCity(address.getCity());
        orgEntity.setRegion(address.getRegion());
        orgEntity.setCountry(address.getCountry());
        if (organization.getDisambiguatedOrganization() != null && organization.getDisambiguatedOrganization().getDisambiguatedOrganizationIdentifier() != null) {
            orgEntity.setOrgDisambiguated(orgDisambiguatedDao.findBySourceIdAndSourceType(organization.getDisambiguatedOrganization().getDisambiguatedOrganizationIdentifier(), organization.getDisambiguatedOrganization().getDisambiguationSource()));
        }
        return orgManager.createUpdate(orgEntity);
    }
    return null;
}
Also used : Organization(org.orcid.jaxb.model.message.Organization) OrganizationAddress(org.orcid.jaxb.model.message.OrganizationAddress) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 53 with OrgEntity

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

the class Jaxb2JpaAdapterImpl method getProfileFundingEntity.

/**
 * Get a ProfileFundingEntity based on a Grant object
 *
 * @param funding
 * @param exisitingProfileFundingEntity
 * @return a ProfileFundingEntity created from the provided funding
 */
private ProfileFundingEntity getProfileFundingEntity(Funding funding, ProfileFundingEntity exisitingProfileFundingEntity) {
    if (funding != null) {
        // Get the org
        OrgEntity orgEntity = getOrgEntity(funding);
        ProfileFundingEntity profileFundingEntity = null;
        if (exisitingProfileFundingEntity == null) {
            String putCode = funding.getPutCode();
            if (StringUtils.isNotBlank(putCode) && !"-1".equals(putCode)) {
                throw new IllegalArgumentException("Invalid put-code was supplied for a funding: " + putCode);
            }
            profileFundingEntity = new ProfileFundingEntity();
            // Set source
            setSource(sourceManager.retrieveSourceEntity(), profileFundingEntity);
        } else {
            profileFundingEntity = exisitingProfileFundingEntity;
            profileFundingEntity.clean();
        }
        FuzzyDate startDate = funding.getStartDate();
        FuzzyDate endDate = funding.getEndDate();
        if (funding.getAmount() != null) {
            String amount = StringUtils.isNotBlank(funding.getAmount().getContent()) ? funding.getAmount().getContent() : null;
            String currencyCode = funding.getAmount().getCurrencyCode() != null ? funding.getAmount().getCurrencyCode() : null;
            if (StringUtils.isNotBlank(amount)) {
                try {
                    BigDecimal bigDecimalAmount = getAmountAsBigDecimal(amount);
                    profileFundingEntity.setNumericAmount(bigDecimalAmount);
                } catch (Exception e) {
                    String sample = getSampleAmountInProperFormat(localeManager.getLocale());
                    throw new IllegalArgumentException("Cannot cast amount: " + amount + " proper format is: " + sample);
                }
                profileFundingEntity.setCurrencyCode(currencyCode);
            }
        }
        profileFundingEntity.setContributorsJson(getFundingContributorsJson(funding.getFundingContributors()));
        profileFundingEntity.setDescription(StringUtils.isNotBlank(funding.getDescription()) ? funding.getDescription() : null);
        profileFundingEntity.setEndDate(endDate != null ? new EndDateEntity(endDate) : null);
        JSONFundingExternalIdentifiersConverterV1 fundingExternalIDConverter = new JSONFundingExternalIdentifiersConverterV1();
        String fundingExternalIdentifiersJSONString = fundingExternalIDConverter.convertTo(funding.getFundingExternalIdentifiers());
        profileFundingEntity.setExternalIdentifiersJson(fundingExternalIdentifiersJSONString);
        profileFundingEntity.setStartDate(startDate != null ? new StartDateEntity(startDate) : null);
        FundingTitle fundingTitle = funding.getTitle();
        if (fundingTitle != null) {
            String title = null, translatedTitle = null, languageCode = null;
            if (fundingTitle.getTitle() != null)
                title = fundingTitle.getTitle().getContent();
            if (fundingTitle.getTranslatedTitle() != null) {
                translatedTitle = fundingTitle.getTranslatedTitle().getContent();
                languageCode = fundingTitle.getTranslatedTitle().getLanguageCode();
            }
            profileFundingEntity.setTitle(StringUtils.isNotBlank(title) ? title : null);
            profileFundingEntity.setTranslatedTitle(StringUtils.isNotBlank(translatedTitle) ? translatedTitle : null);
            profileFundingEntity.setTranslatedTitleLanguageCode(StringUtils.isNotBlank(languageCode) ? languageCode : null);
        }
        if (funding.getType() != null) {
            profileFundingEntity.setType(org.orcid.jaxb.model.record_v2.FundingType.fromValue(funding.getType().value()));
        }
        profileFundingEntity.setOrganizationDefinedType(funding.getOrganizationDefinedFundingType() != null ? funding.getOrganizationDefinedFundingType().getContent() : null);
        if (funding.getUrl() != null)
            profileFundingEntity.setUrl(StringUtils.isNotBlank(funding.getUrl().getValue()) ? funding.getUrl().getValue() : null);
        if (funding.getVisibility() != null) {
            profileFundingEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(funding.getVisibility().value()));
        } else {
            profileFundingEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(OrcidVisibilityDefaults.WORKS_DEFAULT.getVisibility().value()));
        }
        if (funding.getCreatedDate() != null && funding.getCreatedDate().getValue() != null)
            profileFundingEntity.setDateCreated(funding.getCreatedDate().getValue().toGregorianCalendar().getTime());
        if (funding.getLastModifiedDate() != null && funding.getLastModifiedDate().getValue() != null)
            profileFundingEntity.setLastModified(funding.getLastModifiedDate().getValue().toGregorianCalendar().getTime());
        profileFundingEntity.setOrg(orgEntity);
        if (profileFundingEntity.getDisplayIndex() == null) {
            profileFundingEntity.setDisplayIndex(0L);
        }
        return profileFundingEntity;
    }
    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) JSONFundingExternalIdentifiersConverterV1(org.orcid.core.adapter.jsonidentifier.converter.JSONFundingExternalIdentifiersConverterV1) FundingTitle(org.orcid.jaxb.model.message.FundingTitle) BigDecimal(java.math.BigDecimal) ApplicationException(org.orcid.core.exception.ApplicationException) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity)

Aggregations

OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)53 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)30 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)26 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)17 EndDateEntity (org.orcid.persistence.jpa.entities.EndDateEntity)11 StartDateEntity (org.orcid.persistence.jpa.entities.StartDateEntity)11 Test (org.junit.Test)10 OrgDisambiguatedEntity (org.orcid.persistence.jpa.entities.OrgDisambiguatedEntity)8 PeerReviewEntity (org.orcid.persistence.jpa.entities.PeerReviewEntity)8 AmbiguousOrgEntity (org.orcid.persistence.jpa.entities.AmbiguousOrgEntity)7 File (java.io.File)6 Path (java.nio.file.Path)6 ProfileFundingEntity (org.orcid.persistence.jpa.entities.ProfileFundingEntity)6 Transactional (org.springframework.transaction.annotation.Transactional)5 Date (java.util.Date)4 Visibility (org.orcid.jaxb.model.common_v2.Visibility)4 Organization (org.orcid.jaxb.model.message.Organization)4 CompletionDateEntity (org.orcid.persistence.jpa.entities.CompletionDateEntity)4 HashSet (java.util.HashSet)3 Iso3166Country (org.orcid.jaxb.model.message.Iso3166Country)3