Flowable 6.6.0 BPMN用户指南 - 17 高级用例 - 17.7 高级查询API:运行时和历史任务查询之间的无缝切换

《Flowable 6.6.0 BPMN用户指南》

1. 入门
2. 配置
3 The Flowable API
4 Flowable 6.6.0 BPMN用户指南 - (4)Spring集成
5 Spring Boot
6 部署
7 BPMN 2.0简介
8 BPMN 2.0的构造
9 表单(Forms)
10 流程实例迁移
11 JPA
12 历史(History)
13 身份管理(Identity management)
14 REST API
15 CDI集成
16 LDAP集成
17 高级用例
  • 17.1 异步执行器(Async Executor)
    • 17.1.1 异步执行器设计(Async Executor design)
    • 17.1.2 异步执行器配置
    • 17.1.3 基于异步执行器的消息队列
  • 17.2 与流程解析挂钩(Hooking into process parsing)
  • 17.3 用于高并发的UUID ID生成器
  • 17.4 多租户(Multitenancy)
  • 17.5 执行自定义SQL(Execute custom SQL)
  • 17.6 采用ProcessEngineConfigurator 进行高级的流程引擎配置
  • 17.7 高级查询API:运行时和历史任务查询之间的无缝切换
  • 17.8 重写标准SessionFactory实现自定义身份管理
  • 17.9 启用安全的BPMN 2.0 xml
  • 17.10 事件日志记录(Event logging)
  • 17.11 禁用批量插入(Disabling bulk inserts)
  • 17.12 安全脚本(Secure Scripting)
  • 17.13 日志记录会话[实验性]

有关Flowable的更多文档,参见:

《Flowable文档大全》


17.7 高级查询API:运行时和历史任务查询之间的无缝切换

One core component of any BPM user interface is the task list. Typically, end users work on open, runtime tasks, filtering their inbox with various setting. Often also the historic tasks need to be displayed in those lists, with similar filtering. To make that code-wise easier, the TaskQuery and HistoricTaskInstanceQuery both have a shared parent interface, which contains all common operations (and most of the operations are common).

This common interface is the org.flowable.engine.task.TaskInfoQuery class. Both org.flowable.engine.task.Task and org.flowable.engine.task.HistoricTaskInstance have a common superclass org.flowable.engine.task.TaskInfo (with common properties) which is returned from e.g. the list() method. However, Java generics are sometimes more harming than helping: if you want to use the TaskInfoQuery type directly, it would look like this:
TaskInfoQuery, ? extends TaskInfo> taskInfoQuery
Ugh, Right. To ‘solve’ this, a org.flowable.engine.task.TaskInfoQueryWrapper class that can be used to avoid the generics (the following code could come from REST code that returns a task list where the user can switch between open and completed tasks):

任何BPM用户界面的一个核心组件是任务列表。通常,最终用户处理打开的运行时任务,使用各种设置过滤收件箱。通常,历史任务也需要通过类似的过滤显示在那些列表中。为了使代码更简单,TaskQuery 和HistoricTaskInstanceQuery 都有一个共享的父接口,其中包含所有常用操作(大多数操作都是通用的)。

这个公共接口是 org.flowable.engine.task.TaskInfoQuery类。org.flowable.engine.task.Task和org.flowable.engine.task.HistoricTaskInstance 都有一个共同的超类org.flowable.engine.task.TaskInfo(具有公共属性),它是从类似list()方法返回的。但是,Java泛型有时弊大于利:如果您想直接使用TaskInfoQuery 类型,它应该如下所示:

TaskInfoQuery, ? extends TaskInfo> taskInfoQuery
为了“解决”这个问题,可用org.flowable.engine.task.TaskInfoQueryWrapper类来避免泛型(以下代码可来自REST代码,该代码返回任务列表,用户可以在开放的任务和已完成的任务之间切换):

TaskInfoQueryWrapper taskInfoQueryWrapper = null;
if (runtimeQuery) {
     
    taskInfoQueryWrapper = new TaskInfoQueryWrapper(taskService.createTaskQuery());
} else {
     
    taskInfoQueryWrapper = new TaskInfoQueryWrapper(historyService.createHistoricTaskInstanceQuery());
}

List<? extends TaskInfo> taskInfos = taskInfoQueryWrapper.getTaskInfoQuery().or()
    .taskNameLike("%k1%")
    .taskDueAfter(new Date(now.getTime() + (3 * 24L * 60L * 60L * 1000L)))
.endOr()
.list();

你可能感兴趣的:(Flowable,6.6.0,BPMN用户指南,-9-18)