Search in sources :

Example 6 with AttributeValidationReport

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));
}
Also used : AttributeImpl(ddf.catalog.data.impl.AttributeImpl) AttributeValidationReport(ddf.catalog.validation.report.AttributeValidationReport)

Example 7 with AttributeValidationReport

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));
}
Also used : AttributeImpl(ddf.catalog.data.impl.AttributeImpl) AttributeValidationReport(ddf.catalog.validation.report.AttributeValidationReport)

Example 8 with AttributeValidationReport

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);
}
Also used : MetacardValidationReport(ddf.catalog.validation.report.MetacardValidationReport) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) Set(java.util.Set) HashMap(java.util.HashMap) AttributeValidatorRegistry(ddf.catalog.validation.AttributeValidatorRegistry) FederationException(ddf.catalog.federation.FederationException) Collectors(java.util.stream.Collectors) AttributeValidationReport(ddf.catalog.validation.report.AttributeValidationReport) ArrayList(java.util.ArrayList) ReportingMetacardValidator(ddf.catalog.validation.ReportingMetacardValidator) ValidationViolation(ddf.catalog.validation.violation.ValidationViolation) HashSet(java.util.HashSet) AttributeValidator(ddf.catalog.validation.AttributeValidator) List(java.util.List) Metacard(ddf.catalog.data.Metacard) Map(java.util.Map) Optional(java.util.Optional) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) AttributeValidationReport(ddf.catalog.validation.report.AttributeValidationReport) ValidationViolation(ddf.catalog.validation.violation.ValidationViolation) AttributeValidator(ddf.catalog.validation.AttributeValidator) HashSet(java.util.HashSet)

Example 9 with AttributeValidationReport

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;
}
Also used : Arrays(java.util.Arrays) Set(java.util.Set) HashCodeBuilder(org.apache.commons.lang.builder.HashCodeBuilder) Collectors(java.util.stream.Collectors) AttributeValidationReport(ddf.catalog.validation.report.AttributeValidationReport) ValidationViolation(ddf.catalog.validation.violation.ValidationViolation) AttributeValidator(ddf.catalog.validation.AttributeValidator) Attribute(ddf.catalog.data.Attribute) AttributeValidationReportImpl(ddf.catalog.validation.impl.report.AttributeValidationReportImpl) ValidationViolationImpl(ddf.catalog.validation.impl.violation.ValidationViolationImpl) Locale(java.util.Locale) EqualsBuilder(org.apache.commons.lang.builder.EqualsBuilder) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Collections(java.util.Collections) AttributeValidationReportImpl(ddf.catalog.validation.impl.report.AttributeValidationReportImpl) ValidationViolationImpl(ddf.catalog.validation.impl.violation.ValidationViolationImpl)

Example 10 with AttributeValidationReport

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));
}
Also used : AttributeImpl(ddf.catalog.data.impl.AttributeImpl) AttributeValidationReport(ddf.catalog.validation.report.AttributeValidationReport)

Aggregations

AttributeValidationReport (ddf.catalog.validation.report.AttributeValidationReport)12 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)8 AttributeValidator (ddf.catalog.validation.AttributeValidator)2 ISO3CountryCodeValidator (ddf.catalog.validation.impl.validator.ISO3CountryCodeValidator)2 ValidationViolation (ddf.catalog.validation.violation.ValidationViolation)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Preconditions (com.google.common.base.Preconditions)1 Attribute (ddf.catalog.data.Attribute)1 Metacard (ddf.catalog.data.Metacard)1 FederationException (ddf.catalog.federation.FederationException)1 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)1 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)1 AttributeValidatorRegistry (ddf.catalog.validation.AttributeValidatorRegistry)1 ReportingMetacardValidator (ddf.catalog.validation.ReportingMetacardValidator)1 AttributeValidationReportImpl (ddf.catalog.validation.impl.report.AttributeValidationReportImpl)1 ValidationViolationImpl (ddf.catalog.validation.impl.violation.ValidationViolationImpl)1 MetacardValidationReport (ddf.catalog.validation.report.MetacardValidationReport)1 ArrayList (java.util.ArrayList)1