use of io.automatiko.engine.api.expression.ExpressionEvaluator 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);
}
}
use of io.automatiko.engine.api.expression.ExpressionEvaluator in project automatiko-engine by automatiko-io.
the class TaskOutputJqAssignmentAction method execute.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void execute(WorkItem workItem, ProcessContext context) throws Exception {
JsonNode sdata = (JsonNode) workItem.getResult(JsonVariableScope.WORKFLOWDATA_KEY);
if (outputFilterExpression != null) {
ExpressionEvaluator evaluator = (ExpressionEvaluator) ((WorkflowProcess) context.getProcessInstance().getProcess()).getDefaultContext(ExpressionEvaluator.EXPRESSION_EVALUATOR);
Map<String, Object> vars = new HashMap<>();
vars.put("workflowdata", sdata);
Map<String, Object> variables = new HashMap<>();
if (context.getVariable("$CONST") != null) {
variables.put("CONST", context.getVariable("$CONST"));
}
vars.put("workflow_variables", variables);
sdata = (JsonNode) evaluator.evaluate(outputFilterExpression, vars);
if (scopeFilter != null) {
variables.put("v", sdata);
sdata = (JsonNode) evaluator.evaluate(scopeFilter + "=$v", vars);
}
}
ObjectMapper mapper = new ObjectMapper();
if (sdata != null) {
Object updated = mapper.readerForUpdating(context.getVariable(JsonVariableScope.WORKFLOWDATA_KEY)).readValue(sdata);
context.setVariable(JsonVariableScope.WORKFLOWDATA_KEY, updated);
}
}
use of io.automatiko.engine.api.expression.ExpressionEvaluator in project automatiko-engine by automatiko-io.
the class VariableUtil method resolveVariable.
@SuppressWarnings({ "unchecked", "rawtypes" })
public static String resolveVariable(String s, NodeInstance nodeInstance) {
if (s == null) {
return null;
}
Map<String, String> replacements = new HashMap<String, String>();
Matcher matcher = PatternConstants.PARAMETER_MATCHER.matcher(s);
while (matcher.find()) {
String paramName = matcher.group(1);
String replacementKey = paramName;
String defaultValue = "";
if (paramName.contains(":")) {
String[] items = paramName.split(":");
paramName = items[0];
defaultValue = items[1];
}
if (replacements.get(paramName) == null) {
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((io.automatiko.engine.workflow.process.instance.NodeInstance) nodeInstance).resolveContextInstance(VariableScope.VARIABLE_SCOPE, paramName);
if (variableScopeInstance != null) {
Object variableValue = variableScopeInstance.getVariable(paramName);
String variableValueString = variableValue == null ? defaultValue : variableValue.toString();
replacements.put(replacementKey, variableValueString);
} else {
try {
ExpressionEvaluator evaluator = (ExpressionEvaluator) ((WorkflowProcess) nodeInstance.getProcessInstance().getProcess()).getDefaultContext(ExpressionEvaluator.EXPRESSION_EVALUATOR);
Object variableValue = evaluator.evaluate(paramName, new NodeInstanceResolverFactory((io.automatiko.engine.workflow.process.instance.NodeInstance) nodeInstance));
String variableValueString = variableValue == null ? defaultValue : variableValue.toString();
replacements.put(replacementKey, variableValueString);
} catch (Throwable t) {
}
}
}
}
for (Map.Entry<String, String> replacement : replacements.entrySet()) {
s = s.replace("#{" + replacement.getKey() + "}", replacement.getValue());
}
return s;
}
use of io.automatiko.engine.api.expression.ExpressionEvaluator 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);
}
}
use of io.automatiko.engine.api.expression.ExpressionEvaluator in project automatiko-engine by automatiko-io.
the class ProcessImpl method addImports.
public void addImports(Collection<String> imports) {
this.imports.addAll(imports);
ExpressionEvaluator evaluator = (ExpressionEvaluator) getDefaultContext(ExpressionEvaluator.EXPRESSION_EVALUATOR);
evaluator.addImports(imports);
}
Aggregations