Search in sources :

Example 1 with IfStep

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);
}
Also used : BlockCommand(com.walmartlabs.concord.runtime.v2.runner.vm.BlockCommand) IfCommand(com.walmartlabs.concord.runtime.v2.runner.vm.IfCommand) Command(com.walmartlabs.concord.svm.Command) IfCommand(com.walmartlabs.concord.runtime.v2.runner.vm.IfCommand)

Example 2 with IfStep

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);
    }
}
Also used : Context(com.walmartlabs.concord.runtime.v2.sdk.Context) EvalContext(com.walmartlabs.concord.runtime.v2.runner.el.EvalContext) EvalContext(com.walmartlabs.concord.runtime.v2.runner.el.EvalContext) ExpressionEvaluator(com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator) IfStep(com.walmartlabs.concord.runtime.v2.model.IfStep)

Aggregations

IfStep (com.walmartlabs.concord.runtime.v2.model.IfStep)1 EvalContext (com.walmartlabs.concord.runtime.v2.runner.el.EvalContext)1 ExpressionEvaluator (com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)1 BlockCommand (com.walmartlabs.concord.runtime.v2.runner.vm.BlockCommand)1 IfCommand (com.walmartlabs.concord.runtime.v2.runner.vm.IfCommand)1 Context (com.walmartlabs.concord.runtime.v2.sdk.Context)1 Command (com.walmartlabs.concord.svm.Command)1