Search in sources :

Example 1 with EventFilter

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);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) Trigger(io.automatiko.engine.workflow.process.core.node.Trigger) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) Node(io.automatiko.engine.api.definition.process.Node) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger)

Example 2 with EventFilter

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();
    }
}
Also used : Element(org.w3c.dom.Element) Escalation(io.automatiko.engine.workflow.bpmn2.core.Escalation) ArrayList(java.util.ArrayList) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter) NonAcceptingEventTypeFilter(io.automatiko.engine.workflow.base.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 3 with EventFilter

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();
    }
}
Also used : NonAcceptingEventTypeFilter(io.automatiko.engine.workflow.base.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter)

Example 4 with EventFilter

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;
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) Node(io.automatiko.engine.api.definition.process.Node) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) NodeContainer(io.automatiko.engine.api.definition.process.NodeContainer) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) Trigger(io.automatiko.engine.workflow.process.core.node.Trigger) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) HashSet(java.util.HashSet) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger)

Example 5 with EventFilter

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);
    }
}
Also used : ConstraintTrigger(io.automatiko.engine.workflow.process.core.node.ConstraintTrigger) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) Trigger(io.automatiko.engine.workflow.process.core.node.Trigger) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) ConstraintTrigger(io.automatiko.engine.workflow.process.core.node.ConstraintTrigger) Map(java.util.Map) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger)

Aggregations

EventFilter (io.automatiko.engine.workflow.base.core.event.EventFilter)25 EventTypeFilter (io.automatiko.engine.workflow.base.core.event.EventTypeFilter)24 ArrayList (java.util.ArrayList)16 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)14 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)11 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)10 Element (org.w3c.dom.Element)10 Node (io.automatiko.engine.api.definition.process.Node)9 NonAcceptingEventTypeFilter (io.automatiko.engine.workflow.base.core.event.NonAcceptingEventTypeFilter)9 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)8 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)8 EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)8 EventTrigger (io.automatiko.engine.workflow.process.core.node.EventTrigger)8 Trigger (io.automatiko.engine.workflow.process.core.node.Trigger)8 List (java.util.List)7 Map (java.util.Map)7 ConsequenceAction (io.automatiko.engine.workflow.process.core.impl.ConsequenceAction)6 CompositeNode (io.automatiko.engine.workflow.process.core.node.CompositeNode)6 FaultNode (io.automatiko.engine.workflow.process.core.node.FaultNode)6 WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)5