Search in sources :

Example 11 with EventFilter

use of org.jbpm.process.core.event.EventFilter in project jbpm by kiegroup.

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((RuleFlowProcess) parser.getParent(RuleFlowProcess.class), eventNode, parentContainer, attachedTo);
}
Also used : NonAcceptingEventTypeFilter(org.jbpm.process.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) NonAcceptingEventTypeFilter(org.jbpm.process.core.event.NonAcceptingEventTypeFilter) NodeContainer(org.jbpm.workflow.core.NodeContainer) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventFilter(org.jbpm.process.core.event.EventFilter)

Example 12 with EventFilter

use of org.jbpm.process.core.event.EventFilter in project jbpm by kiegroup.

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);
        } else if ("dataOutputAssociation".equals(nodeName)) {
            readDataOutputAssociation(xmlNode, eventNode);
        } 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(org.jbpm.bpmn2.core.Escalation) ArrayList(java.util.ArrayList) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventFilter(org.jbpm.process.core.event.EventFilter) NonAcceptingEventTypeFilter(org.jbpm.process.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) Map(java.util.Map)

Example 13 with EventFilter

use of org.jbpm.process.core.event.EventFilter in project jbpm by kiegroup.

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);
        }
        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) {
                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(org.jbpm.process.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventFilter(org.jbpm.process.core.event.EventFilter)

Example 14 with EventFilter

use of org.jbpm.process.core.event.EventFilter in project jbpm by kiegroup.

the class BoundaryEventHandler method handleMessageNode.

protected void handleMessageNode(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);
        } 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 IllegalArgumentException("Could not find message " + messageRef);
            }
            eventNode.setMetaData("MessageType", message.getType());
            List<EventFilter> eventFilters = new ArrayList<EventFilter>();
            EventTypeFilter eventFilter = new EventTypeFilter();
            eventFilter.setType("Message-" + messageRef);
            eventFilters.add(eventFilter);
            eventNode.setScope("external");
            eventNode.setEventFilters(eventFilters);
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : Message(org.jbpm.bpmn2.core.Message) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventFilter(org.jbpm.process.core.event.EventFilter) NonAcceptingEventTypeFilter(org.jbpm.process.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) Map(java.util.Map)

Example 15 with EventFilter

use of org.jbpm.process.core.event.EventFilter in project jbpm by kiegroup.

the class BoundaryEventHandler method handleErrorNode.

@SuppressWarnings("unchecked")
protected void handleErrorNode(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.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);
        } else if ("dataOutputAssociation".equals(nodeName)) {
            readDataOutputAssociation(xmlNode, eventNode);
        } else if ("errorEventDefinition".equals(nodeName)) {
            String errorRef = ((Element) xmlNode).getAttribute("errorRef");
            if (errorRef != null && errorRef.trim().length() > 0) {
                List<Error> errors = (List<Error>) ((ProcessBuildData) parser.getData()).getMetaData("Errors");
                if (errors == null) {
                    throw new IllegalArgumentException("No errors found");
                }
                Error error = null;
                for (Error listError : errors) {
                    if (errorRef.equals(listError.getId())) {
                        error = listError;
                    }
                }
                if (error == null) {
                    throw new IllegalArgumentException("Could not find error " + errorRef);
                }
                String type = error.getErrorCode();
                boolean hasErrorCode = true;
                if (type == null) {
                    type = error.getId();
                    hasErrorCode = false;
                }
                String structureRef = error.getStructureRef();
                if (structureRef != null) {
                    Map<String, ItemDefinition> itemDefs = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
                    if (itemDefs.containsKey(structureRef)) {
                        structureRef = itemDefs.get(structureRef).getStructureRef();
                    }
                }
                List<EventFilter> eventFilters = new ArrayList<EventFilter>();
                EventTypeFilter eventFilter = new EventTypeFilter();
                eventFilter.setType("Error-" + attachedTo + "-" + type);
                eventFilters.add(eventFilter);
                eventNode.setEventFilters(eventFilters);
                eventNode.setMetaData("ErrorEvent", type);
                eventNode.setMetaData("HasErrorEvent", hasErrorCode);
                eventNode.setMetaData("ErrorStructureRef", structureRef);
            }
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : Element(org.w3c.dom.Element) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) ArrayList(java.util.ArrayList) Error(org.jbpm.bpmn2.core.Error) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventFilter(org.jbpm.process.core.event.EventFilter) NonAcceptingEventTypeFilter(org.jbpm.process.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) Map(java.util.Map)

Aggregations

EventFilter (org.jbpm.process.core.event.EventFilter)21 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)20 ArrayList (java.util.ArrayList)16 BoundaryEventNode (org.jbpm.workflow.core.node.BoundaryEventNode)13 NonAcceptingEventTypeFilter (org.jbpm.process.core.event.NonAcceptingEventTypeFilter)9 EventNode (org.jbpm.workflow.core.node.EventNode)9 Element (org.w3c.dom.Element)9 ActionNode (org.jbpm.workflow.core.node.ActionNode)8 StartNode (org.jbpm.workflow.core.node.StartNode)8 List (java.util.List)7 EndNode (org.jbpm.workflow.core.node.EndNode)7 Map (java.util.Map)6 EventSubProcessNode (org.jbpm.workflow.core.node.EventSubProcessNode)6 Node (org.kie.api.definition.process.Node)6 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)5 EventTrigger (org.jbpm.workflow.core.node.EventTrigger)5 FaultNode (org.jbpm.workflow.core.node.FaultNode)5 RuleSetNode (org.jbpm.workflow.core.node.RuleSetNode)5 StateNode (org.jbpm.workflow.core.node.StateNode)5 SubProcessNode (org.jbpm.workflow.core.node.SubProcessNode)5