Search in sources :

Example 1 with Amount

use of org.orcid.jaxb.model.common_v2.Amount in project ORCID-Source by ORCID.

the class ActivityValidator method validateFunding.

public void validateFunding(Funding funding, SourceEntity sourceEntity, boolean createFlag, boolean isApiRequest, Visibility originalVisibility) {
    FundingTitle title = funding.getTitle();
    if (title == null || title.getTitle() == null || StringUtils.isEmpty(title.getTitle().getContent())) {
        throw new ActivityTitleValidationException();
    }
    // translated title language code
    if (title != null && title.getTranslatedTitle() != null && !PojoUtil.isEmpty(title.getTranslatedTitle().getContent())) {
        // If translated title language code is null or invalid
        if (PojoUtil.isEmpty(title.getTranslatedTitle().getLanguageCode()) || !Arrays.stream(SiteConstants.AVAILABLE_ISO_LANGUAGES).anyMatch(title.getTranslatedTitle().getLanguageCode()::equals)) {
            Map<String, String> params = new HashMap<String, String>();
            String values = Arrays.stream(SiteConstants.AVAILABLE_ISO_LANGUAGES).collect(Collectors.joining(", "));
            params.put("type", "translated title -> language code");
            params.put("values", values);
            throw new ActivityTypeValidationException(params);
        }
    }
    if (isApiRequest) {
        if (funding.getExternalIdentifiers() == null || funding.getExternalIdentifiers().getExternalIdentifier() == null || funding.getExternalIdentifiers().getExternalIdentifier().isEmpty()) {
            throw new ActivityIdentifierValidationException();
        }
    }
    if (funding.getAmount() != null) {
        Amount amount = funding.getAmount();
        if (PojoUtil.isEmpty(amount.getCurrencyCode()) && !PojoUtil.isEmpty(amount.getContent())) {
            throw new OrcidValidationException("Please specify a currency code");
        } else if (!PojoUtil.isEmpty(amount.getCurrencyCode()) && PojoUtil.isEmpty(amount.getContent())) {
            throw new OrcidValidationException("Please specify an amount or remove the amount tag");
        }
    }
    if (funding.getPutCode() != null && createFlag) {
        Map<String, String> params = new HashMap<String, String>();
        if (sourceEntity != null) {
            params.put("clientName", sourceEntity.getSourceName());
        }
        throw new InvalidPutCodeException(params);
    }
    // Check that we are not changing the visibility
    if (isApiRequest && !createFlag) {
        Visibility updatedVisibility = funding.getVisibility();
        validateVisibilityDoesntChange(updatedVisibility, originalVisibility);
    }
    externalIDValidator.validateFunding(funding.getExternalIdentifiers());
}
Also used : ActivityTitleValidationException(org.orcid.core.exception.ActivityTitleValidationException) HashMap(java.util.HashMap) InvalidPutCodeException(org.orcid.core.exception.InvalidPutCodeException) Amount(org.orcid.jaxb.model.common_v2.Amount) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) ActivityTypeValidationException(org.orcid.core.exception.ActivityTypeValidationException) Visibility(org.orcid.jaxb.model.common_v2.Visibility) FundingTitle(org.orcid.jaxb.model.record_v2.FundingTitle) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException)

Example 2 with Amount

use of org.orcid.jaxb.model.common_v2.Amount in project ORCID-Source by ORCID.

the class ActivityValidatorTest method getFunding.

public Funding getFunding() {
    Funding funding = new Funding();
    Amount amount = new Amount();
    amount.setContent("1000");
    amount.setCurrencyCode("$");
    funding.setAmount(amount);
    FundingContributor contributor = new FundingContributor();
    FundingContributorAttributes attributes = new FundingContributorAttributes();
    attributes.setContributorRole(FundingContributorRole.LEAD);
    ContributorOrcid contributorOrcid = new ContributorOrcid();
    contributorOrcid.setHost("http://test.orcid.org");
    contributorOrcid.setPath("0000-0000-0000-0000");
    contributorOrcid.setUri("http://test.orcid.org/0000-0000-0000-0000");
    contributor.setContributorAttributes(attributes);
    contributor.setContributorOrcid(contributorOrcid);
    FundingContributors contributors = new FundingContributors();
    contributors.getContributor().add(contributor);
    funding.setContributors(contributors);
    funding.setDescription("description");
    funding.setEndDate(getFuzzyDate());
    funding.setExternalIdentifiers(getExternalIDs());
    funding.setOrganization(getOrganization());
    funding.setOrganizationDefinedType(new OrganizationDefinedFundingSubType("subtype"));
    funding.setStartDate(getFuzzyDate());
    FundingTitle title = new FundingTitle();
    title.setTitle(new Title("title"));
    title.setTranslatedTitle(new TranslatedTitle("translated title", "en"));
    funding.setTitle(title);
    funding.setType(FundingType.AWARD);
    funding.setUrl(new Url("http://test.orcid.org"));
    funding.setVisibility(Visibility.PUBLIC);
    return funding;
}
Also used : TranslatedTitle(org.orcid.jaxb.model.common_v2.TranslatedTitle) Funding(org.orcid.jaxb.model.record_v2.Funding) Amount(org.orcid.jaxb.model.common_v2.Amount) FundingContributor(org.orcid.jaxb.model.record_v2.FundingContributor) FundingContributors(org.orcid.jaxb.model.record_v2.FundingContributors) FundingContributorAttributes(org.orcid.jaxb.model.record_v2.FundingContributorAttributes) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) TranslatedTitle(org.orcid.jaxb.model.common_v2.TranslatedTitle) FundingTitle(org.orcid.jaxb.model.record_v2.FundingTitle) Title(org.orcid.jaxb.model.common_v2.Title) ContributorOrcid(org.orcid.jaxb.model.common_v2.ContributorOrcid) FundingTitle(org.orcid.jaxb.model.record_v2.FundingTitle) Url(org.orcid.jaxb.model.common_v2.Url) OrganizationDefinedFundingSubType(org.orcid.jaxb.model.common_v2.OrganizationDefinedFundingSubType)

Aggregations

Amount (org.orcid.jaxb.model.common_v2.Amount)2 FundingTitle (org.orcid.jaxb.model.record_v2.FundingTitle)2 HashMap (java.util.HashMap)1 ActivityIdentifierValidationException (org.orcid.core.exception.ActivityIdentifierValidationException)1 ActivityTitleValidationException (org.orcid.core.exception.ActivityTitleValidationException)1 ActivityTypeValidationException (org.orcid.core.exception.ActivityTypeValidationException)1 InvalidPutCodeException (org.orcid.core.exception.InvalidPutCodeException)1 OrcidValidationException (org.orcid.core.exception.OrcidValidationException)1 ContributorOrcid (org.orcid.jaxb.model.common_v2.ContributorOrcid)1 OrganizationDefinedFundingSubType (org.orcid.jaxb.model.common_v2.OrganizationDefinedFundingSubType)1 Title (org.orcid.jaxb.model.common_v2.Title)1 TranslatedTitle (org.orcid.jaxb.model.common_v2.TranslatedTitle)1 Url (org.orcid.jaxb.model.common_v2.Url)1 Visibility (org.orcid.jaxb.model.common_v2.Visibility)1 Funding (org.orcid.jaxb.model.record_v2.Funding)1 FundingContributor (org.orcid.jaxb.model.record_v2.FundingContributor)1 FundingContributorAttributes (org.orcid.jaxb.model.record_v2.FundingContributorAttributes)1 FundingContributors (org.orcid.jaxb.model.record_v2.FundingContributors)1 WorkTitle (org.orcid.jaxb.model.record_v2.WorkTitle)1