Search in sources :

Example 6 with MetacardValidationReportImpl

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

the class MetacardWktValidator method validateMetacard.

@Override
public Optional<MetacardValidationReport> validateMetacard(Metacard metacard) {
    MetacardValidationReportImpl report = null;
    String attributeValue = getAttributeValue(metacard);
    if (StringUtils.isNotEmpty(attributeValue)) {
        if (!wktValidator.isValid(attributeValue)) {
            String message = errorMsg + metacard.getLocation();
            ValidationViolation violation = new ValidationViolationImpl(ImmutableSet.of(validatedAttributeKey), message, ValidationViolation.Severity.ERROR);
            report = new MetacardValidationReportImpl();
            report.addMetacardViolation(violation);
        }
    } else {
        // Put the validation error from the metacard into this validation report
        // Otherwise the validation error gets lost
        Attribute validationErrorAttr = metacard.getAttribute(Validation.VALIDATION_ERRORS);
        if (validationErrorAttr != null) {
            List<Serializable> errors = validationErrorAttr.getValues();
            for (Serializable error : errors) {
                String errorStr = String.valueOf(error);
                if (errorStr.startsWith(errorMsg)) {
                    ValidationViolation violation = new ValidationViolationImpl(ImmutableSet.of(validatedAttributeKey), errorStr, ValidationViolation.Severity.ERROR);
                    report = new MetacardValidationReportImpl();
                    report.addMetacardViolation(violation);
                }
            }
        }
    }
    return Optional.ofNullable(report);
}
Also used : Serializable(java.io.Serializable) ValidationViolation(ddf.catalog.validation.violation.ValidationViolation) Attribute(ddf.catalog.data.Attribute) MetacardValidationReportImpl(ddf.catalog.validation.impl.report.MetacardValidationReportImpl) ValidationViolationImpl(ddf.catalog.validation.impl.violation.ValidationViolationImpl)

Aggregations

MetacardValidationReportImpl (ddf.catalog.validation.impl.report.MetacardValidationReportImpl)6 Attribute (ddf.catalog.data.Attribute)2 ValidationViolationImpl (ddf.catalog.validation.impl.violation.ValidationViolationImpl)2 ValidationViolation (ddf.catalog.validation.violation.ValidationViolation)2 ValidationExceptionImpl (ddf.catalog.validation.impl.ValidationExceptionImpl)1 Serializable (java.io.Serializable)1 Objects (java.util.Objects)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 Templates (javax.xml.transform.Templates)1 StringUtils (org.apache.commons.lang.StringUtils)1