Search in sources :

Example 6 with MetacardValidationReport

use of ddf.catalog.validation.report.MetacardValidationReport in project ddf by codice.

the class SchematronValidationService method validate.

@Override
public void validate(Metacard metacard) throws ValidationException {
    MetacardValidationReport report = generateReport(metacard);
    List<String> errors = new ArrayList<>();
    List<String> warnings = new ArrayList<>();
    report.getMetacardValidationViolations().forEach(violation -> {
        if (violation.getSeverity() == ValidationViolation.Severity.ERROR) {
            errors.add(violation.getMessage());
        } else {
            warnings.add(violation.getMessage());
        }
    });
    SchematronValidationException exception = new SchematronValidationException("Schematron validation failed", errors, warnings);
    if (!errors.isEmpty()) {
        throw exception;
    }
    if (!suppressWarnings && !warnings.isEmpty()) {
        throw exception;
    }
}
Also used : MetacardValidationReport(ddf.catalog.validation.report.MetacardValidationReport) ArrayList(java.util.ArrayList)

Aggregations

MetacardValidationReport (ddf.catalog.validation.report.MetacardValidationReport)6 ValidationExceptionImpl (ddf.catalog.validation.impl.ValidationExceptionImpl)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Sets (com.google.common.collect.Sets)1 Metacard (ddf.catalog.data.Metacard)1 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1 AttributeValidatorRegistry (ddf.catalog.validation.AttributeValidatorRegistry)1 ValidationException (ddf.catalog.validation.ValidationException)1 EnumerationValidator (ddf.catalog.validation.impl.validator.EnumerationValidator)1 FutureDateValidator (ddf.catalog.validation.impl.validator.FutureDateValidator)1 PastDateValidator (ddf.catalog.validation.impl.validator.PastDateValidator)1 PatternValidator (ddf.catalog.validation.impl.validator.PatternValidator)1 SizeValidator (ddf.catalog.validation.impl.validator.SizeValidator)1 ValidationViolation (ddf.catalog.validation.violation.ValidationViolation)1 Instant (java.time.Instant)1 DAYS (java.time.temporal.ChronoUnit.DAYS)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1