Search in sources :

Example 1 with ValidationExceptionImpl

use of ddf.catalog.validation.impl.ValidationExceptionImpl in project ddf by codice.

the class TestXmlInputTransformer method testBadGml3Converter.

@Test
public void testBadGml3Converter() throws FileNotFoundException, CatalogTransformerException, ValidationException {
    inputStream = new FileInputStream("src/test/resources/metacard1.xml");
    xmlInputTransformer = new XmlInputTransformer();
    xmlInputTransformer.setSaxEventHandlerConfiguration(Collections.singletonList("gml-handler"));
    GmlHandlerFactory factory = new GmlHandlerFactory();
    Gml3ToWkt badGml3toWkt = mock(Gml3ToWkt.class);
    when(badGml3toWkt.convert(anyString())).thenThrow(new ValidationExceptionImpl());
    factory.setGml3ToWkt(badGml3toWkt);
    xmlInputTransformer.setSaxEventHandlerFactories(Collections.singletonList((SaxEventHandlerFactory) factory));
    Metacard metacard = xmlInputTransformer.transform(inputStream);
    assertThat(metacard.getAttribute(Validation.VALIDATION_ERRORS).getValue(), is("geospatial-handler"));
}
Also used : Metacard(ddf.catalog.data.Metacard) ValidationExceptionImpl(ddf.catalog.validation.impl.ValidationExceptionImpl) XmlInputTransformer(org.codice.ddf.transformer.xml.streaming.lib.XmlInputTransformer) SaxEventHandlerFactory(org.codice.ddf.transformer.xml.streaming.SaxEventHandlerFactory) FileInputStream(java.io.FileInputStream) Gml3ToWkt(org.codice.ddf.transformer.xml.streaming.Gml3ToWkt) Test(org.junit.Test)

Example 2 with ValidationExceptionImpl

use of ddf.catalog.validation.impl.ValidationExceptionImpl 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;
    }
}
Also used : MetacardValidationReport(ddf.catalog.validation.report.MetacardValidationReport) ValidationExceptionImpl(ddf.catalog.validation.impl.ValidationExceptionImpl)

Example 3 with ValidationExceptionImpl

use of ddf.catalog.validation.impl.ValidationExceptionImpl 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;
    }
}
Also used : MetacardValidationReport(ddf.catalog.validation.report.MetacardValidationReport) ValidationExceptionImpl(ddf.catalog.validation.impl.ValidationExceptionImpl)

Example 4 with ValidationExceptionImpl

use of ddf.catalog.validation.impl.ValidationExceptionImpl 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(XMLUtils.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 | InterruptedException e) {
            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)

Example 5 with ValidationExceptionImpl

use of ddf.catalog.validation.impl.ValidationExceptionImpl in project ddf by codice.

the class Gml3ToWktImpl method convert.

@SuppressWarnings("unchecked")
public String convert(InputStream xml) throws ValidationExceptionImpl {
    AbstractGeometryType geometry = null;
    try {
        JAXBElement<AbstractGeometryType> jaxbElement = parser.unmarshal(configurator, JAXBElement.class, xml);
        geometry = jaxbElement.getValue();
        GML311ToJTSGeometryConverter geometryConverter = new GML311ToJTSGeometryConverter();
        Geometry jtsGeo = geometryConverter.createGeometry(new DefaultRootObjectLocator(jaxbElement), geometry);
        WKTWriter wktWriter = new WKTWriter();
        return wktWriter.write(jtsGeo);
    } catch (ParserException e) {
        LOGGER.debug("Cannot parse gml", e);
        throw new ValidationExceptionImpl(e, Collections.singletonList("Cannot parse gml"), new ArrayList<String>());
    } catch (ConversionFailedException e) {
        LOGGER.debug("Cannot convert gml311 geo object {} to jts", geometry, e);
        throw new ValidationExceptionImpl(e, Collections.singletonList("Cannot convert geo object"), new ArrayList<String>());
    }
}
Also used : GML311ToJTSGeometryConverter(org.jvnet.ogc.gml.v_3_1_1.jts.GML311ToJTSGeometryConverter) Geometry(com.vividsolutions.jts.geom.Geometry) DefaultRootObjectLocator(org.jvnet.jaxb2_commons.locator.DefaultRootObjectLocator) WKTWriter(com.vividsolutions.jts.io.WKTWriter) ParserException(org.codice.ddf.parser.ParserException) ConversionFailedException(org.jvnet.ogc.gml.v_3_1_1.jts.ConversionFailedException) AbstractGeometryType(net.opengis.gml.v_3_1_1.AbstractGeometryType) ValidationExceptionImpl(ddf.catalog.validation.impl.ValidationExceptionImpl) ArrayList(java.util.ArrayList)

Aggregations

ValidationExceptionImpl (ddf.catalog.validation.impl.ValidationExceptionImpl)6 MetacardValidationReport (ddf.catalog.validation.report.MetacardValidationReport)2 Geometry (com.vividsolutions.jts.geom.Geometry)1 WKTWriter (com.vividsolutions.jts.io.WKTWriter)1 Metacard (ddf.catalog.data.Metacard)1 MetacardValidationReportImpl (ddf.catalog.validation.impl.report.MetacardValidationReportImpl)1 ValidationViolationImpl (ddf.catalog.validation.impl.violation.ValidationViolationImpl)1 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 Templates (javax.xml.transform.Templates)1 AbstractGeometryType (net.opengis.gml.v_3_1_1.AbstractGeometryType)1 ParserException (org.codice.ddf.parser.ParserException)1 Gml3ToWkt (org.codice.ddf.transformer.xml.streaming.Gml3ToWkt)1 SaxEventHandlerFactory (org.codice.ddf.transformer.xml.streaming.SaxEventHandlerFactory)1 XmlInputTransformer (org.codice.ddf.transformer.xml.streaming.lib.XmlInputTransformer)1 Test (org.junit.Test)1 DefaultRootObjectLocator (org.jvnet.jaxb2_commons.locator.DefaultRootObjectLocator)1 ConversionFailedException (org.jvnet.ogc.gml.v_3_1_1.jts.ConversionFailedException)1