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