Search in sources :

Example 51 with WorkItemManager

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

the class UIWorkItemHandler method abort.

public void abort(WorkItem workItem) {
    WorkItemManager manager = workItems.get(workItem);
    if (manager != null) {
        manager.abortWorkItem(workItem.getId());
        workItems.remove(workItem);
        reloadWorkItemsList();
    }
    selectButton.setEnabled(getSelectedWorkItem() != null);
}
Also used : WorkItemManager(org.kie.api.runtime.process.WorkItemManager)

Example 52 with WorkItemManager

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

the class ProcessTest method main.

public static final void main(String[] args) {
    try {
        // load up the knowledge base
        final KieSession ksession = getKieSession();
        UIWorkItemHandler handler = new UIWorkItemHandler();
        ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
        handler.setVisible(true);
        ksession.getWorkItemManager().registerWorkItemHandler("Email", new WorkItemHandler() {

            public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
                System.out.println("Sending email ...");
                manager.completeWorkItem(workItem.getId(), null);
            }

            public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
            }
        });
        KieRuntimeLogger logger = KieServices.Factory.get().getLoggers().newFileLogger(ksession, "test");
        // start a new process instance
        Person person = new Person("john", "John Doe");
        person.setAge(20);
        Request request = new Request("12345");
        request.setPersonId("john");
        request.setAmount(1000L);
        ksession.insert(person);
        ksession.insert(request);
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("request", request);
        WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.startProcess("com.sample.requestHandling", params);
        ksession.insert(processInstance);
        ksession.fireAllRules();
        // signaling to select tasks in the ad-hoc sub-process
        ksession.signalEvent("Investigate", null, processInstance.getId());
        // dynamically adding a new sub-process
        DynamicNodeInstance dynamicNodeInstance = (DynamicNodeInstance) processInstance.getNodeInstances().iterator().next();
        DynamicUtils.addDynamicSubProcess(dynamicNodeInstance, ksession, "com.sample.contactCustomer", null);
        // event processing to detect too much processes being started
        ksession.addEventListener(new DefaultProcessEventListener() {

            public void beforeProcessStarted(ProcessStartedEvent event) {
                ksession.insert(event);
            }
        });
        Request request2 = new Request("12346");
        request2.setPersonId("john");
        request2.setAmount(1000L);
        params = new HashMap<String, Object>();
        params.put("request", request2);
        ksession.startProcess("com.sample.requestHandling", params);
        ksession.fireAllRules();
        Request request3 = new Request("12347");
        request3.setPersonId("john");
        request3.setAmount(1000L);
        params = new HashMap<String, Object>();
        params.put("request", request);
        ksession.startProcess("com.sample.requestHandling", params);
        ksession.fireAllRules();
        Request request4 = new Request("12348");
        request4.setPersonId("john");
        request4.setAmount(1000L);
        params = new HashMap<String, Object>();
        params.put("request", request4);
        ksession.startProcess("com.sample.requestHandling", params);
        ksession.fireAllRules();
        Request request5 = new Request("12349");
        request5.setPersonId("john");
        request5.setAmount(1000L);
        params = new HashMap<String, Object>();
        params.put("request", request5);
        ksession.startProcess("com.sample.requestHandling", params);
        ksession.fireAllRules();
        Request request6 = new Request("12350");
        request6.setPersonId("john");
        request6.setAmount(1000L);
        params = new HashMap<String, Object>();
        params.put("request", request6);
        processInstance = (WorkflowProcessInstance) ksession.startProcess("com.sample.requestHandling", params);
        FactHandle handle = ksession.insert(request6);
        ksession.insert(processInstance);
        ksession.fireAllRules();
        // exception handling when canceling request
        request6.setCanceled(true);
        ksession.update(handle, request6);
        ksession.fireAllRules();
        logger.close();
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : DynamicNodeInstance(org.jbpm.workflow.instance.node.DynamicNodeInstance) HashMap(java.util.HashMap) FactHandle(org.kie.api.runtime.rule.FactHandle) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) KieRuntimeLogger(org.kie.api.logger.KieRuntimeLogger) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) KieSession(org.kie.api.runtime.KieSession) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance)

Example 53 with WorkItemManager

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

the class UIWorkItemHandler method abort.

public void abort(WorkItem workItem) {
    WorkItemManager manager = workItems.get(workItem);
    if (manager != null) {
        manager.abortWorkItem(workItem.getId());
        workItems.remove(workItem);
        reloadWorkItemsList();
    }
    selectButton.setEnabled(getSelectedWorkItem() != null);
}
Also used : WorkItemManager(org.kie.api.runtime.process.WorkItemManager)

Example 54 with WorkItemManager

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

the class HumanTaskHandler method complete.

public void complete(WorkItem workItem, Map<String, Object> results) {
    WorkItemManager manager = workItems.get(workItem);
    if (manager != null) {
        manager.completeWorkItem(workItem.getId(), results);
    }
    workItems.remove(workItem);
    update();
    selectButton.setEnabled(getSelectedWorkItem() != null);
}
Also used : WorkItemManager(org.kie.api.runtime.process.WorkItemManager)

Example 55 with WorkItemManager

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

the class DataTest method testDataOutputAssociationsXmlNode.

@Test
public void testDataOutputAssociationsXmlNode() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-DataOutputAssociations-xml-node.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)

Aggregations

WorkItemManager (org.kie.api.runtime.process.WorkItemManager)100 Test (org.junit.Test)84 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)55 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)23 KieBase (org.kie.api.KieBase)21 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)20 KieSession (org.kie.api.runtime.KieSession)14 Map (java.util.Map)9 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)8 DefaultWorkItemManager (org.drools.core.process.instance.impl.DefaultWorkItemManager)7 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