use of com.walmartlabs.concord.runtime.v2.model.ExpressionOptions in project concord by walmartlabs.
the class ExpressionCommand method execute.
@Override
protected void execute(Runtime runtime, State state, ThreadId threadId) {
state.peekFrame(threadId).pop();
Context ctx = runtime.getService(Context.class);
Expression step = getStep();
String expr = step.getExpr();
ExpressionEvaluator ee = runtime.getService(ExpressionEvaluator.class);
Object result = ee.eval(EvalContextFactory.global(ctx), expr, Object.class);
ExpressionOptions opts = Objects.requireNonNull(step.getOptions());
if (!opts.outExpr().isEmpty()) {
ExpressionEvaluator expressionEvaluator = runtime.getService(ExpressionEvaluator.class);
Map<String, Object> vars = Collections.singletonMap("result", result);
Map<String, Serializable> out = expressionEvaluator.evalAsMap(EvalContextFactory.global(ctx, vars), opts.outExpr());
out.forEach((k, v) -> ctx.variables().set(k, v));
} else if (opts.out() != null) {
ctx.variables().set(opts.out(), result);
}
}
Aggregations