use of ddf.catalog.validation.impl.violation.ValidationViolationImpl 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();
}
use of ddf.catalog.validation.impl.violation.ValidationViolationImpl in project ddf by codice.
the class SchematronValidationService method generateReport.
private MetacardValidationReport generateReport(Metacard metacard) throws ValidationExceptionImpl {
MetacardValidationReportImpl report = new MetacardValidationReportImpl();
Set<String> attributes = ImmutableSet.of("metadata");
String metadata = metacard.getMetadata();
boolean canBeValidated = !(StringUtils.isEmpty(metadata) || (namespace != null && !namespace.equals(XMLUtils.getRootNamespace(metadata))));
if (canBeValidated) {
try {
for (Future<Templates> validator : validators) {
schematronReport = generateReport(metadata, validator.get(10, TimeUnit.MINUTES));
schematronReport.getErrors().forEach(errorMsg -> report.addMetacardViolation(new ValidationViolationImpl(attributes, sanitize(errorMsg), ValidationViolation.Severity.ERROR)));
schematronReport.getWarnings().forEach(warningMsg -> report.addMetacardViolation(new ValidationViolationImpl(attributes, sanitize(warningMsg), ValidationViolation.Severity.WARNING)));
}
} catch (TimeoutException | ExecutionException | InterruptedException e) {
throw new ValidationExceptionImpl(e);
}
}
return report;
}
Aggregations