Search in sources :

Example 1 with TaskEvent

use of org.kie.internal.task.api.model.TaskEvent in project jbpm by kiegroup.

the class TaskAuditBaseTest method testComplete.

@Test
public void testComplete() {
    long initTimeMs = new Date().getTime();
    Task task = new TaskFluent().setName("This is my task name").addPotentialGroup("Knights Templer").setAdminUser("Administrator").getTask();
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    List<TaskSummary> allGroupAuditTasks = taskService.getTasksAssignedAsPotentialOwner("salaboy", null, null, null);
    assertEquals(1, allGroupAuditTasks.size());
    assertTrue(allGroupAuditTasks.get(0).getStatusId().equals("Ready"));
    taskService.claim(taskId, "Darth Vader");
    allGroupAuditTasks = taskService.getTasksAssignedAsPotentialOwner("salaboy", null, null, null);
    assertEquals(0, allGroupAuditTasks.size());
    allGroupAuditTasks = taskService.getTasksAssignedAsPotentialOwner("Darth Vader", null, null, null);
    assertEquals(1, allGroupAuditTasks.size());
    assertTrue(allGroupAuditTasks.get(0).getStatusId().equals("Reserved"));
    taskService.release(taskId, "Darth Vader");
    allGroupAuditTasks = taskService.getTasksAssignedAsPotentialOwner("salaboy", null, null, null);
    assertEquals(1, allGroupAuditTasks.size());
    assertTrue(allGroupAuditTasks.get(0).getStatusId().equals("Ready"));
    taskService.claim(taskId, "Darth Vader");
    allGroupAuditTasks = taskService.getTasksAssignedAsPotentialOwner("salaboy", null, null, null);
    assertEquals(0, allGroupAuditTasks.size());
    allGroupAuditTasks = taskService.getTasksAssignedAsPotentialOwner("Darth Vader", null, null, null);
    assertEquals(1, allGroupAuditTasks.size());
    assertTrue(allGroupAuditTasks.get(0).getStatusId().equals("Reserved"));
    // Go straight from Ready to Inprogress
    taskService.start(taskId, "Darth Vader");
    Task task1 = taskService.getTaskById(taskId);
    assertEquals(Status.InProgress, task1.getTaskData().getStatus());
    assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
    // Check is Complete
    taskService.complete(taskId, "Darth Vader", null);
    Task task2 = taskService.getTaskById(taskId);
    assertEquals(Status.Completed, task2.getTaskData().getStatus());
    assertEquals("Darth Vader", task2.getTaskData().getActualOwner().getId());
    List<TaskEvent> allTaskEvents = taskService.execute(new GetAuditEventsCommand(taskId, new QueryFilter(0, 0)));
    assertEquals(6, allTaskEvents.size());
    // test DeleteAuditEventsCommand
    int numFirstTaskEvents = allTaskEvents.size();
    task = new TaskFluent().setName("This is my task name 2").addPotentialGroup("Knights Templer").setAdminUser("Administrator").getTask();
    taskService.addTask(task, new HashMap<String, Object>());
    long secondTaskId = task.getId();
    taskService.claim(secondTaskId, "Darth Vader");
    taskService.start(secondTaskId, "Darth Vader");
    taskService.complete(secondTaskId, "Darth Vader", null);
    allTaskEvents = taskService.execute(new GetAuditEventsCommand());
    int numTaskEvents = allTaskEvents.size();
    assertTrue("Expected more than " + numFirstTaskEvents + " events: " + numTaskEvents, numTaskEvents > numFirstTaskEvents);
    taskService.execute(new DeleteAuditEventsCommand(taskId));
    allTaskEvents = taskService.execute(new GetAuditEventsCommand());
    assertEquals(numTaskEvents - numFirstTaskEvents, allTaskEvents.size());
    taskService.execute(new DeleteAuditEventsCommand());
    allTaskEvents = taskService.execute(new GetAuditEventsCommand());
    assertEquals(0, allTaskEvents.size());
    // test get/delete BAM Task summaries commands
    List<BAMTaskSummaryImpl> bamTaskList = taskService.execute(new GetBAMTaskSummariesCommand());
    assertEquals("BAM Task Summary list size: ", 2, bamTaskList.size());
    taskService.execute(new DeleteBAMTaskSummariesCommand(taskId));
    bamTaskList = taskService.execute(new GetBAMTaskSummariesCommand());
    assertEquals("BAM Task Summary list size after delete (task id: " + taskId + ") : ", 1, bamTaskList.size());
    bamTaskList = taskService.execute(new GetBAMTaskSummariesCommand(secondTaskId));
    assertEquals("BAM Task Summary list size after delete (task id: " + taskId + ") : ", 1, bamTaskList.size());
    taskService.execute(new DeleteBAMTaskSummariesCommand());
    bamTaskList = taskService.execute(new GetBAMTaskSummariesCommand());
    assertEquals("BAM Task Summary list size after delete (task id: " + taskId + ") : ", 0, bamTaskList.size());
    List<AuditTask> allHistoryAuditTasks = taskAuditService.getAllAuditTasks(new QueryFilter(0, 0));
    assertEquals(2, allHistoryAuditTasks.size());
    // test last modification date was generated
    long currentTimeMs = new Date().getTime();
    for (AuditTask at : allHistoryAuditTasks) {
        Date modDate = ((AuditTaskImpl) at).getLastModificationDate();
        assertNotNull(modDate);
        long modDateMs = modDate.getTime();
        assertTrue("Task " + at.getTaskId() + " modification date is not too much in the past", modDateMs >= initTimeMs);
        assertTrue("Task " + at.getTaskId() + " modification date is not in the future", modDateMs <= currentTimeMs);
    }
}
Also used : Task(org.kie.api.task.model.Task) AuditTask(org.kie.internal.task.api.AuditTask) TaskFluent(org.jbpm.services.task.utils.TaskFluent) DeleteBAMTaskSummariesCommand(org.jbpm.services.task.audit.commands.DeleteBAMTaskSummariesCommand) Date(java.util.Date) GetAuditEventsCommand(org.jbpm.services.task.audit.commands.GetAuditEventsCommand) AuditTask(org.kie.internal.task.api.AuditTask) AuditTaskImpl(org.jbpm.services.task.audit.impl.model.AuditTaskImpl) QueryFilter(org.kie.internal.query.QueryFilter) DeleteAuditEventsCommand(org.jbpm.services.task.audit.commands.DeleteAuditEventsCommand) GetBAMTaskSummariesCommand(org.jbpm.services.task.audit.commands.GetBAMTaskSummariesCommand) TaskSummary(org.kie.api.task.model.TaskSummary) TaskEvent(org.kie.internal.task.api.model.TaskEvent) BAMTaskSummaryImpl(org.jbpm.services.task.audit.impl.model.BAMTaskSummaryImpl) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Example 2 with TaskEvent

use of org.kie.internal.task.api.model.TaskEvent in project jbpm by kiegroup.

the class TaskAuditBaseTest method testForwardTaskWithMsgEvents.

@Test
public void testForwardTaskWithMsgEvents() {
    Task task = new TaskFluent().setName("This is my task name").addPotentialGroup("Knights Templer").setAdminUser("Administrator").addPotentialUser("Administrator").getTask();
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    assertAuditTaskInfoGroup("Knights Templer", "Ready", taskId);
    taskService.claim(taskId, "Administrator");
    assertAuditTaskInfo("Administrator", "Reserved", taskId);
    taskService.forward(taskId, "Administrator", "Darth Vader");
    List<TaskEvent> taskEvents = taskAuditService.getAllTaskEvents(taskId, new QueryFilter());
    Assertions.assertThat(taskEvents).hasSize(3);
    Assertions.assertThat(taskEvents.get(0).getType()).isEqualTo(TaskEventType.ADDED);
    Assertions.assertThat(taskEvents.get(0).getUserId()).isNull();
    Assertions.assertThat(taskEvents.get(1).getType()).isEqualTo(TaskEventType.CLAIMED);
    Assertions.assertThat(taskEvents.get(1).getUserId()).isEqualTo("Administrator");
    Assertions.assertThat(taskEvents.get(2).getType()).isEqualTo(TaskEventType.FORWARDED);
    Assertions.assertThat(taskEvents.get(2).getUserId()).isEqualTo("Administrator");
    Assertions.assertThat(taskEvents.get(2).getMessage()).isNotNull();
    Assertions.assertThat(taskEvents.get(2).getMessage()).contains("Darth Vader");
}
Also used : Task(org.kie.api.task.model.Task) AuditTask(org.kie.internal.task.api.AuditTask) QueryFilter(org.kie.internal.query.QueryFilter) TaskFluent(org.jbpm.services.task.utils.TaskFluent) TaskEvent(org.kie.internal.task.api.model.TaskEvent) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Example 3 with TaskEvent

use of org.kie.internal.task.api.model.TaskEvent in project jbpm by kiegroup.

the class TaskAuditBaseTest method testUpdateTaskContentEvents.

@Test
public void testUpdateTaskContentEvents() {
    Task task = new TaskFluent().setName("This is my task name").addPotentialGroup("Knights Templer").setAdminUser("Administrator").getTask();
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    assertAuditTaskInfoGroup("Knights Templer", "Ready", taskId);
    taskService.claim(taskId, "Darth Vader");
    assertAuditTaskInfo("Darth Vader", "Reserved", taskId);
    // Go straight from Ready to Inprogress
    taskService.start(taskId, "Darth Vader");
    assertAuditTaskInfo("Darth Vader", "InProgress", taskId);
    Map<String, Object> params = new HashMap<>();
    params.put("test", "value");
    taskService.addOutputContentFromUser(taskId, "Darth Vader", params);
    // Check is Complete
    params.clear();
    params.put("test", "updated");
    taskService.complete(taskId, "Darth Vader", params);
    assertAuditTaskInfo("Darth Vader", "Completed", taskId);
    List<TaskEvent> taskEvents = taskAuditService.getAllTaskEvents(taskId, new QueryFilter());
    Assertions.assertThat(taskEvents).hasSize(6);
    Assertions.assertThat(taskEvents.get(0).getType()).isEqualTo(TaskEventType.ADDED);
    Assertions.assertThat(taskEvents.get(0).getUserId()).isNull();
    Assertions.assertThat(taskEvents.get(1).getType()).isEqualTo(TaskEventType.CLAIMED);
    Assertions.assertThat(taskEvents.get(1).getUserId()).isEqualTo("Darth Vader");
    Assertions.assertThat(taskEvents.get(2).getType()).isEqualTo(TaskEventType.STARTED);
    Assertions.assertThat(taskEvents.get(2).getUserId()).isEqualTo("Darth Vader");
    // first update of data explicitly
    Assertions.assertThat(taskEvents.get(3).getType()).isEqualTo(TaskEventType.UPDATED);
    Assertions.assertThat(taskEvents.get(3).getUserId()).isEqualTo("Darth Vader");
    // next update of data through complete
    Assertions.assertThat(taskEvents.get(4).getType()).isEqualTo(TaskEventType.UPDATED);
    Assertions.assertThat(taskEvents.get(4).getUserId()).isEqualTo("Darth Vader");
    Assertions.assertThat(taskEvents.get(5).getType()).isEqualTo(TaskEventType.COMPLETED);
    Assertions.assertThat(taskEvents.get(5).getUserId()).isEqualTo("Darth Vader");
}
Also used : Task(org.kie.api.task.model.Task) AuditTask(org.kie.internal.task.api.AuditTask) QueryFilter(org.kie.internal.query.QueryFilter) TaskFluent(org.jbpm.services.task.utils.TaskFluent) HashMap(java.util.HashMap) TaskEvent(org.kie.internal.task.api.model.TaskEvent) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Example 4 with TaskEvent

use of org.kie.internal.task.api.model.TaskEvent in project jbpm by kiegroup.

the class TaskAuditBaseTest method testDueDateUpdate.

private void testDueDateUpdate(Date oldDate, Date newDate, boolean changeExpected) {
    Task task = new TaskFluent().setDueDate(oldDate).setAdminUser("Administrator").getTask();
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    taskService.setExpirationDate(taskId, newDate);
    task = taskService.getTaskById(taskId);
    Assertions.assertThat(task.getTaskData().getExpirationTime()).isEqualTo(newDate);
    List<AuditTask> auditTasks = taskAuditService.getAllAuditTasks(new QueryFilter());
    Assertions.assertThat(auditTasks).hasSize(1);
    Assertions.assertThat(auditTasks.get(0).getDueDate()).isEqualTo(newDate);
    List<TaskEvent> taskEvents = taskAuditService.getAllTaskEvents(taskId, new QueryFilter());
    if (changeExpected) {
        Assertions.assertThat(taskEvents).hasSize(2);
        Assertions.assertThat(taskEvents.get(1).getMessage()).contains(String.valueOf(oldDate), String.valueOf(newDate));
    } else {
        Assertions.assertThat(taskEvents).hasSize(1);
    }
}
Also used : Task(org.kie.api.task.model.Task) AuditTask(org.kie.internal.task.api.AuditTask) QueryFilter(org.kie.internal.query.QueryFilter) TaskFluent(org.jbpm.services.task.utils.TaskFluent) TaskEvent(org.kie.internal.task.api.model.TaskEvent) AuditTask(org.kie.internal.task.api.AuditTask)

Example 5 with TaskEvent

use of org.kie.internal.task.api.model.TaskEvent in project jbpm by kiegroup.

the class UserTaskAdminServiceImplTest method testRemoveBusinessAdmin.

@Test
public void testRemoveBusinessAdmin() {
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    Assertions.assertThat(processInstanceId).isNotNull();
    List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsBusinessAdministrator("Administrator", new QueryFilter());
    Assertions.assertThat(tasks).hasSize(1);
    TaskSummary task = tasks.get(0);
    userTaskAdminService.removeBusinessAdmins(task.getId(), factory.newUser("Administrator"));
    List<TaskEvent> events = runtimeDataService.getTaskEvents(task.getId(), new QueryFilter());
    Assertions.assertThat(events).hasSize(2);
    TaskEvent updatedEvent = events.get(1);
    Assertions.assertThat(updatedEvent.getMessage()).isEqualTo("Business administrators [Administrator] have been removed");
    List<Status> readyStatuses = Arrays.asList(new Status[] { org.kie.api.task.model.Status.Ready });
    tasks = runtimeDataService.getTasksAssignedAsBusinessAdministratorByStatus("Administrator", readyStatuses, new QueryFilter());
    Assertions.assertThat(tasks).hasSize(0);
}
Also used : Status(org.kie.api.task.model.Status) QueryFilter(org.kie.internal.query.QueryFilter) TaskSummary(org.kie.api.task.model.TaskSummary) TaskEvent(org.kie.internal.task.api.model.TaskEvent) KModuleDeploymentServiceTest(org.jbpm.kie.services.test.KModuleDeploymentServiceTest) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Aggregations

TaskEvent (org.kie.internal.task.api.model.TaskEvent)18 QueryFilter (org.kie.internal.query.QueryFilter)17 Test (org.junit.Test)13 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)8 TaskFluent (org.jbpm.services.task.utils.TaskFluent)8 Task (org.kie.api.task.model.Task)8 AuditTask (org.kie.internal.task.api.AuditTask)8 TaskSummary (org.kie.api.task.model.TaskSummary)7 KModuleDeploymentServiceTest (org.jbpm.kie.services.test.KModuleDeploymentServiceTest)6 HumanTaskServicesBaseTest (org.jbpm.services.task.HumanTaskServicesBaseTest)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)3 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)3 I18NTextImpl (org.jbpm.services.task.impl.model.I18NTextImpl)2 WorkflowProcessInstanceImpl (org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)2 WorkItemNodeInstance (org.jbpm.workflow.instance.node.WorkItemNodeInstance)2 NodeInstance (org.kie.api.runtime.process.NodeInstance)2 I18NText (org.kie.api.task.model.I18NText)2 Date (java.util.Date)1