现在,我很高兴使用Flowable Modeler来建模业务流程并创建用户任务和流程实例,但是,我还想使用Flowable的REST API与流程实例和用户任务进行交互。
开始使用Flowable的最简单方法是使用flowable / all-in-one Docker镜像:
docker run --name flowable -p 8080:8080 flowable/all-in-one
要么
docker start --interactive flowable
本地浏览器输入http://localhost:8080/flowable-modeler并使用默认用户ID登录:admin和password:test
然后,您将被重定向到Flowable Modeler仪表板中的“Process”选项卡:
要开始创建业务流程模型(使用BPMN标准),请单击“ 创建流程”按钮:
输入一个Model name,一个Model key和一个Description然后单击Create new model按钮:
“流程设计界面”(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”卡:
注意:您可以将App定义导出为zip文件或可部署的bar文件。
单击“ 发布”按钮:
屏幕截图 - 2018年12月24日 - 在 - 35年8月21日
单击“ 发布应用程序定义”按钮。
现在我们将使用Flowable的REST API来检查我们的应用程序定义是否已部署:
curl -i 'http://admin:test@localhost:8080/flowable-task/process-api/repository/deployments'
您应该看到如下输出:
{
"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
}
让我们检查一下我们的流程定义是否已经部署过:
curl -i 'http://admin:test@localhost:8080/flowable-task/process-api/repository/process-definitions'
您应该看到如下输出:
{
"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 App”卡并导航到“进程”选项卡:
单击“ 启动进程”按钮:
然后单击“ 开始”进程按钮:
现在我们将使用Flowable的REST API来获取有关流程实例的信息:
curl -i 'http://admin:test@localhost:8080/flowable-task/process-api/runtime/process-instances'
您应该看到如下输出:
{
"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
}
让我们检查一下,看看我们是否有任务要完成:
curl -i 'http://admin:test@localhost:8080/flowable-task/process-api/runtime/tasks'
您应该看到如下输出:
{
"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’)。
我们可以在表单存储库中查看“请假申请表”:
curl -i 'http://admin:test@localhost:8080/flowable-task/form-api/form-repository/form-definitions'
您应该看到如下输出:
{
"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表示:
curl -i 'http://admin:test@localhost:8080/flowable-task/form-api/form-repository/form-definitions/c5bdb1a1-06f8-11e9-a85e-0242ac110002/model'
您应该看到如下输出:
{
"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表单:
我们可以填写以下表格:
或者使用Flowable的REST API更新表单的变量并完成User任务:
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:
{
"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"
}
]
}
您应该看到如下输出:
Status: 200 OK
尽管返回OK,但调用似乎不会保存用户任务的变量:
我也试过,POST/form/form-data
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:
{
"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"
}
]
}
您应该看到如下输出:
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