Search in sources :

Example 76 with QueryFilter

use of org.kie.internal.query.QueryFilter in project jbpm by kiegroup.

the class ClientEjbTimerServiceTest method testStartProcessWithHTDeadline.

@Test
public void testStartProcessWithHTDeadline() throws InterruptedException {
    assertNotNull(deploymentService);
    KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    assertNotNull(processService);
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "htdeadlinetest");
    List<TaskSummary> krisTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("krisv", new QueryFilter());
    assertEquals(1, krisTasks.size());
    List<TaskSummary> johnTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
    assertEquals(0, johnTasks.size());
    List<TaskSummary> maryTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("mary", new QueryFilter());
    assertEquals(0, maryTasks.size());
    // now wait for 2 seconds for first reassignment
    Thread.sleep(3000);
    krisTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("krisv", new QueryFilter());
    assertEquals(0, krisTasks.size());
    johnTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
    assertEquals(1, johnTasks.size());
    maryTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("mary", new QueryFilter());
    assertEquals(0, maryTasks.size());
    userTaskService.start(johnTasks.get(0).getId(), "john");
    // now wait for 2 more seconds for second reassignment
    Thread.sleep(2000);
    krisTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("krisv", new QueryFilter());
    assertEquals(0, krisTasks.size());
    johnTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
    assertEquals(1, johnTasks.size());
    maryTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("mary", new QueryFilter());
    assertEquals(0, maryTasks.size());
    // now wait for 1 seconds to make sure that reassignment did not happen any more since task was already started
    Thread.sleep(3000);
    krisTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("krisv", new QueryFilter());
    assertEquals(0, krisTasks.size());
    johnTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
    assertEquals(0, johnTasks.size());
    maryTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("mary", new QueryFilter());
    assertEquals(1, maryTasks.size());
    userTaskService.start(maryTasks.get(0).getId(), "mary");
    userTaskService.complete(maryTasks.get(0).getId(), "mary", null);
    // now wait for 2 seconds to make sure that reassignment did not happen any more since task was completed
    Thread.sleep(2000);
    ProcessInstance processInstance = processService.getProcessInstance(processInstanceId);
    assertNull(processInstance);
    processInstanceId = null;
}
Also used : QueryFilter(org.kie.internal.query.QueryFilter) TaskSummary(org.kie.api.task.model.TaskSummary) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 77 with QueryFilter

use of org.kie.internal.query.QueryFilter in project jbpm by kiegroup.

the class LocalTaskAuditWithDeadlineTest method testDelayedReassignmentOnDeadline.

@Test(timeout = 10000)
public void testDelayedReassignmentOnDeadline() throws Exception {
    CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(1, true, false);
    addCountDownListner(countDownListener);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("now", new Date());
    Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithReassignment));
    Task task = (InternalTask) TaskFactory.evalTask(reader, vars);
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    taskService.claim(taskId, "Tony Stark");
    task = taskService.getTaskById(taskId);
    List<OrganizationalEntity> potentialOwners = (List<OrganizationalEntity>) task.getPeopleAssignments().getPotentialOwners();
    List<String> ids = new ArrayList<String>(potentialOwners.size());
    for (OrganizationalEntity entity : potentialOwners) {
        ids.add(entity.getId());
    }
    assertTrue(ids.contains("Tony Stark"));
    assertTrue(ids.contains("Luke Cage"));
    List<AuditTask> tasks = taskAuditService.getAllAuditTasks(new QueryFilter());
    assertEquals(1, tasks.size());
    AuditTask auditTask = tasks.get(0);
    assertEquals(Status.Reserved.toString(), auditTask.getStatus());
    assertEquals("Tony Stark", auditTask.getActualOwner());
    // should have re-assigned by now
    countDownListener.waitTillCompleted();
    task = taskService.getTaskById(taskId);
    assertNull(task.getTaskData().getActualOwner());
    assertEquals(Status.Ready, task.getTaskData().getStatus());
    potentialOwners = (List<OrganizationalEntity>) task.getPeopleAssignments().getPotentialOwners();
    ids = new ArrayList<String>(potentialOwners.size());
    for (OrganizationalEntity entity : potentialOwners) {
        ids.add(entity.getId());
    }
    assertTrue(ids.contains("Bobba Fet"));
    assertTrue(ids.contains("Jabba Hutt"));
    tasks = taskAuditService.getAllAuditTasks(new QueryFilter());
    assertEquals(1, tasks.size());
    auditTask = tasks.get(0);
    assertEquals(Status.Ready.toString(), auditTask.getStatus());
    assertEquals("", auditTask.getActualOwner());
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) AuditTask(org.kie.internal.task.api.AuditTask) CountDownTaskEventListener(org.jbpm.services.task.util.CountDownTaskEventListener) InputStreamReader(java.io.InputStreamReader) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) InternalTask(org.kie.internal.task.api.model.InternalTask) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Date(java.util.Date) AuditTask(org.kie.internal.task.api.AuditTask) QueryFilter(org.kie.internal.query.QueryFilter) ArrayList(java.util.ArrayList) List(java.util.List) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Example 78 with QueryFilter

use of org.kie.internal.query.QueryFilter in project jbpm by kiegroup.

the class TaskAuditBaseTest method testGroupTasks.

@Test
public void testGroupTasks() {
    Task task = new TaskFluent().setName("This is my task name").addPotentialUser("salaboy").addPotentialUser("krisv").addPotentialGroup("Knights Templer").setAdminUser("Administrator").getTask();
    taskService.addTask(task, new HashMap<String, Object>());
    List<TaskSummary> allGroupTasks = taskService.getTasksAssignedAsPotentialOwner("salaboy", null, null, null);
    assertEquals(1, allGroupTasks.size());
    assertTrue(allGroupTasks.get(0).getStatusId().equals("Ready"));
    List<AuditTask> allGroupAuditTasksByUser = taskAuditService.getAllGroupAuditTasksByUser("salaboy", new QueryFilter(0, 0));
    assertEquals(1, allGroupAuditTasksByUser.size());
    assertTrue(allGroupAuditTasksByUser.get(0).getStatus().equals("Ready"));
}
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) TaskSummary(org.kie.api.task.model.TaskSummary) AuditTask(org.kie.internal.task.api.AuditTask) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Example 79 with QueryFilter

use of org.kie.internal.query.QueryFilter in project jbpm by kiegroup.

the class TaskAuditBaseTest method testLifeCycleWithBAM.

@Test
public void testLifeCycleWithBAM() {
    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<AuditTask> allGroupAuditTasks = taskAuditService.getAllGroupAuditTasksByUser("Knights Templer", new QueryFilter());
    assertEquals(1, allGroupAuditTasks.size());
    assertTrue(allGroupAuditTasks.get(0).getStatus().equals("Ready"));
    assertBAMTask(taskId, "Ready");
    taskService.claim(taskId, "Darth Vader");
    allGroupAuditTasks = taskAuditService.getAllAuditTasksByUser("Darth Vader", new QueryFilter());
    assertEquals(1, allGroupAuditTasks.size());
    assertEquals("Reserved", allGroupAuditTasks.get(0).getStatus());
    assertBAMTask(taskId, "Reserved");
    taskService.release(taskId, "Darth Vader");
    allGroupAuditTasks = taskAuditService.getAllGroupAuditTasksByUser("Knights Templer", new QueryFilter());
    assertEquals(1, allGroupAuditTasks.size());
    assertTrue(allGroupAuditTasks.get(0).getStatus().equals("Ready"));
    assertBAMTask(taskId, "Ready");
    taskService.claim(taskId, "Darth Vader");
    allGroupAuditTasks = taskAuditService.getAllAuditTasksByUser("Darth Vader", new QueryFilter());
    ;
    assertEquals(1, allGroupAuditTasks.size());
    assertEquals("Reserved", allGroupAuditTasks.get(0).getStatus());
    assertBAMTask(taskId, "Reserved");
    // Go straight from Ready to Inprogress
    taskService.start(taskId, "Darth Vader");
    allGroupAuditTasks = taskAuditService.getAllAuditTasksByUser("Darth Vader", new QueryFilter());
    ;
    assertEquals(1, allGroupAuditTasks.size());
    assertEquals("InProgress", allGroupAuditTasks.get(0).getStatus());
    assertBAMTask(taskId, "InProgress");
    taskService.stop(taskId, "Darth Vader");
    allGroupAuditTasks = taskAuditService.getAllAuditTasksByUser("Darth Vader", new QueryFilter());
    ;
    assertEquals(1, allGroupAuditTasks.size());
    assertEquals("Reserved", allGroupAuditTasks.get(0).getStatus());
    assertBAMTask(taskId, "Reserved");
    taskService.start(taskId, "Darth Vader");
    allGroupAuditTasks = taskAuditService.getAllAuditTasksByUser("Darth Vader", new QueryFilter());
    ;
    assertEquals(1, allGroupAuditTasks.size());
    assertEquals("InProgress", allGroupAuditTasks.get(0).getStatus());
    assertBAMTask(taskId, "InProgress");
    // Check is Complete
    taskService.complete(taskId, "Darth Vader", null);
    allGroupAuditTasks = taskAuditService.getAllAuditTasksByUser("Darth Vader", new QueryFilter());
    ;
    assertEquals(1, allGroupAuditTasks.size());
    assertEquals("Completed", allGroupAuditTasks.get(0).getStatus());
    assertBAMTask(taskId, "Completed");
    List<TaskEvent> taskEvents = taskAuditService.getAllTaskEvents(taskId, new QueryFilter());
    Assertions.assertThat(taskEvents).hasSize(8);
    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.RELEASED);
    Assertions.assertThat(taskEvents.get(2).getUserId()).isEqualTo("Darth Vader");
    Assertions.assertThat(taskEvents.get(3).getType()).isEqualTo(TaskEventType.CLAIMED);
    Assertions.assertThat(taskEvents.get(3).getUserId()).isEqualTo("Darth Vader");
    Assertions.assertThat(taskEvents.get(4).getType()).isEqualTo(TaskEventType.STARTED);
    Assertions.assertThat(taskEvents.get(4).getUserId()).isEqualTo("Darth Vader");
    Assertions.assertThat(taskEvents.get(5).getType()).isEqualTo(TaskEventType.STOPPED);
    Assertions.assertThat(taskEvents.get(5).getUserId()).isEqualTo("Darth Vader");
    Assertions.assertThat(taskEvents.get(6).getType()).isEqualTo(TaskEventType.STARTED);
    Assertions.assertThat(taskEvents.get(6).getUserId()).isEqualTo("Darth Vader");
    Assertions.assertThat(taskEvents.get(7).getType()).isEqualTo(TaskEventType.COMPLETED);
    Assertions.assertThat(taskEvents.get(7).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) TaskEvent(org.kie.internal.task.api.model.TaskEvent) AuditTask(org.kie.internal.task.api.AuditTask) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Example 80 with QueryFilter

use of org.kie.internal.query.QueryFilter in project jbpm by kiegroup.

the class TaskAuditBaseTest method testNameUpdate.

private void testNameUpdate(String oldName, String newName, boolean changeExpected) {
    Task task = new TaskFluent().setName(oldName).setAdminUser("Administrator").getTask();
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    List<I18NText> taskNames = new ArrayList<I18NText>();
    taskNames.add(new I18NTextImpl("", newName));
    taskService.setTaskNames(taskId, taskNames);
    task = taskService.getTaskById(taskId);
    Assertions.assertThat(task.getName()).isEqualTo(newName);
    List<AuditTask> auditTasks = taskAuditService.getAllAuditTasks(new QueryFilter());
    Assertions.assertThat(auditTasks).hasSize(1);
    Assertions.assertThat(auditTasks.get(0).getName()).isEqualTo(newName);
    List<TaskEvent> taskEvents = taskAuditService.getAllTaskEvents(taskId, new QueryFilter());
    if (changeExpected) {
        Assertions.assertThat(taskEvents).hasSize(2);
        Assertions.assertThat(taskEvents.get(1).getMessage()).contains(String.valueOf(oldName), String.valueOf(newName));
    } else {
        Assertions.assertThat(taskEvents).hasSize(1);
    }
}
Also used : Task(org.kie.api.task.model.Task) AuditTask(org.kie.internal.task.api.AuditTask) I18NText(org.kie.api.task.model.I18NText) TaskFluent(org.jbpm.services.task.utils.TaskFluent) ArrayList(java.util.ArrayList) AuditTask(org.kie.internal.task.api.AuditTask) QueryFilter(org.kie.internal.query.QueryFilter) I18NTextImpl(org.jbpm.services.task.impl.model.I18NTextImpl) TaskEvent(org.kie.internal.task.api.model.TaskEvent)

Aggregations

QueryFilter (org.kie.internal.query.QueryFilter)149 Test (org.junit.Test)127 TaskSummary (org.kie.api.task.model.TaskSummary)122 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)52 HashMap (java.util.HashMap)47 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)31 KModuleDeploymentServiceTest (org.jbpm.kie.services.test.KModuleDeploymentServiceTest)26 AuditTask (org.kie.internal.task.api.AuditTask)25 ArrayList (java.util.ArrayList)24 QueryContext (org.kie.api.runtime.query.QueryContext)24 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)23 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)21 Task (org.kie.api.task.model.Task)19 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)18 TaskFluent (org.jbpm.services.task.utils.TaskFluent)17 TaskEvent (org.kie.internal.task.api.model.TaskEvent)17 HumanTaskServicesBaseTest (org.jbpm.services.task.HumanTaskServicesBaseTest)14 Status (org.kie.api.task.model.Status)13 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)11 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)10