use of org.kie.api.task.model.Status in project jbpm by kiegroup.
the class RuntimeDataServiceImpl method getTasksByVariable.
@Override
public List<TaskSummary> getTasksByVariable(String userId, String variableName, List<Status> statuses, QueryContext queryContext) {
TaskSummaryQueryBuilder queryBuilder = new TaskSummaryQueryBuilderImpl(userId, taskService).intersect();
addVariableNameAndVariableValueParameters(queryBuilder, variableName);
if (statuses != null && !statuses.isEmpty()) {
queryBuilder.status(statuses.toArray(new Status[statuses.size()]));
}
setQueryContextOptions(queryContext, queryBuilder);
return queryBuilder.build().getResultList();
}
use of org.kie.api.task.model.Status in project jbpm by kiegroup.
the class RuntimeDataServiceImpl method getTasksByVariableAndValue.
@Override
public List<TaskSummary> getTasksByVariableAndValue(String userId, String variableName, String variableValue, List<Status> statuses, QueryContext queryContext) {
TaskSummaryQueryBuilder queryBuilder = new TaskSummaryQueryBuilderImpl(userId, taskService).intersect();
addVariableNameAndVariableValueParameters(queryBuilder, variableName, variableValue);
if (statuses != null && !statuses.isEmpty()) {
queryBuilder.status(statuses.toArray(new Status[statuses.size()]));
}
setQueryContextOptions(queryContext, queryBuilder);
return queryBuilder.build().getResultList();
}
use of org.kie.api.task.model.Status in project jbpm by kiegroup.
the class RuntimeDataServiceEJBIntegrationTest method testTasksByStatusByProcessInstanceIdPagingAndFiltering.
@Test
public void testTasksByStatusByProcessInstanceIdPagingAndFiltering() {
Long pid = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
List<Status> statuses = new ArrayList<Status>();
statuses.add(Status.Ready);
statuses.add(Status.Reserved);
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwnerByStatus("salaboy", statuses, new QueryFilter(0, 5));
assertNotNull(tasks);
assertEquals(1, tasks.size());
long taskId = tasks.get(0).getId();
userTaskService.start(taskId, "salaboy");
userTaskService.complete(taskId, "salaboy", null);
Map<String, Object> params = new HashMap<String, Object>();
params.put("name", "Review Document");
QueryFilter qf = new QueryFilter("t.name = :name", params, "t.id", false);
qf.setOffset(0);
qf.setCount(5);
tasks = runtimeDataService.getTasksByStatusByProcessInstanceId(pid, statuses, qf);
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary userTask = tasks.get(0);
assertNotNull(userTask);
assertEquals("Review Document", userTask.getName());
tasks = runtimeDataService.getTasksByStatusByProcessInstanceId(pid, statuses, new QueryFilter(0, 5));
assertNotNull(tasks);
assertEquals(2, tasks.size());
Collection<ProcessInstanceDesc> activeProcesses = runtimeDataService.getProcessInstances(new QueryContext(0, 20));
for (ProcessInstanceDesc pi : activeProcesses) {
processService.abortProcessInstance(pi.getId());
}
}
use of org.kie.api.task.model.Status in project jbpm by kiegroup.
the class TaskQueryBuilderLocalTest method testTaskQueryBuilder.
@Test
public void testTaskQueryBuilder() {
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 = 231;
long procInstId = 1011;
String busAdmin = "Parzival";
String potOwner = "Art3mis";
String name = "EggHunting";
taskImpl = addTask(workItemId, procInstId, busAdmin, potOwner, 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);
// as much as possible
TaskSummaryQueryBuilder queryBuilder = taskService.taskSummaryQuery(stakeHolder).intersect().workItemId(workItemId).processInstanceId(procInstId).businessAdmin(busAdmin).potentialOwner(potOwner).taskId(taskImpl.getId()).ascending(OrderBy.taskId);
List<TaskSummary> results = queryBuilder.build().getResultList();
assertEquals("List of tasks", 1, results.size());
queryBuilder.clear();
results = queryBuilder.build().getResultList();
assertEquals("List of tasks", 1, results.size());
}
{
long workItemId = 251;
long procInstId = 1031;
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);
// as much as possible
TaskSummaryQueryBuilder queryBuilder = taskService.taskSummaryQuery(stakeHolder).intersect().workItemId(workItemId).processInstanceId(procInstId).businessAdmin(busAdmin).potentialOwner(potOwner).taskId(taskImpl.getId());
List<TaskSummary> results = queryBuilder.build().getResultList();
assertEquals("List of tasks", 1, results.size());
queryBuilder.clear();
results = queryBuilder.build().getResultList();
assertEquals("List of tasks", 2, results.size());
queryBuilder.clear();
queryBuilder.workItemId(workItemId);
results = queryBuilder.build().getResultList();
assertEquals("List of tasks", 1, results.size());
assertEquals("Incorrect task retrieved", tasks[1].getId(), results.get(0).getId());
queryBuilder.clear();
queryBuilder.processInstanceId(procInstId);
results = queryBuilder.build().getResultList();
assertEquals("List of tasks", 1, results.size());
assertEquals("Incorrect task retrieved", tasks[1].getId(), results.get(0).getId());
queryBuilder.clear();
queryBuilder.businessAdmin(busAdmin);
results = queryBuilder.build().getResultList();
assertEquals("List of tasks", 1, results.size());
assertEquals("Incorrect task retrieved", tasks[1].getId(), results.get(0).getId());
queryBuilder.clear();
queryBuilder.potentialOwner(potOwner);
results = queryBuilder.build().getResultList();
assertEquals("List of tasks", 1, results.size());
assertEquals("Incorrect task retrieved", tasks[1].getId(), results.get(0).getId());
queryBuilder.clear();
queryBuilder.taskId(taskImpl.getId());
results = queryBuilder.build().getResultList();
assertEquals("List of tasks", 1, results.size());
assertEquals("Incorrect task retrieved", tasks[1].getId(), results.get(0).getId());
}
{
// Add one more task, just to make sure things are working wel
long workItemId = 57;
long procInstId = 11111;
String busAdmin = "reviewer";
String potOwner = "translator";
String deploymentId = "armitage";
String name = "Koude Bevel";
taskImpl = addTask(workItemId, procInstId, busAdmin, potOwner, name, deploymentId);
procInstIds.add(procInstId);
workItemIds.add(workItemId);
busAdmins.add(busAdmin);
potOwners.add(potOwner);
assertEquals(potOwner, taskImpl.getTaskData().getActualOwner().getId());
taskService.start(taskImpl.getId(), potOwner);
taskService.fail(taskImpl.getId(), busAdmin, null);
TaskSummaryQueryBuilder queryBuilder = taskService.taskSummaryQuery(stakeHolder).maxResults(1);
List<TaskSummary> results = queryBuilder.build().getResultList();
assertEquals("List of tasks", 1, results.size());
queryBuilder.clear();
results = queryBuilder.build().getResultList();
assertFalse("Empty List of tasks", results.isEmpty() || results.size() == 1);
testOrderByTaskIdAscending(results);
queryBuilder.clear();
queryBuilder.descending(OrderBy.processInstanceId);
results = queryBuilder.build().getResultList();
assertFalse("List of tasks too small", results.isEmpty() || results.size() == 1);
for (int i = 1; i < results.size(); ++i) {
Long aVal = results.get(i - 1).getProcessInstanceId();
Long bVal = results.get(i).getProcessInstanceId();
assertTrue("Tasks not correctly ordered: " + aVal + " ?>? " + bVal, aVal > bVal);
}
queryBuilder.offset(results.size() - 1).ascending(OrderBy.taskId);
results = queryBuilder.build().getResultList();
assertFalse("Empty List of tasks", results.isEmpty());
assertEquals("List of tasks", 1, results.size());
assertEquals("Task id", taskImpl.getId(), results.get(0).getId());
}
TaskSummaryQueryBuilder queryBuilder = taskService.taskSummaryQuery(stakeHolder);
List<TaskSummary> results = queryBuilder.businessAdmin(busAdmins.toArray(new String[busAdmins.size()])).build().getResultList();
assertEquals(3, results.size());
// pagination
{
// Add two more tasks, in order to have a quorum
long workItemId = 59;
long procInstId = 12111;
String busAdmin = "Wintermute";
String potOwner = "molly";
String deploymentId = "Dixie Flatline";
String name = "Complete Mission";
taskImpl = addTask(workItemId, procInstId, busAdmin, potOwner, name, deploymentId);
// Add two more tasks, in order to have a quorum
++workItemId;
++procInstId;
busAdmin = "Neuromancer";
potOwner = "case";
deploymentId = "Linda Lee";
name = "Resurrect";
taskImpl = addTask(workItemId, procInstId, busAdmin, potOwner, name, deploymentId);
}
results = queryBuilder.clear().build().getResultList();
assertTrue("Result list too small to test: " + results.size(), results.size() == 5);
results = queryBuilder.clear().offset(1).build().getResultList();
assertTrue("Expected 4, not " + results.size() + " results", results.size() == 4);
results = queryBuilder.clear().offset(1).maxResults(3).build().getResultList();
assertTrue("Expected 3, not " + results.size() + " results", results.size() == 3);
results = queryBuilder.clear().offset(3).maxResults(3).build().getResultList();
assertTrue("Expected 2, not " + results.size() + " results", results.size() == 2);
// pot owner (and no "user-group limiting" clause)
{
// Add two more tasks, in order to have a quorum
long workItemId = 104;
long procInstId = 1766;
String busAdmin = stakeHolder;
String potOwner = stakeHolder;
String deploymentId = "Louis de Ponte du Lac";
String name = "Interview";
taskImpl = addTask(workItemId, procInstId, busAdmin, potOwner, name, deploymentId);
}
queryBuilder.clear();
queryBuilder = taskService.taskSummaryQuery(stakeHolder).intersect().potentialOwner(stakeHolder);
results = queryBuilder.build().getResultList();
assertEquals("List of tasks", 1, results.size());
}
use of org.kie.api.task.model.Status in project jbpm by kiegroup.
the class TaskSummaryQueryCriteriaUtil method doCriteriaQuery.
// Implementation specific methods --------------------------------------------------------------------------------------------
public List<TaskSummary> doCriteriaQuery(String userId, UserGroupCallback userGroupCallback, QueryWhere queryWhere) {
// 1. create builder and query instances
CriteriaBuilder builder = getCriteriaBuilder();
CriteriaQuery<Tuple> criteriaQuery = builder.createTupleQuery();
// 2. query base
Root<TaskImpl> taskRoot = criteriaQuery.from(TaskImpl.class);
criteriaQuery = criteriaQuery.multiselect(// 0
taskRoot.get(TaskImpl_.id), // 1
taskRoot.get(TaskImpl_.name), // 2
taskRoot.get(TaskImpl_.subject), // 3
taskRoot.get(TaskImpl_.description), // 4
taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.status), // 5
taskRoot.get(TaskImpl_.priority), // 6
taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.skipable), // 7
taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.actualOwner).get(UserImpl_.id), // 8
taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.createdBy).get(UserImpl_.id), // 9
taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.createdOn), // 10
taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.activationTime), // 11
taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.expirationTime), // 12
taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.processId), // 13
taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.processSessionId), // 14
taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.processInstanceId), // 15
taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.deploymentId), // 16
taskRoot.get(TaskImpl_.subTaskStrategy), // 17
taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.parentId));
// added for convienence sake, since other logic expects to find this join
taskRoot.join(TaskImpl_.taskData);
addUserGroupsViaCallBackToQueryWhere(userGroupCallback, queryWhere.getCriteria());
// 3. check to see if there's already a user(/security)-limitation in the search
checkExistingCriteriaForUserBasedLimit(queryWhere, userId, userGroupCallback);
for (QueryModificationService queryModificationService : queryModificationServiceLoader) {
queryModificationService.optimizeCriteria(queryWhere);
}
// 4. process query criteria
fillCriteriaQuery(criteriaQuery, queryWhere, builder, TaskImpl.class);
// 5. retrieve result (after also applying meta-criteria)
useDistinctWhenLefOuterJoinsPresent(criteriaQuery);
List<Tuple> result = createQueryAndCallApplyMetaCriteriaAndGetResult(queryWhere, criteriaQuery, builder);
List<TaskSummary> taskSummaryList = new ArrayList<TaskSummary>(result.size());
for (Tuple tupleRow : result) {
int i = 0;
// @formatter:off
TaskSummaryImpl taskSummaryImpl = new TaskSummaryImpl(// id
tupleRow.get(i++, Long.class), // name, subject, description
tupleRow.get(i++, String.class), tupleRow.get(i++, String.class), tupleRow.get(i++, String.class), // status, prio, skippable
tupleRow.get(i++, Status.class), tupleRow.get(i++, Integer.class), tupleRow.get(i++, Boolean.class), // actual owner, created by
tupleRow.get(i++, String.class), tupleRow.get(i++, String.class), // created on, activation time, expiration time
tupleRow.get(i++, Date.class), tupleRow.get(i++, Date.class), tupleRow.get(i++, Date.class), // process id, process session id, process inst id, deployment id
tupleRow.get(i++, String.class), tupleRow.get(i++, Long.class), tupleRow.get(i++, Long.class), tupleRow.get(i++, String.class), tupleRow.get(i++, SubTasksStrategy.class), tupleRow.get(i++, Long.class));
// @formatter:on
taskSummaryList.add(taskSummaryImpl);
}
return taskSummaryList;
}
Aggregations