Overview
JBPM 6 provides REST API for third-party applications to integrate with JBPM 6, this article demonstrates if you are using the rest API:
- Start process
- Get Process Instance Information
- Start User Task
- Completing the User Task
JBPM 6 uses Resteasy to implement rest WebService, so we interact with the rest API provided by JBPM 6 through the rest client API.
The process used in this article is as follows
If the above process has only one user task node, the user task execution start and execution end both output the relevant hints. The process ID is org.brms.test, the node name is test, the userID required for the execution node is Kylin, and the role is IT.
For the convenience of observation, we need JBPM 6 to replace the default H2 database with Mysql.
Start process
Start the process Rest API as follows:
/runtime/{id: [a-za-z0-9-:\\.] +} ")/process/{id: [a-za-z0-9-:\\.] +}/start
Run the Resteasyclientprocessstart.java start process, and after starting the process we look in the database:
Mysql> select ID, Duration, start_date, end_date, ProcessId, Processinstanceid, ProcessName, status from Processinstan celog;+----+----------+---------------------+---------------------+---------------+-------------------+-------- -----+--------+| 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 on 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 |+----+----------+---------------------+---------------------+---------------+-------------------+------------ -+--------+
As the Processinstancelog table has an ID of 8, the process example is a process instance that we started with the Rest API, noting that the Status column 1 indicates that the process was not executed.
Get Process Instance
Get the process instance Rest API as follows:
/runtime/{id: [a-za-z0-9-:\\.] +} ")/process/instance/{id: [0-9]+}
Run Resteasyclientgetprocessinstance.java to get the process instance, we will run the result with the following output
ProcessInstance 1 [processid=org.brms.test,state=1]
Note that our test process has an ID of org.brms.test and the database has a processinstanceid of 1, so our Rest path is as follows:
Http://localhost:8080/business-central/rest/runtime/org.kie.example:project1:1.0.0-SNAPSHOT/process/instance/1
Start User Task
Start the User Task Rest API as follows:
/task/execute{id: \\d+}/start
Run Resteasyclienttaskstart.java start executing the user task, before we start execution we first see the current user task information in the database:
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 |+----+---------------------+-----------------------------------------+-------------------+---------- -----+----------+--------------+
Note that this Task is associated with a process example of Processinstanceid 1, and the current state does not start.
Running Resteasyclienttaskstart.java starts executing the user task, and we also go to the database to view the current user task information:
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 |+----+---------------------+-----------------------------------------+-------------------+---------- -----+------------+--------------+
The state of the main current Task is changed to InProgress.
Completing the user Task
Complete the user Task Rest API as follows:
/task/execute{id: \\d+}/complete
Run Resteasyclienttaskcomplete.java to complete the user task, and then go to the database to view the current user task information:
Mysql> Select ID, CreatedOn, Deploymentid, Processinstanceid, processId, status, createdby_id from Task; Empty Set (0.00 sec)
If there is no task information in the database, that is, in jbpm, when a task executes, it will delete its information, if we proceed to view the information of the process instance:
Mysql> select ID, Duration, start_date, end_date, ProcessId, Processinstanceid, ProcessName, status from Processinstan celog;+----+----------+---------------------+---------------------+---------------+-------------------+-------- -----+--------+| 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 on 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 |+----+----------+---------------------+---------------------+---------------+-------------------+------------ -+--------+
We can find that the process status column with ID 8,processinstanceid 1 becomes 2, indicating that the process has been completed and we can also find that the process start time is 2014-05-11 13:21:05 and the end time is 2014-05-11 13:38: 54, the period of execution (duration) is 1069981 milliseconds.