use of io.automatiko.engine.workflow.base.core.event.EventFilter in project automatiko-engine by automatiko-io.
the class StartEventHandler method handleCompensationNode.
protected void handleCompensationNode(final StartNode startNode, final org.w3c.dom.Node xmlNode) {
if (startNode.isInterrupting()) {
logger.warn("Compensation Event Sub-Processes [" + startNode.getMetaData("UniqueId") + "] may not be specified as interrupting:" + " overriding attribute and setting to not-interrupting.");
}
startNode.setInterrupting(false);
/**
* From the BPMN2 spec, P.264: "For a Start Event: This Event "catches" the
* compensation for an Event Sub-Process. No further information is required.
* The Event Sub-Process will provide the id necessary to match the Compensation
* Event with the Event that threw the compensation"
*
* In other words, the id of the Sub-Process containing this Event Sub-Process
* is what should be used as the activityRef value in any Intermediate (throw)
* or End compensation event that targets this particular Event Sub-Process.
*
* This is similar to the logic used for a Compensation Boundary Event: it's
* signaled using the id of the activity to which the CBE is attached to.
*/
String activityRef = ((Element) xmlNode).getAttribute("activityRef");
if (activityRef != null && activityRef.length() > 0) {
logger.warn("activityRef value [" + activityRef + "] on Start Event '" + startNode.getMetaData("UniqueId") + "' ignored per the BPMN2 specification.");
}
// so that this node will get processed in ProcessHandler.postProcessNodes(...)
EventTrigger startTrigger = new EventTrigger();
EventFilter eventFilter = new NonAcceptingEventTypeFilter();
((NonAcceptingEventTypeFilter) eventFilter).setType("Compensation");
startTrigger.addEventFilter(eventFilter);
List<Trigger> startTriggers = new ArrayList<>();
startTriggers.add(startTrigger);
startNode.setTriggers(startTriggers);
String mapping = (String) startNode.getMetaData("TriggerMapping");
if (mapping != null) {
startTrigger.addInMapping(mapping, startNode.getOutMapping(mapping));
}
}
use of io.automatiko.engine.workflow.base.core.event.EventFilter 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.base.core.event.EventFilter in project automatiko-engine by automatiko-io.
the class BoundaryEventHandler method handleConditionNode.
protected void handleConditionNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser, final String attachedTo, final boolean cancelActivity) throws SAXException {
super.handleNode(node, element, uri, localName, parser);
BoundaryEventNode eventNode = (BoundaryEventNode) node;
eventNode.setMetaData("AttachedTo", attachedTo);
eventNode.setMetaData("CancelActivity", cancelActivity);
eventNode.setAttachedToNodeId(attachedTo);
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("dataOutput".equals(nodeName)) {
String id = ((Element) xmlNode).getAttribute("id");
String outputName = ((Element) xmlNode).getAttribute("name");
dataOutputs.put(id, outputName);
populateDataOutputs(xmlNode, outputName, parser);
} else if ("dataOutputAssociation".equals(nodeName)) {
readDataOutputAssociation(xmlNode, eventNode, parser);
} else if ("conditionalEventDefinition".equals(nodeName)) {
org.w3c.dom.Node subNode = xmlNode.getFirstChild();
while (subNode != null) {
String subnodeName = subNode.getNodeName();
if ("condition".equals(subnodeName)) {
eventNode.setMetaData("Condition", xmlNode.getTextContent());
List<EventFilter> eventFilters = new ArrayList<EventFilter>();
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setType("Condition-" + attachedTo);
eventFilters.add(eventFilter);
eventNode.setScope("external");
eventNode.setEventFilters(eventFilters);
break;
}
subNode = subNode.getNextSibling();
}
}
xmlNode = xmlNode.getNextSibling();
}
}
use of io.automatiko.engine.workflow.base.core.event.EventFilter in project automatiko-engine by automatiko-io.
the class BoundaryEventHandler method handleTimerNode.
protected void handleTimerNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser, final String attachedTo, final boolean cancelActivity) throws SAXException {
super.handleNode(node, element, uri, localName, parser);
BoundaryEventNode eventNode = (BoundaryEventNode) node;
eventNode.setMetaData("AttachedTo", attachedTo);
eventNode.setMetaData("CancelActivity", cancelActivity);
eventNode.setAttachedToNodeId(attachedTo);
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("timerEventDefinition".equals(nodeName)) {
String timeDuration = null;
String timeCycle = null;
String timeDate = null;
String language = "";
org.w3c.dom.Node subNode = xmlNode.getFirstChild();
while (subNode instanceof Element) {
String subNodeName = subNode.getNodeName();
if ("timeDuration".equals(subNodeName)) {
timeDuration = subNode.getTextContent();
break;
} else if ("timeCycle".equals(subNodeName)) {
timeCycle = subNode.getTextContent();
language = ((Element) subNode).getAttribute("language");
break;
} else if ("timeDate".equals(subNodeName)) {
timeDate = subNode.getTextContent();
break;
}
subNode = subNode.getNextSibling();
}
if (timeDuration != null && timeDuration.trim().length() > 0) {
List<EventFilter> eventFilters = new ArrayList<EventFilter>();
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setType("Timer-" + attachedTo + "-" + timeDuration + "-" + eventNode.getId());
eventFilters.add(eventFilter);
eventNode.setEventFilters(eventFilters);
eventNode.setMetaData("TimeDuration", timeDuration);
} else if (timeCycle != null && timeCycle.trim().length() > 0) {
List<EventFilter> eventFilters = new ArrayList<EventFilter>();
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setType("Timer-" + attachedTo + "-" + timeCycle + "-" + eventNode.getId());
eventFilters.add(eventFilter);
eventNode.setEventFilters(eventFilters);
eventNode.setMetaData("TimeCycle", timeCycle);
eventNode.setMetaData("Language", language);
} else if (timeDate != null && timeDate.trim().length() > 0) {
List<EventFilter> eventFilters = new ArrayList<EventFilter>();
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setType("Timer-" + attachedTo + "-" + timeDate + "-" + eventNode.getId());
eventFilters.add(eventFilter);
eventNode.setEventFilters(eventFilters);
eventNode.setMetaData("TimeDate", timeDate);
}
}
xmlNode = xmlNode.getNextSibling();
}
}
use of io.automatiko.engine.workflow.base.core.event.EventFilter in project automatiko-engine by automatiko-io.
the class CompensationTest method createBoundaryEventCompensationHandler.
private void createBoundaryEventCompensationHandler(io.automatiko.engine.workflow.process.core.NodeContainer nodeContainer, Node attachedToNode, final List<String> eventList, final String id) throws Exception {
NodeCreator<BoundaryEventNode> boundaryNodeCreator = new NodeCreator<BoundaryEventNode>(nodeContainer, BoundaryEventNode.class);
BoundaryEventNode boundaryNode = boundaryNodeCreator.createNode("boundary" + id);
String attachedTo = (String) attachedToNode.getMetaData().get("UniqueId");
boundaryNode.setMetaData("AttachedTo", attachedTo);
boundaryNode.setAttachedToNodeId(attachedTo);
EventTypeFilter eventFilter = new NonAcceptingEventTypeFilter();
eventFilter.setType("Compensation");
List<EventFilter> eventFilters = new ArrayList<EventFilter>();
boundaryNode.setEventFilters(eventFilters);
eventFilters.add(eventFilter);
addCompensationScope(boundaryNode, nodeContainer, attachedTo);
NodeCreator<ActionNode> actionNodeCreator = new NodeCreator<ActionNode>(nodeContainer, ActionNode.class);
ActionNode actionNode = actionNodeCreator.createNode("handlerAction" + id);
actionNode.setMetaData("isForCompensation", true);
actionNode.setName("Execute");
ProcessAction action = new ConsequenceAction("java", null);
action.setMetaData("Action", new Action() {
public void execute(ProcessContext context) throws Exception {
eventList.add("action" + id);
}
});
actionNode.setAction(action);
connect(boundaryNode, actionNode);
}
Aggregations