12.7. Retrieving Process And Task Information

There are two services which can be used when building list-based user interfaces: the RuntimeDataService and TaskQueryService. However, the TaskQueryService provides the same functionality as the RuntimeDataService and using it is not the preferred way to query tasks and processes.
The RuntimeDataService interface can be used as the main source of information, as it provides an interface for retrieving data associated with the runtime. It can list process definitions, process instances, tasks for given users, node instance information and other. The service should provide all required information and still be as efficient as possible.
See the following examples:

Example 12.1. Get All Process Definitions

Returns every available process definition.
Collection definitions = runtimeDataService.getProcesses(new QueryContext());

Example 12.2. Get Active Process Instances

Returns a list of all active process instance descriptions.
Collection<processInstanceDesc> activeInstances = runtimeDataService
	.getProcessInstances(new QueryContext());

Example 12.3. Get Active Nodes for Given Process Instance

Returns a trace of all active nodes for given process instance ID.
Collection<nodeInstanceDesc> activeNodes = runtimeDataService
	.getProcessInstanceHistoryActive(processInstanceId, new QueryContext());

Example 12.4. Get Tasks Assigned to Given User

Returns a list of tasks the given user is eligible for.
List<taskSummary> taskSummaries = runtimeDataService
	.getTasksAssignedAsPotentialOwner("john", new QueryFilter(0, 10));

Example 12.5. Get Assigned Tasks as a Business Administrator

Returns a list of assigned tasks such that the given user is a business administrator. Business administrators play the same role as task stakeholders, but at the task type level. Therefore, business administrators can perform the same operations as task stakeholders, but observe the progress of notifications as well.
List<taskSummary> taskSummaries = runtimeDataService
	.getTasksAssignedAsBusinessAdministrator("john", new QueryFilter(0, 10));
The RuntimeDataService is mentioned also in Chapter 18, CDI Integration.
As you can notice, operations of the RuntimeDataService then support two important arguments:
  • QueryContext
  • QueryFilter (which is an extension of QueryContext)
These two classes provide capabilities for an efficient management and search results. The QueryContext allows you to set an offset (by using the offset argument), number of results (count), their order (orderBy) and ascending order (asc) as well.
Since the QueryFilter inherits all of the mentioned attributes, it provides the same features, as well as some others: for example, it is possible to set the language, single result, maximum number of results or paging.
Moreover, additional filtering can be applied to the queries to provide more advanced options when searching for user tasks and processes.