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