Skip to content

Commit

Permalink
[Fix #3809] Allowing additional properties on user input
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado committed Dec 5, 2024
1 parent 26f9c10 commit 6603779
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class JsonNodeModel implements Model, MapInput, MapInputId, MapOutput, Ma
private JsonNode workflowdata;
private JsonNode input;
private String id;
private Map<String, Object> additionalProperties = Collections.emptyMap();
private Map<String, Object> additionalProperties;

public JsonNodeModel() {
}
Expand All @@ -50,7 +50,15 @@ public JsonNodeModel(Object workflowdata) {
this(null, workflowdata);
}

public JsonNodeModel(Object workflowdata, Map<String, Object> additionalProperties) {
this(null, workflowdata, additionalProperties);
}

public JsonNodeModel(String id, Object workflowdata) {
this(id, workflowdata, Collections.emptyMap());
}

public JsonNodeModel(String id, Object workflowdata, Map<String, Object> additionalProperties) {
this.id = id;
if (workflowdata instanceof JsonNode) {
this.workflowdata = (JsonNode) workflowdata;
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,42 @@
*/
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<JsonNodeModel> {

private Object workflowdata;
private Map<String, Object> additionalProperties;

public Object getWorkflowdata() {
return workflowdata;
}

@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);
}
}

0 comments on commit 6603779

Please sign in to comment.