use of io.automatiko.engine.workflow.base.core.event.EventFilter in project automatiko-engine by automatiko-io.
the class LightProcessRuntime method initProcessEventListener.
private void initProcessEventListener(Process process) {
if (process instanceof ExecutableProcess) {
for (Node node : ((ExecutableProcess) process).getNodes()) {
if (node instanceof StartNode) {
StartNode startNode = (StartNode) node;
if (startNode != null) {
List<Trigger> triggers = startNode.getTriggers();
if (triggers != null) {
for (Trigger trigger : triggers) {
if (trigger instanceof EventTrigger) {
final List<EventFilter> filters = ((EventTrigger) trigger).getEventFilters();
String type = null;
for (EventFilter filter : filters) {
if (filter instanceof EventTypeFilter) {
type = ((EventTypeFilter) filter).getType();
}
}
StartProcessEventListener listener = new StartProcessEventListener(process.getId(), filters, trigger.getInMappings(), startNode.getEventTransformer());
signalManager.addEventListener(type, listener);
((ExecutableProcess) process).getRuntimeMetaData().put("StartProcessEventType", type);
((ExecutableProcess) process).getRuntimeMetaData().put("StartProcessEventListener", listener);
}
}
}
}
}
}
}
}
use of io.automatiko.engine.workflow.base.core.event.EventFilter in project automatiko-engine by automatiko-io.
the class BoundaryEventHandler method handleEscalationNode.
@SuppressWarnings("unchecked")
protected void handleEscalationNode(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);
/**
* TODO: because of how we process bpmn2/xml files, we can't tell if the
* cancelActivity attribute is set to false or not (because we override with the
* xsd settings) BPMN2 spec, p. 255, Escalation row: "In contrast to an Error,
* an Escalation by default is assumed to not abort the Activity to which the
* boundary Event is attached."
*/
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 ("escalationEventDefinition".equals(nodeName)) {
String escalationRef = ((Element) xmlNode).getAttribute("escalationRef");
if (escalationRef != null && escalationRef.trim().length() > 0) {
Map<String, Escalation> escalations = (Map<String, Escalation>) ((ProcessBuildData) parser.getData()).getMetaData(ProcessHandler.ESCALATIONS);
if (escalations == null) {
throw new IllegalArgumentException("No escalations found");
}
Escalation escalation = escalations.get(escalationRef);
if (escalation == null) {
throw new IllegalArgumentException("Could not find escalation " + escalationRef);
}
List<EventFilter> eventFilters = new ArrayList<EventFilter>();
EventTypeFilter eventFilter = new EventTypeFilter();
String type = escalation.getEscalationCode();
eventFilter.setType("Escalation-" + attachedTo + "-" + type);
eventFilters.add(eventFilter);
eventNode.setEventFilters(eventFilters);
eventNode.setMetaData("EscalationEvent", type);
} else {
throw new UnsupportedOperationException("General escalation is not yet supported.");
}
}
xmlNode = xmlNode.getNextSibling();
}
}
use of io.automatiko.engine.workflow.base.core.event.EventFilter in project automatiko-engine by automatiko-io.
the class BoundaryEventHandler method handleSignalNode.
protected void handleSignalNode(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);
}
if ("dataOutputAssociation".equals(nodeName)) {
readDataOutputAssociation(xmlNode, eventNode, parser);
} else if ("signalEventDefinition".equals(nodeName)) {
String type = ((Element) xmlNode).getAttribute("signalRef");
if (type != null && type.trim().length() > 0) {
type = checkSignalAndConvertToRealSignalNam(parser, type);
List<EventFilter> eventFilters = new ArrayList<EventFilter>();
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setType(type);
eventFilters.add(eventFilter);
eventNode.setEventFilters(eventFilters);
eventNode.setScope("external");
eventNode.setMetaData("SignalName", type);
}
}
xmlNode = xmlNode.getNextSibling();
}
}
use of io.automatiko.engine.workflow.base.core.event.EventFilter in project automatiko-engine by automatiko-io.
the class ServiceTaskDescriptor method collectHandledErrorCodes.
private Set<String> collectHandledErrorCodes() {
Set<String> errorCodes = new HashSet<>();
NodeContainer container = workItemNode.getParentContainer();
String thisNodeId = (String) workItemNode.getMetaData("UniqueId");
for (Node node : container.getNodes()) {
if (node instanceof BoundaryEventNode) {
String errorCode = (String) node.getMetaData().get("ErrorEvent");
if (errorCode != null && ((BoundaryEventNode) node).getAttachedToNodeId().equals(thisNodeId)) {
errorCodes.add(errorCode);
}
}
}
// next collect event subprocess node with error start event from this level and to all parents
String replaceRegExp = "Error-|Escalation-";
for (Node node : container.getNodes()) {
if (node instanceof EventSubProcessNode) {
EventSubProcessNode eventSubProcessNode = (EventSubProcessNode) node;
Node[] nodes = eventSubProcessNode.getNodes();
for (Node subNode : nodes) {
// avoids cyclomatic complexity
if (subNode == null || !(subNode instanceof StartNode)) {
continue;
}
List<Trigger> triggers = ((StartNode) subNode).getTriggers();
if (triggers == null) {
continue;
}
for (Trigger trigger : triggers) {
if (trigger instanceof EventTrigger) {
final List<EventFilter> filters = ((EventTrigger) trigger).getEventFilters();
for (EventFilter filter : filters) {
if (filter instanceof EventTypeFilter) {
eventSubProcessNode.addEvent((EventTypeFilter) filter);
String type = ((EventTypeFilter) filter).getType();
if (type.startsWith("Error-")) {
String trimmedType = type.replaceFirst(replaceRegExp, "");
for (String error : trimmedType.split(",")) {
errorCodes.add(error);
}
}
}
}
}
}
}
}
}
return errorCodes;
}
use of io.automatiko.engine.workflow.base.core.event.EventFilter in project automatiko-engine by automatiko-io.
the class StartNodeHandler method writeNode.
public void writeNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
StartNode startNode = (StartNode) node;
writeNode("start", startNode, xmlDump, includeMeta);
List<Trigger> triggers = startNode.getTriggers();
if ((triggers == null || triggers.isEmpty()) && (!includeMeta || !containsMetaData(startNode))) {
endNode(xmlDump);
} else {
xmlDump.append(">" + EOL);
if (includeMeta) {
writeMetaData(startNode, xmlDump);
}
if (triggers != null) {
xmlDump.append(" <triggers>" + EOL);
for (Trigger trigger : triggers) {
if (trigger instanceof ConstraintTrigger) {
xmlDump.append(" <trigger type=\"constraint\" >" + EOL);
xmlDump.append(" <constraint type=\"rule\" dialect=\"mvel\" >" + ((ConstraintTrigger) trigger).getConstraint() + "</constraint>" + EOL);
Map<String, String> inMappings = trigger.getInMappings();
if (inMappings != null && !inMappings.isEmpty()) {
for (Map.Entry<String, String> entry : inMappings.entrySet()) {
xmlDump.append(" <mapping type=\"in\" from=\"" + XmlDumper.replaceIllegalChars(entry.getValue()) + "\" to=\"" + entry.getKey() + "\" />" + EOL);
}
}
xmlDump.append(" </trigger>" + EOL);
} else if (trigger instanceof EventTrigger) {
xmlDump.append(" <trigger type=\"event\" >" + EOL);
xmlDump.append(" <eventFilters>" + EOL);
for (EventFilter filter : ((EventTrigger) trigger).getEventFilters()) {
if (filter instanceof EventTypeFilter) {
xmlDump.append(" <eventFilter " + "type=\"eventType\" " + "eventType=\"" + ((EventTypeFilter) filter).getType() + "\" />" + EOL);
} else {
throw new IllegalArgumentException("Unknown filter type: " + filter);
}
}
xmlDump.append(" </eventFilters>" + EOL);
Map<String, String> inMappings = trigger.getInMappings();
if (inMappings != null && !inMappings.isEmpty()) {
for (Map.Entry<String, String> entry : inMappings.entrySet()) {
xmlDump.append(" <mapping type=\"in\" from=\"" + XmlDumper.replaceIllegalChars(entry.getValue()) + "\" to=\"" + entry.getKey() + "\" />" + EOL);
}
}
xmlDump.append(" </trigger>" + EOL);
} else {
throw new IllegalArgumentException("Unknown trigger type " + trigger);
}
}
xmlDump.append(" </triggers>" + EOL);
}
endNode("start", xmlDump);
}
}
Aggregations