use of io.automatiko.engine.workflow.process.core.ProcessAction in project automatiko-engine by automatiko-io.
the class ProcessEventSupportTest method testProcessEventListenerWithEvent.
@Test
public void testProcessEventListenerWithEvent() throws Exception {
ExecutableProcess process = new ExecutableProcess();
process.setId("org.company.core.process.event");
process.setName("Event Process");
StartNode startNode = new StartNode();
startNode.setName("Start");
startNode.setId(1);
process.addNode(startNode);
ActionNode actionNode = new ActionNode();
actionNode.setName("Print");
ProcessAction action = new ConsequenceAction("java", null);
action.setMetaData("Action", new Action() {
public void execute(ProcessContext context) throws Exception {
logger.info("Executed action");
}
});
actionNode.setAction(action);
actionNode.setId(2);
process.addNode(actionNode);
new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, actionNode, Node.CONNECTION_DEFAULT_TYPE);
EventNode eventNode = new EventNode();
eventNode.setName("Event");
eventNode.setId(3);
List<EventFilter> filters = new ArrayList<EventFilter>();
EventTypeFilter filter = new EventTypeFilter();
filter.setType("signal");
filters.add(filter);
eventNode.setEventFilters(filters);
process.addNode(eventNode);
new ConnectionImpl(actionNode, Node.CONNECTION_DEFAULT_TYPE, eventNode, Node.CONNECTION_DEFAULT_TYPE);
EndNode endNode = new EndNode();
endNode.setName("End");
endNode.setId(4);
process.addNode(endNode);
new ConnectionImpl(eventNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
InternalProcessRuntime processRuntime = new ProcessRuntimeImpl(Collections.singletonMap(process.getId(), process));
final List<ProcessEvent> processEventList = new ArrayList<ProcessEvent>();
final ProcessEventListener processEventListener = new ProcessEventListener() {
public void afterNodeLeft(ProcessNodeLeftEvent event) {
processEventList.add(event);
}
public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
processEventList.add(event);
}
public void afterProcessCompleted(ProcessCompletedEvent event) {
processEventList.add(event);
}
public void afterProcessStarted(ProcessStartedEvent event) {
processEventList.add(event);
}
public void beforeNodeLeft(ProcessNodeLeftEvent event) {
processEventList.add(event);
}
public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
processEventList.add(event);
}
public void beforeProcessCompleted(ProcessCompletedEvent event) {
processEventList.add(event);
}
public void beforeProcessStarted(ProcessStartedEvent event) {
processEventList.add(event);
}
public void beforeVariableChanged(ProcessVariableChangedEvent event) {
processEventList.add(event);
}
public void afterVariableChanged(ProcessVariableChangedEvent event) {
processEventList.add(event);
}
};
processRuntime.addEventListener(processEventListener);
// execute the process
ProcessInstance pi = processRuntime.startProcess("org.company.core.process.event");
pi.signalEvent("signal", null);
assertEquals(20, processEventList.size());
assertEquals("org.company.core.process.event", ((ProcessStartedEvent) processEventList.get(0)).getProcessInstance().getProcessId());
assertEquals("Start", ((ProcessNodeTriggeredEvent) processEventList.get(1)).getNodeInstance().getNodeName());
assertEquals("Start", ((ProcessNodeLeftEvent) processEventList.get(2)).getNodeInstance().getNodeName());
assertEquals("Print", ((ProcessNodeTriggeredEvent) processEventList.get(3)).getNodeInstance().getNodeName());
assertEquals("Print", ((ProcessNodeLeftEvent) processEventList.get(4)).getNodeInstance().getNodeName());
assertEquals("Event", ((ProcessNodeTriggeredEvent) processEventList.get(5)).getNodeInstance().getNodeName());
assertEquals("Event", ((ProcessNodeTriggeredEvent) processEventList.get(6)).getNodeInstance().getNodeName());
assertEquals("Print", ((ProcessNodeLeftEvent) processEventList.get(7)).getNodeInstance().getNodeName());
assertEquals("Print", ((ProcessNodeTriggeredEvent) processEventList.get(8)).getNodeInstance().getNodeName());
assertEquals("Start", ((ProcessNodeLeftEvent) processEventList.get(9)).getNodeInstance().getNodeName());
assertEquals("Start", ((ProcessNodeTriggeredEvent) processEventList.get(10)).getNodeInstance().getNodeName());
assertEquals("org.company.core.process.event", ((ProcessStartedEvent) processEventList.get(11)).getProcessInstance().getProcessId());
assertEquals("Event", ((ProcessNodeLeftEvent) processEventList.get(12)).getNodeInstance().getNodeName());
assertEquals("End", ((ProcessNodeTriggeredEvent) processEventList.get(13)).getNodeInstance().getNodeName());
assertEquals("End", ((ProcessNodeLeftEvent) processEventList.get(14)).getNodeInstance().getNodeName());
assertEquals("org.company.core.process.event", ((ProcessCompletedEvent) processEventList.get(15)).getProcessInstance().getProcessId());
assertEquals("org.company.core.process.event", ((ProcessCompletedEvent) processEventList.get(16)).getProcessInstance().getProcessId());
assertEquals("End", ((ProcessNodeLeftEvent) processEventList.get(17)).getNodeInstance().getNodeName());
assertEquals("Event", ((ProcessNodeLeftEvent) processEventList.get(19)).getNodeInstance().getNodeName());
assertEquals("End", ((ProcessNodeTriggeredEvent) processEventList.get(18)).getNodeInstance().getNodeName());
}
use of io.automatiko.engine.workflow.process.core.ProcessAction in project automatiko-engine by automatiko-io.
the class AbstractNodeHandler method handleScript.
protected void handleScript(final ExtendedNodeImpl node, final Element element, String type) {
NodeList nodeList = element.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
if (nodeList.item(i) instanceof Element) {
Element xmlNode = (Element) nodeList.item(i);
String nodeName = xmlNode.getNodeName();
if (nodeName.equals("extensionElements")) {
NodeList subNodeList = xmlNode.getChildNodes();
for (int j = 0; j < subNodeList.getLength(); j++) {
org.w3c.dom.Node subXmlNode = subNodeList.item(j);
if (subXmlNode.getNodeName().contains(type + "-script")) {
List<ProcessAction> actions = node.getActions(type);
if (actions == null) {
actions = new ArrayList<ProcessAction>();
node.setActions(type, actions);
}
ProcessAction action = extractScript((Element) subXmlNode);
actions.add(action);
}
}
}
}
}
}
use of io.automatiko.engine.workflow.process.core.ProcessAction in project automatiko-engine by automatiko-io.
the class ServerlessWorkflowFactory method scriptNode.
public ActionNode scriptNode(long id, String name, String script, NodeContainer nodeContainer) {
ActionNode scriptNode = new ActionNode();
scriptNode.setId(id);
scriptNode.setName(name);
scriptNode.setMetaData(UNIQUE_ID_PARAM, Long.toString(id));
ProcessAction processAction = new ProcessAction();
processAction.setMetaData(ACTION, script);
scriptNode.setAction(processAction);
scriptNode.setAction(new ConsequenceAction("java", script));
nodeContainer.addNode(scriptNode);
return scriptNode;
}
use of io.automatiko.engine.workflow.process.core.ProcessAction 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;
}
use of io.automatiko.engine.workflow.process.core.ProcessAction in project automatiko-engine by automatiko-io.
the class ServerlessWorkflowFactory method injectStateNode.
public ActionNode injectStateNode(long id, String name, NodeContainer nodeContainer, String dataToInject) {
ActionNode actionNode = new ActionNode();
actionNode.setId(id);
actionNode.setName(name);
ConsequenceAction processAction = new ConsequenceAction(null, "inject(context, " + escapeExpression(dataToInject) + ");");
io.automatiko.engine.workflow.base.instance.impl.Action injectAction = context -> {
io.automatiko.engine.workflow.sw.ServerlessFunctions.inject(context, dataToInject);
};
processAction.setMetaData(ACTION, injectAction);
actionNode.setAction(processAction);
nodeContainer.addNode(actionNode);
return actionNode;
}
Aggregations