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