Search in sources :

Example 1 with ExpressionOptions

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);
    }
}
Also used : Context(com.walmartlabs.concord.runtime.v2.sdk.Context) Serializable(java.io.Serializable) ExpressionOptions(com.walmartlabs.concord.runtime.v2.model.ExpressionOptions) Expression(com.walmartlabs.concord.runtime.v2.model.Expression) ExpressionEvaluator(com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)

Aggregations

Expression (com.walmartlabs.concord.runtime.v2.model.Expression)1 ExpressionOptions (com.walmartlabs.concord.runtime.v2.model.ExpressionOptions)1 ExpressionEvaluator (com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)1 Context (com.walmartlabs.concord.runtime.v2.sdk.Context)1 Serializable (java.io.Serializable)1