Search in sources :

Example 1 with TaskEventInstance

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

the class ByPassUserTaskServiceIntegrationTest method testProcessWithUserTasks.

@Test
public void testProcessWithUserTasks() {
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK2);
    assertNotNull(processInstanceId);
    assertTrue(processInstanceId > 0);
    try {
        List<TaskSummary> taskList = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
        assertTaskList(taskList, "First task", 1);
        TaskSummary taskSummary = taskList.get(0);
        // startTask and completeTask task
        taskClient.startTask(CONTAINER_ID, taskSummary.getId(), USER_YODA);
        Map<String, Object> taskOutcome = new HashMap<String, Object>();
        taskOutcome.put("string_", "my custom data");
        Map<String, Object> content = new HashMap<>();
        content.put("name", "joda");
        taskClient.saveTaskContent(CONTAINER_ID, taskSummary.getId(), "admin", content);
        List<TaskEventInstance> events = taskClient.findTaskEvents(taskSummary.getId(), 0, 10);
        assertEquals("admin", events.get(events.size() - 1).getUserId());
        taskClient.saveTaskContent(CONTAINER_ID, taskSummary.getId(), "other", content);
        events = taskClient.findTaskEvents(taskSummary.getId(), 0, 10);
        assertEquals("other", events.get(events.size() - 1).getUserId());
        taskClient.completeTask(CONTAINER_ID, taskSummary.getId(), USER_YODA, taskOutcome);
        String stringVar = (String) processClient.getProcessInstanceVariable(CONTAINER_ID, processInstanceId, "stringData");
        assertNotNull(stringVar);
        assertEquals("my custom data", stringVar);
        taskList = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
        assertTaskList(taskList, "Second task", 1);
    } finally {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
    }
}
Also used : HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) TaskEventInstance(org.kie.server.api.model.instance.TaskEventInstance) Test(org.junit.Test)

Example 2 with TaskEventInstance

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

the class RuntimeDataServiceBase method getTaskEvents.

public TaskEventInstanceList getTaskEvents(long taskId, Integer page, Integer pageSize, String sort, boolean sortOrder) {
    if (sort == null || sort.isEmpty()) {
        sort = "Id";
    }
    logger.debug("About to search for task {} events", taskId);
    List<TaskEvent> tasks = runtimeDataService.getTaskEvents(taskId, buildQueryFilter(page, pageSize, sort, sortOrder));
    logger.debug("Found {} task events available for task '{}'", tasks.size(), taskId);
    TaskEventInstanceList result = null;
    if (tasks == null) {
        result = new TaskEventInstanceList(new TaskEventInstance[0]);
    } else {
        TaskEventInstance[] instances = new TaskEventInstance[tasks.size()];
        int counter = 0;
        for (TaskEvent taskSummary : tasks) {
            TaskEventInstance task = TaskEventInstance.builder().id(taskSummary.getTaskId()).taskId(taskSummary.getTaskId()).date(taskSummary.getLogTime()).processInstanceId(taskSummary.getProcessInstanceId()).type(taskSummary.getType().toString()).user(taskSummary.getUserId()).workItemId(taskSummary.getWorkItemId()).message(taskSummary.getMessage()).correlationKey(taskSummary.getCorrelationKey()).processType(taskSummary.getProcessType()).assignedOwner(taskSummary.getCurrentOwner()).build();
            instances[counter] = task;
            counter++;
        }
        result = new TaskEventInstanceList(instances);
    }
    return result;
}
Also used : TaskEvent(org.kie.internal.task.api.model.TaskEvent) TaskEventInstanceList(org.kie.server.api.model.instance.TaskEventInstanceList) TaskEventInstance(org.kie.server.api.model.instance.TaskEventInstance)

Example 3 with TaskEventInstance

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

the class RuntimeDataServiceIntegrationTest method testFindTaskEvents.

@Test
public void testFindTaskEvents() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("stringData", "waiting for signal");
    parameters.put("personData", createPersonInstance(USER_JOHN));
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK, parameters);
    try {
        List<TaskSummary> tasks = taskClient.findTasksByStatusByProcessInstanceId(processInstanceId, null, 0, 10);
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        TaskSummary taskInstance = tasks.get(0);
        List<TaskEventInstance> events = taskClient.findTaskEvents(taskInstance.getId(), 0, 10);
        assertNotNull(events);
        assertEquals(2, events.size());
        TaskEventInstance expectedTaskEventInstance = TaskEventInstance.builder().type(TaskEvent.TaskEventType.ADDED.toString()).processInstanceId(processInstanceId).taskId(taskInstance.getId()).assignedOwner(USER_YODA).user(TestConfig.getUsername()).build();
        TaskEventInstance event = events.get(0);
        assertTaskEventInstance(expectedTaskEventInstance, event);
        // now let's start it
        taskClient.startTask(CONTAINER_ID, taskInstance.getId(), USER_YODA);
        events = taskClient.findTaskEvents(taskInstance.getId(), 0, 10);
        assertNotNull(events);
        assertEquals(3, events.size());
        event = getTaskEventInstanceFromListByType(events, TaskEvent.TaskEventType.ADDED.toString());
        assertTaskEventInstance(expectedTaskEventInstance, event);
        event = getTaskEventInstanceFromListByType(events, TaskEvent.TaskEventType.STARTED.toString());
        expectedTaskEventInstance.setType(TaskEvent.TaskEventType.STARTED.toString());
        expectedTaskEventInstance.setUserId(USER_YODA);
        assertTaskEventInstance(expectedTaskEventInstance, event);
        // now let's stop it
        taskClient.stopTask(CONTAINER_ID, taskInstance.getId(), USER_YODA);
        events = taskClient.findTaskEvents(taskInstance.getId(), 0, 10);
        assertNotNull(events);
        assertEquals(4, events.size());
        event = getTaskEventInstanceFromListByType(events, TaskEvent.TaskEventType.ADDED.toString());
        expectedTaskEventInstance.setType(TaskEvent.TaskEventType.ADDED.toString());
        expectedTaskEventInstance.setUserId(USER_YODA);
        assertTaskEventInstance(expectedTaskEventInstance, event);
        event = getTaskEventInstanceFromListByType(events, TaskEvent.TaskEventType.STARTED.toString());
        expectedTaskEventInstance.setType(TaskEvent.TaskEventType.STARTED.toString());
        expectedTaskEventInstance.setUserId(USER_YODA);
        assertTaskEventInstance(expectedTaskEventInstance, event);
        event = getTaskEventInstanceFromListByType(events, TaskEvent.TaskEventType.STOPPED.toString());
        expectedTaskEventInstance.setType(TaskEvent.TaskEventType.STOPPED.toString());
        assertTaskEventInstance(expectedTaskEventInstance, event);
    } finally {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
    }
}
Also used : HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) TaskEventInstance(org.kie.server.api.model.instance.TaskEventInstance) Test(org.junit.Test)

Example 4 with TaskEventInstance

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

the class RuntimeDataServiceIntegrationTest method testFindTaskEventsSortedByType.

@Test
public void testFindTaskEventsSortedByType() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("stringData", "waiting for signal");
    parameters.put("personData", createPersonInstance(USER_JOHN));
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK, parameters);
    try {
        List<TaskSummary> tasks = taskClient.findTasksByStatusByProcessInstanceId(processInstanceId, null, 0, 10);
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        TaskSummary taskInstance = tasks.get(0);
        // now let's start it
        taskClient.startTask(CONTAINER_ID, taskInstance.getId(), USER_YODA);
        // now let's stop it
        taskClient.stopTask(CONTAINER_ID, taskInstance.getId(), USER_YODA);
        // test paging of the result
        List<TaskEventInstance> events = taskClient.findTaskEvents(taskInstance.getId(), 0, 4, SORT_BY_TASK_EVENTS_TYPE, true);
        assertNotNull(events);
        assertEquals(4, events.size());
        TaskEventInstance event = events.get(0);
        assertNotNull(event);
        assertEquals(taskInstance.getId(), event.getTaskId());
        assertEquals(TaskEvent.TaskEventType.ACTIVATED.toString(), event.getType());
        event = events.get(1);
        assertNotNull(event);
        assertEquals(taskInstance.getId(), event.getTaskId());
        assertEquals(TaskEvent.TaskEventType.ADDED.toString(), event.getType());
        event = events.get(2);
        assertNotNull(event);
        assertEquals(taskInstance.getId(), event.getTaskId());
        assertEquals(TaskEvent.TaskEventType.STARTED.toString(), event.getType());
        event = events.get(3);
        assertNotNull(event);
        assertEquals(taskInstance.getId(), event.getTaskId());
        assertEquals(TaskEvent.TaskEventType.STOPPED.toString(), event.getType());
        try {
            events = taskClient.findTaskEvents(taskInstance.getId(), 2, 3, SORT_BY_TASK_EVENTS_TYPE, true);
            KieServerAssert.assertNullOrEmpty("Task events list is not empty.", events);
        } catch (KieServicesException ee) {
            if (configuration.isRest()) {
                KieServerAssert.assertResultContainsString(ee.getMessage(), "Could not find task instance with id " + taskInstance.getId());
                KieServicesHttpException httpEx = (KieServicesHttpException) ee;
                assertEquals(Integer.valueOf(404), httpEx.getHttpCode());
            } else {
                assertTrue(ee.getMessage().contains("No task found with id " + taskInstance.getId()));
            }
        }
        events = taskClient.findTaskEvents(taskInstance.getId(), 0, 10, SORT_BY_TASK_EVENTS_TYPE, false);
        assertNotNull(events);
        assertEquals(4, events.size());
        event = events.get(0);
        assertNotNull(event);
        assertEquals(taskInstance.getId(), event.getTaskId());
        assertEquals(TaskEvent.TaskEventType.STOPPED.toString(), event.getType());
        event = events.get(1);
        assertNotNull(event);
        assertEquals(taskInstance.getId(), event.getTaskId());
        assertEquals(TaskEvent.TaskEventType.STARTED.toString(), event.getType());
    } finally {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
    }
}
Also used : KieServicesHttpException(org.kie.server.api.exception.KieServicesHttpException) HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) KieServicesException(org.kie.server.api.exception.KieServicesException) TaskEventInstance(org.kie.server.api.model.instance.TaskEventInstance) Test(org.junit.Test)

Example 5 with TaskEventInstance

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

the class UserTaskServiceIntegrationTest method testFindTaskEvents.

@Test
public void testFindTaskEvents() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("stringData", "waiting for signal");
    parameters.put("personData", createPersonInstance(USER_JOHN));
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK, parameters);
    try {
        List<TaskSummary> tasks = taskClient.findTasksByStatusByProcessInstanceId(processInstanceId, null, 0, 10);
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        TaskSummary taskInstance = tasks.get(0);
        TaskEventInstance expectedTaskEventInstance = TaskEventInstance.builder().type(TaskEvent.TaskEventType.ADDED.toString()).processInstanceId(processInstanceId).taskId(taskInstance.getId()).user(TestConfig.getUsername()).build();
        List<TaskEventInstance> events = taskClient.findTaskEvents(CONTAINER_ID, taskInstance.getId(), 0, 10);
        assertNotNull(events);
        assertEquals(2, events.size());
        assertTaskEventInstance(expectedTaskEventInstance, events.get(0));
        // now let's start it
        taskClient.startTask(CONTAINER_ID, taskInstance.getId(), USER_YODA);
        events = taskClient.findTaskEvents(CONTAINER_ID, taskInstance.getId(), 0, 10);
        assertNotNull(events);
        assertEquals(3, events.size());
        assertTaskEventInstance(expectedTaskEventInstance, events.get(0));
        expectedTaskEventInstance.setType(TaskEvent.TaskEventType.STARTED.toString());
        expectedTaskEventInstance.setUserId(USER_YODA);
        assertTaskEventInstance(expectedTaskEventInstance, events.get(2));
    } finally {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
    }
}
Also used : HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) TaskEventInstance(org.kie.server.api.model.instance.TaskEventInstance) Test(org.junit.Test)

Aggregations

TaskEventInstance (org.kie.server.api.model.instance.TaskEventInstance)6 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 TaskSummary (org.kie.server.api.model.instance.TaskSummary)5 KieServicesException (org.kie.server.api.exception.KieServicesException)2 KieServicesHttpException (org.kie.server.api.exception.KieServicesHttpException)2 TaskEvent (org.kie.internal.task.api.model.TaskEvent)1 TaskEventInstanceList (org.kie.server.api.model.instance.TaskEventInstanceList)1