Search in sources :

Example 6 with TaskSummary

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

the class TaskAuditBaseTest method testExitBeforeClaim.

@Test
public void testExitBeforeClaim() {
    Task task = new TaskFluent().setName("This is my task name 2").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.exit(taskId, "Administrator");
    List<AuditTask> allHistoryAuditTasks = taskAuditService.getAllAuditTasks(new QueryFilter(0, 0));
    assertEquals(1, allHistoryAuditTasks.size());
    allGroupAuditTasks = taskService.getTasksAssignedAsPotentialOwner("salaboy", null, null, null);
    assertEquals(0, allGroupAuditTasks.size());
}
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 7 with TaskSummary

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

the class TaskAuditBaseTest method testVariableIndexInputAndOutputWithCustomIdexer.

@Test
public void testVariableIndexInputAndOutputWithCustomIdexer() {
    Task task = new TaskFluent().setName("This is my task name").addPotentialGroup("Knights Templer").setAdminUser("Administrator").getTask();
    Map<String, Object> inputVariables = new HashMap<String, Object>();
    inputVariables.put("firstVariable", "string content");
    inputVariables.put("person", new Person("john", 25));
    taskService.addTask(task, inputVariables);
    long taskId = task.getId();
    List<TaskSummary> allGroupAuditTasks = taskService.getTasksAssignedAsPotentialOwner("salaboy", null, null, null);
    assertEquals(1, allGroupAuditTasks.size());
    assertTrue(allGroupAuditTasks.get(0).getStatusId().equals("Ready"));
    List<TaskVariable> inputVars = taskAuditService.taskVariableQuery().taskId(taskId).intersect().type(VariableType.INPUT).build().getResultList();
    assertNotNull(inputVars);
    assertEquals(3, inputVars.size());
    Map<String, String> vars = collectVariableNameAndValue(inputVars);
    assertTrue(vars.containsKey("firstVariable"));
    assertTrue(vars.containsKey("person.name"));
    assertTrue(vars.containsKey("person.age"));
    assertEquals("string content", vars.get("firstVariable"));
    assertEquals("john", vars.get("person.name"));
    assertEquals("25", vars.get("person.age"));
    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.start(taskId, "Darth Vader");
    Task task1 = taskService.getTaskById(taskId);
    assertEquals(Status.InProgress, task1.getTaskData().getStatus());
    assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
    Map<String, Object> outputVariables = new HashMap<String, Object>();
    outputVariables.put("reply", "updated content");
    outputVariables.put("person", new Person("mary", 28));
    // Check is Complete
    taskService.complete(taskId, "Darth Vader", outputVariables);
    List<TaskVariable> outputVars = taskAuditService.taskVariableQuery().taskId(taskId).intersect().type(VariableType.OUTPUT).build().getResultList();
    assertNotNull(outputVars);
    assertEquals(3, outputVars.size());
    Map<String, String> outvars = collectVariableNameAndValue(outputVars);
    assertTrue(outvars.containsKey("reply"));
    assertTrue(vars.containsKey("person.name"));
    assertTrue(vars.containsKey("person.age"));
    assertEquals("updated content", outvars.get("reply"));
    assertEquals("mary", outvars.get("person.name"));
    assertEquals("28", outvars.get("person.age"));
}
Also used : Task(org.kie.api.task.model.Task) AuditTask(org.kie.internal.task.api.AuditTask) TaskFluent(org.jbpm.services.task.utils.TaskFluent) HashMap(java.util.HashMap) TaskVariable(org.kie.internal.task.api.TaskVariable) TaskSummary(org.kie.api.task.model.TaskSummary) Person(org.jbpm.services.task.audit.service.objects.Person) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Example 8 with TaskSummary

use of org.kie.api.task.model.TaskSummary 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 9 with TaskSummary

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

the class TaskAuditBaseTest method testOnlyActiveTasks.

@Test
public void testOnlyActiveTasks() {
    Task task = new TaskFluent().setName("This is my task name").addPotentialUser("salaboy").setAdminUser("Administrator").getTask();
    taskService.addTask(task, new HashMap<String, Object>());
    List<TaskSummary> allActiveTasks = taskService.getTasksAssignedAsPotentialOwner("salaboy", null, null, null);
    assertEquals(1, allActiveTasks.size());
    assertTrue(allActiveTasks.get(0).getStatusId().equals("Reserved"));
    QueryFilter queryFilter = new QueryFilter(0, 0);
    Map<String, Object> params = new HashMap<String, Object>();
    List<String> statuses = new ArrayList<String>();
    statuses.add(Status.Reserved.toString());
    params.put("statuses", statuses);
    queryFilter.setParams(params);
    List<AuditTask> allActiveAuditTasksByUser = taskAuditService.getAllAuditTasksByStatus("salaboy", queryFilter);
    assertEquals(1, allActiveAuditTasksByUser.size());
    assertTrue(allActiveAuditTasksByUser.get(0).getStatus().equals("Reserved"));
    statuses = new ArrayList<String>();
    statuses.add(Status.Completed.toString());
    params.put("statuses", statuses);
    queryFilter.setParams(params);
    allActiveAuditTasksByUser = taskAuditService.getAllAuditTasksByStatus("salaboy", queryFilter);
    assertEquals(0, allActiveAuditTasksByUser.size());
}
Also used : Task(org.kie.api.task.model.Task) AuditTask(org.kie.internal.task.api.AuditTask) TaskFluent(org.jbpm.services.task.utils.TaskFluent) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AuditTask(org.kie.internal.task.api.AuditTask) QueryFilter(org.kie.internal.query.QueryFilter) TaskSummary(org.kie.api.task.model.TaskSummary) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Example 10 with TaskSummary

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

the class TaskAuditBaseTest method testVariableIndexInputAndOutputWitlLongTextTrimmed.

@Test
public void testVariableIndexInputAndOutputWitlLongTextTrimmed() {
    System.setProperty("org.jbpm.task.var.log.length", "10");
    try {
        Task task = new TaskFluent().setName("This is my task name").addPotentialGroup("Knights Templer").setAdminUser("Administrator").getTask();
        Map<String, Object> inputVariables = new HashMap<String, Object>();
        inputVariables.put("firstVariable", "string content");
        inputVariables.put("number", 1234);
        taskService.addTask(task, inputVariables);
        long taskId = task.getId();
        List<TaskSummary> allGroupAuditTasks = taskService.getTasksAssignedAsPotentialOwner("salaboy", null, null, null);
        assertEquals(1, allGroupAuditTasks.size());
        assertTrue(allGroupAuditTasks.get(0).getStatusId().equals("Ready"));
        List<TaskVariable> inputVars = taskAuditService.taskVariableQuery().taskId(taskId).intersect().type(VariableType.INPUT).build().getResultList();
        assertNotNull(inputVars);
        assertEquals(2, inputVars.size());
        Map<String, String> vars = collectVariableNameAndValue(inputVars);
        assertTrue(vars.containsKey("firstVariable"));
        assertTrue(vars.containsKey("number"));
        // the variable was longer that 10 so it had to be trimmed
        assertEquals("string con", vars.get("firstVariable"));
        assertEquals("1234", vars.get("number"));
        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.start(taskId, "Darth Vader");
        Task task1 = taskService.getTaskById(taskId);
        assertEquals(Status.InProgress, task1.getTaskData().getStatus());
        assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
        String reply = "Just a short part of the reply";
        String veryLongReply = reply;
        for (int i = 0; i < 15; i++) {
            veryLongReply += reply;
        }
        Map<String, Object> outputVariables = new HashMap<String, Object>();
        outputVariables.put("reply", veryLongReply);
        outputVariables.put("age", 25);
        // Check is Complete
        taskService.complete(taskId, "Darth Vader", outputVariables);
        List<TaskVariable> outputVars = taskAuditService.taskVariableQuery().taskId(taskId).intersect().type(VariableType.OUTPUT).build().getResultList();
        assertNotNull(outputVars);
        assertEquals(2, outputVars.size());
        Map<String, String> outvars = collectVariableNameAndValue(outputVars);
        assertTrue(outvars.containsKey("reply"));
        assertTrue(outvars.containsKey("age"));
        assertEquals("Just a sho", outvars.get("reply"));
        assertEquals("25", outvars.get("age"));
    } finally {
        System.clearProperty("org.jbpm.task.var.log.length");
    }
}
Also used : Task(org.kie.api.task.model.Task) AuditTask(org.kie.internal.task.api.AuditTask) TaskFluent(org.jbpm.services.task.utils.TaskFluent) HashMap(java.util.HashMap) TaskVariable(org.kie.internal.task.api.TaskVariable) TaskSummary(org.kie.api.task.model.TaskSummary) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Aggregations

TaskSummary (org.kie.api.task.model.TaskSummary)371 Test (org.junit.Test)327 HashMap (java.util.HashMap)132 QueryFilter (org.kie.internal.query.QueryFilter)126 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)100 Task (org.kie.api.task.model.Task)91 ArrayList (java.util.ArrayList)87 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)86 KieSession (org.kie.api.runtime.KieSession)84 TaskService (org.kie.api.task.TaskService)66 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)58 StringReader (java.io.StringReader)55 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)49 QueryContext (org.kie.api.runtime.query.QueryContext)49 Status (org.kie.api.task.model.Status)47 InternalTask (org.kie.internal.task.api.model.InternalTask)47 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)41 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)38 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)36 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)28