Search in sources :

Example 16 with EventFilter

use of io.automatiko.engine.workflow.base.core.event.EventFilter in project automatiko-engine by automatiko-io.

the class EventNodeHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
    EventNode eventNode = (EventNode) node;
    writeNode("eventNode", eventNode, xmlDump, includeMeta);
    String variableName = eventNode.getVariableName();
    if (variableName != null && variableName.length() != 0) {
        xmlDump.append("variableName=\"" + variableName + "\" ");
    }
    String scope = eventNode.getScope();
    if (scope != null && scope.length() != 0) {
        xmlDump.append("scope=\"" + scope + "\" ");
    }
    xmlDump.append(">" + EOL);
    if (includeMeta) {
        writeMetaData(eventNode, xmlDump);
    }
    xmlDump.append("      <eventFilters>" + EOL);
    for (EventFilter filter : eventNode.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);
    endNode("eventNode", xmlDump);
}
Also used : EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter)

Example 17 with EventFilter

use of io.automatiko.engine.workflow.base.core.event.EventFilter in project automatiko-engine by automatiko-io.

the class ProcessHandler method handleIntermediateOrEndThrowCompensationEvent.

protected void handleIntermediateOrEndThrowCompensationEvent(ExtendedNodeImpl throwEventNode) {
    if (throwEventNode.getMetaData("compensation-activityRef") != null) {
        String activityRef = (String) throwEventNode.getMetaData().remove("compensation-activityRef");
        NodeContainer nodeParent = (NodeContainer) throwEventNode.getParentContainer();
        if (nodeParent instanceof EventSubProcessNode) {
            boolean compensationEventSubProcess = false;
            List<Trigger> startTriggers = ((EventSubProcessNode) nodeParent).findStartNode().getTriggers();
            CESP_CHECK: for (Trigger trigger : startTriggers) {
                if (trigger instanceof EventTrigger) {
                    for (EventFilter filter : ((EventTrigger) trigger).getEventFilters()) {
                        if (((EventTypeFilter) filter).getType().equals("Compensation")) {
                            compensationEventSubProcess = true;
                            break CESP_CHECK;
                        }
                    }
                }
            }
            if (compensationEventSubProcess) {
                // BPMN2 spec, p. 252, p. 248: intermediate and end compensation event
                // visibility scope
                nodeParent = (NodeContainer) ((NodeImpl) nodeParent).getParentContainer();
            }
        }
        String parentId;
        if (nodeParent instanceof ExecutableProcess) {
            parentId = ((ExecutableProcess) nodeParent).getId();
        } else {
            parentId = (String) ((NodeImpl) nodeParent).getMetaData("UniqueId");
        }
        String compensationEvent;
        if (activityRef.length() == 0) {
            // general/implicit compensation
            compensationEvent = CompensationScope.IMPLICIT_COMPENSATION_PREFIX + parentId;
        } else {
            // specific compensation
            compensationEvent = activityRef;
        }
        throwEventNode.setMetaData("CompensationEvent", compensationEvent);
        ConsequenceAction compensationAction = new ConsequenceAction("java", "");
        compensationAction.setMetaData("Action", new ProcessInstanceCompensationAction(compensationEvent));
        if (throwEventNode instanceof ActionNode) {
            ((ActionNode) throwEventNode).setAction(compensationAction);
        } else if (throwEventNode instanceof EndNode) {
            List<ProcessAction> actions = new ArrayList<ProcessAction>();
            actions.add(compensationAction);
            ((EndNode) throwEventNode).setActions(EndNode.EVENT_NODE_ENTER, actions);
        }
        throwEventNode.setMetaData("TriggerType", "Compensation");
    }
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) NodeImpl(io.automatiko.engine.workflow.process.core.impl.NodeImpl) ExtendedNodeImpl(io.automatiko.engine.workflow.process.core.impl.ExtendedNodeImpl) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) NodeContainer(io.automatiko.engine.api.definition.process.NodeContainer) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter) ProcessInstanceCompensationAction(io.automatiko.engine.workflow.base.instance.impl.actions.ProcessInstanceCompensationAction) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) Trigger(io.automatiko.engine.workflow.process.core.node.Trigger) ConstraintTrigger(io.automatiko.engine.workflow.process.core.node.ConstraintTrigger) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) List(java.util.List) ArrayList(java.util.ArrayList) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger)

Example 18 with EventFilter

use of io.automatiko.engine.workflow.base.core.event.EventFilter in project automatiko-engine by automatiko-io.

the class IntermediateCatchEventHandler method handleSignalNode.

protected void handleSignalNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    EventNode eventNode = (EventNode) node;
    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);
        } else if ("signalEventDefinition".equals(nodeName)) {
            String type = ((Element) xmlNode).getAttribute("signalRef");
            if (type != null && type.trim().length() > 0) {
                Signal signal = findSignalByName(parser, type);
                if (signal != null) {
                    eventNode.setMetaData("MessageType", retrieveDataType(signal.getStructureRef(), null, parser));
                }
                type = checkSignalAndConvertToRealSignalNam(parser, type);
                List<EventFilter> eventFilters = new ArrayList<EventFilter>();
                EventTypeFilter eventFilter = new EventTypeFilter();
                eventFilter.setType(type);
                eventFilters.add(eventFilter);
                eventNode.setEventFilters(eventFilters);
            }
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) Signal(io.automatiko.engine.workflow.bpmn2.core.Signal) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter)

Example 19 with EventFilter

use of io.automatiko.engine.workflow.base.core.event.EventFilter in project automatiko-engine by automatiko-io.

the class IntermediateCatchEventHandler method handleMessageNode.

@SuppressWarnings("unchecked")
protected void handleMessageNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    EventNode eventNode = (EventNode) node;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        String id = ((Element) xmlNode).getAttribute("id");
        String name = ((Element) xmlNode).getAttribute("name");
        if ("dataOutput".equals(nodeName)) {
            dataOutputs.put(id, name);
            populateDataOutputs(xmlNode, name, parser);
        } else if ("dataOutputAssociation".equals(nodeName)) {
            readDataOutputAssociation(xmlNode, eventNode);
        } else if ("messageEventDefinition".equals(nodeName)) {
            String messageRef = ((Element) xmlNode).getAttribute("messageRef");
            Map<String, Message> messages = (Map<String, Message>) ((ProcessBuildData) parser.getData()).getMetaData("Messages");
            if (messages == null) {
                throw new IllegalArgumentException("No messages found");
            }
            Message message = messages.get(messageRef);
            if (message == null) {
                throw new MalformedNodeException(id, name, MessageFormat.format("Could not find message \"{0}\"", messageRef));
            }
            eventNode.setMetaData("MessageType", message.getType());
            eventNode.setMetaData("TriggerType", "ConsumeMessage");
            eventNode.setMetaData("TriggerRef", message.getName());
            eventNode.setMetaData("TriggerCorrelation", message.getCorrelation());
            eventNode.setMetaData("TriggerCorrelationExpr", message.getCorrelationExpression());
            for (Entry<String, Object> entry : message.getMetaData().entrySet()) {
                eventNode.setMetaData(entry.getKey(), entry.getValue());
            }
            List<EventFilter> eventFilters = new ArrayList<EventFilter>();
            EventTypeFilter eventFilter = new EventTypeFilter();
            eventFilter.setType("Message-" + message.getName());
            eventFilters.add(eventFilter);
            eventNode.setEventFilters(eventFilters);
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : Message(io.automatiko.engine.workflow.bpmn2.core.Message) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 20 with EventFilter

use of io.automatiko.engine.workflow.base.core.event.EventFilter in project automatiko-engine by automatiko-io.

the class BoundaryEventHandler method handleCompensationNode.

protected void handleCompensationNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser, final String attachedTo, final boolean cancelActivity) throws SAXException {
    BoundaryEventNode eventNode = (BoundaryEventNode) parser.getCurrent();
    super.handleNode(node, element, uri, localName, parser);
    NodeList childs = element.getChildNodes();
    for (int i = 0; i < childs.getLength(); i++) {
        if (childs.item(i) instanceof Element) {
            Element el = (Element) childs.item(i);
            if ("compensateEventDefinition".equalsIgnoreCase(el.getNodeName())) {
                String activityRef = el.getAttribute("activityRef");
                if (activityRef != null && activityRef.length() > 0) {
                    logger.warn("activityRef value [" + activityRef + "] on Boundary Event '" + eventNode.getMetaData("UniqueId") + "' ignored per the BPMN2 specification.");
                }
            }
        }
    }
    eventNode.setMetaData("AttachedTo", attachedTo);
    eventNode.setAttachedToNodeId(attachedTo);
    // 1. Find the parent (sub-)process
    NodeContainer parentContainer = (NodeContainer) parser.getParent();
    // 2. Add the event filter (never fires, purely for dumping purposes)
    EventTypeFilter eventFilter = new NonAcceptingEventTypeFilter();
    eventFilter.setType("Compensation");
    List<EventFilter> eventFilters = new ArrayList<EventFilter>();
    eventNode.setEventFilters(eventFilters);
    eventFilters.add(eventFilter);
    // 3. Add compensation scope (with key/id: attachedTo)
    ProcessHandler.addCompensationScope((ExecutableProcess) parser.getParent(ExecutableProcess.class), eventNode, parentContainer, attachedTo);
}
Also used : NonAcceptingEventTypeFilter(io.automatiko.engine.workflow.base.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) NonAcceptingEventTypeFilter(io.automatiko.engine.workflow.base.core.event.NonAcceptingEventTypeFilter) NodeContainer(io.automatiko.engine.workflow.process.core.NodeContainer) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter)

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