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

Eval nested params #1827

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -187,22 +187,23 @@ else if (value.isObject()) {
evaluated = evalObjectRecursive((ObjectNode) value);
}
else if (value.isArray()) {
evaluated = evalArrayRecursive(built, (ArrayNode) value);
evaluated = evalArrayRecursive((ArrayNode) value);
}
else if (value.isTextual()) {
// eval using template engine
String code = value.textValue();
evaluated = evalValue(built, code);
evaluated = evalValue(code);
}
else {
evaluated = value;
}
built.set(pair.getKey(), evaluated);
params.set(pair.getKey(), evaluated);
}
return built;
}

private ArrayNode evalArrayRecursive(ObjectNode local, ArrayNode array)
private ArrayNode evalArrayRecursive(ArrayNode array)
throws TemplateException
{
ArrayNode built = array.arrayNode();
Expand All @@ -212,12 +213,12 @@ private ArrayNode evalArrayRecursive(ObjectNode local, ArrayNode array)
evaluated = evalObjectRecursive((ObjectNode) value);
}
else if (value.isArray()) {
evaluated = evalArrayRecursive(local, (ArrayNode) value);
evaluated = evalArrayRecursive((ArrayNode) value);
}
else if (value.isTextual()) {
// eval using template engine
String code = value.textValue();
evaluated = evalValue(local, code);
evaluated = evalValue(code);
}
else {
evaluated = value;
Expand All @@ -227,16 +228,12 @@ else if (value.isTextual()) {
return built;
}

private JsonNode evalValue(ObjectNode local, String code)
private JsonNode evalValue(String code)
throws TemplateException
{
Config scopedParams = params.deepCopy();
for (Map.Entry<String, JsonNode> pair : ImmutableList.copyOf(local.fields())) {
scopedParams.set(pair.getKey(), pair.getValue());
}
String resultText = null;
if (isInvokeTemplateRequired(code)) {
resultText = evaluator.evaluate(code, scopedParams, jsonMapper);
resultText = evaluator.evaluate(code, params, jsonMapper);
}
else {
resultText = code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ a: ${timezone}
b: ${a}
c: ${a}${b}
nested:
value: v
value: ${c}
ref: ${nested.value}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ a: UTC
b: UTC
c: UTCUTC
nested:
value: v
ref: v
value: UTCUTC
ref: UTCUTC