use of com.walmartlabs.concord.runtime.v2.model.IfStep in project concord by walmartlabs.
the class IfCompiler method compile.
@Override
public Command compile(CompilerContext context, IfStep step) {
Command thenCommand = compile(context, step.getThenSteps());
Command elseCommand = compile(context, step.getElseSteps());
return new IfCommand(step, thenCommand, elseCommand);
}
use of com.walmartlabs.concord.runtime.v2.model.IfStep 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);
}
}
Aggregations