Flowable的REST API(一)

@[TOC](Flowable的REST API(一))
关于flowable的一些操作和介绍。

现在,我很高兴使用Flowable Modeler来建模业务流程并创建用户任务和流程实例,但是,我还想使用Flowable的REST API与流程实例和用户任务进行交互。

Flowable Modeler

开始使用Flowable的最简单方法是使用flowable / all-in-one Docker镜像:

run --name flowable -p 8080:8080 flowable/all-in-one```
1
2
3
4

要么

```docker start --interactive flowable

本地浏览器输入http://localhost:8080/flowable-modeler并使用默认用户ID登录:admin和password:test

登入

然后,您将被重定向到Flowable Modeler仪表板中的“Process”选项卡:

流程模型设计器-1

要开始创建业务流程模型(使用BPMN标准),请单击“ 创建流程”按钮:

创建业务流程模型-1

输入一个Model name,一个Model key和一个Description然后单击Create new model按钮:

BPMN编辑器

“流程设计界面”(Flowable的BPMN编辑器)包括一个侧面菜单,其中包含BPMN 2.0元素的调色板和页面底部的属性面板。每个新流程都以Start事件(小圆圈)开头。

您可以从侧面菜单中拖放元素,也可以使用所选元素的“快捷菜单”。单击“ 开始”事件元素,将显示其快捷菜单。

我们要添加一个User任务,所以单击代表用户的图标:

添加用户任务

这将添加一个箭头链接到Start事件的框。双击该框,为任务命名为“填写请假申请表”,然后在框外单击以保存更改:

填空题形式

再次单击该框以显示其快捷菜单,然后选择停止事件图标(带有粗边框的圆圈):

快捷菜单

我们的业务流程模型现在包含一个Start事件,一个User任务和一个End事件:

最终事件

分配任务

为了使Flowable成功执行我们的业务流程,它需要知道哪些用户可以完成用户任务。选择“填写请假申请表”用户任务,然后单击其Assignments属性:

任务

您可以将任务分配给个人或组:

分配任务

勾选“允许流程创建人完成任务”框,然后单击“ 保存”按钮。

关联表单

要将表单与用户任务相关联,请选择“填写请假申请表单”用户任务,然后单击其Form reference属性:

表单参考

我们还没有任何形式:

新形式

单击“ 新建表单”按钮:

创建一个表单

输入Form name,Form key和Description然后单击“ 创建表单”按钮:

形式建设者

表单设计器包含一个侧面菜单,其中包含可以拖放到设计画布上的表单组件选项板:

请假单应用形式

应用定义

现在我们已经建模了我们的业务流程,我们需要让它供人们使用。导航到Flowable Modeler仪表板中的“应用程序”选项卡,然后单击“ 创建应用程序”按钮:

新建应用程序定义

输入App definition name,App definition key和Description然后单击Create new app definition按钮:

应用程序定义,细节

我更改了Icon,使用Edit included models按钮将’Leave Application Process‘添加到’HR App‘,然后点击Save图标:

应用标签小时应用内

点击“HR App”卡:

HR-APP-发布

注意:您可以将App定义导出为zip文件或可部署的bar文件。

单击“ 发布”按钮:

屏幕截图 - 2018年12月24日 - 在 - 35年8月21日

单击“ 发布应用程序定义”按钮。

现在我们将使用Flowable的REST API来检查我们的应用程序定义是否已部署:

1
curl -i 'http://admin:test@localhost:8080/flowable-task/process-api/repository/deployments'

您应该看到如下输出:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
"data": [
{
"id": "c56b72eb-06f8-11e9-a85e-0242ac110002",
"name": "hr-app.zip",
"deploymentTime": "2018-12-23T21:21:54.532Z",
"category": null,
"parentDeploymentId": "c55ec8b6-06f8-11e9-a85e-0242ac110002",
"url": "http://localhost:8080/flowable-task/process-api/repository/deployments/c56b72eb-06f8-11e9-a85e-0242ac110002",
"tenantId": ""
}
],
"total": 1,
"start": 0,
"sort": "id",
"order": "asc",
"size": 1
}

让我们检查一下我们的流程定义是否已经部署过:

1
curl -i 'http://admin:test@localhost:8080/flowable-task/process-api/repository/process-definitions'

您应该看到如下输出:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
"data": [
{
"id": "leave-application-process:1:c5ae6f5e-06f8-11e9-a85e-0242ac110002",
"url": "http://localhost:8080/flowable-task/process-api/repository/process-definitions/leave-application-process:1:c5ae6f5e-06f8-11e9-a85e-0242ac110002",
"key": "leave-application-process",
"version": 1,
"name": "Leave Application Process",
"description": "An employee wants to take some time off.",
"tenantId": "",
"deploymentId": "c56b72eb-06f8-11e9-a85e-0242ac110002",
"deploymentUrl": "http://localhost:8080/flowable-task/process-api/repository/deployments/c56b72eb-06f8-11e9-a85e-0242ac110002",
"resource": "http://localhost:8080/flowable-task/process-api/repository/deployments/c56b72eb-06f8-11e9-a85e-0242ac110002/resources/leave-application-process.bpmn",
"diagramResource": "http://localhost:8080/flowable-task/process-api/repository/deployments/c56b72eb-06f8-11e9-a85e-0242ac110002/resources/leave-application-process.leave-application-process.png",
"category": "http://www.flowable.org/processdef",
"graphicalNotationDefined": true,
"suspended": false,
"startFormDefined": false
}
],
"total": 1,
"start": 0,
"sort": "name",
"order": "asc",
"size": 1
}

流程任务

地址访问: http://localhost:8080/flowable-task

流动性任务-HR-应用

单击“HR App”卡并导航到“进程”选项卡:

流动性任务流程标签

单击“ 启动进程”按钮:

流动性任务,离开应用程序进程

然后单击“ 开始”进程按钮:

流动性任务圈-2

现在我们将使用Flowable的REST API来获取有关流程实例的信息:

1
curl -i 'http://admin:test@localhost:8080/flowable-task/process-api/runtime/process-instances'

您应该看到如下输出:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
{
"data": [
{
"id": "02d460bb-070e-11e9-a85e-0242ac110002",
"url": "http://localhost:8080/flowable-task/process-api/runtime/process-instances/02d460bb-070e-11e9-a85e-0242ac110002",
"name": "Leave Application Process - December 24th 2018",
"businessKey": null,
"suspended": false,
"ended": false,
"processDefinitionId": "leave-application-process:1:c5ae6f5e-06f8-11e9-a85e-0242ac110002",
"processDefinitionUrl": "http://localhost:8080/flowable-task/process-api/repository/process-definitions/leave-application-process:1:c5ae6f5e-06f8-11e9-a85e-0242ac110002",
"activityId": null,
"startedBy": "admin",
"started": "2018-12-23T23:53:56.992Z",
"variables": [],
"callbackId": null,
"callbackType": null,
"tenantId": "",
"completed": false
}
],
"total": 1,
"start": 0,
"sort": "id",
"order": "asc",
"size": 1
}

让我们检查一下,看看我们是否有任务要完成:

1
curl -i 'http://admin:test@localhost:8080/flowable-task/process-api/runtime/tasks'

您应该看到如下输出:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{
"data": [
{
"id": "1fae489a-070f-11e9-a85e-0242ac110002",
"url": "http://localhost:8080/flowable-task/process-api/runtime/tasks/1fae489a-070f-11e9-a85e-0242ac110002",
"owner": null,
"assignee": "admin",
"delegationState": null,
"name": "Fill in a Leave Application Form",
"description": null,
"createTime": "2018-12-24T00:01:54.893Z",
"dueDate": null,
"priority": 50,
"suspended": false,
"taskDefinitionKey": "sid-3BA1F4D1-500F-4766-89BF-519166929F2D",
"scopeDefinitionId": null,
"scopeId": null,
"scopeType": null,
"tenantId": "",
"category": null,
"formKey": "leave-application-form",
"parentTaskId": null,
"parentTaskUrl": null,
"executionId": "1fadfa77-070f-11e9-a85e-0242ac110002",
"executionUrl": "http://localhost:8080/flowable-task/process-api/runtime/executions/1fadfa77-070f-11e9-a85e-0242ac110002",
"processInstanceId": "1fadfa74-070f-11e9-a85e-0242ac110002",
"processInstanceUrl": "http://localhost:8080/flowable-task/process-api/runtime/process-instances/1fadfa74-070f-11e9-a85e-0242ac110002",
"processDefinitionId": "leave-application-process:1:c5ae6f5e-06f8-11e9-a85e-0242ac110002",
"processDefinitionUrl": "http://localhost:8080/flowable-task/process-api/repository/process-definitions/leave-application-process:1:c5ae6f5e-06f8-11e9-a85e-0242ac110002",
"variables": []
}
],
"total": 1,
"start": 0,
"sort": "id",
"order": "asc",
"size": 1
}

formKey 包含与User任务关联的表单名称(’leave-application-form’)。

我们可以在表单存储库中查看“请假申请表”:

1
curl -i 'http://admin:test@localhost:8080/flowable-task/form-api/form-repository/form-definitions'

您应该看到如下输出:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
"data": [
{
"id": "c5bdb1a1-06f8-11e9-a85e-0242ac110002",
"url": "http://localhost:8080/flowable-task/form-api/form-repository/form-definitions/c5bdb1a1-06f8-11e9-a85e-0242ac110002",
"category": null,
"name": "Leave Application Form",
"key": "leave-application-form",
"description": null,
"version": 1,
"resourceName": "form-leave-application-form.form",
"deploymentId": "c5b0b94f-06f8-11e9-a85e-0242ac110002",
"tenantId": ""
}
],
"total": 1,
"start": 0,
"sort": "name",
"order": "asc",
"size": 1
}

我们可以使用它id来获取表单模型的JSON表示:

1
curl -i 'http://admin:test@localhost:8080/flowable-task/form-api/form-repository/form-definitions/c5bdb1a1-06f8-11e9-a85e-0242ac110002/model'

您应该看到如下输出:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
{
"id": "c5bdb1a1-06f8-11e9-a85e-0242ac110002",
"name": "Leave Application Form",
"key": "leave-application-form",
"version": 1,
"url": "http://localhost:8080/flowable-task/form-api/form/model",
"fields": [
{
"fieldType": "FormField",
"id": "givenName",
"name": "Given Name",
"type": "text",
"value": null,
"required": true,
"readOnly": false,
"overrideId": true,
"placeholder": "",
"layout": null
},
{
"fieldType": "FormField",
"id": "familyName",
"name": "Family Name",
"type": "text",
"value": null,
"required": true,
"readOnly": false,
"overrideId": true,
"placeholder": null,
"layout": null
},
{
"fieldType": "FormField",
"id": "employeeNumber",
"name": "Employee Number",
"type": "integer",
"value": null,
"required": true,
"readOnly": false,
"overrideId": true,
"placeholder": null,
"layout": null
},
{
"fieldType": "FormField",
"id": "fromDate",
"name": "From Date",
"type": "date",
"value": null,
"required": true,
"readOnly": false,
"overrideId": true,
"placeholder": null,
"layout": null
},
{
"fieldType": "FormField",
"id": "toDate",
"name": "To Date",
"type": "date",
"value": null,
"required": true,
"readOnly": false,
"overrideId": true,
"placeholder": null,
"layout": null
}
],
"outcomes": []
}

现在导航到Tasks选项卡,查看Flowable的Form引擎如何呈现我们的Leave Application表单:

流动性任务圈-3

我们可以填写以下表格:

流动性任务圈-4

或者使用Flowable的REST API更新表单的变量并完成User任务:

1
2
3
curl -H "Content-Type: application/json" 
-X POST http://admin:test@localhost:8080/flowable-task/process-api/runtime/tasks/1fae489a-070f-11e9-a85e-0242ac110002
-d "@data-1.json"

数据1.json:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{
"action" : "complete",
"variables" : [
{
"id": "givenName",
"name": "Given Name",
"type": "string",
"value": "Rob"
},
{
"id": "familyName",
"name": "Family Name",
"type": "string",
"value": "Ferguson"
},
{
"id": "employeeNumber",
"name": "Employee Number",
"type": "integer",
"value": 123456
},
{
"id": "fromDate",
"name": "From Date",
"type": "date",
"value": "2018-12-21T00:00:00+00:00"
},
{
"id": "toDate",
"name": "To Date",
"type": "date",
"value": "2019-01-07T00:00:00+00:00"
}
]
}

您应该看到如下输出:

1
Status: 200 OK

尽管返回OK,但调用似乎不会保存用户任务的变量:

空白表格
这里提出了以下Flowable问题:

我也试过,POST/form/form-data

1
2
3
curl -H "Content-Type: application/json" 
-X POST http://admin:test@localhost:8080/flowable-task/process-api/form/form-data
-d "@data-2.json"

数据2.json:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{
"taskId" : "1fae489a-070f-11e9-a85e-0242ac110002",
"properties" : [
{
"id": "givenName",
"name": "Given Name",
"type": "string",
"value": "Rob"
},
{
"id": "familyName",
"name": "Family Name",
"type": "string",
"value": "Ferguson"
},
{
"id": "employeeNumber",
"name": "Employee Number",
"type": "integer",
"value": 123456
},
{
"id": "fromDate",
"name": "From Date",
"type": "date",
"value": "2018-12-21T00:00:00+00:00"
},
{
"id": "toDate",
"name": "To Date",
"type": "date",
"value": "2019-01-07T00:00:00+00:00"
}
]
}

您应该看到如下输出:

1
Status: 204 No Content

我不知道它为什么会返回,204 No Content所以我提出了以下Flowable问题:

可流动引擎:POST/Form/Form-Data
但它确实似乎保存了用户任务的变量(并完成了用户任务):

形式数据

流动问题

提出的关于Flowable的问题:

Flowable Engine: POST /runtime/tasks/{taskId}
Flowable Engine:POST /form/form-data
Flowable Engine:JSON body parameters

下一步是什么

在下一篇文章中,我们将使用Angular,Angular Material和Flowable的REST API来创建一个定制的Task List组件:

任务列表

源代码:
GitHub:Serendipity
参考文献:
Paul Holmes-Higgin的博客:Instant Gratification with Flowable 6


   转载规则


《Flowable的REST API(一)》 Jack Chan 采用 知识共享署名 4.0 国际许可协议 进行许可。
  目录