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());
}
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;
}
Aggregations