Search in sources :

Example 11 with TaskEvent

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

the class RuntimeDataServiceImplTest method testGetTaskEvents.

@Test
public void testGetTaskEvents() {
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    assertNotNull(processInstanceId);
    ProcessInstance instance = processService.getProcessInstance(processInstanceId);
    assertNotNull(instance);
    Collection<NodeInstance> activeNodes = ((WorkflowProcessInstanceImpl) instance).getNodeInstances();
    assertNotNull(activeNodes);
    assertEquals(1, activeNodes.size());
    NodeInstance node = activeNodes.iterator().next();
    assertNotNull(node);
    assertTrue(node instanceof WorkItemNodeInstance);
    Long workItemId = ((WorkItemNodeInstance) node).getWorkItemId();
    assertNotNull(workItemId);
    UserTaskInstanceDesc userTask = runtimeDataService.getTaskByWorkItemId(workItemId);
    assertNotNull(userTask);
    List<TaskEvent> auditTasks = runtimeDataService.getTaskEvents(userTask.getTaskId(), new QueryFilter());
    assertNotNull(auditTasks);
    assertEquals(1, auditTasks.size());
    assertEquals(TaskEvent.TaskEventType.ADDED, auditTasks.get(0).getType());
    userTaskService.start(userTask.getTaskId(), "salaboy");
    auditTasks = runtimeDataService.getTaskEvents(userTask.getTaskId(), new QueryFilter());
    assertNotNull(auditTasks);
    assertEquals(2, auditTasks.size());
    assertEquals(TaskEvent.TaskEventType.ADDED, auditTasks.get(0).getType());
    assertEquals(TaskEvent.TaskEventType.STARTED, auditTasks.get(1).getType());
    QueryFilter filter = new QueryFilter();
    filter.setFilterParams("t.type = :type ");
    filter.setParams(Collections.singletonMap("type", TaskEvent.TaskEventType.COMPLETED));
    auditTasks = runtimeDataService.getTaskEvents(userTask.getTaskId(), filter);
    assertNotNull(auditTasks);
    assertEquals(0, auditTasks.size());
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
Also used : QueryFilter(org.kie.internal.query.QueryFilter) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) TaskEvent(org.kie.internal.task.api.model.TaskEvent) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) NodeInstance(org.kie.api.runtime.process.NodeInstance) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 12 with TaskEvent

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

the class UserTaskServiceImplTest method testTaskOperationWithUserOrWithIdentityProvider.

@Test
public void testTaskOperationWithUserOrWithIdentityProvider() {
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    assertNotNull(processInstanceId);
    ProcessInstance instance = processService.getProcessInstance(processInstanceId);
    assertNotNull(instance);
    List<Long> taskIds = runtimeDataService.getTasksByProcessInstanceId(processInstanceId);
    assertNotNull(taskIds);
    assertEquals(1, taskIds.size());
    Long taskId = taskIds.get(0);
    userTaskService.start(taskId, "salaboy");
    List<TaskEvent> auditTasks = runtimeDataService.getTaskEvents(taskId, new QueryFilter());
    assertNotNull(auditTasks);
    assertEquals(2, auditTasks.size());
    assertEquals(TaskEvent.TaskEventType.ADDED, auditTasks.get(0).getType());
    assertEquals("org.jbpm.writedocument", auditTasks.get(0).getUserId());
    assertEquals(TaskEvent.TaskEventType.STARTED, auditTasks.get(1).getType());
    assertEquals("salaboy", auditTasks.get(1).getUserId());
    identityProvider.setName("salaboy");
    userTaskService.stop(taskId, null);
    auditTasks = runtimeDataService.getTaskEvents(taskId, new QueryFilter());
    assertNotNull(auditTasks);
    assertEquals(3, auditTasks.size());
    assertEquals(TaskEvent.TaskEventType.ADDED, auditTasks.get(0).getType());
    assertEquals("org.jbpm.writedocument", auditTasks.get(0).getUserId());
    assertEquals(TaskEvent.TaskEventType.STARTED, auditTasks.get(1).getType());
    assertEquals("salaboy", auditTasks.get(1).getUserId());
    assertEquals(TaskEvent.TaskEventType.STOPPED, auditTasks.get(2).getType());
    assertEquals("salaboy", auditTasks.get(2).getUserId());
    Map<String, Object> params = new HashMap<>();
    params.put("test", "value");
    userTaskService.saveContent(taskId, params);
    auditTasks = runtimeDataService.getTaskEvents(taskId, new QueryFilter());
    assertNotNull(auditTasks);
    assertEquals(4, auditTasks.size());
    assertEquals(TaskEvent.TaskEventType.ADDED, auditTasks.get(0).getType());
    assertEquals("org.jbpm.writedocument", auditTasks.get(0).getUserId());
    assertEquals(TaskEvent.TaskEventType.STARTED, auditTasks.get(1).getType());
    assertEquals("salaboy", auditTasks.get(1).getUserId());
    assertEquals(TaskEvent.TaskEventType.STOPPED, auditTasks.get(2).getType());
    assertEquals("salaboy", auditTasks.get(2).getUserId());
    assertEquals(TaskEvent.TaskEventType.UPDATED, auditTasks.get(3).getType());
    assertEquals("salaboy", auditTasks.get(3).getUserId());
    identityProvider.setName("testUser");
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
Also used : QueryFilter(org.kie.internal.query.QueryFilter) HashMap(java.util.HashMap) TaskEvent(org.kie.internal.task.api.model.TaskEvent) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 13 with TaskEvent

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

the class UserTaskAdminServiceImplTest method testAddBusinessAdmins.

@Test
public void testAddBusinessAdmins() {
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    Assertions.assertThat(processInstanceId).isNotNull();
    List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter());
    Assertions.assertThat(tasks).hasSize(1);
    TaskSummary task = tasks.get(0);
    userTaskService.release(task.getId(), "salaboy");
    tasks = runtimeDataService.getTasksAssignedAsBusinessAdministrator("salaboy", new QueryFilter());
    Assertions.assertThat(tasks).hasSize(0);
    userTaskAdminService.addBusinessAdmins(task.getId(), false, factory.newUser("salaboy"));
    List<TaskEvent> events = runtimeDataService.getTaskEvents(task.getId(), new QueryFilter());
    Assertions.assertThat(events).hasSize(3);
    TaskEvent updatedEvent = events.get(2);
    Assertions.assertThat(updatedEvent.getMessage()).isEqualTo("Business administrators [salaboy] have been added");
    tasks = runtimeDataService.getTasksAssignedAsBusinessAdministrator("salaboy", new QueryFilter());
    Assertions.assertThat(tasks).hasSize(1);
    tasks = runtimeDataService.getTasksAssignedAsBusinessAdministrator("Administrator", new QueryFilter());
    Assertions.assertThat(tasks).hasSize(1);
    userTaskAdminService.addBusinessAdmins(task.getId(), true, factory.newUser("salaboy"));
    tasks = runtimeDataService.getTasksAssignedAsBusinessAdministrator("salaboy", new QueryFilter());
    Assertions.assertThat(tasks).hasSize(1);
    tasks = runtimeDataService.getTasksAssignedAsBusinessAdministrator("Administrator", new QueryFilter());
    Assertions.assertThat(tasks).hasSize(0);
}
Also used : 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)

Example 14 with TaskEvent

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

the class UserTaskAdminServiceImplTest method testAddExcludedOwners.

@Test
public void testAddExcludedOwners() {
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    Assertions.assertThat(processInstanceId).isNotNull();
    List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter());
    Assertions.assertThat(tasks).hasSize(1);
    TaskSummary task = tasks.get(0);
    userTaskService.release(task.getId(), "salaboy");
    userTaskAdminService.addExcludedOwners(task.getId(), false, factory.newUser("salaboy"));
    List<TaskEvent> events = runtimeDataService.getTaskEvents(task.getId(), new QueryFilter());
    Assertions.assertThat(events).hasSize(3);
    TaskEvent updatedEvent = events.get(2);
    Assertions.assertThat(updatedEvent.getMessage()).isEqualTo("Excluded owners [salaboy] have been added");
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter());
    Assertions.assertThat(tasks).hasSize(0);
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
    Assertions.assertThat(tasks).hasSize(0);
    userTaskAdminService.addExcludedOwners(task.getId(), true, factory.newUser("john"));
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter());
    Assertions.assertThat(tasks).hasSize(1);
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
    Assertions.assertThat(tasks).hasSize(0);
}
Also used : 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)

Example 15 with TaskEvent

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

the class UserTaskAdminServiceImplTest method testAddPotentialOwners.

@Test
public void testAddPotentialOwners() {
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    Assertions.assertThat(processInstanceId).isNotNull();
    List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter());
    Assertions.assertThat(tasks).hasSize(1);
    TaskSummary task = tasks.get(0);
    userTaskService.release(task.getId(), "salaboy");
    userTaskAdminService.addPotentialOwners(task.getId(), false, factory.newUser("john"));
    List<TaskEvent> events = runtimeDataService.getTaskEvents(task.getId(), new QueryFilter());
    Assertions.assertThat(events).hasSize(3);
    TaskEvent updatedEvent = events.get(2);
    Assertions.assertThat(updatedEvent.getMessage()).isEqualTo("Potential owners [john] have been added");
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter());
    Assertions.assertThat(tasks).hasSize(1);
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
    Assertions.assertThat(tasks).hasSize(1);
    userTaskAdminService.addPotentialOwners(task.getId(), true, factory.newUser("john"));
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter());
    Assertions.assertThat(tasks).hasSize(0);
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
    Assertions.assertThat(tasks).hasSize(1);
}
Also used : 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