Search in sources :

Example 16 with Message

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

the class SendTaskHandler 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("MessageType", message.getType());
}
Also used : Message(org.jbpm.bpmn2.core.Message) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) Map(java.util.Map)

Example 17 with Message

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

the class StandaloneBPMNProcessTest method runTestErrorSignallingExceptionServiceTask.

public static void runTestErrorSignallingExceptionServiceTask(KieSession ksession) throws Exception {
    // Setup
    String eventType = "Error-code";
    SignallingTaskHandlerDecorator signallingTaskWrapper = new SignallingTaskHandlerDecorator(ServiceTaskHandler.class, eventType);
    signallingTaskWrapper.setWorkItemExceptionParameterName(ExceptionService.exceptionParameterName);
    ksession.getWorkItemManager().registerWorkItemHandler("Service Task", signallingTaskWrapper);
    Object[] caughtEventObjectHolder = new Object[1];
    caughtEventObjectHolder[0] = null;
    ExceptionService.setCaughtEventObjectHolder(caughtEventObjectHolder);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    // Start process
    Map<String, Object> params = new HashMap<String, Object>();
    String input = "this is my service input";
    params.put("serviceInputItem", input);
    ProcessInstance processInstance = ksession.startProcess("ServiceProcess", params);
    assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    WorkItem workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNotNull();
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    // Check that event was passed to Event SubProcess (and grabbed by WorkItemHandler);
    assertThat(caughtEventObjectHolder[0] != null && caughtEventObjectHolder[0] instanceof WorkItem).isTrue().withFailMessage("Event was not passed to Event Subprocess.");
    workItem = (WorkItem) caughtEventObjectHolder[0];
    Object throwObj = workItem.getParameter(ExceptionService.exceptionParameterName);
    assertThat(throwObj instanceof Throwable).isTrue().withFailMessage("WorkItem doesn't contain Throwable.");
    assertThat(((Throwable) throwObj).getMessage().endsWith(input)).isTrue().withFailMessage("Exception message does not match service input.");
    // Complete process
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertThat(processInstance == null || processInstance.getState() == ProcessInstance.STATE_ABORTED).isTrue().withFailMessage("Process instance has not been aborted.");
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) SignallingTaskHandlerDecorator(org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem)

Example 18 with Message

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

the class StandaloneBPMNProcessTest method runTestSignallingExceptionServiceTask.

public static void runTestSignallingExceptionServiceTask(KieSession ksession) throws Exception {
    // Setup
    String eventType = "exception-signal";
    SignallingTaskHandlerDecorator signallingTaskWrapper = new SignallingTaskHandlerDecorator(ServiceTaskHandler.class, eventType);
    signallingTaskWrapper.setWorkItemExceptionParameterName(ExceptionService.exceptionParameterName);
    ksession.getWorkItemManager().registerWorkItemHandler("Service Task", signallingTaskWrapper);
    Object[] caughtEventObjectHolder = new Object[1];
    caughtEventObjectHolder[0] = null;
    ExceptionService.setCaughtEventObjectHolder(caughtEventObjectHolder);
    // Start process
    Map<String, Object> params = new HashMap<String, Object>();
    String input = "this is my service input";
    params.put("serviceInputItem", input);
    ProcessInstance processInstance = ksession.startProcess("ServiceProcess", params);
    // Check that event was passed to Event SubProcess (and grabbed by WorkItemHandler);
    assertThat(caughtEventObjectHolder[0] != null && caughtEventObjectHolder[0] instanceof WorkItem).isTrue().withFailMessage("Event was not passed to Event Subprocess.");
    WorkItem workItem = (WorkItem) caughtEventObjectHolder[0];
    Object throwObj = workItem.getParameter(ExceptionService.exceptionParameterName);
    assertThat(throwObj instanceof Throwable).isTrue().withFailMessage("WorkItem doesn't contain Throwable.");
    assertThat(((Throwable) throwObj).getMessage().endsWith(input)).isTrue().withFailMessage("Exception message does not match service input.");
    // Complete process
    assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE).withFailMessage("Process instance is not active.");
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    processInstance = ksession.getProcessInstance(processInstance.getId());
    if (processInstance != null) {
        assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_COMPLETED).withFailMessage("Process instance is not completed.");
    }
// otherwise, persistence use => processInstance == null => process is completed
}
Also used : HashMap(java.util.HashMap) SignallingTaskHandlerDecorator(org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem)

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