Search in sources :

Example 1 with MetacardValidationReportImpl

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

the class ReportingMetacardValidatorImpl method getReport.

private Optional<MetacardValidationReport> getReport(final Set<ValidationViolation> violations) {
    final MetacardValidationReportImpl report = new MetacardValidationReportImpl();
    violations.forEach(report::addAttributeViolation);
    return Optional.of(report);
}
Also used : MetacardValidationReportImpl(ddf.catalog.validation.impl.report.MetacardValidationReportImpl)

Example 2 with MetacardValidationReportImpl

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

the class DuplicationValidator method getReport.

private Optional<MetacardValidationReport> getReport(final Set<ValidationViolation> violations) {
    if (CollectionUtils.isNotEmpty(violations)) {
        final MetacardValidationReportImpl report = new MetacardValidationReportImpl();
        violations.forEach(report::addMetacardViolation);
        return Optional.of(report);
    }
    return Optional.empty();
}
Also used : MetacardValidationReportImpl(ddf.catalog.validation.impl.report.MetacardValidationReportImpl)

Example 3 with MetacardValidationReportImpl

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

the class RelationshipValidator method validateMetacard.

@Override
public Optional<MetacardValidationReport> validateMetacard(Metacard metacard) {
    Attribute attribute = metacard.getAttribute(sourceAttribute);
    if (attribute != null && attribute.getValues().stream().anyMatch(Objects::nonNull) && (StringUtils.isEmpty(sourceValue) || attribute.getValues().contains(sourceValue))) {
        MetacardValidationReportImpl report = new MetacardValidationReportImpl();
        Attribute actualAttribute = metacard.getAttribute(targetAttribute);
        Collection<String> actualValues = actualAttribute == null ? Collections.emptyList() : actualAttribute.getValues().stream().map(Objects::toString).filter(StringUtils::isNotEmpty).collect(Collectors.toList());
        Optional<ValidationViolation> violation = relationships.get(relationship).apply(actualValues);
        violation.ifPresent(report::addAttributeViolation);
        if (violation.isPresent()) {
            return Optional.of(report);
        } else {
            return Optional.empty();
        }
    } else {
        return Optional.empty();
    }
}
Also used : ValidationViolation(ddf.catalog.validation.violation.ValidationViolation) Attribute(ddf.catalog.data.Attribute) StringUtils(org.apache.commons.lang.StringUtils) Objects(java.util.Objects) MetacardValidationReportImpl(ddf.catalog.validation.impl.report.MetacardValidationReportImpl)

Example 4 with MetacardValidationReportImpl

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

the class RequiredAttributesMetacardValidator method getReport.

private Optional<MetacardValidationReport> getReport(final Set<ValidationViolation> violations) {
    final MetacardValidationReportImpl report = new MetacardValidationReportImpl();
    violations.forEach(report::addMetacardViolation);
    return Optional.of(report);
}
Also used : MetacardValidationReportImpl(ddf.catalog.validation.impl.report.MetacardValidationReportImpl)

Example 5 with MetacardValidationReportImpl

use of ddf.catalog.validation.impl.report.MetacardValidationReportImpl 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(XML_UTILS.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 e) {
            throw new ValidationExceptionImpl(e);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            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

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