Search in sources :

Example 26 with TaskInstance

use of org.kie.server.api.model.instance.TaskInstance in project droolsjbpm-integration by kiegroup.

the class ProcessServiceIntegrationTest method testWorkItemOperations.

@Test
public void testWorkItemOperations() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("person", createPersonInstance(USER_JOHN));
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_EVALUATION, parameters);
    try {
        assertNotNull(processInstanceId);
        assertTrue(processInstanceId.longValue() > 0);
        // Completing human task so we can move in process flow to work item.
        // User task shouldn't be handled as work item because in such case it doesn't behave consistently:
        // i.e. leaving open tasks after finishing process instance.
        List<String> status = Arrays.asList(Status.Ready.toString());
        List<TaskSummary> taskList = taskClient.findTasksByStatusByProcessInstanceId(processInstanceId, status, 0, 10);
        assertEquals(1, taskList.size());
        TaskSummary taskSummary = taskList.get(0);
        taskClient.startTask(CONTAINER_ID, taskSummary.getId(), USER_YODA);
        taskClient.completeTask(CONTAINER_ID, taskSummary.getId(), USER_YODA, null);
        TaskInstance userTask = taskClient.findTaskById(taskSummary.getId());
        assertNotNull(userTask);
        assertEquals("Evaluate items?", userTask.getName());
        assertEquals(Status.Completed.toString(), userTask.getStatus());
        List<WorkItemInstance> workItems = processClient.getWorkItemByProcessInstance(CONTAINER_ID, processInstanceId);
        assertNotNull(workItems);
        assertEquals(1, workItems.size());
        WorkItemInstance workItemInstance = workItems.get(0);
        assertNotNull(workItemInstance);
        assertEquals(processInstanceId, workItemInstance.getProcessInstanceId());
        assertEquals("Email", workItemInstance.getName());
        assertEquals(CONTAINER_ID, workItemInstance.getContainerId());
        assertEquals(0, workItemInstance.getState().intValue());
        assertEquals(5, workItemInstance.getParameters().size());
        assertNotNull(workItemInstance.getId());
        assertNotNull(workItemInstance.getNodeId());
        assertNotNull(workItemInstance.getProcessInstanceId());
        workItemInstance = processClient.getWorkItem(CONTAINER_ID, processInstanceId, workItemInstance.getId());
        assertNotNull(workItemInstance);
        assertEquals(processInstanceId, workItemInstance.getProcessInstanceId());
        assertEquals("Email", workItemInstance.getName());
        assertEquals(CONTAINER_ID, workItemInstance.getContainerId());
        assertEquals(0, workItemInstance.getState().intValue());
        assertEquals(5, workItemInstance.getParameters().size());
        assertNotNull(workItemInstance.getId());
        assertNotNull(workItemInstance.getNodeId());
        assertNotNull(workItemInstance.getProcessInstanceId());
        processClient.abortWorkItem(CONTAINER_ID, processInstanceId, workItemInstance.getId());
        ProcessInstance processInstance = processClient.getProcessInstance(CONTAINER_ID, processInstanceId);
        assertNotNull(processInstance);
        assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED, processInstance.getState().intValue());
    } catch (Exception e) {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
        throw e;
    } finally {
        changeUser(TestConfig.getUsername());
    }
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) HashMap(java.util.HashMap) WorkItemInstance(org.kie.server.api.model.instance.WorkItemInstance) KieServicesException(org.kie.server.api.exception.KieServicesException) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) Test(org.junit.Test)

Example 27 with TaskInstance

use of org.kie.server.api.model.instance.TaskInstance in project droolsjbpm-integration by kiegroup.

the class QueryDataServiceIntegrationTest method testGetTasksWithPotentialOwnerDoubleGroup.

@Test
public void testGetTasksWithPotentialOwnerDoubleGroup() throws Exception {
    changeUser(USER_JOHN);
    Long pidOne = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK_DOUBLE_GROUP);
    Long pidTwo = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK_DOUBLE_GROUP);
    QueryDefinition query = getTasksWithPotentialOwnerQueryDefinition();
    try {
        queryClient.registerQuery(query);
        List<org.kie.server.api.model.instance.TaskSummary> test = taskClient.findTasksAssignedAsPotentialOwner(USER_JOHN, 0, 10);
        assertNotNull(test);
        assertEquals(2, test.size());
        QueryFilterSpec filterSpec = new QueryFilterSpecBuilder().in("processInstanceId", Arrays.asList(pidOne, pidTwo)).get();
        List<TaskInstance> tasks = queryClient.query(query.getName(), QueryServicesClient.QUERY_MAP_TASK, filterSpec, 0, 10, TaskInstance.class);
        assertNotNull(tasks);
        assertEquals(2, tasks.size());
    } finally {
        processClient.abortProcessInstance(CONTAINER_ID, pidOne);
        processClient.abortProcessInstance(CONTAINER_ID, pidTwo);
        queryClient.unregisterQuery(query.getName());
        changeUser(USER_YODA);
    }
}
Also used : QueryDefinition(org.kie.server.api.model.definition.QueryDefinition) QueryFilterSpecBuilder(org.kie.server.api.util.QueryFilterSpecBuilder) TaskInstance(org.kie.server.api.model.instance.TaskInstance) QueryFilterSpec(org.kie.server.api.model.definition.QueryFilterSpec) Test(org.junit.Test)

Example 28 with TaskInstance

use of org.kie.server.api.model.instance.TaskInstance in project droolsjbpm-integration by kiegroup.

the class RollingUpdateProcessServiceIntegrationTest method testCompleteWorkItemInNewProcessWithAlias.

@Test
public void testCompleteWorkItemInNewProcessWithAlias() throws Exception {
    Long oldPid = processClient.startProcess(CONTAINER_ALIAS, PROCESS_ID_EVALUATION);
    assertThat(oldPid).isNotNull().isGreaterThan(0);
    createExtraContainer();
    Long pid = processClient.startProcess(CONTAINER_ALIAS, PROCESS_ID_EVALUATION_2);
    assertThat(pid).isNotNull().isGreaterThan(0);
    List<TaskSummary> taskList = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
    assertThat(taskList).hasSize(2);
    // Complete task from the first (old) process
    taskList = taskClient.findTasksByStatusByProcessInstanceId(oldPid, null, 0, 10);
    TaskSummary taskSummary = taskList.get(0);
    taskClient.startTask(CONTAINER_ALIAS, taskSummary.getId(), USER_YODA);
    taskClient.completeTask(CONTAINER_ALIAS, taskSummary.getId(), USER_YODA, null);
    TaskInstance userTask = taskClient.getTaskInstance(CONTAINER_ALIAS, taskSummary.getId());
    assertThat(userTask).isNotNull();
    assertThat(userTask.getContainerId()).isEqualTo(CONTAINER_ID);
    assertThat(userTask.getName()).isEqualTo("Evaluate items?");
    assertThat(userTask.getStatus()).isEqualTo(Status.Completed.toString());
    // Complete tasks from the second (new) process - there are two tasks instead of one
    taskList = taskClient.findTasksByStatusByProcessInstanceId(pid, null, 0, 10);
    assertThat(taskList).hasSize(1);
    // First one - Evaluate items
    taskSummary = taskList.get(0);
    taskClient.startTask(CONTAINER_ALIAS, taskSummary.getId(), USER_YODA);
    taskClient.completeTask(CONTAINER_ALIAS, taskSummary.getId(), USER_YODA, null);
    userTask = taskClient.getTaskInstance(CONTAINER_ALIAS, taskSummary.getId());
    assertThat(userTask).isNotNull();
    assertThat(userTask.getContainerId()).isEqualTo(CONTAINER_ID_101);
    assertThat(userTask.getName()).isEqualTo("Evaluate items?");
    assertThat(userTask.getStatus()).isEqualTo(Status.Completed.toString());
    // Second one - Approve
    taskList = taskClient.findTasksByStatusByProcessInstanceId(pid, null, 0, 10);
    assertThat(taskList).hasSize(1);
    taskSummary = taskList.get(0);
    taskClient.startTask(CONTAINER_ALIAS, taskSummary.getId(), USER_YODA);
    taskClient.completeTask(CONTAINER_ALIAS, taskSummary.getId(), USER_YODA, null);
    userTask = taskClient.getTaskInstance(CONTAINER_ALIAS, taskSummary.getId());
    assertThat(userTask).isNotNull();
    assertThat(userTask.getContainerId()).isEqualTo(CONTAINER_ID_101);
    assertThat(userTask.getName()).isEqualTo("Approve");
    assertThat(userTask.getStatus()).isEqualTo(Status.Completed.toString());
    List<WorkItemInstance> workItems = processClient.getWorkItemByProcessInstance(CONTAINER_ALIAS, pid);
    assertThat(workItems).isNotNull().hasSize(1);
    WorkItemInstance workItemInstance = workItems.get(0);
    assertThat(workItemInstance).isNotNull();
    assertThat(workItemInstance.getContainerId()).isEqualTo(CONTAINER_ID_101);
    assertThat(workItemInstance.getName()).isEqualTo("Email");
    assertThat(workItemInstance.getState()).isEqualTo(WorkItem.PENDING);
    WorkItemInstance workItemInstance2 = processClient.getWorkItem(CONTAINER_ALIAS, pid, workItemInstance.getId());
    assertThat(workItemInstance2.getId()).isEqualTo(workItemInstance.getId());
    processClient.completeWorkItem(CONTAINER_ALIAS, pid, workItemInstance.getId(), null);
    ProcessInstance pi = processClient.getProcessInstance(CONTAINER_ALIAS, pid);
    assertThat(pi).isNotNull();
    assertThat(pi.getState()).isEqualTo(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED);
    pi = processClient.getProcessInstance(CONTAINER_ALIAS, oldPid);
    assertThat(pi).isNotNull();
    assertThat(pi.getState()).isEqualTo(org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE);
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) TaskSummary(org.kie.server.api.model.instance.TaskSummary) WorkItemInstance(org.kie.server.api.model.instance.WorkItemInstance) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) Test(org.junit.Test)

Example 29 with TaskInstance

use of org.kie.server.api.model.instance.TaskInstance in project droolsjbpm-integration by kiegroup.

the class TaskSearchServiceIntegrationTest method testFindTaskWithAndEqualsToFilter.

@Test
public void testFindTaskWithAndEqualsToFilter() throws Exception {
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK);
    Assertions.assertThat(processInstanceId).isNotNull();
    List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
    Assertions.assertThat(tasks).isNotEmpty();
    TaskSummary task = tasks.get(0);
    HashMap<TaskField, Comparable<?>> compareList = new HashMap<>();
    compareList.put(TaskField.TASKID, task.getId());
    compareList.put(TaskField.DEPLOYMENTID, CONTAINER_ID);
    compareList.put(TaskField.PROCESSINSTANCEID, processInstanceId);
    compareList.put(TaskField.NAME, FIRST_TASK_NAME);
    compareList.put(TaskField.CREATEDBY, USER_YODA);
    compareList.put(TaskField.ACTUALOWNER, USER_YODA);
    compareList.put(TaskField.DESCRIPTION, task.getDescription());
    compareList.put(TaskField.DUEDATE, task.getExpirationTime());
    compareList.put(TaskField.PRIORITY, task.getPriority());
    compareList.put(TaskField.STATUS, task.getStatus());
    List<Long> resultsIds = new ArrayList<>();
    List<TaskInstance> results = queryClient.findHumanTasksWithFilters(QUERY_NAME, createQueryFilterAndEqualsTo(compareList), 0, 100);
    for (TaskInstance res : results) {
        resultsIds.add(res.getId());
    }
    Assertions.assertThat(results).isNotNull();
    Assertions.assertThat(results).isNotEmpty();
    Assertions.assertThat(resultsIds).contains(task.getId());
    TaskInstance instance = results.stream().filter(taskInstance -> taskInstance.getId().equals(task.getId())).findFirst().orElse(null);
    Assertions.assertThat(instance).isNotNull();
    Assertions.assertThat(instance.getContainerId()).isEqualTo(CONTAINER_ID);
    Assertions.assertThat(instance.getProcessInstanceId()).isEqualTo(processInstanceId);
    Assertions.assertThat(instance.getName()).isEqualTo(FIRST_TASK_NAME);
    Assertions.assertThat(instance.getActualOwner()).isEqualTo(USER_YODA);
    Assertions.assertThat(instance.getCreatedBy()).isEqualTo(USER_YODA);
    Assertions.assertThat(instance.getDescription()).isEqualTo(task.getDescription());
    Assertions.assertThat(instance.getExpirationDate()).isEqualTo(task.getExpirationTime());
    Assertions.assertThat(instance.getPriority()).isEqualTo(task.getPriority());
    Assertions.assertThat(instance.getStatus()).isEqualTo(task.getStatus());
}
Also used : TaskField(org.kie.server.api.model.definition.TaskField) TaskInstance(org.kie.server.api.model.instance.TaskInstance) HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 30 with TaskInstance

use of org.kie.server.api.model.instance.TaskInstance in project droolsjbpm-integration by kiegroup.

the class UserTaskClientIntegrationTest method testFindTaskById.

@Test
public void testFindTaskById() {
    final Map<String, Object> initialProcessVariables = new HashMap<>();
    initialProcessVariables.put(PROCESS_VARIABLE_NAME, "initialValue");
    final long processInstanceId = startProcess(CONTAINER_ID, PROCESS_WITH_HUMAN_TASK, initialProcessVariables);
    Assertions.assertThat(processInstanceId).isPositive();
    final List<TaskSummary> allTasks = listTaskInstancesAsPotentialOwner();
    Assertions.assertThat(allTasks).isNotEmpty();
    final Map<String, Object> parameters = new HashMap<>();
    parameters.put("taskId", allTasks.get(0).getId());
    final ExecutionServerCommand executionServerCommand = new ExecutionServerCommand();
    executionServerCommand.setClient("userTask");
    executionServerCommand.setOperation("findTaskById");
    executionServerCommand.setParameters(parameters);
    final Object response = runOnExecutionServer(executionServerCommand);
    Assertions.assertThat(response).isNotNull();
    Assertions.assertThat(response).isInstanceOf(TaskInstance.class);
    final TaskInstance taskInstance = (TaskInstance) response;
    Assertions.assertThat(taskInstance.getId()).isEqualTo(allTasks.get(0).getId());
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ExecutionServerCommand(org.kie.camel.container.api.ExecutionServerCommand) Test(org.junit.Test)

Aggregations

TaskInstance (org.kie.server.api.model.instance.TaskInstance)44 Test (org.junit.Test)29 TaskSummary (org.kie.server.api.model.instance.TaskSummary)27 HashMap (java.util.HashMap)24 OrgEntities (org.kie.server.api.model.admin.OrgEntities)8 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)7 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)6 QueryDefinition (org.kie.server.api.model.definition.QueryDefinition)5 WorkItemInstance (org.kie.server.api.model.instance.WorkItemInstance)5 ArrayList (java.util.ArrayList)4 CommandScript (org.kie.server.api.commands.CommandScript)4 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)4 KieServerCommand (org.kie.server.api.model.KieServerCommand)4 ServiceResponse (org.kie.server.api.model.ServiceResponse)4 Calendar (java.util.Calendar)3 Date (java.util.Date)3 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)3 UserTaskInstanceWithVarsDesc (org.jbpm.services.api.model.UserTaskInstanceWithVarsDesc)3 QueryFilterSpecBuilder (org.kie.server.api.util.QueryFilterSpecBuilder)3 ApiOperation (io.swagger.annotations.ApiOperation)2