Search in sources :

Example 1 with JsonMergePatch

use of com.github.fge.jsonpatch.mergepatch.JsonMergePatch 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)1 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 ProcessingException (com.github.fge.jsonschema.core.exceptions.ProcessingException)1 ListReportProvider (com.github.fge.jsonschema.core.report.ListReportProvider)1 IOException (java.io.IOException)1