use of org.orcid.core.adapter.jsonidentifier.converter.JSONFundingExternalIdentifiersConverterV1 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;
}
use of org.orcid.core.adapter.jsonidentifier.converter.JSONFundingExternalIdentifiersConverterV1 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) {
JSONFundingExternalIdentifiersConverterV1 converter = new JSONFundingExternalIdentifiersConverterV1();
funding.setFundingExternalIdentifiers(converter.convertFrom(profileFundingEntity.getExternalIdentifiersJson()));
}
// 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;
}
Aggregations