jbpm4.4: The realization of the sign

Source: Internet
Author: User

Recently has been in the study of jbpm4.4, in the process of doing the project found a lot of problems, some of the problems in the online material, of course, can be solved smoothly, but when I realized the multi-person sign function, spent

A great deal of energy has not found a good solution, after a half-day code test after the final solution, jbpm4.4 sign the function of the online information is very few, here I will my realization of the idea,

Hope to help beginners.


The implementation code for finding information online is as follows:

public void assign (assignable assignable, openexecution openexecution)
Throws Exception {
String pid = Openexecution.getprocessinstance (). GetId ();
Task task = Workflowservice.gettaskservice (). Createtaskquery (). Processinstanceid (PID)
. Activityname (Openexecution.getname ()). Uniqueresult ();
Createsubtasks (Task);
}

public void Createsubtasks (task Task) {
Get things defined list of countersigned roles
List = (list<string>) workflowservice.gettaskservice (). GetVariable (Task.getid (), "clerk");
Dynamically create subtasks for each role
if (list! = null) {
for (String participant:list) {
Taskimpl SubTask = (Taskimpl) ((opentask) Task). Createsubtask ();
Subtask.setassignee (participant);
Subtask.setformresourcename (Task.getformresourcename ());
Subtask.setname (Task.getname ());
Subtask.setactivityname (Task.getactivityname ());
Workflowservice.gettaskservice (). Addtaskparticipatinguser (Task.getid (), participant, participation.client);
}
}

However, there is a problem with this approach: the subtasks do not get a variable bound to the parent task: for example, if the first task node is the applicant, the form is submitted with a variable of form form

Value, while in this case the task can be assigned dynamically, but when I find my task list, I cannot get the value of the form variable, but the error of the null pointer exception. Now my solution is as follows:


public class Counterassignhandler implements Assignmenthandler {
Private String RoleName;
private static Processengine Processengine;
private static Userdao Userdao;

public void Setuserdao (Userdao Userdao) {
This.userdao = Userdao;
}

public void Setprocessengine (Processengine processengine) {
This.processengine = Processengine;
}

@SuppressWarnings ("Unchecked")
public void assign (assignable assignable, openexecution execution)
Throws Exception {
TODO auto-generated Method Stub
Taskservice Taskservice = Processengine.gettaskservice ();
String pid=execution.getprocessinstance (). GetId ();
Task task=taskservice.createtaskquery (). Processinstanceid (PID). Activityname (Execution.getname ()). UniqueResult () ;
Object value=taskservice.getvariable (Task.getid (), "form"); Get the parent task bound variable
Map<string,object> variables=new hashmap<string, object> ();
Variables.put ("form", value);
List<string> Loginnames=userdao.searchusersofrole (roleName);
if (loginnames!=null) {
for (String actorid:loginnames) {
Taskimpl t = (taskimpl) task; The task coercion type must be converted to Taskimpl here
Taskimpl subTask = T.createsubtask ();
Subtask.setassignee (Actorid);
Subtask.setvariable ("form", value); This is where the parent task-bound variable is set to the child task directly
Taskservice.addtaskparticipatinguser (Task.getid (), Actorid, participation.client);
}
}
}

}


In this way the subtasks can get the variables of the parent task to achieve a smooth flow, and here is also a special reminder, in the fallback and choose the next function, if passed in is the task of TaskID,

Then it is important to remember that the task has a parent task, and if there is a parent task that indicates that it is a subtask, the child task should be in the fallback and select the next step as follows

The node where the parent task is located to get the history task node that has gone through and all the transition that can flow down. When committing a sub-task, we first get all the subtasks through the parent task, and then commit the completion

corresponding subtasks, and then submit the parent task after all the subtasks have been completed so that the process can continue to flow down. I hope it will be of help to you.







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.