Search in sources :

Example 21 with Message

use of io.automatiko.engine.workflow.bpmn2.core.Message in project jbpm by kiegroup.

the class StartEventHandler method handleNode.

@Override
@SuppressWarnings("unchecked")
protected void handleNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    StartNode startNode = (StartNode) node;
    // TODO: StartEventHandler.handleNode(): the parser doesn't discriminate between the schema default and the actual set value
    // However, while the schema says the "isInterrupting" attr should default to true
    // The spec says that Escalation start events should default to not interrupting..
    startNode.setInterrupting(Boolean.parseBoolean(element.getAttribute("isInterrupting")));
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("dataOutput".equals(nodeName)) {
            readDataOutput(xmlNode);
        } else if ("dataOutputAssociation".equals(nodeName)) {
            readDataOutputAssociation(xmlNode, startNode);
        } else if ("outputSet".equals(nodeName)) {
            // p. 225, BPMN2 spec (2011-01-03)
            // InputSet and OutputSet elements imply that process execution should wait for them to be filled
            // and are therefore not applicable to catch events
            String message = "Ignoring <" + nodeName + "> element: " + "<" + nodeName + "> elements should not be used on start or other catch events.";
            SAXParseException saxpe = new SAXParseException(message, parser.getLocator());
            parser.warning(saxpe);
        // no exception thrown for backwards compatibility (we used to ignore these elements)
        } else if ("conditionalEventDefinition".equals(nodeName)) {
            String constraint = null;
            org.w3c.dom.Node subNode = xmlNode.getFirstChild();
            while (subNode != null) {
                String subnodeName = subNode.getNodeName();
                if ("condition".equals(subnodeName)) {
                    constraint = xmlNode.getTextContent();
                    break;
                }
                subNode = subNode.getNextSibling();
            }
            ConstraintTrigger trigger = new ConstraintTrigger();
            trigger.setConstraint(constraint);
            startNode.addTrigger(trigger);
            break;
        } else if ("signalEventDefinition".equals(nodeName)) {
            String type = ((Element) xmlNode).getAttribute("signalRef");
            type = checkSignalAndConvertToRealSignalNam(parser, type, s -> s.addIncomingNode(node));
            if (type != null && type.trim().length() > 0) {
                addTriggerWithInMappings(startNode, type);
            }
        } 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);
            }
            message.addIncomingNode(node);
            startNode.setMetaData("MessageType", message.getType());
            addTriggerWithInMappings(startNode, "Message-" + message.getName(), message.getId(), ((RuleFlowProcess) parser.getMetaData().get("CurrentProcessDefinition")).getCorrelationManager());
        } else if ("timerEventDefinition".equals(nodeName)) {
            handleTimerNode(startNode, element, uri, localName, parser);
        // following event definitions are only for event sub process and will be validated to not be included in top process definitions
        } else if ("errorEventDefinition".equals(nodeName)) {
            if (!startNode.isInterrupting()) {
                // BPMN2 spec (p.245-246, (2011-01-03)) implies that
                // - a <startEvent> in an Event Sub-Process
                // - *without* the 'isInterupting' attribute always interrupts (containing process)
                String errorMsg = "Error Start Events in an Event Sub-Process always interrupt the containing (sub)process(es).";
                throw new IllegalArgumentException(errorMsg);
            }
            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);
                }
                startNode.setMetaData("FaultCode", error.getErrorCode());
                addTriggerWithInMappings(startNode, "Error-" + error.getErrorCode());
            }
        } 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);
                }
                addTriggerWithInMappings(startNode, "Escalation-" + escalation.getEscalationCode());
            }
        } else if ("compensateEventDefinition".equals(nodeName)) {
            handleCompensationNode(startNode, xmlNode);
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : ConstraintTrigger(org.jbpm.workflow.core.node.ConstraintTrigger) EventFilter(org.jbpm.process.core.event.EventFilter) ConstraintTrigger(org.jbpm.workflow.core.node.ConstraintTrigger) CorrelationManager(org.jbpm.process.core.correlation.CorrelationManager) EventTransformerImpl(org.jbpm.process.core.event.EventTransformerImpl) Escalation(org.jbpm.bpmn2.core.Escalation) StartNode(org.jbpm.workflow.core.node.StartNode) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) ArrayList(java.util.ArrayList) ExtensibleXmlParser(org.drools.core.xml.ExtensibleXmlParser) Timer(org.jbpm.process.core.timer.Timer) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) Map(java.util.Map) Attributes(org.xml.sax.Attributes) EventTrigger(org.jbpm.workflow.core.node.EventTrigger) Transformation(org.jbpm.workflow.core.node.Transformation) XmlDumper(org.drools.compiler.compiler.xml.XmlDumper) DataTransformer(org.kie.api.runtime.process.DataTransformer) NonAcceptingEventTypeFilter(org.jbpm.process.core.event.NonAcceptingEventTypeFilter) Message(org.jbpm.bpmn2.core.Message) List(java.util.List) Error(org.jbpm.bpmn2.core.Error) SAXParseException(org.xml.sax.SAXParseException) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) Element(org.w3c.dom.Element) DataTransformerRegistry(org.jbpm.process.core.impl.DataTransformerRegistry) Node(org.jbpm.workflow.core.Node) SAXException(org.xml.sax.SAXException) Trigger(org.jbpm.workflow.core.node.Trigger) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) StartNode(org.jbpm.workflow.core.node.StartNode) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) Message(org.jbpm.bpmn2.core.Message) StartNode(org.jbpm.workflow.core.node.StartNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) Node(org.jbpm.workflow.core.Node) Element(org.w3c.dom.Element) Escalation(org.jbpm.bpmn2.core.Escalation) Error(org.jbpm.bpmn2.core.Error) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) SAXParseException(org.xml.sax.SAXParseException) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 22 with Message

use of io.automatiko.engine.workflow.bpmn2.core.Message in project jbpm by kiegroup.

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();
        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);
            }
            message.addIncomingNode(node);
            eventNode.setMetaData("MessageType", message.getType());
            List<EventFilter> eventFilters = new ArrayList<EventFilter>();
            EventTypeFilter eventFilter = new EventTypeFilter();
            eventFilter.setCorrelationManager(((RuleFlowProcess) parser.getMetaData().get("CurrentProcessDefinition")).getCorrelationManager());
            eventFilter.setType("Message-" + message.getName());
            eventFilter.setMessageRef(message.getId());
            eventFilters.add(eventFilter);
            eventNode.setEventFilters(eventFilters);
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : Message(org.jbpm.bpmn2.core.Message) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) EventFilter(org.jbpm.process.core.event.EventFilter) EventNode(org.jbpm.workflow.core.node.EventNode) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 23 with Message

use of io.automatiko.engine.workflow.bpmn2.core.Message in project jbpm by kiegroup.

the class InMessageRefHandler method end.

@SuppressWarnings("unchecked")
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    Element element = parser.endElementBuilder();
    String messageId = element.getTextContent();
    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(messageId);
    if (message == null) {
        throw new IllegalArgumentException("Could not find message " + messageId);
    }
    Operation operation = (Operation) parser.getParent();
    operation.setMessage(message);
    return parser.getCurrent();
}
Also used : Message(org.jbpm.bpmn2.core.Message) Element(org.w3c.dom.Element) Operation(org.jbpm.bpmn2.core.Interface.Operation) Map(java.util.Map)

Example 24 with Message

use of io.automatiko.engine.workflow.bpmn2.core.Message 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)) {
            ((BoundaryEventNode) parser.getCurrent()).addOutAssociation(DataAssociationFactory.readDataOutputAssociation(xmlNode, dataOutputs));
        } 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);
            }
            message.addIncomingNode(node);
            eventNode.setMetaData("MessageType", message.getType());
            List<EventFilter> eventFilters = new ArrayList<EventFilter>();
            EventTypeFilter eventFilter = new EventTypeFilter();
            eventFilter.setCorrelationManager(((RuleFlowProcess) parser.getMetaData().get("CurrentProcessDefinition")).getCorrelationManager());
            eventFilter.setType("Message-" + message.getName());
            eventFilter.setMessageRef(message.getId());
            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 25 with Message

use of io.automatiko.engine.workflow.bpmn2.core.Message in project jbpm by kiegroup.

the class ProcessAssetDescTest method testClone.

@Test
public void testClone() {
    ProcessAssetDesc processDefinition = new ProcessAssetDesc("pepe", "manolo", "1_0", "package", "one", "???", "namespace", "common_names");
    processDefinition.setSignalsDesc(Collections.singletonList(SignalDescImpl.from(new Signal("id", "id"))));
    processDefinition.setMessagesDesc(Collections.singletonList(MessageDescImpl.from(new Message("id"))));
    assertEquals(processDefinition.copy(), processDefinition);
}
Also used : Signal(org.jbpm.bpmn2.core.Signal) Message(org.jbpm.bpmn2.core.Message) Test(org.junit.Test)

Aggregations

Map (java.util.Map)28 Message (org.jbpm.bpmn2.core.Message)27 Element (org.w3c.dom.Element)16 ArrayList (java.util.ArrayList)14 Message (io.automatiko.engine.workflow.bpmn2.core.Message)9 Test (org.junit.Test)9 List (java.util.List)7 EventFilter (org.jbpm.process.core.event.EventFilter)7 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)7 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)6 Signal (org.jbpm.bpmn2.core.Signal)5 ProcessBuildData (org.jbpm.compiler.xml.ProcessBuildData)5 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)5 StartNode (org.jbpm.workflow.core.node.StartNode)5 HashMap (java.util.HashMap)4 Error (org.jbpm.bpmn2.core.Error)4 Escalation (org.jbpm.bpmn2.core.Escalation)4 ConstraintTrigger (org.jbpm.workflow.core.node.ConstraintTrigger)4 EventNode (org.jbpm.workflow.core.node.EventNode)4 Node (org.kie.api.definition.process.Node)4