Search in sources :

Example 1 with HandleMessageAction

use of io.automatiko.engine.workflow.base.instance.impl.actions.HandleMessageAction in project automatiko-engine by automatiko-io.

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 ("dataInput".equals(nodeName)) {
            String id = ((Element) xmlNode).getAttribute("id");
            String inputName = ((Element) xmlNode).getAttribute("name");
            dataInputs.put(id, inputName);
        } else if ("dataInputAssociation".equals(nodeName)) {
            readDataInputAssociation(xmlNode, actionNode, parser);
        } 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);
            }
            String variable = (String) actionNode.getMetaData(MAPPING_VARIABLE_KEY);
            Variable v = (Variable) ((ProcessBuildData) parser.getData()).getMetaData("Variable");
            if (v != null) {
                variable = (String) v.getMetaData(variable);
            }
            actionNode.setMetaData("MessageType", message.getType());
            actionNode.setMetaData("TriggerType", "ProduceMessage");
            actionNode.setMetaData("TriggerRef", message.getName());
            for (Entry<String, Object> entry : message.getMetaData().entrySet()) {
                actionNode.setMetaData(entry.getKey(), entry.getValue());
            }
            ConsequenceAction action = createJavaAction(new HandleMessageAction(message.getType(), variable, (Transformation) actionNode.getMetaData().get(TRANSFORMATION_KEY)));
            actionNode.setAction(action);
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) Message(io.automatiko.engine.workflow.bpmn2.core.Message) Element(org.w3c.dom.Element) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) HandleMessageAction(io.automatiko.engine.workflow.base.instance.impl.actions.HandleMessageAction) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 2 with HandleMessageAction

use of io.automatiko.engine.workflow.base.instance.impl.actions.HandleMessageAction in project automatiko-engine by automatiko-io.

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 ("dataInputAssociation".equals(nodeName)) {
            readEndDataInputAssociation(xmlNode, endNode);
        } 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);
            }
            String variable = (String) endNode.getMetaData("MappingVariable");
            endNode.setMetaData("MessageType", message.getType());
            endNode.setMetaData("TriggerType", "ProduceMessage");
            endNode.setMetaData("TriggerRef", message.getName());
            for (Entry<String, Object> entry : message.getMetaData().entrySet()) {
                endNode.setMetaData(entry.getKey(), entry.getValue());
            }
            List<ProcessAction> actions = new ArrayList<ProcessAction>();
            ConsequenceAction action = createJavaAction(new HandleMessageAction(message.getType(), variable));
            actions.add(action);
            endNode.setActions(EndNode.EVENT_NODE_ENTER, actions);
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) Message(io.automatiko.engine.workflow.bpmn2.core.Message) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) HandleMessageAction(io.automatiko.engine.workflow.base.instance.impl.actions.HandleMessageAction) Entry(java.util.Map.Entry) ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Aggregations

HandleMessageAction (io.automatiko.engine.workflow.base.instance.impl.actions.HandleMessageAction)2 Message (io.automatiko.engine.workflow.bpmn2.core.Message)2 ConsequenceAction (io.automatiko.engine.workflow.process.core.impl.ConsequenceAction)2 Map (java.util.Map)2 Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)1 ProcessBuildData (io.automatiko.engine.workflow.compiler.xml.ProcessBuildData)1 ProcessAction (io.automatiko.engine.workflow.process.core.ProcessAction)1 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)1 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)1 Transformation (io.automatiko.engine.workflow.process.core.node.Transformation)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 Element (org.w3c.dom.Element)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1 NodeList (org.w3c.dom.NodeList)1