Search in sources :

Example 56 with TaskSummary

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

the class TaskQueryBuilderLocalTest method testGetTasksByVariousFields.

@Test
public void testGetTasksByVariousFields() {
    Task[] tasks = new Task[12];
    List<Long> workItemIds = new ArrayList<Long>();
    List<Long> procInstIds = new ArrayList<Long>();
    List<Long> taskIds = new ArrayList<Long>();
    List<String> busAdmins = new ArrayList<String>();
    List<String> potOwners = new ArrayList<String>();
    List<Status> statuses = new ArrayList<Status>();
    statuses.add(Status.Reserved);
    TaskImpl taskImpl;
    Long firstTaskId;
    {
        long workItemId = 23;
        long procInstId = 101;
        String busAdmin = "Wintermute";
        String potOwner = "Maelcum";
        taskImpl = addTask(workItemId, procInstId, busAdmin, potOwner, "This is my task name", null);
        firstTaskId = taskImpl.getId();
        taskIds.add(firstTaskId);
        assertEquals(potOwner, taskImpl.getTaskData().getActualOwner().getId());
        tasks[0] = taskImpl;
        procInstIds.add(procInstId);
        workItemIds.add(workItemId);
        busAdmins.add(busAdmin);
        potOwners.add(potOwner);
    }
    List<TaskSummary> results = taskService.taskSummaryQuery(stakeHolder).build().getResultList();
    assertFalse("No tasks retrieved!", results.isEmpty());
    results = taskService.taskSummaryQuery(stakeHolder).workItemId(getUnboxedArray(workItemIds)).build().getResultList();
    assertEquals("List of tasks: work item id", 1, results.size());
    {
        long workItemId = 25;
        long procInstId = 103;
        String busAdmin = "Neuromancer";
        String potOwner = "Hideo";
        taskImpl = addTask(workItemId, procInstId, busAdmin, potOwner, "This is my task name", null);
        taskIds.add(taskImpl.getId());
        assertEquals(potOwner, taskImpl.getTaskData().getActualOwner().getId());
        // start task
        taskService.start(taskImpl.getId(), potOwner);
        tasks[1] = (Task) taskService.getTaskById(taskImpl.getId());
        statuses.add(tasks[1].getTaskData().getStatus());
        procInstIds.add(procInstId);
        workItemIds.add(workItemId);
        busAdmins.add(busAdmin);
        potOwners.add(potOwner);
    }
    {
        // Add one more task, just to make sure things are working well
        long workItemId = 57;
        long procInstId = 111;
        String busAdmin = "reviewer";
        String potOwner = "translator";
        String deploymentId = "armitage";
        String name = "Koude Bevel";
        taskImpl = addTask(workItemId, procInstId, busAdmin, potOwner, name, deploymentId);
        assertEquals(potOwner, taskImpl.getTaskData().getActualOwner().getId());
        taskService.start(taskImpl.getId(), potOwner);
        taskService.fail(taskImpl.getId(), busAdmin, null);
    }
    // everything
    results = taskService.taskSummaryQuery(stakeHolder).build().getResultList();
    assertEquals("List of tasks: everything", 3, results.size());
    testOrderByTaskIdAscending(results);
    // max results
    results = taskService.taskSummaryQuery(stakeHolder).maxResults(2).build().getResultList();
    assertEquals("List of tasks: max results", 2, results.size());
    testOrderByTaskIdAscending(results);
    assertEquals("Did not order when returning tasks (first task id: " + results.get(0).getId(), firstTaskId.longValue(), results.get(0).getId().longValue());
    // single param tests
    results = taskService.taskSummaryQuery(stakeHolder).workItemId(getUnboxedArray(workItemIds)).build().getResultList();
    assertEquals("List of tasks: work item ids", 2, results.size());
    testOrderByTaskIdAscending(results);
    results = taskService.taskSummaryQuery(stakeHolder).taskId(getUnboxedArray(taskIds)).build().getResultList();
    assertEquals("List of tasks: task ids", 2, results.size());
    testOrderByTaskIdAscending(results);
    results = taskService.taskSummaryQuery(stakeHolder).processInstanceId(getUnboxedArray(procInstIds)).build().getResultList();
    assertEquals("List of tasks: process instance ids", 2, results.size());
    testOrderByTaskIdAscending(results);
    results = taskService.taskSummaryQuery(stakeHolder).businessAdmin(busAdmins.toArray(new String[0])).build().getResultList();
    assertEquals("List of tasks: bus admins", 2, results.size());
    testOrderByTaskIdAscending(results);
    results = taskService.taskSummaryQuery(stakeHolder).potentialOwner(potOwners.toArray(new String[0])).build().getResultList();
    assertEquals("List of tasks: pot owners", 2, results.size());
    testOrderByTaskIdAscending(results);
    results = taskService.taskSummaryQuery(stakeHolder).actualOwner(potOwners.toArray(new String[0])).build().getResultList();
    assertEquals("List of tasks: task owners", 2, results.size());
    testOrderByTaskIdAscending(results);
    results = taskService.taskSummaryQuery(stakeHolder).status(statuses.toArray(new Status[0])).build().getResultList();
    assertEquals("List of tasks: status", 2, results.size());
    testOrderByTaskIdAscending(results);
    // work item id and/or task id
    List<Long> testLongList = new ArrayList<Long>();
    testLongList.add(workItemIds.get(0));
    List<Long> testLongListTwo = new ArrayList<Long>();
    testLongListTwo.add(taskIds.get(1));
    results = taskService.taskSummaryQuery(stakeHolder).and().workItemId(getUnboxedArray(testLongList)).taskId(getUnboxedArray(testLongListTwo)).build().getResultList();
    assertEquals("List of tasks", 0, results.size());
    results = taskService.taskSummaryQuery(stakeHolder).or().workItemId(getUnboxedArray(testLongList)).taskId(getUnboxedArray(testLongListTwo)).build().getResultList();
    assertEquals("List of tasks", 2, results.size());
    testOrderByTaskIdAscending(results);
    // task id and/or process instance id
    testLongList.clear();
    testLongList.add(procInstIds.get(1));
    results = taskService.taskSummaryQuery(stakeHolder).or().taskId(getUnboxedArray(testLongListTwo)).processInstanceId(getUnboxedArray(testLongList)).build().getResultList();
    assertEquals("List of tasks", 1, results.size());
    testOrderByTaskIdAscending(results);
    results = taskService.taskSummaryQuery(stakeHolder).and().taskId(getUnboxedArray(testLongListTwo)).processInstanceId(getUnboxedArray(testLongList)).build().getResultList();
    assertEquals("List of tasks", 1, results.size());
    testOrderByTaskIdAscending(results);
    // process instance id and/or bus admin
    List<String> testStringList = new ArrayList<String>();
    testStringList.add(busAdmins.get(0));
    results = taskService.taskSummaryQuery(stakeHolder).and().processInstanceId(getUnboxedArray(testLongList)).businessAdmin(testStringList.toArray(new String[0])).build().getResultList();
    assertEquals("List of tasks", 0, results.size());
    results = taskService.taskSummaryQuery(stakeHolder).or().processInstanceId(getUnboxedArray(testLongList)).businessAdmin(testStringList.toArray(new String[0])).build().getResultList();
    assertEquals("List of tasks", 2, results.size());
    testOrderByTaskIdAscending(results);
    // bus admin and/or pot owner
    testStringList.clear();
    testStringList.add(busAdmins.get(1));
    List<String> testStringListTwo = new ArrayList<String>();
    testStringListTwo.add(potOwners.get(0));
    results = taskService.taskSummaryQuery(stakeHolder).and().businessAdmin(testStringList.toArray(new String[0])).potentialOwner(testStringListTwo.toArray(new String[0])).build().getResultList();
    assertEquals("List of tasks", 0, results.size());
    results = taskService.taskSummaryQuery(stakeHolder).or().businessAdmin(testStringList.toArray(new String[0])).potentialOwner(testStringListTwo.toArray(new String[0])).build().getResultList();
    assertEquals("List of tasks", 2, results.size());
    testOrderByTaskIdAscending(results);
    // pot owner and/or task owner
    testStringList.clear();
    testStringList.add(tasks[1].getTaskData().getActualOwner().getId());
    results = taskService.taskSummaryQuery(stakeHolder).and().potentialOwner(testStringListTwo.toArray(new String[0])).actualOwner(testStringList.toArray(new String[0])).build().getResultList();
    assertEquals("List of tasks", 0, results.size());
    results = taskService.taskSummaryQuery(stakeHolder).or().potentialOwner(testStringListTwo.toArray(new String[0])).actualOwner(testStringList.toArray(new String[0])).build().getResultList();
    assertEquals("List of tasks", 2, results.size());
    testOrderByTaskIdAscending(results);
    // task owner and/or status
    List<Status> testStatusList = new ArrayList<Status>();
    testStatusList.add(statuses.get(0));
    results = taskService.taskSummaryQuery(stakeHolder).and().actualOwner(testStringList.toArray(new String[0])).status(testStatusList.toArray(new Status[0])).build().getResultList();
    assertEquals("List of tasks", 0, results.size());
    results = taskService.taskSummaryQuery(stakeHolder).or().actualOwner(testStringList.toArray(new String[0])).status(testStatusList.toArray(new Status[0])).build().getResultList();
    assertEquals("List of tasks", 2, results.size());
    testOrderByTaskIdAscending(results);
}
Also used : Status(org.kie.api.task.model.Status) Task(org.kie.api.task.model.Task) TaskImpl(org.jbpm.services.task.impl.model.TaskImpl) ArrayList(java.util.ArrayList) TaskSummary(org.kie.api.task.model.TaskSummary) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Example 57 with TaskSummary

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

the class TaskQueryBuilderLocalTest method testGetTasksByVariousFieldsWithUserGroupCallbackAdmin.

@Test
public void testGetTasksByVariousFieldsWithUserGroupCallbackAdmin() {
    String potOwner = "Administrator";
    List<String> busAdmins = new ArrayList<String>();
    busAdmins.add(potOwner);
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { " + "businessAdministrators = [new Group('Administrators')]," + "potentialOwners = [new Group('Crusaders')]" + " }),";
    str += "name =  'This is my task name' })";
    Task task = TaskFactory.evalTask(new StringReader(str));
    ((InternalTaskData) task.getTaskData()).setWorkItemId(1);
    ((InternalTaskData) task.getTaskData()).setProcessInstanceId(1);
    taskService.addTask(task, new HashMap<String, Object>());
    List<TaskSummary> results = taskService.taskSummaryQuery(potOwner).businessAdmin(busAdmins.toArray(new String[0])).build().getResultList();
    assertNotNull(results);
    assertEquals(1, results.size());
}
Also used : Task(org.kie.api.task.model.Task) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) TaskSummary(org.kie.api.task.model.TaskSummary) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Example 58 with TaskSummary

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

the class TaskQueryBuilderLocalTest method testGetTasksByVariousFieldsWithUserGroupCallbackAdminByParams.

@Test
public void testGetTasksByVariousFieldsWithUserGroupCallbackAdminByParams() {
    String busAdmin = "Administrator";
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { " + "businessAdministrators = [new Group('Administrators')]," + "potentialOwners = [new Group('Crusaders')]" + " }),";
    str += "name = 'This is my task name' })";
    Task task = TaskFactory.evalTask(new StringReader(str));
    ((InternalTaskData) task.getTaskData()).setWorkItemId(1);
    ((InternalTaskData) task.getTaskData()).setProcessInstanceId(1);
    taskService.addTask(task, new HashMap<String, Object>());
    List<TaskSummary> results = taskService.taskSummaryQuery("Crusaders").businessAdmin(busAdmin).build().getResultList();
    assertNotNull(results);
    assertEquals(1, results.size());
}
Also used : Task(org.kie.api.task.model.Task) StringReader(java.io.StringReader) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) TaskSummary(org.kie.api.task.model.TaskSummary) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Example 59 with TaskSummary

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

the class TaskQueryBuilderLocalTest method testGetTasksByVariousFieldsWithUserGroupCallback.

@Test
public void testGetTasksByVariousFieldsWithUserGroupCallback() {
    String potOwner = "Bobba Fet";
    List<String> potOwners = new ArrayList<String>();
    potOwners.add(potOwner);
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { " + "businessAdministrators = [new Group('Administrators')]," + "potentialOwners = [new Group('Crusaders')]" + " }),";
    str += "name = 'This is my task name' })";
    Task task = TaskFactory.evalTask(new StringReader(str));
    ((InternalTaskData) task.getTaskData()).setWorkItemId(1);
    ((InternalTaskData) task.getTaskData()).setProcessInstanceId(1);
    taskService.addTask(task, new HashMap<String, Object>());
    List<TaskSummary> results = taskService.taskSummaryQuery("Administrator").potentialOwner(potOwner).build().getResultList();
    assertNotNull(results);
    assertEquals(1, results.size());
    TaskSummary resultTask = results.get(0);
    // "Wintermute" does not have the proper permissions
    results = taskService.taskSummaryQuery("Wintermute").potentialOwner(potOwner).build().getResultList();
    assertEquals(0, results.size());
}
Also used : Task(org.kie.api.task.model.Task) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) TaskSummary(org.kie.api.task.model.TaskSummary) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Example 60 with TaskSummary

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

the class LifeCycleBaseTest method testExitNotAvailableToUsers.

@Test
public void testExitNotAvailableToUsers() {
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { skipable = false} ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet')], businessAdministrators = [ new User('Administrator')] }),";
    str += "name = 'This is my task name' })";
    Task task = TaskFactory.evalTask(new StringReader(str));
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    task = taskService.getTaskById(taskId);
    assertEquals(Status.Reserved, task.getTaskData().getStatus());
    taskService.exit(taskId, "Administrator");
    Task task1 = taskService.getTaskById(taskId);
    assertEquals(Status.Exited, task1.getTaskData().getStatus());
    List<TaskSummary> exitedTasks = taskService.getTasksAssignedAsPotentialOwner("Bobba Fet", "en-UK");
    assertEquals(0, exitedTasks.size());
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) StringReader(java.io.StringReader) TaskSummary(org.kie.api.task.model.TaskSummary) 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