From 144ffc25e4fc530bfa99aa8621ece516b354514c Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti Date: Thu, 6 Jul 2023 10:53:14 +0200 Subject: [PATCH] [KOGITO-9501] Update dependencies --- kogito-build/kogito-dependencies-bom/pom.xml | 8 ---- .../pom.xml | 4 -- .../pom.xml | 4 +- .../workflow/actions/JsonSchemaValidator.java | 45 ++++++++----------- .../schema/OpenApiModelSchemaGenerator.java | 2 +- 5 files changed, 21 insertions(+), 42 deletions(-) diff --git a/kogito-build/kogito-dependencies-bom/pom.xml b/kogito-build/kogito-dependencies-bom/pom.xml index 5afd0f9b953..dd8aca64814 100644 --- a/kogito-build/kogito-dependencies-bom/pom.xml +++ b/kogito-build/kogito-dependencies-bom/pom.xml @@ -36,7 +36,6 @@ 3.24.2 2.2.14 2.14.2 - 1.14.2 4.18.0 2.33.2 3.22.0 @@ -707,19 +706,12 @@ com.github.java-json-tools json-schema-validator ${version.com.github.java-json-tools} - test com.fasterxml.jackson.datatype jackson-datatype-json-org ${version.com.fasterxml.jackson.datatype} - - com.github.erosb - everit-json-schema - ${version.com.github.erosb} - - io.serverlessworkflow diff --git a/kogito-serverless-workflow/kogito-serverless-workflow-builder/pom.xml b/kogito-serverless-workflow/kogito-serverless-workflow-builder/pom.xml index f19d46a5307..b7a5000a6d1 100644 --- a/kogito-serverless-workflow/kogito-serverless-workflow-builder/pom.xml +++ b/kogito-serverless-workflow/kogito-serverless-workflow-builder/pom.xml @@ -22,10 +22,6 @@ org.kie.kogito kogito-serverless-workflow-runtime - - com.github.erosb - everit-json-schema - org.kie.kogito kogito-codegen-api diff --git a/kogito-serverless-workflow/kogito-serverless-workflow-runtime/pom.xml b/kogito-serverless-workflow/kogito-serverless-workflow-runtime/pom.xml index 7d037dfba77..ee2688e0016 100644 --- a/kogito-serverless-workflow/kogito-serverless-workflow-runtime/pom.xml +++ b/kogito-serverless-workflow/kogito-serverless-workflow-runtime/pom.xml @@ -27,8 +27,8 @@ kogito-rest-utils - com.github.erosb - everit-json-schema + com.github.java-json-tools + json-schema-validator com.fasterxml.jackson.datatype diff --git a/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/actions/JsonSchemaValidator.java b/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/actions/JsonSchemaValidator.java index aee96420316..c5eed93f3a7 100644 --- a/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/actions/JsonSchemaValidator.java +++ b/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/actions/JsonSchemaValidator.java @@ -19,18 +19,17 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicReference; -import org.everit.json.schema.Schema; -import org.everit.json.schema.ValidationException; -import org.everit.json.schema.loader.SchemaClient; -import org.everit.json.schema.loader.SchemaLoader; import org.jbpm.workflow.core.WorkflowModelValidator; -import org.json.JSONObject; import org.kie.kogito.jackson.utils.ObjectMapperFactory; import org.kie.kogito.serverless.workflow.SWFConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.NullNode; +import com.github.fge.jsonschema.core.exceptions.ProcessingException; +import com.github.fge.jsonschema.core.report.ProcessingReport; +import com.github.fge.jsonschema.main.JsonSchemaFactory; import static org.kie.kogito.serverless.workflow.io.URIContentLoaderFactory.readAllBytes; import static org.kie.kogito.serverless.workflow.io.URIContentLoaderFactory.runtimeLoader; @@ -43,8 +42,7 @@ public class JsonSchemaValidator implements WorkflowModelValidator { protected final String schemaRef; protected final boolean failOnValidationErrors; - - private final AtomicReference schemaObject = new AtomicReference<>(); + private final AtomicReference schemaObject = new AtomicReference<>(); public JsonSchemaValidator(String schema, boolean failOnValidationErrors) { this.schemaRef = schema; @@ -54,32 +52,25 @@ public JsonSchemaValidator(String schema, boolean failOnValidationErrors) { @Override public void validate(Map model) { try { - load().validate(ObjectMapperFactory.get().convertValue(model.getOrDefault(SWFConstants.DEFAULT_WORKFLOW_VAR, NullNode.instance), JSONObject.class)); - } catch (ValidationException ex) { - handleException(ex, ex.getCausingExceptions().isEmpty() ? ex : ex.getCausingExceptions()); - } catch (IOException ex) { - handleException(ex, ex); + ProcessingReport report = JsonSchemaFactory.byDefault().getJsonSchema(schemaData()).validate((JsonNode) model.getOrDefault(SWFConstants.DEFAULT_WORKFLOW_VAR, NullNode.instance)); + if (!report.isSuccess()) { + final String validationMessage = String.format("Validation errors %s", report.toString()); + logger.warn(validationMessage); + if (failOnValidationErrors) { + throw new IllegalArgumentException(validationMessage); + } + } + } catch (ProcessingException | IOException ex) { + throw new IllegalStateException("Unexpected error validating schema", ex); } } - public Schema load() throws IOException { - Schema result = schemaObject.get(); + public JsonNode schemaData() throws IOException { + JsonNode result = schemaObject.get(); if (result == null) { - result = SchemaLoader.builder() - .schemaJson(ObjectMapperFactory.get().readValue(readAllBytes(runtimeLoader(schemaRef)), JSONObject.class)) - .resolutionScope(schemaRef) - .schemaClient(SchemaClient.classPathAwareClient()) - .build().load().build(); + result = ObjectMapperFactory.get().readTree(readAllBytes(runtimeLoader(schemaRef))); schemaObject.set(result); } return result; } - - private void handleException(Throwable ex, Object toAppend) { - String validationError = String.format("Error validating schema: %s", toAppend); - logger.warn(validationError, ex); - if (failOnValidationErrors) { - throw new IllegalArgumentException(validationError); - } - } } diff --git a/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-deployment/src/main/java/org/kie/kogito/serverless/workflow/parser/schema/OpenApiModelSchemaGenerator.java b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-deployment/src/main/java/org/kie/kogito/serverless/workflow/parser/schema/OpenApiModelSchemaGenerator.java index 2fd573c56f4..4759f8b5436 100644 --- a/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-deployment/src/main/java/org/kie/kogito/serverless/workflow/parser/schema/OpenApiModelSchemaGenerator.java +++ b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-deployment/src/main/java/org/kie/kogito/serverless/workflow/parser/schema/OpenApiModelSchemaGenerator.java @@ -115,7 +115,7 @@ private static Optional getSchema(Optional valid private static Schema getSchema(JsonSchemaValidator validator) { try { - return ObjectMapperFactory.get().readValue(validator.load().toString(), JsonSchemaImpl.class); + return ObjectMapperFactory.get().convertValue(validator.schemaData(), JsonSchemaImpl.class); } catch (IOException e) { throw new UncheckedIOException(e); }