JBPM Learning (iv): Running a Process instance

Source: Internet
Author: User

Concept :

ProcessInstance, Process instance : represents one execution of a process definition . as : Zhang San yesterday, according to the process of leave a leave . a Process instance contains all the execution phases , the most typical of which is to track pointers to the current node , for example.

Execution, run: Under normal circumstances, a process instance is the root node of a running tree.

The reason for using a tree structure is that the concept has only one running path and is simpler to use. The business API does not need to understand the differences between the process instances and the functions that run between them. Therefore , there is only one run type in the API that references process instances and runs.

If the remittance and archive can be run at the same time. Then the main process instance consists of 2 child nodes that are used to track the state:

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvdjeymzqxmtczoq==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">

Overall:

ProcessInstance ( process Instance ) is execution (running object), Processinstanceid is Executionid.

In the source code. The ProcessInstance interface directly inherits the execution interface.

Package org.jbpm.api;/** A process instance is one execution of a process definition. * One process instance can has many concurrent executions.   * Executions is structured in a tree of which the processinstance  * is the root. *  @author Tom baeyens */public Interface ProcessInstance extends Execution {}

The gaze probably means:

A process instance is the run of a process definition.

A process instance can have multiple running objects at the same time.

The running object forms a tree, and the process instance is the root node of the tree.


1. Start the process instance

A) Common method

Start process instance//jbpm4_execution, running Information table//Jbpm4_hist_procinst, historical information table @testpublic void Startprocessinstance () {// Starts the process instance using the process definition of the latest version number of the specified key, returns an instance process object ProcessInstance pi = Processengine.getexecutionservice (). Startprocessinstancebykey ("test"); System.out.println ("id=" + pi.getid ()//+ ", state=" + pi.getstate ()//+ ", processdefinitionid=" + Pi.getprocessdefinitionid ());}

b) Start the process instance and set up some process variables

map<string, object> variables = new hashmap<string, object> (); Variables.put ("Applicant", "Zhang San"); Variables.put (" Reimbursement amount ", 1000.00); Start the process instance and set some process variables processinstance pi = Processengine.getexecutionservice (). Startprocessinstancebykey ( Processdefinitionkey, variables);


2. Run Backward one step (Signal)

A) run one step backwards. leave the activity with a unique outcome

Processengine.getexecutionservice (). Signalexecutionbyid (Executionid);

b) Run backward, use a unique outcome to leave the activity, and set some process variables

Prepare the process variable map<string, object> variables = new hashmap<string, object> (), variables.put ("Approval result", "allow"); Processengine.getexecutionservice (). Signalexecutionbyid (Executionid, variables);


c) Run one step backwards. leave the activity using the specified outcome


String outcome= "to End1";p rocessengine.getexecutionservice (). Signalexecutionbyid (Executionid, outcome);

d) Run backward, use the specified outcome to leave the activity, and set some process variables

String outcome= "to End1"; map<string, object> variables = new hashmap<string, object> (); Variables.put ("Approval result", "allow"); Processengine.getexecutionservice (). Signalexecutionbyid (Executionid, outcome, variables);


3. Query tasks

A) Query personal task List

Query my unfinished Task list//Jbpm4_task, running Information table//Jbpm4_hist_task, historical information table @testpublic void Findmytasklist () {String userId = "Employee"; /string UserID = "department manager";//string userid = "General manager";//Mode 1. Query the list of all the tasks I have not handled//list<task> list = Processengine.gettaskserv Ice (). Findpersonaltasks (userId);//Mode 2. Paged query List<task> list = Processengine.gettaskservice ()//. Createtaskquery ()//.assignee (userId)//.page (0, +). List ();//Display System.out.println ("==============" "+ UserId +" "  Non-transacted Task List ============= "); for (Task T:list) {System.out.println (" id= "+ t.getid ()//+", name= "+ t.getname ()//Task Name +", Assignee= "+ t.getassignee ()//task of the Person +", createtime= "+ t.getcreatetime ()//Task creation time +", executionid= "+ T.getexecutionid ()); The ID of the owning run object}}

b) Query Group Task List

Mode 1:

Taskservice.findgrouptasks (USERID);

mode 2:  

list<task> list = Processengine.gettaskservice ()//. Createtaskquery ()//. Candidate (USERID)//. List ();

4. Handling Tasks

A) normal complete task

@Testpublic void Completetask () {String taskId = "180009";//Common Method Processengine.gettaskservice (). Completetask (TaskId) ;//Specify the next method Processengine.gettaskservice (). Completetask (taskId, outcome);//method of setting process variables Processengine.gettaskservice (). Completetask (taskId, outcome, variables);}

b) whether to flow backwards after the task has been controlled ( less )

String taskId = "120001";//1, set to false means: do not move backwards after finishing tasks (default is True) Taskimpl Taskimpl = (Taskimpl) Processengine.gettaskservice (). Gettask (TaskId); taskimpl.setsignalling (false);// 2, finish the task Processengine.gettaskservice (). Completetask (TaskId);

5. Pick up tasks ( less )

A) Taskservice.taketask (TaskId, UserId), pick group task to the Personal task List. Assuming that the task has assignee, it throws an exception.

b) Processengine.gettaskservice (). Assigntask (TaskId, UserId), transferring tasks to others (assuming that the task has assignee, then running this method represents another assignment.) You can also set assignee to null to indicate that the group task is not handled by anyone.

6. Set and get process variables

A) mode 1: set or get process variables according to Executionid

Executionservice.setvariable (Executionid, name, value), Object obj = executionservice.getvariable (Executionid, "absence person") ;

b) Mode 2: set or get process variables according to TaskId

Taskservice.setvariables (taskId, variables); Set multiple variables at once object obj = executionservice.getvariable (Executionid, "absence person");

7. Direct End Process Instance ( manual )

String Processinstanceid = "test.10001";p rocessengine.getexecutionservice (). Endprocessinstance (ProcessInstanceId, processinstance.state_ended);


JBPM Learning (iv): Running a Process instance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.