JBoss 系列九十九:Rest WebService jBPM 6 集成演示样例

概述

jBPM 6 提供 Rest API 供第三方应用整合使用 jBPM 6,本文演示假设通过 Rest API:

  • 启动流程
  • 获取流程实例信息
  • 启动 User Task
  • 完毕 User Task
 jBPM 6 中使用 RestEasy 实现 Rest WebService ,所以我们通过 Rest client 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

运行 RestEasyClientProcessStart.java 启动流程。启动流程后我们到数据库中查看:

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 |
+----+----------+---------------------+---------------------+---------------+-------------------+-------------+--------+

如上ProcessInstanceLog表中 ID 为 8 的;流程演示样例为我们通过 Rest API 启动的流程实例。注意,status列为1表示流程未被运行。

获取流程实例

获取流程实例 Rest API 例如以下:

/runtime/{id: [a-zA-Z0-9-:\.]+}")/process/instance/{id: [0-9]+}

运行 RestEasyClientGetProcessInstance.java 获取流程实例 ,我们运行结果会有例如以下输出

ProcessInstance 1 [processId=org.brms.test,state=1]

注意,我们測试流程的ID 为 org.brms.test,数据库中 processInstanceId 为 1,所以我们的 Rest Path例如以下:

http://localhost:8080/business-central/rest/runtime/org.kie.example:project1:1.0.0-SNAPSHOT/process/instance/1

開始 User Task

開始 User Task Rest API 例如以下:

/task/execute{id: \d+}/start

运行 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 | Reserved | kylin        |
+----+---------------------+-----------------------------------------+-------------------+---------------+----------+--------------+

注意。此 Task 与 processInstanceId 为 1 的流程演示样例关联,当前状态没有開始。

运行 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        |
+----+---------------------+-----------------------------------------+-------------------+---------------+------------+--------------+

主要当前 Task 的状态改变为 InProgress。

完毕User Task

完毕User Task Rest API 例如以下:

/task/execute{id: \d+}/complete

运行 RestEasyClientTaskComplete.java 能够完毕 User Task ,运行完毕后去数据库查看当前 User Task  的信息:

mysql> select id, createdOn, deploymentId, processInstanceId, processId, status, createdBy_id from Task;
Empty set (0.00 sec)

如上数据库中没有Task信息。即jBPM 中当某一 Task 运行完毕后会将其的信息删除。假设我们接着去查看流程实例的信息:

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 |
+----+----------+---------------------+---------------------+---------------+-------------------+-------------+--------+

我们能够发现 ID 为 8,processInstanceId 为 1的流程 status栏变为 2,这表明流程已经运行完毕,我们也能够发现流程開始时间为 2014-05-11 13:21:05,结束时间为 2014-05-11 13:38:54,运行的周期(duration)为 1069981 毫秒。


原文地址:https://www.cnblogs.com/lcchuguo/p/5275498.html