Search in sources :

Example 6 with FundingExternalIdentifiers

use of org.orcid.core.adapter.impl.jsonidentifiers.FundingExternalIdentifiers 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(funding.getSource(), 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);
        FundingExternalIdentifiers recordExternalIdentifiers = new FundingExternalIdentifiers(funding.getFundingExternalIdentifiers());
        profileFundingEntity.setExternalIdentifiersJson(recordExternalIdentifiers.toDBJSONString());
        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) FundingTitle(org.orcid.jaxb.model.message.FundingTitle) FundingExternalIdentifiers(org.orcid.core.adapter.impl.jsonidentifiers.FundingExternalIdentifiers) BigDecimal(java.math.BigDecimal) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity)

Example 7 with FundingExternalIdentifiers

use of org.orcid.core.adapter.impl.jsonidentifiers.FundingExternalIdentifiers in project ORCID-Source by ORCID.

the class Jpa2JaxbAdapterImpl method getFunding.

/**
     * Transforms a profileFundingEntity into a Funding
     * 
     * @param profileFundingEntity
     * @return Funding
     * */
public Funding getFunding(ProfileFundingEntity profileFundingEntity) {
    Funding funding = new Funding();
    if (profileFundingEntity.getNumericAmount() != null) {
        String stringAmount = profileFundingEntity.getNumericAmount().toString();
        Amount orcidAmount = new Amount();
        orcidAmount.setContent(stringAmount);
        orcidAmount.setCurrencyCode(profileFundingEntity.getCurrencyCode() != null ? profileFundingEntity.getCurrencyCode() : null);
        funding.setAmount(orcidAmount);
    }
    funding.setDescription(StringUtils.isNotEmpty(profileFundingEntity.getDescription()) ? profileFundingEntity.getDescription() : null);
    FundingTitle title = new FundingTitle();
    title.setTitle(StringUtils.isNotEmpty(profileFundingEntity.getTitle()) ? new Title(profileFundingEntity.getTitle()) : null);
    if (StringUtils.isNotEmpty(profileFundingEntity.getTranslatedTitle())) {
        String translatedTitleValue = profileFundingEntity.getTranslatedTitle();
        String code = profileFundingEntity.getTranslatedTitleLanguageCode();
        TranslatedTitle translatedTitle = new TranslatedTitle(translatedTitleValue, code);
        title.setTranslatedTitle(translatedTitle);
    }
    funding.setTitle(title);
    if (profileFundingEntity.getType() != null) {
        funding.setType(FundingType.fromValue(profileFundingEntity.getType().value()));
    }
    funding.setOrganizationDefinedFundingType(profileFundingEntity.getOrganizationDefinedType() != null ? new OrganizationDefinedFundingSubType(profileFundingEntity.getOrganizationDefinedType()) : null);
    funding.setUrl(StringUtils.isNotEmpty(profileFundingEntity.getUrl()) ? new Url(profileFundingEntity.getUrl()) : new Url(new String()));
    if (profileFundingEntity.getVisibility() != null) {
        funding.setVisibility(Visibility.fromValue(profileFundingEntity.getVisibility().value()));
    } else {
        funding.setVisibility(Visibility.PRIVATE);
    }
    funding.setPutCode(Long.toString(profileFundingEntity.getId()));
    funding.setFundingContributors(getFundingContributors(profileFundingEntity));
    if (profileFundingEntity.getExternalIdentifiersJson() != null) {
        FundingExternalIdentifiers ids = FundingExternalIdentifiers.fromDBJSONString(profileFundingEntity.getExternalIdentifiersJson());
        funding.setFundingExternalIdentifiers(ids.toMessagePojo());
    }
    // Set organization
    Organization organization = new Organization();
    OrgDisambiguatedEntity orgDisambiguatedEntity = profileFundingEntity.getOrg().getOrgDisambiguated();
    if (orgDisambiguatedEntity != null) {
        organization.setDisambiguatedOrganization(getDisambiguatedOrganization(orgDisambiguatedEntity));
    }
    organization.setAddress(getAddress(profileFundingEntity.getOrg()));
    organization.setName(profileFundingEntity.getOrg().getName());
    funding.setOrganization(organization);
    // Set start and end date
    FuzzyDateEntity startDate = profileFundingEntity.getStartDate();
    FuzzyDateEntity endDate = profileFundingEntity.getEndDate();
    funding.setStartDate(startDate != null ? new FuzzyDate(startDate.getYear(), startDate.getMonth(), startDate.getDay()) : null);
    funding.setEndDate(endDate != null ? new FuzzyDate(endDate.getYear(), endDate.getMonth(), endDate.getDay()) : null);
    // Set source
    funding.setSource(getSource(profileFundingEntity));
    funding.setCreatedDate(new CreatedDate(toXMLGregorianCalendar(profileFundingEntity.getDateCreated())));
    funding.setLastModifiedDate(new LastModifiedDate(toXMLGregorianCalendar(profileFundingEntity.getLastModified())));
    return funding;
}
Also used : FuzzyDateEntity(org.orcid.persistence.jpa.entities.FuzzyDateEntity) OrgDisambiguatedEntity(org.orcid.persistence.jpa.entities.OrgDisambiguatedEntity) FundingExternalIdentifiers(org.orcid.core.adapter.impl.jsonidentifiers.FundingExternalIdentifiers)

Aggregations

FundingExternalIdentifiers (org.orcid.core.adapter.impl.jsonidentifiers.FundingExternalIdentifiers)7 Test (org.junit.Test)4 FundingExternalIdentifier (org.orcid.core.adapter.impl.jsonidentifiers.FundingExternalIdentifier)3 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)2 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)2 BigDecimal (java.math.BigDecimal)1 FundingTitle (org.orcid.jaxb.model.message.FundingTitle)1 FuzzyDate (org.orcid.jaxb.model.message.FuzzyDate)1 EndDateEntity (org.orcid.persistence.jpa.entities.EndDateEntity)1 FuzzyDateEntity (org.orcid.persistence.jpa.entities.FuzzyDateEntity)1 OrgDisambiguatedEntity (org.orcid.persistence.jpa.entities.OrgDisambiguatedEntity)1 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)1 ProfileFundingEntity (org.orcid.persistence.jpa.entities.ProfileFundingEntity)1 StartDateEntity (org.orcid.persistence.jpa.entities.StartDateEntity)1