Search in sources :

Example 1 with Message

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

the class IntermediateEventTest method testMessageIntermediateThrowWithTransformation.

@Test
public void testMessageIntermediateThrowWithTransformation() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2");
    ksession = createKnowledgeSession(kbase);
    final StringBuffer messageContent = new StringBuffer();
    ksession.getWorkItemManager().registerWorkItemHandler("Send Task", new SendTaskHandler() {

        @Override
        public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
            // collect message content for verification
            messageContent.append(workItem.getParameter("Message"));
            super.executeWorkItem(workItem, manager);
        }
    });
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "MyValue");
    ProcessInstance processInstance = ksession.startProcess("MessageIntermediateEvent", params);
    assertProcessInstanceCompleted(processInstance);
    assertThat(messageContent.toString()).isEqualTo("MYVALUE");
}
Also used : HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) SendTaskHandler(org.jbpm.bpmn2.handler.SendTaskHandler) Test(org.junit.Test)

Example 2 with Message

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

the class BPMN2XMLTest method testInvalidXMLInCompositeNode.

public void testInvalidXMLInCompositeNode() 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-XMLProcessWithErrorInCompositeNode.bpmn2"));
    assertNotNull(getErrorMessage());
    assertThat(getErrorMessage()).contains("Process Info: id:abc.abc, pkg:org.drools.bpmn2, name:abc, version:1.0 \n" + "Node Info: id:_47489F3D-FEBD-4452-B62E-B04EF191C6C3 name: \n" + "Parser message: (null: 24, 185): 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 3 with Message

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

the class LoggingTaskHandlerWrapperTest method testFormatLoggingError.

@Test
public void testFormatLoggingError() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-ExceptionThrowingServiceProcess.bpmn2");
    ksession = createKnowledgeSession(kbase);
    LoggingTaskHandlerDecorator loggingTaskHandlerWrapper = new LoggingTaskHandlerDecorator(ServiceTaskHandler.class, 2);
    loggingTaskHandlerWrapper.setLoggedMessageFormat("{0} - {1} - {2} - {3}");
    List<InputParameter> inputParameters = new ArrayList<LoggingTaskHandlerDecorator.InputParameter>();
    inputParameters.add(InputParameter.EXCEPTION_CLASS);
    inputParameters.add(InputParameter.WORK_ITEM_ID);
    inputParameters.add(InputParameter.WORK_ITEM_NAME);
    inputParameters.add(InputParameter.PROCESS_INSTANCE_ID);
    loggingTaskHandlerWrapper.setLoggedMessageInput(inputParameters);
    loggingTaskHandlerWrapper.setPrintStackTrace(false);
    ksession.getWorkItemManager().registerWorkItemHandler("Service Task", loggingTaskHandlerWrapper);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("serviceInputItem", "exception message");
    ksession.startProcess("ServiceProcess", params);
    ksession.startProcess("ServiceProcess", params);
    ksession.startProcess("ServiceProcess", params);
}
Also used : HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) InputParameter(org.jbpm.bpmn2.handler.LoggingTaskHandlerDecorator.InputParameter) Test(org.junit.Test)

Example 4 with Message

use of org.jbpm.bpmn2.core.Message in project jbpm 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 ("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);
        } 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("MappingVariable");
            actionNode.setMetaData("MessageType", message.getType());
            actionNode.setAction(new DroolsConsequenceAction("java", " Object tVariable = " + (variable == null ? "null" : variable) + ";" + "org.jbpm.workflow.core.node.Transformation transformation = (org.jbpm.workflow.core.node.Transformation)kcontext.getNodeInstance().getNode().getMetaData().get(\"Transformation\");" + "if (transformation != null) {" + "  tVariable = new org.jbpm.process.core.event.EventTransformerImpl(transformation)" + "  .transformEvent(" + (variable == null ? "null" : variable) + ");" + "}" + "org.drools.core.process.instance.impl.WorkItemImpl workItem = new org.drools.core.process.instance.impl.WorkItemImpl();" + EOL + "workItem.setName(\"Send Task\");" + EOL + "workItem.setProcessInstanceId(kcontext.getProcessInstance().getId());" + EOL + "workItem.setParameter(\"MessageType\", \"" + message.getType() + "\");" + EOL + "workItem.setNodeInstanceId(kcontext.getNodeInstance().getId());" + EOL + "workItem.setNodeId(kcontext.getNodeInstance().getNodeId());" + EOL + "workItem.setDeploymentId((String) kcontext.getKnowledgeRuntime().getEnvironment().get(\"deploymentId\"));" + EOL + (variable == null ? "" : "workItem.setParameter(\"Message\", tVariable);" + EOL) + "((org.drools.core.process.instance.WorkItemManager) kcontext.getKnowledgeRuntime().getWorkItemManager()).internalExecuteWorkItem(workItem);"));
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : 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) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 5 with Message

use of org.jbpm.bpmn2.core.Message in project jbpm 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 ("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());
            List<DroolsAction> actions = new ArrayList<DroolsAction>();
            actions.add(new DroolsConsequenceAction("java", "org.drools.core.process.instance.impl.WorkItemImpl workItem = new org.drools.core.process.instance.impl.WorkItemImpl();" + EOL + "workItem.setName(\"Send Task\");" + EOL + "workItem.setNodeInstanceId(kcontext.getNodeInstance().getId());" + EOL + "workItem.setProcessInstanceId(kcontext.getProcessInstance().getId());" + EOL + "workItem.setNodeId(kcontext.getNodeInstance().getNodeId());" + EOL + "workItem.setParameter(\"MessageType\", \"" + message.getType() + "\");" + EOL + (variable == null ? "" : "workItem.setParameter(\"Message\", " + variable + ");" + EOL) + "workItem.setDeploymentId((String) kcontext.getKnowledgeRuntime().getEnvironment().get(\"deploymentId\"));" + EOL + "((org.drools.core.process.instance.WorkItemManager) kcontext.getKnowledgeRuntime().getWorkItemManager()).internalExecuteWorkItem(workItem);"));
            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) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) EndNode(org.jbpm.workflow.core.node.EndNode) ArrayList(java.util.ArrayList) List(java.util.List) 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