Search in sources :

Example 6 with Message

use of io.automatiko.engine.workflow.bpmn2.core.Message in project kogito-runtimes by kiegroup.

the class SendTaskHandler method handleNode.

@SuppressWarnings("unchecked")
protected Node 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);
    WorkItemNode workItemNode = (WorkItemNode) node;
    String messageRef = element.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);
    }
    workItemNode.getWork().setParameter("MessageType", message.getType());
    return node;
}
Also used : Message(org.jbpm.bpmn2.core.Message) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) Map(java.util.Map)

Example 7 with Message

use of io.automatiko.engine.workflow.bpmn2.core.Message in project kogito-runtimes 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();
        String id = ((Element) xmlNode).getAttribute("id");
        String name = ((Element) xmlNode).getAttribute("name");
        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 MalformedNodeException(id, name, MessageFormat.format("Could not find message \"{0}\"", messageRef));
            }
            eventNode.setMetaData(MESSAGE_TYPE, message.getType());
            eventNode.setMetaData(TRIGGER_TYPE, CONSUME_MESSAGE);
            eventNode.setMetaData(TRIGGER_REF, message.getName());
            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 8 with Message

use of io.automatiko.engine.workflow.bpmn2.core.Message 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)

Example 9 with Message

use of io.automatiko.engine.workflow.bpmn2.core.Message in project kogito-runtimes by kiegroup.

the class StartEventHandler method handleNode.

@Override
@SuppressWarnings("unchecked")
protected Node 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")));
    startNode.setIoSpecification(readCatchSpecification(parser, element));
    findTargetMappingVar(startNode.getIoSpecification().getDataOutputAssociation()).ifPresent(data -> {
        startNode.getMetaData().put(TRIGGER_MAPPING, data.getLabel());
        startNode.getMetaData().put(MAPPING_VARIABLE, data.getLabel());
    });
    findSourceMappingVar(startNode.getIoSpecification().getDataOutputAssociation()).ifPresent(data -> {
        startNode.getMetaData().put(TRIGGER_MAPPING_INPUT, data.getLabel());
    });
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        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);
            if (type != null && type.trim().length() > 0) {
                addTriggerWithInMappings(startNode, type);
            }
            startNode.setMetaData(MESSAGE_TYPE, type);
            startNode.setMetaData(TRIGGER_TYPE, TriggerMetaData.TriggerType.Signal.name());
            Signal signal = findSignalByName(parser, type);
            if (signal != null) {
                String eventType = signal.getStructureRef();
                startNode.setMetaData(TRIGGER_REF, eventType);
            } else {
                startNode.setMetaData(TRIGGER_REF, 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 ProcessParsingValidationException("No messages found");
            }
            Message message = messages.get(messageRef);
            if (message == null) {
                throw new ProcessParsingValidationException("Could not find message " + messageRef);
            }
            startNode.setMetaData(EVENT_TYPE, EVENT_TYPE_MESSAGE);
            startNode.setMetaData(MESSAGE_TYPE, message.getType());
            startNode.setMetaData(TRIGGER_TYPE, TriggerMetaData.TriggerType.ConsumeMessage.name());
            startNode.setMetaData(TRIGGER_REF, message.getName());
            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)) {
            // 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)
            startNode.setInterrupting(true);
            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 ProcessParsingValidationException("No errors found");
                }
                Error error = null;
                for (Error listError : errors) {
                    if (errorRef.equals(listError.getId())) {
                        error = listError;
                    }
                }
                if (error == null) {
                    throw new ProcessParsingValidationException("Could not find error " + errorRef);
                }
                startNode.setMetaData("FaultCode", error.getErrorCode());
                startNode.setMetaData(MESSAGE_TYPE, error.getErrorCode());
                startNode.setMetaData(TRIGGER_REF, error.getErrorCode());
                startNode.setMetaData(TRIGGER_TYPE, TriggerMetaData.TriggerType.Signal.name());
                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 ProcessParsingValidationException("No escalations found");
                }
                Escalation escalation = escalations.get(escalationRef);
                if (escalation == null) {
                    throw new ProcessParsingValidationException("Could not find escalation " + escalationRef);
                }
                addTriggerWithInMappings(startNode, "Escalation-" + escalation.getEscalationCode());
            }
        } else if ("compensateEventDefinition".equals(nodeName)) {
            handleCompensationNode(startNode, xmlNode);
        }
        xmlNode = xmlNode.getNextSibling();
    }
    if (startNode.getName() == null) {
        startNode.setName("Start");
    }
    return startNode;
}
Also used : ConstraintTrigger(org.jbpm.workflow.core.node.ConstraintTrigger) StartNode(org.jbpm.workflow.core.node.StartNode) Message(org.jbpm.bpmn2.core.Message) Element(org.w3c.dom.Element) Escalation(org.jbpm.bpmn2.core.Escalation) Error(org.jbpm.bpmn2.core.Error) Signal(org.jbpm.bpmn2.core.Signal) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 10 with Message

use of io.automatiko.engine.workflow.bpmn2.core.Message in project droolsjbpm-integration by kiegroup.

the class KafkaServerExtensionConsumerTest method testKafkaServerExecutorMessageTopic.

@Test
public void testKafkaServerExecutorMessageTopic() {
    final String topicProperty = TOPIC_PREFIX + "Hello";
    System.setProperty(topicProperty, "MyTopic");
    try {
        Message msg = new Message("MyMessage");
        msg.setName("Hello");
        msg.setType("String");
        msg.addIncomingNode(mock(Node.class));
        when(processDefinition.getMessagesDesc()).thenReturn(Collections.singletonList(MessageDescImpl.from(msg)));
        extension.onDeploy(getDeploymentEvent("MyDeploy3"));
        publishEvent("MyTopic", "{\"id\":\"javi\",\"type\":\"one\",\"source\":\"pepe\",\"data\":\"pepe\"}");
        verify(processService, getTimeout()).signalEvent("MyDeploy3", "Message-Hello", "pepe");
    } finally {
        System.clearProperty(topicProperty);
    }
}
Also used : Message(org.jbpm.bpmn2.core.Message) Node(org.kie.api.definition.process.Node) 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