use of io.kestra.core.exceptions.IllegalVariableEvaluationException in project kestra by kestra-io.
the class FlowableUtils method resolveEachTasks.
public static List<ResolvedTask> resolveEachTasks(RunContext runContext, TaskRun parentTaskRun, List<Task> tasks, String value) throws IllegalVariableEvaluationException {
String renderValue = runContext.render(value);
List<Object> values;
try {
values = MAPPER.readValue(renderValue, TYPE_REFERENCE);
} catch (JsonProcessingException e) {
throw new IllegalVariableEvaluationException(e);
}
List<Object> distinctValue = values.stream().distinct().collect(Collectors.toList());
long nullCount = distinctValue.stream().filter(Objects::isNull).count();
if (nullCount > 0) {
throw new IllegalVariableEvaluationException("Found '" + nullCount + "' null values on Each, " + "with values=" + Arrays.toString(values.toArray()));
}
ArrayList<ResolvedTask> result = new ArrayList<>();
for (Object current : distinctValue) {
for (Task task : tasks) {
try {
String resolvedValue = current instanceof String ? (String) current : MAPPER.writeValueAsString(current);
result.add(ResolvedTask.builder().task(task).value(resolvedValue).parentId(parentTaskRun.getId()).build());
} catch (JsonProcessingException e) {
throw new IllegalVariableEvaluationException(e);
}
}
}
return result;
}
use of io.kestra.core.exceptions.IllegalVariableEvaluationException in project kestra by kestra-io.
the class VariableRenderer method recursiveRender.
public String recursiveRender(String inline, Map<String, Object> variables) throws IllegalVariableEvaluationException {
if (inline == null) {
return null;
}
boolean isSame = false;
String currentTemplate = inline;
String current = "";
PebbleTemplate compiledTemplate;
while (!isSame) {
try {
compiledTemplate = pebbleEngine.getLiteralTemplate(currentTemplate);
Writer writer = new JsonWriter(new StringWriter());
compiledTemplate.evaluate(writer, variables);
current = writer.toString();
} catch (IOException | PebbleException e) {
if (this.variableConfiguration.disableHandlebars) {
if (e instanceof PebbleException) {
throw properPebbleException((PebbleException) e);
}
throw new IllegalVariableEvaluationException(e);
}
try {
Template template = handlebars.compileInline(currentTemplate);
current = template.apply(variables);
} catch (HandlebarsException | IOException hbE) {
throw new IllegalVariableEvaluationException("Pebble evaluation failed with '" + e.getMessage() + "' " + "and Handlebars fallback failed also with '" + hbE.getMessage() + "'", e);
}
}
isSame = currentTemplate.equals(current);
currentTemplate = current;
}
return current;
}
Aggregations