Search in sources :

Example 6 with ValidationViolationImpl

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();
}
Also used : Serializable(java.io.Serializable) AttributeValidationReportImpl(ddf.catalog.validation.impl.report.AttributeValidationReportImpl) ValidationViolationImpl(ddf.catalog.validation.impl.violation.ValidationViolationImpl)

Example 7 with ValidationViolationImpl

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;
}
Also used : ValidationExceptionImpl(ddf.catalog.validation.impl.ValidationExceptionImpl) MetacardValidationReportImpl(ddf.catalog.validation.impl.report.MetacardValidationReportImpl) ValidationViolationImpl(ddf.catalog.validation.impl.violation.ValidationViolationImpl) Templates(javax.xml.transform.Templates) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

ValidationViolationImpl (ddf.catalog.validation.impl.violation.ValidationViolationImpl)7 AttributeValidationReportImpl (ddf.catalog.validation.impl.report.AttributeValidationReportImpl)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 ValidationExceptionImpl (ddf.catalog.validation.impl.ValidationExceptionImpl)1 MetacardValidationReportImpl (ddf.catalog.validation.impl.report.MetacardValidationReportImpl)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 ExecutionException (java.util.concurrent.ExecutionException)1