Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle booleans in Workflow Node user input parsing #321

Merged
merged 1 commit into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading