Skip to content

Commit

Permalink
Handle booleans in Workflow Node user input parsing
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis committed Dec 26, 2023
1 parent 113b008 commit 068ddd5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
xContentBuilder.startObject(USER_INPUTS_FIELD);
for (Entry<String, Object> e : userInputs.entrySet()) {
xContentBuilder.field(e.getKey());
if (e.getValue() instanceof String || e.getValue() instanceof Number) {
if (e.getValue() instanceof String || e.getValue() instanceof Number || e.getValue() instanceof Boolean) {
xContentBuilder.value(e.getValue());
} else if (e.getValue() instanceof Map<?, ?>) {
buildStringToStringMap(xContentBuilder, (Map<?, ?>) e.getValue());
Expand Down Expand Up @@ -191,6 +191,9 @@ public static WorkflowNode parse(XContentParser parser) throws IOException {
throw new IOException("Unable to parse field [" + inputFieldName + "] in a node object.");
}
break;
case VALUE_BOOLEAN:
userInputs.put(inputFieldName, parser.booleanValue());
break;
default:
throw new IOException("Unable to parse field [" + inputFieldName + "] in a node object.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void testNode() throws IOException {
Map.entry("foo", "a string"),
Map.entry("bar", Map.of("key", "value")),
Map.entry("baz", new Map<?, ?>[] { Map.of("A", "a"), Map.of("B", "b") }),
Map.entry("qux", false),
Map.entry("processors", new PipelineProcessor[] { new PipelineProcessor("test-type", Map.of("key2", "value2")) }),
Map.entry("created_time", 1689793598499L),
Map.entry("tools_order", new String[] { "foo", "bar" })
Expand All @@ -42,6 +43,7 @@ public void testNode() throws IOException {
assertEquals("a string", (String) map.get("foo"));
assertEquals(Map.of("key", "value"), (Map<?, ?>) map.get("bar"));
assertArrayEquals(new Map<?, ?>[] { Map.of("A", "a"), Map.of("B", "b") }, (Map<?, ?>[]) map.get("baz"));
assertFalse((Boolean) map.get("qux"));
PipelineProcessor[] pp = (PipelineProcessor[]) map.get("processors");
assertEquals(1, pp.length);
assertEquals("test-type", pp[0].type());
Expand All @@ -62,6 +64,7 @@ public void testNode() throws IOException {
assertTrue(json.contains("\"foo\":\"a string\""));
assertTrue(json.contains("\"baz\":[{\"A\":\"a\"},{\"B\":\"b\"}]"));
assertTrue(json.contains("\"bar\":{\"key\":\"value\"}"));
assertTrue(json.contains("\"qux\":false"));
assertTrue(json.contains("\"processors\":[{\"type\":\"test-type\",\"params\":{\"key2\":\"value2\"}}]"));
assertTrue(json.contains("\"created_time\":1689793598499"));
assertTrue(json.contains("\"tools_order\":[\"foo\",\"bar\"]"));
Expand Down

0 comments on commit 068ddd5

Please sign in to comment.