use of com.walmartlabs.concord.runtime.v2.runner.el.EvalContext in project concord by walmartlabs.
the class FlowCallCommand method execute.
@Override
protected void execute(Runtime runtime, State state, ThreadId threadId) {
state.peekFrame(threadId).pop();
Context ctx = runtime.getService(Context.class);
ExpressionEvaluator ee = runtime.getService(ExpressionEvaluator.class);
EvalContext evalCtx = EvalContextFactory.global(ctx);
FlowCall call = getStep();
// the called flow's name
String flowName = ee.eval(evalCtx, call.getFlowName(), String.class);
// the called flow's steps
Compiler compiler = runtime.getService(Compiler.class);
ProcessDefinition pd = runtime.getService(ProcessDefinition.class);
ProcessConfiguration pc = runtime.getService(ProcessConfiguration.class);
Command steps = CompilerUtils.compile(compiler, pc, pd, flowName);
FlowCallOptions opts = Objects.requireNonNull(call.getOptions());
Map<String, Object> input = VMUtils.prepareInput(ee, ctx, opts.input(), opts.inputExpression());
// the call's frame should be a "root" frame
// all local variables will have this frame as their base
Frame innerFrame = Frame.builder().root().commands(steps).locals(input).build();
// an "out" handler:
// grab the out variable from the called flow's frame
// and put it into the callee's frame
Command processOutVars;
if (!opts.outExpr().isEmpty()) {
processOutVars = new EvalVariablesCommand(ctx, opts.outExpr(), innerFrame);
} else {
processOutVars = new CopyVariablesCommand(opts.out(), innerFrame, VMUtils::assertNearestRoot);
}
// push the out handler first so it executes after the called flow's frame is done
state.peekFrame(threadId).push(processOutVars);
state.pushFrame(threadId, innerFrame);
}
use of com.walmartlabs.concord.runtime.v2.runner.el.EvalContext in project concord by walmartlabs.
the class IfCommand method execute.
@Override
protected void execute(Runtime runtime, State state, ThreadId threadId) {
Frame frame = state.peekFrame(threadId);
frame.pop();
IfStep step = getStep();
String expr = step.getExpression();
Context ctx = runtime.getService(Context.class);
EvalContext evalContext = EvalContextFactory.global(ctx);
ExpressionEvaluator ee = runtime.getService(ExpressionEvaluator.class);
Boolean ifResult = ee.eval(evalContext, expr, Boolean.class);
if (ifResult != null && ifResult) {
frame.push(thenCommand);
} else if (elseCommand != null) {
frame.push(elseCommand);
}
}
use of com.walmartlabs.concord.runtime.v2.runner.el.EvalContext in project concord by walmartlabs.
the class SwitchCommand method execute.
@Override
protected void execute(Runtime runtime, State state, ThreadId threadId) {
Frame frame = state.peekFrame(threadId);
frame.pop();
SwitchStep step = getStep();
String expr = step.getExpression();
Context ctx = runtime.getService(Context.class);
EvalContext evalContext = EvalContextFactory.global(ctx);
ExpressionEvaluator ee = runtime.getService(ExpressionEvaluator.class);
String switchResult = ee.eval(evalContext, expr, String.class);
boolean caseFound = false;
for (Map.Entry<String, Command> kv : caseCommands) {
String caseLabel = ee.eval(evalContext, kv.getKey(), String.class);
if (Objects.equals(switchResult, caseLabel)) {
frame.push(kv.getValue());
caseFound = true;
break;
}
}
if (!caseFound && defaultCommand != null) {
frame.push(defaultCommand);
}
// TODO: log case not found?
}
Aggregations