JBPM (3) - - JPDL Process Definition Language

JPDL, full name JBossjBPMProcess Definition Language, is JBPM's process definition language.

JPDL process definition language mainly grasps the following several kinds:
1.process (process)
2.transition (Connection, Transfer)
3.start (Start Activities)
4.end, end-error, end-cancel
5.state (state activity)
6.task (Task Activities)
7.decision (Judgment Activity)
8.fork, join (branching/aggregation activities)

Top-level element process definition

name is used for display, usually defined in Chinese
key is used for code operations, usually defined in English
Version version number, not specified, same key process, version automatically + 1 (if specified version does not conflict with other)
Generating pdId process definition id = pdKey + "-" + pdVersion in jbpm4_deployprop
Publishing process guarantees that key and name are identical

Code example:
process.jpdl.xml

<?xml version="1.0" encoding="UTF-8"?>

<process key="process" name="Test flow" xmlns="http://jbpm.org/4.4/jpdl">
    <!-- root node -->
   <start g="235,30,48,48" name="start1">
      <transition g="-47,-17" name="to leave" to="leave"/>
   </start>
   <end g="251,315,48,48" name="end1"/>
   <task g="223,128,92,52" name="leave">
      <transition g="-47,-17" name="to Approval" to="Approval"/>
   </task>
   <task g="231,211,92,52" name="Approval">
      <transition g="-47,-17" name="to end1" to="end1"/>
   </task>
</process>

ProcessTest.java

package com.my.jbpm.jpdl;

import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.RepositoryService;
import org.junit.Test;

public class ProcessTest {

    @Test
    // Publish process.jpdl.xml
    public void demo(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Get Service
        RepositoryService repositoryService = processEngine.getRepositoryService();
        //Release
        repositoryService.createDeployment().addResourceFromClasspath("process.jpdl.xml").deploy();
    }

}

Transition Node (Transition Node)
One or more transition s can be specified in an activity
There can only be one transition to start the activity
Closing activities without transition
Other activities can have one or more transition s

If there is only one, you can not specify a name, if there are more than one, you need to specify a unique name separately.
Nameless transition
executionService.signalExecutionById(executionId)
Named transition
executionService.signalExecutionById(executionId, transitionName)

Define the transition element to become the default transition node without writing the name attribute
If there is no name attribute of transition, the default transition node (transition without name attribute) will be used in the backward flow.

Code example:
transition.jpdl.xml

<?xml version="1.0" encoding="UTF-8"?>

<process name="transition" xmlns="http://jbpm.org/4.4/jpdl">
   <start g="280,9,48,48" name="start1">
      <transition g="-53,-17" name="to task1" to="task1"/>
   </start>
   <end g="290,299,48,48" name="end1"/>
   <task g="269,89,92,52" name="task1">
      <!-- No name Of transition Become the default transition -->
      <transition to="task2"/>
      <transition g="-53,-17" name="to task3" to="task3"/>
   </task>
   <task g="157,182,92,52" name="task2">
      <transition g="-47,-17" name="to end1" to="end1"/>
   </task>
   <task g="376,186,92,52" name="task3">
      <transition g="-47,-17" name="to end1" to="end1"/>
   </task>
</process>

TransitionTest.java

package com.my.jbpm.jpdl;

import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessEngine;
import org.junit.Test;

public class TransitionTest {

    @Test
    //Publish start transition.jpdl.xml
    public void demo1(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Release process 
        processEngine.getRepositoryService().createDeployment().addResourceFromClasspath("transition.jpdl.xml").deploy();
        //Startup instance
        processEngine.getExecutionService().startProcessInstanceByKey("transition");
    }

    @Test
    //Complete task 1
    public void demo2(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Backward flow
        //processEngine.getExecutionService().signalExecutionById("transition.10007"); // No name is specified to use the default transition
         processEngine.getExecutionService().signalExecutionById("transition.10007","to task3");// executionId in the execution table ID_
    }

}

start and end nodes
start starts
Representing the start boundary of a process, a process has and can only have one Start activity. Only one Transition can be specified to start the activity. After the process instance is started, this unique Transition is automatically used to leave the start activity to the next activity.

end closes the activity
Representing the end boundary of a process, there can be multiple or none. If there are more than one, the whole process ends at either end activity; if not, the process ends at the last activity without Transition.

Discontinue process code
processEngine.getExecutionService().endProcessInstance(processInstanceId, ProcessInstance.STATE_ENDED);
At any node, the process can be terminated

State node (state node, current state changed, flow backward)
State node, wait meaning, automatically trigger flow executionService.signalExecutionById when the server processes some data

Code example:
state.jpdl.xml

<?xml version="1.0" encoding="UTF-8"?>

<process name="state" xmlns="http://jbpm.org/4.4/jpdl">
   <start g="264,13,48,48" name="start1">
      <transition g="-71,-17" name="to User registration" to="User registration"/>
   </start>
   <end g="263,284,48,48" name="end1"/>
   <task g="245,92,92,52" name="User registration">
      <transition g="-95,-17" name="to Send Activated Mail" to="Send Activated Mail"/>
   </task>
   <state g="241,182,92,52" name="Send Activated Mail">
      <transition g="-47,-17" name="to end1" to="end1"/>
   </state>
</process>

StateTest.java

package com.my.jbpm.jpdl;

import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessEngine;
import org.junit.Test;

public class StateTest {

    @Test
    //Publish process, start instance 
    public void demo1(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Release process 
        processEngine.getRepositoryService().createDeployment().addResourceFromClasspath("state.jpdl.xml").deploy();
        //Startup instance
        processEngine.getExecutionService().startProcessInstanceByKey("state");
    }

    @Test
    //User registration 
    public void demo2(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Man-made tasks
        processEngine.getTaskService().completeTask("40008");
    }

    @Test
    //Send Activated Mail
    public void demo3(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Through the state node
        processEngine.getExecutionService().signalExecutionById("state.40007");
    }

}

decision Judgment Node
Use expression, such as expr="#{expression}"
Using Handler to implement the DecisionHandler interface
If both expression and handler are configured, expression is valid and Handler is ignored

Code example:
Mode 1: Control program flow by expr={expression}. Before executing to decision node, condition variables must be stored in process variables. Expr="{condition}" obtains process variables. When the value of variables is compared with the name attribute of each transition node, which is consistent, it flows to which transition.

decision1.jpdl.xml

<?xml version="1.0" encoding="UTF-8"?>

<process name="decision1" xmlns="http://jbpm.org/4.4/jpdl">
   <start g="276,-7,48,48" name="start1">
      <transition g="-59,-17" name="to have a stroll in the park" to="Shopping in the park to buy tickets"/>
   </start>
   <end g="283,346,48,48" name="end1"/>
   <task g="256,61,92,52" name="Shopping in the park to buy tickets">
      <transition g="-83,-17" name="to exclusive1" to="exclusive1"/>
   </task>
   <decision expr="#{condition}" g="274,133,48,48" name="exclusive1">
      <transition g="-83,-17" name="to Ticket-free for the elderly" to="Ticket-free for the elderly"/>
      <transition g="-71,-17" name="to Demi-Tarif" to="Demi-Tarif"/>
      <transition g="-71,-17" name="to Ordinary ticket sales" to="Ordinary ticket sales"/>
   </decision>
   <task g="81,220,92,52" name="Ticket-free for the elderly">
      <transition g="-47,-17" name="to end1" to="end1"/>
   </task>
   <task g="259,216,89,56" name="Demi-Tarif">
      <transition g="-47,-17" name="to end1" to="end1"/>
   </task>
   <task g="448,217,92,52" name="Ordinary ticket sales">
      <transition g="-47,-17" name="to end1" to="end1"/>
   </task>
</process>

DecisionTest.java

@Test
    //Publish process definitions and start process instances
    public void demo1(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Release process 
        processEngine.getRepositoryService().createDeployment().addResourceFromClasspath("decision1.jpdl.xml").deploy();
        //Startup instance
        processEngine.getExecutionService().startProcessInstanceByKey("decision1");
    }

    @Test
    //Shopping in the park to buy tickets
    public void demo2(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Complete tasks
        //Setting condition variable
        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put("condition", "to Demi-Tarif");
        processEngine.getTaskService().setVariables("70008", variables);

        processEngine.getTaskService().completeTask("70008");
    }

Mode 2: DecisionHandler interface implementation class to control and judge node flow
MyDecisionHandler.java

package com.my.jbpm.handler;

import org.jbpm.api.jpdl.DecisionHandler;
import org.jbpm.api.model.OpenExecution;

@SuppressWarnings("serial")
public class MyDecisionHandler implements DecisionHandler{

    @Override
    public String decide(OpenExecution openExecution) {
        // According to the age of process variables, the elderly, children and normal people were judged.
        int age = Integer.parseInt((String)openExecution.getVariable("age"));
        if(age > 65){
            return "to Ticket-free for the elderly";
        }else if(age < 4){
            return "to Demi-Tarif";
        }else{
            return "to Ordinary ticket sales";
        }
    }

}

decision2.jpdl.xml

<?xml version="1.0" encoding="UTF-8"?>

<process name="decision2" xmlns="http://jbpm.org/4.4/jpdl">
   <start g="274,4,48,48" name="start1">
      <transition g="-59,-17" name="to have a stroll in the park" to="Shopping in the park to buy tickets"/>
   </start>
   <end g="289,436,48,48" name="end1"/>
   <task g="256,69,92,52" name="Shopping in the park to buy tickets">
      <transition g="-83,-17" name="to exclusive1" to="exclusive1"/>
   </task>
   <decision g="276,147,48,48" name="exclusive1">
      <!-- Specify one handler class -->
      <handler class="com.my.jbpm.handler.MyDecisionHandler" />
      <transition g="-83,-17" name="to Ticket-free for the elderly" to="Ticket-free for the elderly"/>
      <transition g="-71,-17" name="to Demi-Tarif" to="Demi-Tarif"/>
      <transition g="-71,-17" name="to Ordinary ticket sales" to="Ordinary ticket sales"/>
   </decision>
   <task g="75,270,92,52" name="Ticket-free for the elderly">
      <transition g="-47,-17" name="to end1" to="end1"/>
   </task>
   <task g="263,271,92,52" name="Demi-Tarif">
      <transition g="-47,-17" name="to end1" to="end1"/>
   </task>
   <task g="461,272,92,52" name="Ordinary ticket sales">
      <transition g="-47,-17" name="to end1" to="end1"/>
   </task>
</process>

DecisionTest.java

@Test
    //Publish process definitions and start process instances
    public void demo3(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Release process 
        processEngine.getRepositoryService().createDeployment().addResourceFromClasspath("decision2.jpdl.xml").deploy();
        //Startup instance
        processEngine.getExecutionService().startProcessInstanceByKey("decision2");
    }

    @Test
    // Complete the Parks Shopping Task
    public void demo4(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Complete tasks
        //Setting age variable
        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put("age", "80");
        processEngine.getTaskService().setVariables("90008", variables);

        processEngine.getTaskService().completeTask("90008");
    }

fork, join (branching / aggregation)
Solve concurrent tasks in the process (without emphasis on the sequence of tasks)
fork must appear at the same time as join

After running to the fork node, each branch generates a subprocess, each of which stores the current task node.
Branch nodes, where the current task of a process becomes multiple

Code example:
fork.jpdl.xml

<?xml version="1.0" encoding="UTF-8"?>

<process name="fork" xmlns="http://jbpm.org/4.4/jpdl">
   <start g="254,-4,48,48" name="start1">
      <transition g="-47,-17" name="to Reimbursement" to="Reimbursement"/>
   </start>
   <end g="268,395,48,48" name="end1"/>
   <task g="234,75,92,52" name="Reimbursement">
      <transition g="-53,-17" name="to fork1" to="fork1"/>
   </task>
   <fork g="257,142,48,48" name="fork1">
      <transition g="-71,-17" name="to Division Manager" to="Division Manager"/>
      <transition g="-71,-17" name="to Chief Financial Officer" to="Chief Financial Officer"/>
   </fork>
   <join g="267,308,48,48" name="join1">
      <transition g="-47,-17" name="to end1" to="end1"/>
   </join>
   <task g="69,219,92,52" name="Division Manager">
      <transition g="-53,-17" name="to join1" to="join1"/>
   </task>
   <task g="396,220,107,48" name="Chief Financial Officer">
      <transition g="-53,-17" name="to join1" to="join1"/>
   </task>
</process>

ForkJoinTest.java

package com.my.jbpm.jpdl;

import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessEngine;
import org.junit.Test;

public class ForkJoinTest {

    @Test
    //Publish process definitions and start process instances
    public void demo1(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Release process 
        processEngine.getRepositoryService().createDeployment().addResourceFromClasspath("fork.jpdl.xml").deploy();
        //Startup instance
        processEngine.getExecutionService().startProcessInstanceByKey("fork");
    }

    @Test
    //To reimburse and complete the task
    public void demo2(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Complete tasks
        processEngine.getTaskService().completeTask("8");
    }

    @Test
    //Complete tasks for each branch
    public void demo3(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Complete tasks
//      ProceEngine. getTaskService (). CompleteTask ("10003"); approval by Department Manager
        processEngine.getTaskService().completeTask("10005"); //Financial Controller's Approval
    }

}

Task node (task node)

Personal Tasks, Personal Task Managers, Three Ways
1. Task-holder designation by assignee attribute
2. Designate the person in charge through Assignment Handler
3. Replace the person in charge directly through TaskService

Personal Task Common Operations:
Query personal task taskService.findPersonalTasks(userId);
Handling personal tasks taskService.completeTask(taskId)

Code example:
MyAssignmentHandler.java

package com.my.jbpm.handler;

import org.jbpm.api.model.OpenExecution;
import org.jbpm.api.task.Assignable;
import org.jbpm.api.task.AssignmentHandler;

@SuppressWarnings("serial")
public class MyAssignmentHandler implements AssignmentHandler{

    @Override
    public void assign(Assignable assignable, OpenExecution openExecution) throws Exception {
        // Personal tasks
        assignable.setAssignee("Lou Reed");// Designation of Personal Task Managers
    }

}

personaltask.jpdl.xml

<?xml version="1.0" encoding="UTF-8"?>

<process name="personaltask" xmlns="http://jbpm.org/4.4/jpdl">
   <start g="295,6,48,48" name="start1">
      <transition g="-95,-17" name="to Employees apply" to="Employees apply"/>
   </start>
   <end g="292,370,48,48" name="end1"/>
   <task assignee="Zhang San" g="270,85,92,52" name="Employees apply">
      <transition g="-95,-17" name="to Departmental Manager Approval" to="Departmental Manager Approval"/>
   </task>
   <task assignee="#{manager}" g="271,176,92,52" name="Departmental Manager Approval">
      <transition g="-83,-17" name="to General Manager's Approval" to="General Manager's Approval"/>
   </task>
   <task g="273,265,92,52" name="General Manager's Approval">
      <assignment-handler class="com.my.jbpm.handler.MyAssignmentHandler"/>
      <transition g="-47,-17" name="to end1" to="end1"/>
   </task>
</process>

PersonalTaskTest.java

package com.my.jbpm.jpdl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.task.Task;
import org.junit.Test;

public class PersonalTaskTest {

    @Test
    //Publish process definitions and start process instances
    public void demo1(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Release process 
        processEngine.getRepositoryService().createDeployment().addResourceFromClasspath("personaltask.jpdl.xml").deploy();
        //Startup instance
        processEngine.getExecutionService().startProcessInstanceByKey("personaltask");
    }

    @Test
    //Query individual tasks to get task id
    public void demo2(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Query Personal Tasks
        List<Task> tasks = processEngine.getTaskService().findPersonalTasks("Zhang San");
        for (Task task : tasks) {
            System.out.println(task.getId());
        }
    }

    @Test
    // Handling Personal Tasks (Employee Leave)
    public void demo3(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();

        //Handling Personal Tasks
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("manager", "Lao Wang");
        processEngine.getTaskService().setVariables("8", map);

        processEngine.getTaskService().completeTask("8");
    }

    @Test
    //Handling Personal Tasks (Departmental Manager Approval)
    public void demo4(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();

        //Handling Personal Tasks
        processEngine.getTaskService().completeTask("10002");
    }

    @Test
    //Head of Change Task 
    public void demo5(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Replacement of person in charge
        processEngine.getTaskService().assignTask("20001", "Li Si");
    }

}

Group tasks, task nodes, designated groups of people, each person in the group, all have the ability to handle tasks.
Group tasks can be specified in three ways
1. Designate group task leaders through candidate-users or candidate-groups attributes
2. Assignment Handler Program to Assign Group Task Leaders for Task Nodes
3. Add group user processEngine. getTaskService (). addTaskParticipating User (taskId, userId, Participation. CANDIDATE) directly to the task;

Query Group Tasks: taskService.findGroupTasks(userId)
Pick up tasks (turn group tasks into personal tasks): taskService.takeTask(taskId, userId);
The person responsible for the change of task:
taskService.assignTask can change the person responsible for the task
TaskService. assignTask (taskId, null); set the task manager to null and revert to group tasks

The JBPM system provides three tables to manage users and user groups.
jbpm4_id_group stores group information
jbpm4_id_user stores user information
jbpm4_id_memership repository group and user relationship information
Group and user information must be stored in the system before the candidate-groups attribute can be used.

Code example:
MyAssignmentHandler.java

package com.my.jbpm.handler;

import org.jbpm.api.model.OpenExecution;
import org.jbpm.api.task.Assignable;
import org.jbpm.api.task.AssignmentHandler;

@SuppressWarnings("serial")
public class MyAssignmentHandler implements AssignmentHandler{

    @Override
    public void assign(Assignable assignable, OpenExecution openExecution) throws Exception {

        //Group Tasks
        assignable.addCandidateUser("Xiao Ming");
        assignable.addCandidateUser("Xiao Wang");

        assignable.addCandidateGroup("boss");// Designated Task Responsibility Group
    }

}

grouptask.jpdl.xml

<?xml version="1.0" encoding="UTF-8"?>

<process name="grouptask" xmlns="http://jbpm.org/4.4/jpdl">
   <start g="322,5,48,48" name="start1">
      <transition g="-119,-17" name="to Employees submit leave applications" to="Employees submit leave applications"/>
   </start>
   <end g="343,340,48,48" name="end1"/>
   <!-- candidate-users Assign multiple responsible users to a task at a time -->
   <task candidate-users="Zhang San,Li Si,Wang Wu" g="290,81,131,53" name="Employees submit leave applications">
      <transition g="-95,-17" name="to Departmental Manager Approval" to="Departmental Manager Approval"/>
   </task>
   <!-- candidate-groups Assign a responsible group for the task id  -->
   <!-- manager Is the name of a group -->
   <task candidate-groups="manager" g="304,171,122,52" name="Departmental Manager Approval">
      <transition g="-83,-17" name="to General Manager's Approval" to="General Manager's Approval"/>
   </task>
   <task g="303,250,135,52" name="General Manager's Approval">
      <assignment-handler class="com.my.jbpm.handler.MyAssignmentHandler"/>
      <transition g="-47,-17" name="to end1" to="end1"/>
   </task>
</process>

GroupTaskTest.java

package com.my.jbpm.jpdl;

import java.util.List;

import org.jbpm.api.Configuration;
import org.jbpm.api.IdentityService;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.task.Participation;
import org.jbpm.api.task.Task;
import org.junit.Test;

public class GroupTaskTest {
    @Test
    //Publish process definitions and start process instances
    public void demo1(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Release process 
        processEngine.getRepositoryService().createDeployment().addResourceFromClasspath("grouptask.jpdl.xml").deploy();
        //Startup instance
        processEngine.getExecutionService().startProcessInstanceByKey("grouptask");
    }

    @Test
    //Query Group Tasks
    public void demo2(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Query Group Tasks
        List<Task> list = processEngine.getTaskService().findGroupTasks("Li Si");
        System.out.println("Length:" + list.size());
        for (Task task : list) {
            System.out.println(task.getId());
        }
    }

    @Test
    //Query Personal Tasks 
    public void demo3(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Query Personal Tasks
        List<Task> list = processEngine.getTaskService().findPersonalTasks("Zhang San");
        System.out.println("Length:" + list.size());
        for (Task task : list) {
            System.out.println(task.getId());
        }
    }

    @Test
    //To handle group tasks, it is necessary to pick up tasks first.
    public void demo4(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Pick-up task
        processEngine.getTaskService().takeTask("8", "Zhang San");
    }

    @Test
    //Restore the picked-up task to group task
    public void demo5(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Put the pickup task back into the group
        processEngine.getTaskService().assignTask("8", null);
    }

    @Test
    //Dealing with Leave Tasks 
    public void demo6(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Handling tasks
        processEngine.getTaskService().completeTask("8");
    }

    @Test
    //Manager approval (creating groups and users)
    public void demo7(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Obtain the corresponding Service
        IdentityService identityService = processEngine.getIdentityService();
        //Establish manager group and corresponding users
        identityService.createGroup("manager"); // Create Groups 

        identityService.createUser("1", "Zhang", "old");  // Creating Users 
        identityService.createUser("2", "king", "old");
        identityService.createUser("3", "Li", "old");

        identityService.createMembership("1", "manager"); // Establishing relationships
        identityService.createMembership("2", "manager");
    }

    @Test
    //Query Group Tasks (Manager Approval)
    public void demo8(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Query Group Tasks
        List<Task> list = processEngine.getTaskService().findGroupTasks("1");// Lao Zhang
        System.out.println("Length:" + list.size());
        for (Task task : list) {
            System.out.println(task.getId());
        }
    }

    @Test
    //Picking up Tasks (Manager Approval)
    public void demo9(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Pick-up task
        processEngine.getTaskService().takeTask("10001", "1");
    }

    @Test
    //Handling Manager's Examination and Approval Task 
    public void demo10(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Handling tasks
        processEngine.getTaskService().completeTask("10001");
    }

    @Test
    //Add a new group of users for GM approval
    public void demo11(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //New Group Users
        processEngine.getTaskService().addTaskParticipatingUser("30001", "Xiaohong", Participation.CANDIDATE);
    }

}

Swimming lanes
Swimming lanes can ensure that in the same process, multiple task nodes are completed by the same user.
For example, in the financial reimbursement process, after the completion of the financial reimbursement task, the confirmation signature becomes a personal task directly, and it is the user who completes the financial reimbursement task.
Code example:
swimlanes.jpdl.xml

<?xml version="1.0" encoding="UTF-8"?>

<process name="swimlanes" xmlns="http://jbpm.org/4.4/jpdl">
   <!-- Define swimming lanes -->
   <swimlane candidate-users="Zhang San,Li Si,Wang Wu" name="operator"/>
   <start g="298,10,48,48" name="start1">
      <transition g="-71,-17" name="to Financial reimbursement" to="Financial reimbursement"/>
   </start>
   <end g="313,325,48,48" name="end1"/>
   <task g="286,101,92,52" name="Financial reimbursement" swimlane="operator">
      <transition g="-71,-17" name="to Confirmation of signature" to="Confirmation of signature"/>
   </task>
   <task g="287,215,92,52" name="Confirmation of signature" swimlane="operator">
      <transition g="-47,-17" name="to end1" to="end1"/>
   </task>
</process>

SwimlanesTest.java

package com.my.jbpm.jpdl;

import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessEngine;
import org.junit.Test;

public class SwimlanesTest {

    @Test
    //Publish process definitions and start process instances
    public void demo1(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Release process 
        processEngine.getRepositoryService().createDeployment().addResourceFromClasspath("swimlanes.jpdl.xml").deploy();
        //Startup instance
        processEngine.getExecutionService().startProcessInstanceByKey("swimlanes");
    }

    @Test
    //pickup
    public void demo2(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Pick-up task
        processEngine.getTaskService().takeTask("8", "Zhang San");
    }

    @Test
    //Handling financial reimbursement
    public void demo3(){
        //Process Engine
        ProcessEngine processEngine = new Configuration().buildProcessEngine();
        //Handling tasks
        processEngine.getTaskService().completeTask("8");
    }

}

Keywords: xml Java encoding Junit

Added by NuLL[PL] on Mon, 24 Jun 2019 03:53:41 +0300