use of io.serverlessworkflow.api.filters.ActionDataFilter in project kogito-runtimes by kiegroup.
the class CompositeContextNodeHandler method getActionNode.
public MakeNodeResult getActionNode(RuleFlowNodeContainerFactory<?, ?> embeddedSubProcess, Action action, String collectVar, String... extraVariables) {
ActionDataFilter actionFilter = action.getActionDataFilter();
String fromExpr = null;
String resultExpr = null;
String toExpr = null;
boolean useData = true;
if (actionFilter != null) {
fromExpr = actionFilter.getFromStateData();
resultExpr = actionFilter.getResults();
toExpr = actionFilter.getToStateData();
useData = actionFilter.isUseResults();
}
if (action.getFunctionRef() != null) {
return filterAndMergeNode(embeddedSubProcess, fromExpr, resultExpr, toExpr, useData, (factory, inputVar, outputVar) -> getActionNode(factory, action.getFunctionRef(), inputVar, outputVar, collectVar, extraVariables));
} else if (action.getEventRef() != null) {
return filterAndMergeNode(embeddedSubProcess, fromExpr, resultExpr, toExpr, useData, (factory, inputVar, outputVar) -> getActionNode(factory, action.getEventRef(), inputVar));
} else if (action.getSubFlowRef() != null) {
return filterAndMergeNode(embeddedSubProcess, fromExpr, resultExpr, toExpr, useData, (factory, inputVar, outputVar) -> getActionNode(factory, action.getSubFlowRef(), inputVar, outputVar));
} else {
throw new IllegalArgumentException("Action node " + action.getName() + " of state " + state.getName() + " does not have function or event defined");
}
}
use of io.serverlessworkflow.api.filters.ActionDataFilter in project automatiko-engine by automatiko-io.
the class ServerlessWorkflowFactory method expressionActionStateNode.
public ActionNode expressionActionStateNode(long id, String name, NodeContainer nodeContainer, String expression, Action action) {
ActionNode actionNode = new ActionNode();
actionNode.setId(id);
actionNode.setName(name);
ActionDataFilter actionDataFilter = action.getActionDataFilter();
StringBuilder functionArguments = new StringBuilder();
if (action.getFunctionRef().getArguments() != null) {
functionArguments.append("(");
for (JsonNode argument : action.getFunctionRef().getArguments()) {
functionArguments.append(unwrapExpression(argument.toString())).append(",");
}
functionArguments.deleteCharAt(functionArguments.length() - 1);
functionArguments.append(")");
}
String inputFilter = actionDataFilter == null ? null : unwrapExpression(actionDataFilter.getFromStateData());
String outputFilter = actionDataFilter == null ? null : unwrapExpression(actionDataFilter.getResults());
String scopeFilter = actionDataFilter == null ? null : unwrapExpression(actionDataFilter.getToStateData());
ConsequenceAction processAction = new ConsequenceAction(null, "expression(context, " + escapeExpression(expression + functionArguments) + ", " + escapeExpression(inputFilter) + ");");
if (actionDataFilter != null && actionDataFilter.isUseResults()) {
processAction = new ConsequenceAction(null, "expression(context, " + escapeExpression(expression + functionArguments) + ", " + escapeExpression(inputFilter) + ", " + escapeExpression(outputFilter) + ", " + escapeExpression(scopeFilter) + ");");
}
io.automatiko.engine.workflow.base.instance.impl.Action injectAction = context -> {
if (actionDataFilter != null && actionDataFilter.isUseResults()) {
io.automatiko.engine.workflow.sw.ServerlessFunctions.expression(context, expression, inputFilter, outputFilter, scopeFilter);
} else {
io.automatiko.engine.workflow.sw.ServerlessFunctions.expression(context, expression, inputFilter);
}
};
processAction.setMetaData(ACTION, injectAction);
actionNode.setAction(processAction);
nodeContainer.addNode(actionNode);
return actionNode;
}
Aggregations