Search in sources :

Example 26 with WorkItemManager

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

the class DataTest method testDataOutputAssociations.

@Test
public void testDataOutputAssociations() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-DataOutputAssociations.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) {
            try {
                Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream("<user hello='hello world' />".getBytes()));
                Map<String, Object> params = new HashMap<String, Object>();
                params.put("output", document.getFirstChild());
                mgr.completeWorkItem(workItem.getId(), params);
            } catch (Throwable e) {
                throw new RuntimeException(e);
            }
        }
    });
    ProcessInstance processInstance = ksession.startProcess("process", null);
}
Also used : 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) ByteArrayInputStream(java.io.ByteArrayInputStream) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 27 with WorkItemManager

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

the class DataTest method testDataInputAssociationsWithTwoAssigns.

/**
 * TODO testDataInputAssociationsWithTwoAssigns
 */
@Test
@Ignore
public void testDataInputAssociationsWithTwoAssigns() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-DataInputAssociations-two-assigns.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("foo", ((Element) workItem.getParameter("Comment")).getNodeName());
        // assertEquals("mynode", ((Element)
        // workItem.getParameter("Comment")).getFirstChild().getNodeName());
        // assertEquals("user", ((Element)
        // workItem.getParameter("Comment")).getFirstChild().getFirstChild().getNodeName());
        // assertEquals("hello world", ((Element)
        // workItem.getParameter("coId")).getFirstChild().getFirstChild().getAttributes().getNamedItem("hello").getNodeValue());
        }
    });
    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream("<user hello='hello world' />".getBytes()));
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("instanceMetadata", document.getFirstChild());
    ProcessInstance processInstance = ksession.startProcess("process", params);
}
Also used : WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) Element(org.w3c.dom.Element) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Document(org.w3c.dom.Document) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 28 with WorkItemManager

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

the class DataTest method testDataInputAssociationsWithStringWithoutQuotes.

@Test
public void testDataInputAssociationsWithStringWithoutQuotes() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-DataInputAssociations-string-no-quotes.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 29 with WorkItemManager

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

the class DataTest method testDataInputAssociationsWithLazyLoading.

/**
 * TODO testDataInputAssociationsWithLazyLoading
 */
@Test
@Ignore
public void testDataInputAssociationsWithLazyLoading() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-DataInputAssociations-lazy-creating.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) {
            Object coIdParamObj = workItem.getParameter("coId");
            assertEquals("mydoc", ((Element) coIdParamObj).getNodeName());
            assertEquals("mynode", ((Element) workItem.getParameter("coId")).getFirstChild().getNodeName());
            assertEquals("user", ((Element) workItem.getParameter("coId")).getFirstChild().getFirstChild().getNodeName());
            assertEquals("hello world", ((Element) workItem.getParameter("coId")).getFirstChild().getFirstChild().getAttributes().getNamedItem("hello").getNodeValue());
        }
    });
    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream("<user hello='hello world' />".getBytes()));
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("instanceMetadata", document.getFirstChild());
    ProcessInstance processInstance = ksession.startProcess("process", params);
}
Also used : WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) Element(org.w3c.dom.Element) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Document(org.w3c.dom.Document) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 30 with WorkItemManager

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

the class ErrorEventTest method testCatchErrorBoundaryEventOnTask.

@Test
public void testCatchErrorBoundaryEventOnTask() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-ErrorBoundaryEventOnTask.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new TestWorkItemHandler() {

        @Override
        public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
            if (workItem.getParameter("ActorId").equals("mary")) {
                throw new MyError();
            }
        }

        @Override
        public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
            manager.abortWorkItem(workItem.getId());
        }
    });
    ProcessInstance processInstance = ksession.startProcess("BPMN2-ErrorBoundaryEventOnTask");
    assertProcessInstanceActive(processInstance);
    assertNodeTriggered(processInstance.getId(), "start", "split", "User Task", "User task error attached", "Script Task", "error1", "error2");
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) MyError(org.jbpm.bpmn2.objects.MyError) KieBase(org.kie.api.KieBase) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) 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)

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