Search in sources :

Example 1 with HandleMessageAction

use of org.jbpm.process.instance.impl.actions.HandleMessageAction in project kogito-runtimes by kiegroup.

the class EndEventHandler method handleMessageNode.

@SuppressWarnings("unchecked")
public void handleMessageNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    EndNode endNode = (EndNode) node;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        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 ProcessParsingValidationException("No messages found");
            }
            Message message = messages.get(messageRef);
            if (message == null) {
                throw new ProcessParsingValidationException("Could not find message " + messageRef);
            }
            String variable = (String) endNode.getMetaData(MAPPING_VARIABLE);
            endNode.setMetaData(Metadata.EVENT_TYPE, EVENT_TYPE_MESSAGE);
            endNode.setMetaData(Metadata.MESSAGE_TYPE, message.getType());
            endNode.setMetaData(Metadata.TRIGGER_TYPE, PRODUCE_MESSAGE);
            endNode.setMetaData(Metadata.TRIGGER_REF, message.getName());
            List<DroolsAction> actions = new ArrayList<>();
            DroolsConsequenceAction action = createJavaAction(new HandleMessageAction(message.getType(), variable));
            actions.add(action);
            endNode.setActions(EndNode.EVENT_NODE_ENTER, actions);
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) Message(org.jbpm.bpmn2.core.Message) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) HandleMessageAction(org.jbpm.process.instance.impl.actions.HandleMessageAction) EndNode(org.jbpm.workflow.core.node.EndNode) Map(java.util.Map)

Example 2 with HandleMessageAction

use of org.jbpm.process.instance.impl.actions.HandleMessageAction in project kogito-runtimes by kiegroup.

the class IntermediateThrowEventHandler method handleMessageNode.

@SuppressWarnings("unchecked")
public void handleMessageNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    ActionNode actionNode = (ActionNode) node;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        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 ProcessParsingValidationException("No messages found");
            }
            Message message = messages.get(messageRef);
            if (message == null) {
                throw new ProcessParsingValidationException("Could not find message " + messageRef);
            }
            String variable = (String) actionNode.getMetaData(MAPPING_VARIABLE);
            Variable v = (Variable) ((ProcessBuildData) parser.getData()).getMetaData("Variable");
            if (v != null) {
                variable = (String) v.getMetaData(variable);
            }
            actionNode.setMetaData(EVENT_TYPE, EVENT_TYPE_MESSAGE);
            actionNode.setMetaData(MESSAGE_TYPE, message.getType());
            actionNode.setMetaData(TRIGGER_TYPE, PRODUCE_MESSAGE);
            actionNode.setMetaData(TRIGGER_REF, message.getName());
            DroolsConsequenceAction action = createJavaAction(new HandleMessageAction(message.getType(), variable));
            actionNode.setAction(action);
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : Variable(org.jbpm.process.core.context.variable.Variable) Message(org.jbpm.bpmn2.core.Message) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) Element(org.w3c.dom.Element) ActionNode(org.jbpm.workflow.core.node.ActionNode) HandleMessageAction(org.jbpm.process.instance.impl.actions.HandleMessageAction) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Aggregations

Map (java.util.Map)2 Message (org.jbpm.bpmn2.core.Message)2 HandleMessageAction (org.jbpm.process.instance.impl.actions.HandleMessageAction)2 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)2 Element (org.w3c.dom.Element)2 ArrayList (java.util.ArrayList)1 Variable (org.jbpm.process.core.context.variable.Variable)1 DroolsAction (org.jbpm.workflow.core.DroolsAction)1 ActionNode (org.jbpm.workflow.core.node.ActionNode)1 EndNode (org.jbpm.workflow.core.node.EndNode)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1