Search in sources :

Example 1 with StartDateEntity

use of org.orcid.persistence.jpa.entities.StartDateEntity 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)

Example 2 with StartDateEntity

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

the class JpaJaxbEducationAdapterTest method getEducationEntity.

private OrgAffiliationRelationEntity getEducationEntity() {
    OrgEntity orgEntity = new OrgEntity();
    orgEntity.setCity("org:city");
    orgEntity.setCountry(org.orcid.jaxb.model.message.Iso3166Country.US);
    orgEntity.setName("org:name");
    orgEntity.setRegion("org:region");
    orgEntity.setUrl("org:url");
    orgEntity.setSource(new SourceEntity("APP-000000001"));
    OrgAffiliationRelationEntity result = new OrgAffiliationRelationEntity();
    result.setAffiliationType(AffiliationType.EDUCATION);
    result.setDepartment("education:department");
    result.setEndDate(new EndDateEntity(2020, 2, 2));
    result.setId(123456L);
    result.setOrg(orgEntity);
    result.setProfile(new ProfileEntity("0000-0001-0002-0003"));
    result.setStartDate(new StartDateEntity(2000, 1, 1));
    result.setTitle("education:title");
    result.setVisibility(Visibility.PRIVATE);
    result.setClientSourceId("APP-000000001");
    return result;
}
Also used : EndDateEntity(org.orcid.persistence.jpa.entities.EndDateEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) StartDateEntity(org.orcid.persistence.jpa.entities.StartDateEntity) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 3 with StartDateEntity

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

the class JpaJaxbEmploymentAdapterTest method getEmploymentEntity.

private OrgAffiliationRelationEntity getEmploymentEntity() {
    OrgEntity orgEntity = new OrgEntity();
    orgEntity.setCity("org:city");
    orgEntity.setCountry(org.orcid.jaxb.model.message.Iso3166Country.US);
    orgEntity.setName("org:name");
    orgEntity.setRegion("org:region");
    orgEntity.setUrl("org:url");
    orgEntity.setSource(new SourceEntity("APP-000000001"));
    OrgAffiliationRelationEntity result = new OrgAffiliationRelationEntity();
    result.setAffiliationType(AffiliationType.EMPLOYMENT);
    result.setDepartment("employment:department");
    result.setEndDate(new EndDateEntity(2020, 2, 2));
    result.setId(123456L);
    result.setOrg(orgEntity);
    result.setProfile(new ProfileEntity("0000-0001-0002-0003"));
    result.setStartDate(new StartDateEntity(2000, 1, 1));
    result.setTitle("employment:title");
    result.setVisibility(Visibility.PRIVATE);
    result.setClientSourceId("APP-000000001");
    return result;
}
Also used : EndDateEntity(org.orcid.persistence.jpa.entities.EndDateEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) StartDateEntity(org.orcid.persistence.jpa.entities.StartDateEntity) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 4 with StartDateEntity

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

the class JpaJaxbFundingAdapterTest method getProfileFundingEntity.

private ProfileFundingEntity getProfileFundingEntity() {
    ProfileFundingEntity result = new ProfileFundingEntity();
    result.setContributorsJson("{\"contributor\":[{\"contributorOrcid\":{\"value\":null,\"valueAsString\":null,\"uri\":\"http://orcid.org/8888-8888-8888-8880\",\"path\":\"8888-8888-8888-8880\",\"host\":\"orcid.org\"},\"creditName\":{\"content\":\"funding:creditName\"},\"contributorEmail\":{\"value\":\"funding@contributorEmail.com\"},\"contributorAttributes\":{\"contributorRole\":\"LEAD\"}}]}");
    result.setDescription("funding:description");
    result.setEndDate(new EndDateEntity(2020, 1, 1));
    result.setStartDate(new StartDateEntity(2000, 1, 1));
    result.setExternalIdentifiersJson("{\"fundingExternalIdentifier\":[{\"type\":\"GRANT_NUMBER\",\"value\":\"12345\",\"url\":{\"value\":\"http://tempuri.org\"}},{\"type\":\"GRANT_NUMBER\",\"value\":\"67890\",\"url\":{\"value\":\"http://tempuri.org/2\"}}]}");
    result.setId(12345L);
    result.setNumericAmount(new BigDecimal(123456));
    result.setCurrencyCode("CRC");
    result.setTitle("funding:title");
    result.setTranslatedTitle("funding:translatedTitle");
    result.setTranslatedTitleLanguageCode("ES");
    result.setType(FundingType.SALARY_AWARD);
    result.setVisibility(Visibility.PRIVATE);
    return result;
}
Also used : EndDateEntity(org.orcid.persistence.jpa.entities.EndDateEntity) StartDateEntity(org.orcid.persistence.jpa.entities.StartDateEntity) BigDecimal(java.math.BigDecimal) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity)

Example 5 with StartDateEntity

use of org.orcid.persistence.jpa.entities.StartDateEntity 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)

Aggregations

EndDateEntity (org.orcid.persistence.jpa.entities.EndDateEntity)5 StartDateEntity (org.orcid.persistence.jpa.entities.StartDateEntity)5 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)4 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)3 BigDecimal (java.math.BigDecimal)2 FuzzyDate (org.orcid.jaxb.model.message.FuzzyDate)2 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)2 ProfileFundingEntity (org.orcid.persistence.jpa.entities.ProfileFundingEntity)2 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)2 FundingExternalIdentifiers (org.orcid.core.adapter.impl.jsonidentifiers.FundingExternalIdentifiers)1 FundingTitle (org.orcid.jaxb.model.message.FundingTitle)1