Search in sources :

Example 1 with ContextableInstance

use of io.automatiko.engine.workflow.base.instance.ContextableInstance in project automatiko-engine by automatiko-io.

the class TaskInputJqAssignmentAction method execute.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void execute(WorkItem workItem, ProcessContext context) throws Exception {
    Object sdata = context.getVariable(JsonVariableScope.WORKFLOWDATA_KEY);
    ExpressionEvaluator evaluator = (ExpressionEvaluator) ((WorkflowProcess) context.getProcessInstance().getProcess()).getDefaultContext(ExpressionEvaluator.EXPRESSION_EVALUATOR);
    Map<String, Object> vars = new HashMap<>();
    vars.put("workflowdata", sdata);
    if (context.getVariable("$CONST") != null) {
        vars.put("workflow_variables", Collections.singletonMap("CONST", context.getVariable("$CONST")));
    }
    if (inputFilterExpression != null) {
        sdata = evaluator.evaluate(inputFilterExpression, vars);
    }
    if (context.getNodeInstance() instanceof ContextableInstance) {
        VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((ContextableInstance) context.getNodeInstance()).getContextInstance(VariableScope.VARIABLE_SCOPE);
        variableScopeInstance.setVariable(JsonVariableScope.WORKFLOWDATA_KEY, sdata);
    }
    if (paramNames != null && !paramNames.isEmpty()) {
        vars = new HashMap<>();
        vars.put("workflowdata", sdata);
        if (context.getVariable("$CONST") != null) {
            vars.put("workflow_variables", Collections.singletonMap("CONST", context.getVariable("$CONST")));
        }
        for (String name : paramNames) {
            Object param = workItem.getParameter(name);
            if (param != null) {
                param = evaluator.evaluate(param.toString(), vars);
                ((WorkItemImpl) workItem).setParameter(name, param);
            }
        }
    } else {
        ((WorkItemImpl) workItem).setParameter("Parameter", sdata);
    }
}
Also used : ContextableInstance(io.automatiko.engine.workflow.base.instance.ContextableInstance) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) HashMap(java.util.HashMap) WorkItemImpl(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl) ExpressionEvaluator(io.automatiko.engine.api.expression.ExpressionEvaluator)

Example 2 with ContextableInstance

use of io.automatiko.engine.workflow.base.instance.ContextableInstance in project automatiko-engine by automatiko-io.

the class InputJqAssignmentAction method execute.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void execute(WorkItem workItem, ProcessContext context) throws Exception {
    Object sdata = context.getProcessInstance().getVariable(JsonVariableScope.WORKFLOWDATA_KEY);
    if (inputFilterExpression != null) {
        ExpressionEvaluator evaluator = (ExpressionEvaluator) ((WorkflowProcess) context.getProcessInstance().getProcess()).getDefaultContext(ExpressionEvaluator.EXPRESSION_EVALUATOR);
        Map<String, Object> vars = new HashMap<>();
        vars.put("workflowdata", sdata);
        if (context.getVariable("$CONST") != null) {
            vars.put("workflow_variables", Collections.singletonMap("CONST", context.getVariable("$CONST")));
        }
        sdata = evaluator.evaluate(inputFilterExpression, vars);
    }
    if (context.getNodeInstance() instanceof ContextableInstance) {
        VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((ContextableInstance) context.getNodeInstance()).getContextInstance(VariableScope.VARIABLE_SCOPE);
        variableScopeInstance.setVariable(JsonVariableScope.WORKFLOWDATA_KEY, sdata);
    }
}
Also used : ContextableInstance(io.automatiko.engine.workflow.base.instance.ContextableInstance) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) HashMap(java.util.HashMap) ExpressionEvaluator(io.automatiko.engine.api.expression.ExpressionEvaluator)

Aggregations

ExpressionEvaluator (io.automatiko.engine.api.expression.ExpressionEvaluator)2 ContextableInstance (io.automatiko.engine.workflow.base.instance.ContextableInstance)2 VariableScopeInstance (io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance)2 HashMap (java.util.HashMap)2 WorkItemImpl (io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl)1