Search in sources :

Example 6 with AttributeValidationReportImpl

use of ddf.catalog.validation.impl.report.AttributeValidationReportImpl in project ddf by codice.

the class PatternValidator method validate.

/**
     * {@inheritDoc}
     * <p>
     * Validates only the values of {@code attribute} that are {@link CharSequence}s.
     */
@Override
public Optional<AttributeValidationReport> validate(final Attribute attribute) {
    Preconditions.checkArgument(attribute != null, "The attribute cannot be null.");
    final String name = attribute.getName();
    for (final Serializable value : attribute.getValues()) {
        if (value instanceof CharSequence && !(pattern.matcher((CharSequence) value)).matches()) {
            final AttributeValidationReportImpl report = new AttributeValidationReportImpl();
            report.addViolation(new ValidationViolationImpl(Collections.singleton(name), name + " does not follow the pattern " + pattern.pattern(), Severity.ERROR));
            return Optional.of(report);
        }
    }
    return Optional.empty();
}
Also used : Serializable(java.io.Serializable) AttributeValidationReportImpl(ddf.catalog.validation.impl.report.AttributeValidationReportImpl) ValidationViolationImpl(ddf.catalog.validation.impl.violation.ValidationViolationImpl)

Aggregations

AttributeValidationReportImpl (ddf.catalog.validation.impl.report.AttributeValidationReportImpl)6 ValidationViolationImpl (ddf.catalog.validation.impl.violation.ValidationViolationImpl)6 Serializable (java.io.Serializable)5 Preconditions (com.google.common.base.Preconditions)1 Attribute (ddf.catalog.data.Attribute)1 AttributeValidator (ddf.catalog.validation.AttributeValidator)1 AttributeValidationReport (ddf.catalog.validation.report.AttributeValidationReport)1 ValidationViolation (ddf.catalog.validation.violation.ValidationViolation)1 BigDecimal (java.math.BigDecimal)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 EqualsBuilder (org.apache.commons.lang.builder.EqualsBuilder)1 HashCodeBuilder (org.apache.commons.lang.builder.HashCodeBuilder)1