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

概述

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

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

运行 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 毫秒。


JBoss 系列九十九:Rest WebService jBPM 6 集成示例,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。