Search in sources :

Example 91 with TaskService

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

the class HumanTaskTest method testInputTransformation.

@Test
@BZ("1081508")
public void testInputTransformation() {
    KieSession ksession = createKSession(INPUT_TRANSFORMATION);
    ProcessInstance pi = ksession.startProcess(INPUT_TRANSFORMATION_ID);
    RuntimeEngine engine = getRuntimeEngine();
    TaskService taskService = engine.getTaskService();
    List<TaskSummary> taskList = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    Long taskId = taskList.get(0).getId();
    taskService.start(taskId, "john");
    Map<String, Object> taskById = taskService.getTaskContent(taskId);
    Assertions.assertThat(taskById).containsEntry("Input", "Transformed String");
    taskService.complete(taskId, "john", null);
    assertProcessInstanceCompleted(pi.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) BZ(qa.tools.ikeeper.annotation.BZ)

Example 92 with TaskService

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

the class HumanTaskTest method testAbortWorkItemTaskStatus.

@Test
@BZ("1145046")
public void testAbortWorkItemTaskStatus() {
    for (int i = 0; i < 5; i++) {
        createRuntimeManager(Strategy.PROCESS_INSTANCE, "abortWorkItemTaskStatus" + i, ABORT_WORKITEM_TASK_STATUS);
        RuntimeEngine runtime = getRuntimeEngine();
        KieSession ksession = runtime.getKieSession();
        Map<String, Object> params = new HashMap<String, Object>();
        ProcessInstance pi = ksession.startProcess(ABORT_WORKITEM_TASK_STATUS_ID, params);
        TaskService taskService = runtime.getTaskService();
        List<Long> list = taskService.getTasksByProcessInstanceId(pi.getId());
        for (long taskId : list) {
            Task task = taskService.getTaskById(taskId);
            Assertions.assertThat(task.getTaskData().getStatus()).isEqualTo(Status.Exited);
        }
        disposeRuntimeManager();
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) Task(org.kie.api.task.model.Task) HashMap(java.util.HashMap) TaskService(org.kie.api.task.TaskService) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test) BZ(qa.tools.ikeeper.annotation.BZ)

Example 93 with TaskService

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

the class SingleRuntimeManagerTest method testProcessStartOnManager.

private void testProcessStartOnManager(RuntimeEngine runtime, RuntimeManager manager) {
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    ProcessInstance processInstance = ksession.startProcess("UserTask");
    assertNotNull(processInstance);
    TaskService taskService = runtime.getTaskService();
    String deploymentId = taskService.execute(new TaskCommand<String>() {

        @Override
        public String execute(Context context) {
            return (String) context.get(EnvironmentName.DEPLOYMENT_ID);
        }
    });
    assertNotNull(deploymentId);
    assertEquals(manager.getIdentifier(), deploymentId);
    List<Status> statuses = new ArrayList<Status>();
    statuses.add(Status.Reserved);
    List<TaskSummary> tasks = taskService.getTasksOwnedByStatus("john", statuses, "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    taskService.start(tasks.get(0).getId(), "john");
    taskService.complete(tasks.get(0).getId(), "john", null);
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertNull(processInstance);
}
Also used : ProcessInstanceIdContext(org.kie.internal.runtime.manager.context.ProcessInstanceIdContext) Context(org.kie.api.runtime.Context) EmptyContext(org.kie.internal.runtime.manager.context.EmptyContext) Status(org.kie.api.task.model.Status) TaskService(org.kie.api.task.TaskService) CommandBasedTaskService(org.jbpm.services.task.impl.command.CommandBasedTaskService) ArrayList(java.util.ArrayList) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) PerProcessInstance(org.kie.internal.runtime.manager.cdi.qualifier.PerProcessInstance)

Example 94 with TaskService

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

the class SingleRuntimeManagerWithListenersTest method testProcessStartOnManager.

private void testProcessStartOnManager(RuntimeEngine runtime) {
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    Collection<ProcessEventListener> pListeners = ksession.getProcessEventListeners();
    assertNotNull(pListeners);
    // prepare listeners class names for assertion
    List<String> listenerCLassNames = new ArrayList<String>();
    for (Object o : pListeners) {
        listenerCLassNames.add(o.getClass().getName());
    }
    // DebugProcessEventListener was added by custom producer
    assertTrue(listenerCLassNames.contains(DebugProcessEventListener.class.getName()));
    // JPAWorkingMemoryDbLogger one is always added to deal with user tasks
    assertTrue(listenerCLassNames.contains(JPAWorkingMemoryDbLogger.class.getName()));
    if (((RuntimeEngineImpl) runtime).getManager() instanceof PerProcessInstanceRuntimeManager) {
        assertEquals(3, pListeners.size());
    } else {
        assertEquals(2, pListeners.size());
    }
    TaskService taskService = runtime.getTaskService();
    assertNotNull(taskService);
    List<?> listeners = ((EventService<?>) taskService).getTaskEventListeners();
    assertNotNull(listeners);
    assertEquals(3, listeners.size());
    // prepare listeners class names for assertion
    listenerCLassNames = new ArrayList<String>();
    for (Object o : listeners) {
        System.out.println("###### " + o.getClass().getName());
        listenerCLassNames.add(o.getClass().getName());
    }
    assertEquals(3, listenerCLassNames.size());
    // JPATaskLifeCycleEventListener was added by custom producer
    assertTrue(listenerCLassNames.contains(JPATaskLifeCycleEventListener.class.getName()));
    // external one is always added to deal with user tasks
    assertTrue(listenerCLassNames.contains(ExternalTaskEventListener.class.getName()));
    // BAMTaskEventListener was added by custom producer
    assertTrue(listenerCLassNames.contains(BAMTaskEventListener.class.getName()));
    ProcessInstance processInstance = ksession.startProcess("UserTask");
    assertNotNull(processInstance);
    List<Status> statuses = new ArrayList<Status>();
    statuses.add(Status.Reserved);
    List<TaskSummary> tasks = taskService.getTasksOwnedByStatus("john", statuses, "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    taskService.start(tasks.get(0).getId(), "john");
    taskService.complete(tasks.get(0).getId(), "john", null);
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertNull(processInstance);
}
Also used : Status(org.kie.api.task.model.Status) TaskService(org.kie.api.task.TaskService) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DebugProcessEventListener(org.drools.core.event.DebugProcessEventListener) ArrayList(java.util.ArrayList) PerProcessInstanceRuntimeManager(org.jbpm.runtime.manager.impl.PerProcessInstanceRuntimeManager) EventService(org.kie.internal.task.api.EventService) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) PerProcessInstance(org.kie.internal.runtime.manager.cdi.qualifier.PerProcessInstance)

Example 95 with TaskService

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

the class SupportProcessBaseTest method testSupportProcess.

@Test
public void testSupportProcess() {
    DeploymentUnit deploymentUnitSupport = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnitSupport);
    units.add(deploymentUnitSupport);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("customer", "polymita");
    RuntimeManager managerSupport = deploymentService.getRuntimeManager(deploymentUnitSupport.getIdentifier());
    assertNotNull(managerSupport);
    int currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
    assertEquals(0, currentNumberOfEvents);
    RuntimeEngine engine = managerSupport.getRuntimeEngine(EmptyContext.get());
    assertNotNull(engine);
    ProcessInstance pI = engine.getKieSession().startProcess("support.process", params);
    assertNotNull(pI);
    TaskService taskService = engine.getTaskService();
    currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
    assertEquals(2, currentNumberOfEvents);
    // Configure Release
    List<TaskSummary> tasksAssignedToSalaboy = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
    assertEquals(1, tasksAssignedToSalaboy.size());
    assertEquals("Create Support", tasksAssignedToSalaboy.get(0).getName());
    TaskSummary createSupportTask = tasksAssignedToSalaboy.get(0);
    taskService.start(createSupportTask.getId(), "salaboy");
    currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
    assertEquals(4, currentNumberOfEvents);
    Map<String, Object> taskContent = ((InternalTaskService) taskService).getTaskContent(createSupportTask.getId());
    assertEquals("polymita", taskContent.get("input_customer"));
    Map<String, String> taskOutputMappings = bpmn2Service.getTaskOutputMappings(deploymentUnitSupport.getIdentifier(), "support.process", createSupportTask.getName());
    assertEquals(1, taskOutputMappings.size());
    assertEquals("output_customer", taskOutputMappings.keySet().iterator().next());
    Map<String, Object> output = new HashMap<String, Object>();
    output.put("output_customer", "polymita/redhat");
    taskService.complete(createSupportTask.getId(), "salaboy", output);
    currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
    assertEquals(8, currentNumberOfEvents);
    tasksAssignedToSalaboy = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
    assertEquals(1, tasksAssignedToSalaboy.size());
    assertEquals("Resolve Support", tasksAssignedToSalaboy.get(0).getName());
    TaskSummary resolveSupportTask = tasksAssignedToSalaboy.get(0);
    taskService.start(resolveSupportTask.getId(), "salaboy");
    currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
    assertEquals(10, currentNumberOfEvents);
    taskService.complete(resolveSupportTask.getId(), "salaboy", null);
    currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
    assertEquals(14, currentNumberOfEvents);
    tasksAssignedToSalaboy = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
    assertEquals(1, tasksAssignedToSalaboy.size());
    assertEquals("Notify Customer", tasksAssignedToSalaboy.get(0).getName());
    TaskSummary notifySupportTask = tasksAssignedToSalaboy.get(0);
    taskService.start(notifySupportTask.getId(), "salaboy");
    currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
    assertEquals(16, currentNumberOfEvents);
    output = new HashMap<String, Object>();
    output.put("output_solution", "solved today");
    taskService.complete(notifySupportTask.getId(), "salaboy", output);
    currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
    assertEquals(18, currentNumberOfEvents);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) HashMap(java.util.HashMap) InternalTaskService(org.kie.internal.task.api.InternalTaskService) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalTaskService(org.kie.internal.task.api.InternalTaskService) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) TaskSummary(org.kie.api.task.model.TaskSummary) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) DeploymentUnit(org.jbpm.services.api.model.DeploymentUnit) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) 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