Search in sources :

Example 11 with Message

use of org.jbpm.bpmn2.core.Message in project jbpm by kiegroup.

the class IntermediateEventTest method testMessageBoundaryEventOnTaskComplete.

@Test
public void testMessageBoundaryEventOnTaskComplete() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-BoundaryMessageEventOnTask.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    ProcessInstance processInstance = ksession.startProcess("BoundaryMessageOnTask");
    ksession.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);
    ksession.signalEvent("Message-HelloMessage", "message data");
    ksession.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
    assertNodeTriggered(processInstance.getId(), "StartProcess", "User Task", "User Task2", "End1");
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 12 with Message

use of org.jbpm.bpmn2.core.Message in project jbpm by kiegroup.

the class IntermediateEventTest method testMessageBoundaryEventOnTask.

@Test
public void testMessageBoundaryEventOnTask() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-BoundaryMessageEventOnTask.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new TestWorkItemHandler());
    ProcessInstance processInstance = ksession.startProcess("BoundaryMessageOnTask");
    ksession.signalEvent("Message-HelloMessage", "message data");
    assertProcessInstanceFinished(processInstance, ksession);
    assertNodeTriggered(processInstance.getId(), "StartProcess", "User Task", "Boundary event", "Condition met", "End2");
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 13 with Message

use of org.jbpm.bpmn2.core.Message in project jbpm by kiegroup.

the class StartEventHandler method handleNode.

@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, startNode);
        } 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);
            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);
            }
            startNode.setMetaData("MessageType", message.getType());
            addTriggerWithInMappings(startNode, "Message-" + messageRef);
        } 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, element, xmlNode, parser);
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : ConstraintTrigger(org.jbpm.workflow.core.node.ConstraintTrigger) StartNode(org.jbpm.workflow.core.node.StartNode) 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 14 with Message

use of org.jbpm.bpmn2.core.Message in project jbpm by kiegroup.

the class BPMN2XMLTest method testInvalidXML.

public void testInvalidXML() throws Exception, SAXException {
    SemanticModules modules = new SemanticModules();
    modules.addSemanticModule(new BPMNSemanticModule());
    modules.addSemanticModule(new BPMNDISemanticModule());
    XmlProcessReader processReader = new XmlProcessReader(modules, getClass().getClassLoader()) {

        @Override
        protected String processParserMessage(LinkedList<Object> parents, org.xml.sax.Attributes attr, String errorMessage) {
            setErrorMessage(super.processParserMessage(parents, attr, errorMessage));
            return errorMessage;
        }
    };
    processReader.read(BPMN2XMLTest.class.getResourceAsStream("/BPMN2-XMLProcessWithError.bpmn2"));
    assertNotNull(getErrorMessage());
    assertThat(getErrorMessage()).contains("Process Info: id:error.process, pkg:org.jbpm, name:errorprocess, version:1.0 \n" + "Node Info: id:_F8A89567-7416-4CCA-9CCD-BC1DDE870F1E name: \n" + "Parser message: (null: 45, 181): cvc-complex-type.2.4.a: Invalid content was found");
}
Also used : SemanticModules(org.drools.core.xml.SemanticModules) BPMNDISemanticModule(org.jbpm.bpmn2.xml.BPMNDISemanticModule) XmlProcessReader(org.jbpm.compiler.xml.XmlProcessReader) BPMNSemanticModule(org.jbpm.bpmn2.xml.BPMNSemanticModule) LinkedList(java.util.LinkedList)

Example 15 with Message

use of org.jbpm.bpmn2.core.Message in project jbpm by kiegroup.

the class ReceiveTaskHandler method handleNode.

@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);
    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 IllegalArgumentException("No messages found");
    }
    Message message = messages.get(messageRef);
    if (message == null) {
        throw new IllegalArgumentException("Could not find message " + messageRef);
    }
    workItemNode.getWork().setParameter("MessageId", message.getId());
    workItemNode.getWork().setParameter("MessageType", message.getType());
}
Also used : Message(org.jbpm.bpmn2.core.Message) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) Map(java.util.Map)

Aggregations

Map (java.util.Map)8 Message (org.jbpm.bpmn2.core.Message)8 ArrayList (java.util.ArrayList)6 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)6 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)6 Test (org.junit.Test)5 KieBase (org.kie.api.KieBase)5 Element (org.w3c.dom.Element)5 HashMap (java.util.HashMap)4 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)4 WorkItem (org.kie.api.runtime.process.WorkItem)4 LinkedList (java.util.LinkedList)2 List (java.util.List)2 SemanticModules (org.drools.core.xml.SemanticModules)2 SignallingTaskHandlerDecorator (org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator)2 BPMNDISemanticModule (org.jbpm.bpmn2.xml.BPMNDISemanticModule)2 BPMNSemanticModule (org.jbpm.bpmn2.xml.BPMNSemanticModule)2 ProcessBuildData (org.jbpm.compiler.xml.ProcessBuildData)2 XmlProcessReader (org.jbpm.compiler.xml.XmlProcessReader)2 EventFilter (org.jbpm.process.core.event.EventFilter)2