use of ddf.catalog.validation.report.AttributeValidationReport in project ddf by codice.
the class PastDateValidatorTest method validateWithErrors.
private void validateWithErrors(final Instant instant, final int expectedErrors) {
final Optional<AttributeValidationReport> reportOptional = VALIDATOR.validate(new AttributeImpl("test", Date.from(instant)));
assertThat(reportOptional.get().getAttributeValidationViolations(), hasSize(expectedErrors));
}
use of ddf.catalog.validation.report.AttributeValidationReport in project ddf by codice.
the class FutureDateValidatorTest method validateNoErrors.
private void validateNoErrors(final Instant instant) {
final Optional<AttributeValidationReport> reportOptional = VALIDATOR.validate(new AttributeImpl("test", Date.from(instant)));
assertThat(reportOptional.isPresent(), is(false));
}
use of ddf.catalog.validation.report.AttributeValidationReport in project ddf by codice.
the class Validator method validateAttribute.
public AttributeValidationResponse validateAttribute(String attribute, String value) {
Set<AttributeValidator> validators = attributeValidatorRegistry.stream().map(avr -> avr.getValidators(attribute)).reduce((left, right) -> {
left.addAll(right);
return left;
}).orElse(new HashSet<>());
Set<String> suggestedValues = new HashSet<>();
Set<ValidationViolation> violations = new HashSet<>();
for (AttributeValidator validator : validators) {
Optional<AttributeValidationReport> validationReport = validator.validate(new AttributeImpl(attribute, value));
if (validationReport.isPresent()) {
AttributeValidationReport report = validationReport.get();
if (!report.getSuggestedValues().isEmpty()) {
suggestedValues = report.getSuggestedValues();
}
violations.addAll(report.getAttributeValidationViolations());
}
}
return new AttributeValidationResponse(violations, suggestedValues);
}
use of ddf.catalog.validation.report.AttributeValidationReport in project ddf by codice.
the class ISO3CountryCodeValidator method buildReport.
private AttributeValidationReport buildReport(Attribute attribute) {
AttributeValidationReportImpl report = new AttributeValidationReportImpl();
attribute.getValues().stream().filter(String.class::isInstance).map(String.class::cast).map(ignoreCase ? String::toUpperCase : String::toString).filter(s -> !COUNTRY_CODES.contains(s)).map(s -> new ValidationViolationImpl(Collections.singleton(attribute.getName()), s + " is not a valid ISO_3166-1 Alpha3 country code.", ValidationViolation.Severity.ERROR)).forEach(report::addViolation);
COUNTRY_CODES.forEach(report::addSuggestedValue);
return report;
}
use of ddf.catalog.validation.report.AttributeValidationReport in project ddf by codice.
the class PastDateValidatorTest method validateNoErrors.
private void validateNoErrors(final Instant instant) {
final Optional<AttributeValidationReport> reportOptional = VALIDATOR.validate(new AttributeImpl("test", Date.from(instant)));
assertThat(reportOptional.isPresent(), is(false));
}
Aggregations