Search in sources :

Example 1 with ProcessingException

use of com.github.fge.jsonschema.core.exceptions.ProcessingException in project KaiZen-OpenAPI-Editor by RepreZen.

the class Validator method validateAgainstSchema.

public Set<SwaggerError> validateAgainstSchema(ErrorProcessor processor, JsonNode schemaAsJson, JsonNode documentAsJson) {
    final JsonSchemaFactory factory = JsonSchemaFactory.newBuilder().setLoadingConfiguration(loadingConfiguration).freeze();
    final Set<SwaggerError> errors = Sets.newHashSet();
    JsonSchema schema = null;
    try {
        schema = factory.getJsonSchema(schemaAsJson);
    } catch (ProcessingException e) {
        YEditLog.logException(e);
        return errors;
    }
    try {
        ProcessingReport report = schema.validate(documentAsJson, true);
        errors.addAll(processor.processReport(report));
    } catch (ProcessingException e) {
        errors.addAll(processor.processMessage(e.getProcessingMessage()));
    }
    return errors;
}
Also used : ProcessingReport(com.github.fge.jsonschema.core.report.ProcessingReport) JsonSchema(com.github.fge.jsonschema.main.JsonSchema) JsonSchemaFactory(com.github.fge.jsonschema.main.JsonSchemaFactory) ProcessingException(com.github.fge.jsonschema.core.exceptions.ProcessingException)

Example 2 with ProcessingException

use of com.github.fge.jsonschema.core.exceptions.ProcessingException in project ocvn by devgateway.

the class OcdsSchemaValidatorService method validate.

/**
     * Validates the incoming {@link JsonNode} against OCDS schema
     *
     * @param jsonNode
     * @return
     */
public ProcessingReportWithNode validate(final JsonNode jsonNode) {
    try {
        ProcessingReport processingReport = schema.validate(jsonNode);
        ProcessingReportWithNode processingReportWithNode = null;
        try {
            processingReportWithNode = new ProcessingReportWithNode(processingReport, processingReport.isSuccess() ? null : jacksonObjectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonNode.get("ocid")));
        } catch (JsonProcessingException e) {
            logger.error(e.getMessage());
            e.printStackTrace();
        }
        return processingReportWithNode;
    } catch (ProcessingException e) {
        logger.error(e.getMessage());
        e.printStackTrace();
    }
    return null;
}
Also used : ProcessingReport(com.github.fge.jsonschema.core.report.ProcessingReport) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ProcessingException(com.github.fge.jsonschema.core.exceptions.ProcessingException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 3 with ProcessingException

use of com.github.fge.jsonschema.core.exceptions.ProcessingException in project ocvn by devgateway.

the class OcdsSchemaValidatorService method init.

/**
     * Intializes the JSON schema validator plus the provided patches
     */
public void init() {
    try {
        ocdsSchemaNode = JsonLoader.fromResource(schemaLocation == null ? OCDS_SCHEMA_LOCATION : schemaLocation);
        if (patchResourceNames != null && patchResourceNames.length > 0) {
            for (int i = 0; i < patchResourceNames.length; i++) {
                JsonNode node = JsonLoader.fromResource(patchResourceNames[i]);
                if (patchResourceNames[i].contains("mergepatch")) {
                    JsonMergePatch patch = JsonMergePatch.fromJson(node);
                    ocdsSchemaNode = patch.apply(ocdsSchemaNode);
                } else {
                    JsonPatch patch = JsonPatch.fromJson(node);
                    ocdsSchemaNode = patch.apply(ocdsSchemaNode);
                }
            }
        }
        logger.debug(jacksonObjectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(ocdsSchemaNode));
        schema = JsonSchemaFactory.newBuilder().setReportProvider(new ListReportProvider(LogLevel.ERROR, LogLevel.FATAL)).freeze().getJsonSchema(ocdsSchemaNode);
    } catch (ProcessingException | IOException e) {
        logger.error(e.getMessage());
        e.printStackTrace();
    } catch (JsonPatchException e) {
        logger.error(e.getMessage());
        e.printStackTrace();
    }
}
Also used : ListReportProvider(com.github.fge.jsonschema.core.report.ListReportProvider) JsonPatchException(com.github.fge.jsonpatch.JsonPatchException) JsonMergePatch(com.github.fge.jsonpatch.mergepatch.JsonMergePatch) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) JsonPatch(com.github.fge.jsonpatch.JsonPatch) ProcessingException(com.github.fge.jsonschema.core.exceptions.ProcessingException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

ProcessingException (com.github.fge.jsonschema.core.exceptions.ProcessingException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ProcessingReport (com.github.fge.jsonschema.core.report.ProcessingReport)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 JsonPatch (com.github.fge.jsonpatch.JsonPatch)1 JsonPatchException (com.github.fge.jsonpatch.JsonPatchException)1 JsonMergePatch (com.github.fge.jsonpatch.mergepatch.JsonMergePatch)1 ListReportProvider (com.github.fge.jsonschema.core.report.ListReportProvider)1 JsonSchema (com.github.fge.jsonschema.main.JsonSchema)1 JsonSchemaFactory (com.github.fge.jsonschema.main.JsonSchemaFactory)1 IOException (java.io.IOException)1