From 660377972030ca19001ed9391e42b7568e0c202f Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti Date: Thu, 5 Dec 2024 19:26:15 +0100 Subject: [PATCH] [Fix #3809] Allowing additional properties on user input --- .../workflow/models/JsonNodeModel.java | 11 +++++++++- .../workflow/models/JsonNodeModelInput.java | 21 ++++++++++++------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/models/JsonNodeModel.java b/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/models/JsonNodeModel.java index cd8bdb78ebf..bfde4c1d61b 100644 --- a/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/models/JsonNodeModel.java +++ b/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/models/JsonNodeModel.java @@ -41,7 +41,7 @@ public class JsonNodeModel implements Model, MapInput, MapInputId, MapOutput, Ma private JsonNode workflowdata; private JsonNode input; private String id; - private Map additionalProperties = Collections.emptyMap(); + private Map additionalProperties; public JsonNodeModel() { } @@ -50,7 +50,15 @@ public JsonNodeModel(Object workflowdata) { this(null, workflowdata); } + public JsonNodeModel(Object workflowdata, Map additionalProperties) { + this(null, workflowdata, additionalProperties); + } + public JsonNodeModel(String id, Object workflowdata) { + this(id, workflowdata, Collections.emptyMap()); + } + + public JsonNodeModel(String id, Object workflowdata, Map additionalProperties) { this.id = id; if (workflowdata instanceof JsonNode) { this.workflowdata = (JsonNode) workflowdata; @@ -59,6 +67,7 @@ public JsonNodeModel(String id, Object workflowdata) { this.workflowdata = workflowdata == null ? mapper.createObjectNode() : mapper.convertValue(workflowdata, JsonNode.class); } this.input = this.workflowdata.deepCopy(); + this.additionalProperties = additionalProperties == null ? Collections.emptyMap() : additionalProperties; } public String getId() { diff --git a/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/models/JsonNodeModelInput.java b/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/models/JsonNodeModelInput.java index 98adedb04f5..d53aa9ea777 100644 --- a/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/models/JsonNodeModelInput.java +++ b/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/models/JsonNodeModelInput.java @@ -18,20 +18,23 @@ */ package org.kie.kogito.serverless.workflow.models; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; + import org.kie.kogito.MapInput; import org.kie.kogito.MapInputId; import org.kie.kogito.MapOutput; import org.kie.kogito.MappableToModel; import org.kie.kogito.Model; -import org.kie.kogito.jackson.utils.ObjectMapperFactory; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; public class JsonNodeModelInput implements Model, MapInput, MapInputId, MapOutput, MappableToModel { private Object workflowdata; + private Map additionalProperties; public Object getWorkflowdata() { return workflowdata; @@ -39,16 +42,18 @@ public Object getWorkflowdata() { @JsonAnySetter public void setData(String key, JsonNode value) { - if (workflowdata == null) { - workflowdata = ObjectMapperFactory.listenerAware().createObjectNode(); - } - if (workflowdata instanceof ObjectNode) { - ((ObjectNode) workflowdata).set(key, value); + if (additionalProperties == null) { + additionalProperties = new LinkedHashMap<>(); } + additionalProperties.put(key, value); } @Override public JsonNodeModel toModel() { - return new JsonNodeModel(workflowdata); + if (workflowdata == null) { + workflowdata = additionalProperties; + additionalProperties = Collections.emptyMap(); + } + return new JsonNodeModel(workflowdata, additionalProperties); } }