Search in sources :

Example 21 with WorkItemManager

use of org.kie.api.runtime.process.WorkItemManager 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 22 with WorkItemManager

use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.

the class IntermediateEventTest method testThrowIntermediateSignalWithExternalScope.

@Test
public void testThrowIntermediateSignalWithExternalScope() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-IntermediateThrowEventExternalScope.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    WorkItemHandler externalHandler = new WorkItemHandler() {

        @Override
        public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
            String signal = (String) workItem.getParameter("Signal");
            ksession.signalEvent(signal, null);
            manager.completeWorkItem(workItem.getId(), null);
        }

        @Override
        public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
        }
    };
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    ksession.getWorkItemManager().registerWorkItemHandler("External Send Task", externalHandler);
    Map<String, Object> params = new HashMap<String, Object>();
    ProcessInstance processInstance = ksession.startProcess("intermediate-event-scope", params);
    assertProcessInstanceActive(processInstance);
    assertNodeActive(processInstance.getId(), ksession, "Complete work", "Wait");
    List<WorkItem> items = handler.getWorkItems();
    assertThat(items.size()).isEqualTo(1);
    WorkItem wi = items.get(0);
    Map<String, Object> result = new HashMap<String, Object>();
    result.put("_output", "sending event");
    ksession.getWorkItemManager().completeWorkItem(wi.getId(), result);
    assertProcessInstanceCompleted(processInstance);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) WorkItemHandler(org.drools.core.process.instance.WorkItemHandler) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler) TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) 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) Test(org.junit.Test)

Example 23 with WorkItemManager

use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.

the class DataTest method testDataInputAssociationsWithStringObject.

@Test
public void testDataInputAssociationsWithStringObject() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-DataInputAssociations-string-object.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new WorkItemHandler() {

        public void abortWorkItem(WorkItem manager, WorkItemManager mgr) {
        }

        public void executeWorkItem(WorkItem workItem, WorkItemManager mgr) {
            assertEquals("hello", workItem.getParameter("coId"));
        }
    });
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("instanceMetadata", "hello");
    ProcessInstance processInstance = ksession.startProcess("process", params);
}
Also used : WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Test(org.junit.Test)

Example 24 with WorkItemManager

use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.

the class DataTest method testDataInputAssociationsWithString.

@Test
public void testDataInputAssociationsWithString() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-DataInputAssociations-string.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new WorkItemHandler() {

        public void abortWorkItem(WorkItem manager, WorkItemManager mgr) {
        }

        public void executeWorkItem(WorkItem workItem, WorkItemManager mgr) {
            assertEquals("hello", workItem.getParameter("coId"));
        }
    });
    ProcessInstance processInstance = ksession.startProcess("process", null);
}
Also used : WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Test(org.junit.Test)

Example 25 with WorkItemManager

use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.

the class DataTest method testDataOutputAssociationsforHumanTask.

@Test
public void testDataOutputAssociationsforHumanTask() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-DataOutputAssociations-HumanTask.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new WorkItemHandler() {

        public void abortWorkItem(WorkItem manager, WorkItemManager mgr) {
        }

        public void executeWorkItem(WorkItem workItem, WorkItemManager mgr) {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder;
            try {
                builder = factory.newDocumentBuilder();
            } catch (ParserConfigurationException e) {
                throw new RuntimeException(e);
            }
            final Map<String, Object> results = new HashMap<String, Object>();
            // process metadata
            org.w3c.dom.Document processMetadaDoc = builder.newDocument();
            org.w3c.dom.Element processMetadata = processMetadaDoc.createElement("previoustasksowner");
            processMetadaDoc.appendChild(processMetadata);
            // org.w3c.dom.Element procElement =
            // processMetadaDoc.createElement("previoustasksowner");
            processMetadata.setAttribute("primaryname", "my_result");
            // processMetadata.appendChild(procElement);
            results.put("output", processMetadata);
            mgr.completeWorkItem(workItem.getId(), results);
        }
    });
    Map<String, Object> params = new HashMap<String, Object>();
    ProcessInstance processInstance = ksession.startProcess("process", params);
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) DocumentBuilder(javax.xml.parsers.DocumentBuilder) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

WorkItemManager (org.kie.api.runtime.process.WorkItemManager)102 Test (org.junit.Test)86 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)56 TestWorkItemManager (org.jbpm.process.workitem.core.TestWorkItemManager)36 WorkItem (org.kie.api.runtime.process.WorkItem)31 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)27 HashMap (java.util.HashMap)25 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)25 KieBase (org.kie.api.KieBase)23 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)20 KieSession (org.kie.api.runtime.KieSession)15 Map (java.util.Map)9 DefaultWorkItemManager (org.drools.core.process.instance.impl.DefaultWorkItemManager)8 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)8 AsyncWorkItemHandler (org.jbpm.executor.impl.wih.AsyncWorkItemHandler)7 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)7 QueryContext (org.kie.api.runtime.query.QueryContext)6 Document (org.w3c.dom.Document)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ArrayList (java.util.ArrayList)5