Search in sources :

Example 1 with ListReportProvider

use of com.github.fge.jsonschema.core.report.ListReportProvider in project oc-explorer 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)

Example 2 with ListReportProvider

use of com.github.fge.jsonschema.core.report.ListReportProvider 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

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