Search in sources :

Example 1 with RuntimeManager

use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.

the class EvaluationExample2 method main.

public static final void main(String[] args) {
    try {
        RuntimeManager manager = getRuntimeManager("evaluation/Evaluation2.bpmn");
        RuntimeEngine runtime = manager.getRuntimeEngine(null);
        KieSession ksession = runtime.getKieSession();
        // start a new process instance
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("employee", "krisv");
        params.put("reason", "Yearly performance evaluation");
        ksession.startProcess("com.sample.evaluation", params);
        // "krisv" executes his own performance evaluation
        TaskService taskService = runtime.getTaskService();
        TaskSummary task1 = taskService.getTasksAssignedAsPotentialOwner("krisv", "en-UK").get(0);
        System.out.println("Krisv executing task " + task1.getName() + "(" + task1.getId() + ": " + task1.getDescription() + ")");
        taskService.start(task1.getId(), "krisv");
        taskService.complete(task1.getId(), "krisv", null);
        // "john", part of the "PM" group, executes a performance evaluation
        TaskSummary task2 = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK").get(0);
        System.out.println("John executing task " + task2.getName() + "(" + task2.getId() + ": " + task2.getDescription() + ")");
        System.out.println(taskService.getTasksAssignedAsPotentialOwner("john", "en-UK").size());
        taskService.claim(task2.getId(), "john");
        taskService.start(task2.getId(), "john");
        taskService.complete(task2.getId(), "john", null);
        // "mary", part of the "HR" group, delegates a performance evaluation
        TaskSummary task3 = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK").get(0);
        System.out.println("Mary delegating task " + task3.getName() + "(" + task3.getId() + ": " + task3.getDescription() + ") to krisv");
        taskService.claim(task3.getId(), "mary");
        taskService.delegate(task3.getId(), "mary", "krisv");
        // "administrator" delegates the task back to mary
        System.out.println("Administrator delegating task back to mary");
        taskService.delegate(task3.getId(), "Administrator", "mary");
        // mary executing the task
        TaskSummary task3b = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK").get(0);
        System.out.println("Mary executing task " + task3b.getName() + "(" + task3b.getId() + ": " + task3b.getDescription() + ")");
        taskService.start(task3b.getId(), "mary");
        taskService.complete(task3b.getId(), "mary", null);
        System.out.println("Process instance completed");
        manager.disposeRuntimeEngine(runtime);
    } catch (Throwable t) {
        t.printStackTrace();
    }
    System.exit(0);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) HashMap(java.util.HashMap) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession)

Example 2 with RuntimeManager

use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.

the class ExceptionHandlingErrorExample method runExample.

public static ProcessInstance runExample() {
    // load up the knowledge base
    RuntimeManager manager = createManager();
    KieSession ksession = manager.getRuntimeEngine(null).getKieSession();
    String eventType = "Error-code";
    SignallingTaskHandlerDecorator signallingTaskWrapper = new SignallingTaskHandlerDecorator(ServiceTaskHandler.class, eventType);
    signallingTaskWrapper.setWorkItemExceptionParameterName(ExceptionService.exceptionParameterName);
    ksession.getWorkItemManager().registerWorkItemHandler("Service Task", signallingTaskWrapper);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("serviceInputItem", "Input to Original Service");
    ProcessInstance processInstance = ksession.startProcess("ProcessWithExceptionHandlingError", params);
    manager.close();
    return processInstance;
}
Also used : HashMap(java.util.HashMap) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) SignallingTaskHandlerDecorator(org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance)

Example 3 with RuntimeManager

use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.

the class ExceptionHandlingSignalExample method runExample.

public static void runExample() {
    // load up the knowledge base
    RuntimeManager manager = createManager();
    KieSession ksession = manager.getRuntimeEngine(null).getKieSession();
    String eventType = "exception-signal";
    SignallingTaskHandlerDecorator signallingTaskWrapper = new SignallingTaskHandlerDecorator(ServiceTaskHandler.class, eventType);
    signallingTaskWrapper.setWorkItemExceptionParameterName(ExceptionService.exceptionParameterName);
    ksession.getWorkItemManager().registerWorkItemHandler("Service Task", signallingTaskWrapper);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("serviceInputItem", "Input to Original Service");
    ksession.startProcess("ProcessWithExceptionHandlingSignal", params);
    manager.close();
}
Also used : HashMap(java.util.HashMap) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) SignallingTaskHandlerDecorator(org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator) KieSession(org.kie.api.runtime.KieSession)

Example 4 with RuntimeManager

use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.

the class ScriptTaskExceptionExample method runExample.

public static void runExample() {
    RuntimeManager manager = createManager();
    KieSession ksession = manager.getRuntimeEngine(null).getKieSession();
    Map<String, Object> params = new HashMap<String, Object>();
    String varName = "var1";
    params.put(varName, "valueOne");
    try {
        ksession.startProcess("ExceptionScriptTask", params);
    } catch (WorkflowRuntimeException wfre) {
        String msg = "An exception happened in " + "process instance [" + wfre.getProcessInstanceId() + "] of process [" + wfre.getProcessId() + "] in node [id: " + wfre.getNodeId() + ", name: " + wfre.getNodeName() + "] and variable " + varName + " had the value [" + wfre.getVariables().get(varName) + "]";
        System.out.println(msg);
    }
    manager.close();
}
Also used : HashMap(java.util.HashMap) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) KieSession(org.kie.api.runtime.KieSession) WorkflowRuntimeException(org.jbpm.workflow.instance.WorkflowRuntimeException)

Example 5 with RuntimeManager

use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.

the class HumanTaskExample method main.

public static final void main(String[] args) {
    try {
        RuntimeManager manager = getRuntimeManager("humantask/HumanTask.bpmn");
        RuntimeEngine runtime = manager.getRuntimeEngine(null);
        KieSession ksession = runtime.getKieSession();
        // start a new process instance
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userId", "krisv");
        params.put("description", "Need a new laptop computer");
        ksession.startProcess("com.sample.humantask", params);
        // "sales-rep" reviews request
        TaskService taskService = runtime.getTaskService();
        TaskSummary task1 = taskService.getTasksAssignedAsPotentialOwner("sales-rep", "en-UK").get(0);
        System.out.println("Sales-rep executing task " + task1.getName() + "(" + task1.getId() + ": " + task1.getDescription() + ")");
        taskService.claim(task1.getId(), "sales-rep");
        taskService.start(task1.getId(), "sales-rep");
        Map<String, Object> results = new HashMap<String, Object>();
        results.put("comment", "Agreed, existing laptop needs replacing");
        results.put("outcome", "Accept");
        taskService.complete(task1.getId(), "sales-rep", results);
        // "krisv" approves result
        TaskSummary task2 = taskService.getTasksAssignedAsPotentialOwner("krisv", "en-UK").get(0);
        System.out.println("krisv executing task " + task2.getName() + "(" + task2.getId() + ": " + task2.getDescription() + ")");
        taskService.start(task2.getId(), "krisv");
        results = new HashMap<String, Object>();
        results.put("outcome", "Agree");
        taskService.complete(task2.getId(), "krisv", results);
        // "john" as manager reviews request
        TaskSummary task3 = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK").get(0);
        System.out.println("john executing task " + task3.getName() + "(" + task3.getId() + ": " + task3.getDescription() + ")");
        taskService.claim(task3.getId(), "john");
        taskService.start(task3.getId(), "john");
        results = new HashMap<String, Object>();
        results.put("outcome", "Agree");
        taskService.complete(task3.getId(), "john", results);
        // "sales-rep" gets notification
        TaskSummary task4 = taskService.getTasksAssignedAsPotentialOwner("sales-rep", "en-UK").get(0);
        System.out.println("sales-rep executing task " + task4.getName() + "(" + task4.getId() + ": " + task4.getDescription() + ")");
        taskService.start(task4.getId(), "sales-rep");
        Map<String, Object> content = taskService.getTaskContent(task4.getId());
        for (Map.Entry<?, ?> entry : content.entrySet()) {
            System.out.println(entry.getKey() + " = " + entry.getValue());
        }
        taskService.complete(task4.getId(), "sales-rep", null);
        System.out.println("Process instance completed");
        manager.disposeRuntimeEngine(runtime);
    } catch (Throwable t) {
        t.printStackTrace();
    }
    System.exit(0);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) HashMap(java.util.HashMap) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)150 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)116 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)79 KieSession (org.kie.api.runtime.KieSession)55 TaskService (org.kie.api.task.TaskService)53 Test (org.junit.Test)51 HashMap (java.util.HashMap)49 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)46 InternalTaskService (org.kie.internal.task.api.InternalTaskService)44 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)38 UserTaskService (org.jbpm.services.api.UserTaskService)36 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)35 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)23 TaskSummary (org.kie.api.task.model.TaskSummary)21 ArrayList (java.util.ArrayList)19 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)19 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)18 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)15 DeploymentUnit (org.jbpm.services.api.model.DeploymentUnit)15 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)15