jBPM 6 提供 Rest API 供第三方应用整合使用 jBPM 6,本文演示如果通过 Rest API:
本文所使用的流程如下
如上流程只有一个 User Task 节点,User Task 执行开始和执行结束都输出相关提示。流程 ID为 org.brms.test,节点名字为 Test,执行节点需要的 userID 为 kylin,角色为 IT。
为方便观察,我们需要 jBPM 6 使用 Mysql 替换默认的 H2 数据库。
启动流程 Rest API 如下:
/runtime/{id: [a-zA-Z0-9-:\\.]+}")/process/{id: [a-zA-Z0-9-:\\.]+}/start
mysql> select id, duration, start_date, end_date, processId, processInstanceId, processName, status from ProcessInstanceLog; +----+----------+---------------------+---------------------+---------------+-------------------+-------------+--------+ | id | duration | start_date | end_date | processId | processInstanceId | processName | status | +----+----------+---------------------+---------------------+---------------+-------------------+-------------+--------+ | 1 | 51569 | 2014-05-10 21:17:20 | 2014-05-10 21:18:11 | org.brms.test | 1 | test | 2 | | 2 | 3770025 | 2014-05-10 21:24:57 | 2014-05-10 22:27:47 | org.brms.test | 2 | test | 2 | | 3 | 4060507 | 2014-05-10 21:25:33 | 2014-05-10 22:33:13 | org.brms.test | 3 | test | 2 | | 4 | 2620216 | 2014-05-10 21:49:41 | 2014-05-10 22:33:21 | org.brms.test | 4 | test | 2 | | 5 | 2561315 | 2014-05-10 21:50:49 | 2014-05-10 22:33:30 | org.brms.test | 5 | test | 2 | | 6 | 2557182 | 2014-05-10 21:51:01 | 2014-05-10 22:33:38 | org.brms.test | 6 | test | 2 | | 7 | 2558504 | 2014-05-10 21:51:07 | 2014-05-10 22:33:45 | org.brms.test | 7 | test | 2 | | 8 | NULL | 2014-05-11 13:21:05 | NULL | org.brms.test | 1 | test | 1 | +----+----------+---------------------+---------------------+---------------+-------------------+-------------+--------+
获取流程实例 Rest API 如下:
/runtime/{id: [a-zA-Z0-9-:\\.]+}")/process/instance/{id: [0-9]+}
ProcessInstance 1 [processId=org.brms.test,state=1]
http://localhost:8080/business-central/rest/runtime/org.kie.example:project1:1.0.0-SNAPSHOT/process/instance/1
开始 User Task Rest API 如下:
/task/execute{id: \\d+}/start
mysql> select id, createdOn, deploymentId, processInstanceId, processId, status, createdBy_id from Task; +----+---------------------+-----------------------------------------+-------------------+---------------+----------+--------------+ | id | createdOn | deploymentId | processInstanceId | processId | status | createdBy_id | +----+---------------------+-----------------------------------------+-------------------+---------------+----------+--------------+ | 1 | 2014-05-11 13:21:05 | org.kie.example:project1:1.0.0-SNAPSHOT | 1 | org.brms.test | Reserved | kylin | +----+---------------------+-----------------------------------------+-------------------+---------------+----------+--------------+
运行 RestEasyClientTaskStart.java 开始执行 User Task ,执行之后我们同样到数据库查看当前 User Task 的信息:
mysql> select id, createdOn, deploymentId, processInstanceId, processId, status, createdBy_id from Task; +----+---------------------+-----------------------------------------+-------------------+---------------+------------+--------------+ | id | createdOn | deploymentId | processInstanceId | processId | status | createdBy_id | +----+---------------------+-----------------------------------------+-------------------+---------------+------------+--------------+ | 1 | 2014-05-11 13:21:05 | org.kie.example:project1:1.0.0-SNAPSHOT | 1 | org.brms.test | InProgress | kylin | +----+---------------------+-----------------------------------------+-------------------+---------------+------------+--------------+
完成User Task Rest API 如下:
/task/execute{id: \\d+}/complete
mysql> select id, createdOn, deploymentId, processInstanceId, processId, status, createdBy_id from Task; Empty set (0.00 sec)
mysql> select id, duration, start_date, end_date, processId, processInstanceId, processName, status from ProcessInstanceLog; +----+----------+---------------------+---------------------+---------------+-------------------+-------------+--------+ | id | duration | start_date | end_date | processId | processInstanceId | processName | status | +----+----------+---------------------+---------------------+---------------+-------------------+-------------+--------+ | 1 | 51569 | 2014-05-10 21:17:20 | 2014-05-10 21:18:11 | org.brms.test | 1 | test | 2 | | 2 | 3770025 | 2014-05-10 21:24:57 | 2014-05-10 22:27:47 | org.brms.test | 2 | test | 2 | | 3 | 4060507 | 2014-05-10 21:25:33 | 2014-05-10 22:33:13 | org.brms.test | 3 | test | 2 | | 4 | 2620216 | 2014-05-10 21:49:41 | 2014-05-10 22:33:21 | org.brms.test | 4 | test | 2 | | 5 | 2561315 | 2014-05-10 21:50:49 | 2014-05-10 22:33:30 | org.brms.test | 5 | test | 2 | | 6 | 2557182 | 2014-05-10 21:51:01 | 2014-05-10 22:33:38 | org.brms.test | 6 | test | 2 | | 7 | 2558504 | 2014-05-10 21:51:07 | 2014-05-10 22:33:45 | org.brms.test | 7 | test | 2 | | 8 | 1069981 | 2014-05-11 13:21:05 | 2014-05-11 13:38:54 | org.brms.test | 1 | test | 2 | +----+----------+---------------------+---------------------+---------------+-------------------+-------------+--------+