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