Search in sources :

Example 1 with WorkItem

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

the class RequestUI method createKieSession.

private KieSession createKieSession() {
    try {
        final KieSession ksession = getKieSession();
        KieServices.Factory.get().getLoggers().newThreadedFileLogger(ksession, "test", 1000);
        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) {
            }
        });
        Person person = new Person("john", "John Doe");
        person.setAge(40);
        ksession.insert(person);
        person = new Person("krisv", "Kris Verlaenen");
        person.setAge(30);
        ksession.insert(person);
        person = new Person("baby", "Baby");
        person.setAge(1);
        ksession.insert(person);
        ksession.addEventListener(new DefaultProcessEventListener() {

            public void beforeProcessStarted(ProcessStartedEvent event) {
                ksession.insert(event);
            }
        });
        return ksession;
    } catch (Throwable t) {
        throw new RuntimeException("Could not initialize session!", t);
    }
}
Also used : WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) KieSession(org.kie.api.runtime.KieSession) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.kie.api.runtime.process.WorkItemManager)

Example 2 with WorkItem

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

the class UIWorkItemHandler method select.

private void select() {
    WorkItem workItem = getSelectedWorkItem();
    if (workItem != null) {
        UIWorkItemHandlerDialog dialog = new UIWorkItemHandlerDialog(UIWorkItemHandler.this, workItem);
        dialog.setVisible(true);
    }
}
Also used : WorkItem(org.kie.api.runtime.process.WorkItem)

Example 3 with WorkItem

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

the class UIWorkItemHandler method reloadWorkItemsList.

private void reloadWorkItemsList() {
    List<WorkItemWrapper> result = new ArrayList<WorkItemWrapper>();
    for (Iterator<WorkItem> iterator = workItems.keySet().iterator(); iterator.hasNext(); ) {
        WorkItem workItem = iterator.next();
        result.add(new WorkItemWrapper(workItem));
    }
    workItemsList.setListData(result.toArray());
}
Also used : ArrayList(java.util.ArrayList) WorkItem(org.kie.api.runtime.process.WorkItem)

Example 4 with WorkItem

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

the class ProcessServiceImpl method abortWorkItem.

@Override
public void abortWorkItem(String deploymentId, Long processInstanceId, Long id) {
    DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
    if (deployedUnit == null) {
        throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
    }
    RuntimeManager manager = deployedUnit.getRuntimeManager();
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
    try {
        KieSession ksession = engine.getKieSession();
        WorkItem workItem = ((WorkItemManager) ksession.getWorkItemManager()).getWorkItem(id);
        if (workItem == null) {
            throw new WorkItemNotFoundException("Work item with id " + id + " was not found");
        }
        ksession.getWorkItemManager().abortWorkItem(id);
    } catch (SessionNotFoundException e) {
        throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found", e);
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) WorkItemNotFoundException(org.jbpm.services.api.WorkItemNotFoundException) KieSession(org.kie.api.runtime.KieSession) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.drools.core.process.instance.WorkItemManager) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException)

Example 5 with WorkItem

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

the class ProcessServiceImpl method getWorkItem.

@Override
public WorkItem getWorkItem(String deploymentId, Long processInstanceId, Long id) {
    DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
    if (deployedUnit == null) {
        throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
    }
    RuntimeManager manager = deployedUnit.getRuntimeManager();
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
    try {
        KieSession ksession = engine.getKieSession();
        WorkItem workItem = ((WorkItemManager) ksession.getWorkItemManager()).getWorkItem(id);
        if (workItem == null) {
            throw new WorkItemNotFoundException("Work item with id " + id + " was not found");
        }
        return workItem;
    } catch (SessionNotFoundException e) {
        throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found", e);
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) WorkItemNotFoundException(org.jbpm.services.api.WorkItemNotFoundException) KieSession(org.kie.api.runtime.KieSession) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.drools.core.process.instance.WorkItemManager) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException)

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