use of ddf.catalog.validation.report.MetacardValidationReport in project ddf by codice.
the class RequiredAttributesMetacardValidator method validate.
@Override
public void validate(final Metacard metacard) throws ValidationException {
final Optional<MetacardValidationReport> reportOptional = validateMetacard(metacard);
if (reportOptional.isPresent()) {
final List<String> errors = reportOptional.get().getMetacardValidationViolations().stream().map(ValidationViolation::getMessage).collect(Collectors.toList());
final ValidationExceptionImpl exception = new ValidationExceptionImpl();
exception.setErrors(errors);
throw exception;
}
}
use of ddf.catalog.validation.report.MetacardValidationReport in project ddf by codice.
the class DuplicationValidator method validate.
@Override
public void validate(Metacard metacard) throws ValidationException {
final Optional<MetacardValidationReport> report = validateMetacard(metacard);
if (report.isPresent()) {
final List<String> errors = report.get().getMetacardValidationViolations().stream().filter(validationViolation -> validationViolation.getSeverity().equals(ValidationViolation.Severity.ERROR)).map(ValidationViolation::getMessage).collect(Collectors.toList());
final List<String> warnings = report.get().getMetacardValidationViolations().stream().filter(validationViolation -> validationViolation.getSeverity().equals(ValidationViolation.Severity.WARNING)).map(ValidationViolation::getMessage).collect(Collectors.toList());
String message = String.format("Duplicate data found in catalog for ID {%s}.", metacard.getId());
final ValidationExceptionImpl exception = new ValidationExceptionImpl(message);
exception.setErrors(errors);
exception.setWarnings(warnings);
throw exception;
}
}
use of ddf.catalog.validation.report.MetacardValidationReport in project ddf by codice.
the class ReportingMetacardValidatorImpl method validate.
@Override
public void validate(final Metacard metacard) throws ValidationException {
final Optional<MetacardValidationReport> reportOptional = validateMetacard(metacard);
if (reportOptional.isPresent()) {
final MetacardValidationReport report = reportOptional.get();
final List<String> warnings = new ArrayList<>();
final List<String> errors = new ArrayList<>();
getMessages(report.getAttributeValidationViolations(), warnings, errors);
getMessages(report.getMetacardValidationViolations(), warnings, errors);
final ValidationExceptionImpl exception = new ValidationExceptionImpl();
exception.setWarnings(warnings);
exception.setErrors(errors);
throw exception;
}
}
use of ddf.catalog.validation.report.MetacardValidationReport in project ddf by codice.
the class ReportingMetacardValidatorImplTest method testValidateInvalidMetacardByReport.
@Test
public void testValidateInvalidMetacardByReport() {
final Optional<MetacardValidationReport> reportOptional = validator.validateMetacard(getInvalidMetacard());
assertThat("Expected some validation violations but no report was returned (which indicates that there are no violations).", reportOptional.isPresent(), is(true));
final MetacardValidationReport report = reportOptional.get();
// 2 title violations and 1 violation each for modified, effective, and content type
assertThat(report.getAttributeValidationViolations(), hasSize(5));
assertThat(report.getMetacardValidationViolations(), empty());
final List<String> violatedAttributes = report.getAttributeValidationViolations().stream().flatMap(violation -> violation.getAttributes().stream()).collect(Collectors.toList());
assertThat(violatedAttributes, containsInAnyOrder(Metacard.TITLE, Metacard.TITLE, Metacard.MODIFIED, Metacard.EFFECTIVE, Metacard.CONTENT_TYPE));
}
use of ddf.catalog.validation.report.MetacardValidationReport in project ddf by codice.
the class TestDuplicationValidator method testValidateMetacardWithValidationErrorAndWarning.
@Test
public void testValidateMetacardWithValidationErrorAndWarning() {
String[] checksumAttribute = { Metacard.CHECKSUM };
String[] idAttribute = { Metacard.ID };
validator.setWarnOnDuplicateAttributes(checksumAttribute);
validator.setErrorOnDuplicateAttributes(idAttribute);
Optional<MetacardValidationReport> report = validator.validateMetacard(testMetacard);
assertThat(report.isPresent(), is(true));
assertThat(report.get().getMetacardValidationViolations(), hasSize(2));
Map<ValidationViolation.Severity, ValidationViolation> violations = report.get().getMetacardValidationViolations().stream().collect(Collectors.toMap(ValidationViolation::getSeverity, Function.identity()));
ValidationViolation warnViolation = violations.get(ValidationViolation.Severity.WARNING);
ValidationViolation errorViolation = violations.get(ValidationViolation.Severity.ERROR);
assertThat(warnViolation.getAttributes(), is(new HashSet<>(Arrays.asList(checksumAttribute))));
assertThat(warnViolation.getMessage(), containsString(Metacard.CHECKSUM));
assertThat(errorViolation.getAttributes(), is(new HashSet<>(Arrays.asList(idAttribute))));
assertThat(errorViolation.getMessage(), containsString(Metacard.ID));
}
Aggregations