Search in sources :

Example 31 with WorkItem

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

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

use of org.kie.api.runtime.process.WorkItem 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)

Example 34 with WorkItem

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

use of org.kie.api.runtime.process.WorkItem 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)

Aggregations

WorkItem (org.kie.api.runtime.process.WorkItem)174 Test (org.junit.Test)139 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)127 KieBase (org.kie.api.KieBase)110 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)91 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)87 HashMap (java.util.HashMap)72 KieSession (org.kie.api.runtime.KieSession)48 WorkItemManager (org.kie.api.runtime.process.WorkItemManager)33 ArrayList (java.util.ArrayList)29 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)27 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)26 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)22 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)20 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)14 TestWorkItemHandler (org.jbpm.persistence.session.objects.TestWorkItemHandler)13 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)13 Map (java.util.Map)11 StringReader (java.io.StringReader)10 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)10