Search in sources :

Example 81 with TaskService

use of org.kie.api.task.TaskService in project jbpm by kiegroup.

the class ProcessHumanTaskTest method testProcessProcessInstanceStrategy.

@Test
public void testProcessProcessInstanceStrategy() {
    RuntimeManager manager = createRuntimeManager(Strategy.PROCESS_INSTANCE, "manager", "org/jbpm/test/functional/task/humantask.bpmn");
    RuntimeEngine runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession = runtimeEngine.getKieSession();
    TaskService taskService = runtimeEngine.getTaskService();
    long ksessionID = ksession.getIdentifier();
    ProcessInstance processInstance = ksession.startProcess("com.sample.bpmn.hello");
    assertProcessInstanceActive(processInstance.getId(), ksession);
    assertNodeTriggered(processInstance.getId(), "Start", "Task 1");
    manager.disposeRuntimeEngine(runtimeEngine);
    runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
    ksession = runtimeEngine.getKieSession();
    taskService = runtimeEngine.getTaskService();
    assertEquals(ksessionID, ksession.getIdentifier());
    // let john execute Task 1
    List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    TaskSummary task = list.get(0);
    logger.info("John is executing task {}", task.getName());
    taskService.start(task.getId(), "john");
    taskService.complete(task.getId(), "john", null);
    assertNodeTriggered(processInstance.getId(), "Task 2");
    // let mary execute Task 2
    list = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
    task = list.get(0);
    logger.info("Mary is executing task {}", task.getName());
    taskService.start(task.getId(), "mary");
    taskService.complete(task.getId(), "mary", null);
    assertNodeTriggered(processInstance.getId(), "End");
    assertProcessInstanceNotActive(processInstance.getId(), ksession);
    manager.disposeRuntimeEngine(runtimeEngine);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) 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) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 82 with TaskService

use of org.kie.api.task.TaskService in project jbpm by kiegroup.

the class ProcessHumanTaskTest method testProcess.

@Test
public void testProcess() {
    createRuntimeManager("org/jbpm/test/functional/task/humantask.bpmn");
    RuntimeEngine runtimeEngine = getRuntimeEngine();
    KieSession ksession = runtimeEngine.getKieSession();
    TaskService taskService = runtimeEngine.getTaskService();
    ProcessInstance processInstance = ksession.startProcess("com.sample.bpmn.hello");
    assertProcessInstanceActive(processInstance.getId(), ksession);
    assertNodeTriggered(processInstance.getId(), "Start", "Task 1");
    // let john execute Task 1
    List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    TaskSummary task = list.get(0);
    logger.info("John is executing task {}", task.getName());
    taskService.start(task.getId(), "john");
    taskService.complete(task.getId(), "john", null);
    assertNodeTriggered(processInstance.getId(), "Task 2");
    // let mary execute Task 2
    list = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
    task = list.get(0);
    logger.info("Mary is executing task {}", task.getName());
    taskService.start(task.getId(), "mary");
    taskService.complete(task.getId(), "mary", null);
    assertNodeTriggered(processInstance.getId(), "End");
    assertProcessInstanceNotActive(processInstance.getId(), ksession);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) TaskService(org.kie.api.task.TaskService) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 83 with TaskService

use of org.kie.api.task.TaskService in project jbpm by kiegroup.

the class ProcessPersistenceHumanTaskOnLaneTest method testProcess.

@Test
public void testProcess() throws Exception {
    createRuntimeManager("org/jbpm/test/functional/task/HumanTaskOnLane.bpmn2");
    RuntimeEngine runtimeEngine = getRuntimeEngine();
    KieSession ksession = runtimeEngine.getKieSession();
    TaskService taskService = runtimeEngine.getTaskService();
    ProcessInstance processInstance = ksession.startProcess("UserTask");
    assertProcessInstanceActive(processInstance.getId());
    // simulating a system restart
    logger.debug("Reloading the environemnt to simulate system restart");
    disposeRuntimeManager();
    createRuntimeManager("org/jbpm/test/functional/task/HumanTaskOnLane.bpmn2");
    runtimeEngine = getRuntimeEngine();
    ksession = runtimeEngine.getKieSession();
    taskService = runtimeEngine.getTaskService();
    // let john execute Task 1
    String taskUser = "john";
    String locale = "en-UK";
    List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner(taskUser, locale);
    assertEquals(1, list.size());
    TaskSummary task = list.get(0);
    taskService.claim(task.getId(), taskUser);
    taskService.start(task.getId(), taskUser);
    taskService.complete(task.getId(), taskUser, null);
    // simulating a system restart
    logger.debug("Reloading the environemnt to simulate system restart once again");
    List<Status> reservedOnly = new ArrayList<Status>();
    reservedOnly.add(Status.Reserved);
    list = taskService.getTasksAssignedAsPotentialOwnerByStatus(taskUser, reservedOnly, locale);
    assertEquals(1, list.size());
    task = list.get(0);
    taskService.start(task.getId(), taskUser);
    taskService.complete(task.getId(), taskUser, null);
    assertProcessInstanceCompleted(processInstance.getId());
}
Also used : Status(org.kie.api.task.model.Status) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) TaskService(org.kie.api.task.TaskService) TaskSummary(org.kie.api.task.model.TaskSummary) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 84 with TaskService

use of org.kie.api.task.TaskService in project jbpm by kiegroup.

the class ProcessPersistenceHumanTaskOnLaneTest method testProcessWIthDifferentGroups.

@Test
public void testProcessWIthDifferentGroups() throws Exception {
    createRuntimeManager("org/jbpm/test/functional/task/HumanTaskOnLaneDifferentGroups.bpmn2");
    RuntimeEngine runtimeEngine = getRuntimeEngine();
    KieSession ksession = runtimeEngine.getKieSession();
    TaskService taskService = runtimeEngine.getTaskService();
    ProcessInstance processInstance = ksession.startProcess("UserTask");
    assertProcessInstanceActive(processInstance.getId());
    // simulating a system restart
    logger.debug("Reloading the environemnt to simulate system restart");
    disposeRuntimeManager();
    createRuntimeManager("org/jbpm/test/functional/task/HumanTaskOnLaneDifferentGroups.bpmn2");
    runtimeEngine = getRuntimeEngine();
    ksession = runtimeEngine.getKieSession();
    taskService = runtimeEngine.getTaskService();
    // let manager execute Task 1
    String taskUser = "manager";
    String locale = "en-UK";
    List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner(taskUser, locale);
    assertEquals(1, list.size());
    TaskSummary task = list.get(0);
    taskService.claim(task.getId(), taskUser);
    taskService.start(task.getId(), taskUser);
    taskService.complete(task.getId(), taskUser, null);
    // simulating a system restart
    logger.debug("Reloading the environemnt to simulate system restart once again");
    disposeRuntimeManager();
    createRuntimeManager("org/jbpm/test/functional/task/HumanTaskOnLane.bpmn2");
    runtimeEngine = getRuntimeEngine();
    ksession = runtimeEngine.getKieSession();
    taskService = runtimeEngine.getTaskService();
    List<Status> reservedAndRegistered = new ArrayList<Status>();
    reservedAndRegistered.add(Status.Reserved);
    reservedAndRegistered.add(Status.Ready);
    // manager does not have access to the second task
    list = taskService.getTasksAssignedAsPotentialOwnerByStatus(taskUser, reservedAndRegistered, locale);
    assertEquals(0, list.size());
    // now try john
    taskUser = "john";
    list = taskService.getTasksAssignedAsPotentialOwnerByStatus(taskUser, reservedAndRegistered, locale);
    assertEquals(1, list.size());
    task = list.get(0);
    // task is in ready state so claim is required
    assertEquals(Status.Ready, task.getStatus());
    taskService.claim(task.getId(), taskUser);
    taskService.start(task.getId(), taskUser);
    taskService.complete(task.getId(), taskUser, null);
    assertProcessInstanceCompleted(processInstance.getId());
}
Also used : Status(org.kie.api.task.model.Status) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) TaskService(org.kie.api.task.TaskService) TaskSummary(org.kie.api.task.model.TaskSummary) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 85 with TaskService

use of org.kie.api.task.TaskService in project jbpm by kiegroup.

the class ProcessPersistenceHumanTaskTest method testProcess.

@Test
public void testProcess() throws Exception {
    createRuntimeManager("org/jbpm/test/functional/task/humantask.bpmn");
    RuntimeEngine runtimeEngine = getRuntimeEngine();
    KieSession ksession = runtimeEngine.getKieSession();
    TaskService taskService = runtimeEngine.getTaskService();
    ProcessInstance processInstance = ksession.startProcess("com.sample.bpmn.hello");
    assertProcessInstanceActive(processInstance.getId());
    assertNodeTriggered(processInstance.getId(), "Start", "Task 1");
    // simulating a system restart
    logger.debug("Reloading the environemnt to simulate system restart");
    disposeRuntimeManager();
    createRuntimeManager("org/jbpm/test/functional/task/humantask.bpmn");
    runtimeEngine = getRuntimeEngine();
    ksession = runtimeEngine.getKieSession();
    taskService = runtimeEngine.getTaskService();
    // let john execute Task 1
    String taskGroup = "en-UK";
    List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", taskGroup);
    TaskSummary task = list.get(0);
    logger.debug("John is executing task " + task.getName());
    taskService.start(task.getId(), "john");
    taskService.complete(task.getId(), "john", null);
    assertNodeTriggered(processInstance.getId(), "Task 2");
    // simulating a system restart
    logger.debug("Reloading the environemnt to simulate system restart once again");
    disposeRuntimeManager();
    createRuntimeManager("org/jbpm/test/functional/task/humantask.bpmn");
    runtimeEngine = getRuntimeEngine();
    ksession = runtimeEngine.getKieSession();
    taskService = runtimeEngine.getTaskService();
    // let mary execute Task 2
    String taskUser = "mary";
    list = taskService.getTasksAssignedAsPotentialOwner(taskUser, taskGroup);
    assertTrue("No tasks found for potential owner " + taskUser + "/" + taskGroup, list.size() > 0);
    task = list.get(0);
    logger.debug("Mary is executing task " + task.getName());
    taskService.start(task.getId(), "mary");
    taskService.complete(task.getId(), "mary", null);
    assertNodeTriggered(processInstance.getId(), "End");
    assertProcessInstanceCompleted(processInstance.getId());
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) TaskService(org.kie.api.task.TaskService) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Aggregations

TaskService (org.kie.api.task.TaskService)129 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)111 KieSession (org.kie.api.runtime.KieSession)79 Test (org.junit.Test)73 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)70 TaskSummary (org.kie.api.task.model.TaskSummary)66 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)53 InternalTaskService (org.kie.internal.task.api.InternalTaskService)52 HashMap (java.util.HashMap)41 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)39 UserTaskService (org.jbpm.services.api.UserTaskService)38 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)34 ArrayList (java.util.ArrayList)17 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)17 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)15 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)15 Task (org.kie.api.task.model.Task)14 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)12 BZ (qa.tools.ikeeper.annotation.BZ)10 TaskCleanUpProcessEventListener (org.jbpm.services.task.admin.listener.TaskCleanUpProcessEventListener)9