Jbpm4.4 learning Summary (3) common interfaces

Source: Internet
Author: User
Tags jbpm

During jbpm4.4 development, we need to use the interfaces provided by jbpm to complete the task. Why are we willing to be kidnapped by jbpm? This is mainly because it is simple ......
1. AssignmentHandler
AssignmentHandler is an interface provided by jbpm to bind users and assign tasks. We can use this interface to specify Task executors, which must work with jpdl. labels and programs in xml are used. In web environments, users in sessions are generally used.
For example:
An employee submits a leave application. If we add an AssignmentHandler to this Task and bind the employee's name, jbpm will know that this process was created by this employee ......
We have submitted the ticket to the lead based on the normal logic. We can implement an AssignmentHandler interface, dynamically define the Actor for the process instance through AssignmentHandler, and set the lead to the executor of the task. The advantage of doing so is flexibility ......
When a leader logs on, the session contains the name of the leader. When the leader queries his/her task list, the employee submits a ticket.
Part of jpdl. xml (mainly two labels: <assignment-handler> and <demo->)
<Task assignee = "$ {name}" g = "235,146, 92,52" name = "LeaveApplication">
<Assignment-handler class = "com. mtf. jbpm. handler. NewApplicationAssignmentHandler"/> // bind the user and employee before creating the ticket
<Transition g = "-113,-17" name = "SubmitApply" to = "ManagerApprove"/>
</Task>
<Task assignee = "$ {name}" g = "244,235, 92,52" name = "ManagerApprove">
<Assignment-handler class = "com. mtf. jbpm. handler. ManagerApproveAssignmentHandler"/> // when a ticket is sent to the manager, the lead
<Transition g = "-46,-23" name = "ManagerApproved" to = "DaysCheck"/>
<Transition g = "-15,-35" name = "ManagerDisApproved" to = "end"/>
</Task>
<Demo-g = "67,240," name = "DaysCheck">
<Handler class = "com. mtf. jbpm. handler. DaysCheckHandler"/> // branch Process
<Transition g = "-20,-2" name = "LessThan3Days" to = "HrMakeSure"/>
<Transition g = "-49,-11" name = "MoreThan3Days" to = "ExecutiveApprove"/>
</Demo->
 
AssignmentHandler for Application Form
Public class NewApplicationAssignmentHandler implements AssignmentHandler {
 
@ Override
Public void assign (Assignable assignable, OpenExecution execution)
Throws Exception {
System. out. println ("pxj creates a leave ");
String name = (String) execution. getVariable ("name ");
System. out. println (name );
Assignable. setAssignee (name );
}
}
AssignmentHandler
Public class ManagerApproveAssignmentHandler implements AssignmentHandler {
 
@ Override
Public void assign (Assignable assignable, OpenExecution execution)
Throws Exception {
System. out. println ("the manager starts to approve ");
String id = (String) execution. getVariable ("parentId ");
Int managerId = Integer. parseInt (id );
EmployeeDao employeeDao = new EmployeeDaoImpl ();
Employee e = employeeDao. findEmployeeById (managerId );
Assignable. setAssignee (e. getE_name_cn ());
}
}
The parentId is set when the application form is submitted. To explain, the employee submits the application form to his/her supervisor, so I found the id of my leader in the method of submitting the application form, which exists in this parentId. Here I am looking for the name of this person (the name of the Leader) through assignable. setAssignee (e. getE_name_cn (); set the executor of the Task to lead ...... As a result, when a leader queries his/her task list, he/she can find the application form submitted by his/her subordinates.
This method is the method for submitting the application form. It should be written in front of it. The idea is a bit confusing ......
/**
* SubmitApplication
*/
@ Override
Public void submitApplication (String actorId, float days,
ProcessInstance pi, int id ){
String taskId = processEngine. getTaskService (). createTaskQuery ()
. ProcessInstanceId (pi. getId (). uniqueResult (). getId ();
// Binding process
// Find the superior
LeaveDao dao = new LeaveDaoImpl ();
Leaves leaves = null;
Try {
List <Leaves> all = dao. queryParentById (id, 1 );
For (int I = 0; I <all. size (); I ++ ){
Leaves = all. get (I );
}
} Catch (Exception e ){
}
System. out. println ("TaskId" + taskId );
Task tasks = processEngine. getTaskService (). getTask (taskId );
String executionId = tasks. getExecutionId ();
ProcessEngine. getExecutionService (). setVariable (executionId,
"ParentId", new String (leaves. getL_emp_id () + ""));
ProcessEngine. getExecutionService (). setVariable (executionId, "days ",
Days );
ProcessEngine. getTaskService (). completeTask (taskId );
}
Main recipients: Process instance id, creator name, and leave id. In this summary, I just want to summarize the jbpm interface. For more information about the process, see the following section.
In fact, there are many task allocation methods.
Task classification and allocation methods
Task category:
Personal task
Method 1: Specify the assignee attribute
Can be specified as a specific String (specific person );
You can also specify a process variable and use the calculated result (the result is String type) to indicate the handler.
Method 2:
AssignmentHandler
Assignable. setAssignee (userId );
Method 3:
ProcessEngine. getTaskService (). assignTask (taskId, userId );
Group task
Method 1: Specify the candidate-users attribute
Can be specified as a specific String (multiple people are separated by commas );
You can also specify a process variable and use the calculated result (if the result is String type, multiple people are separated by commas) to indicate candidates.
Method 2:
AssignmentHandler
Assignable. addCandidateUser (userId); // Add a group member (candidate)
Method 3:
ProcessEngine. getTaskService (). addtaskparticipant ipatinguser (taskId, userId, participant. CANDIDATE );
At this point, the problems related to AssignmentHandler are almost the same.
2. DecisionHandler
The DecisionHandler interface is used to determine the conditions you pass in, and then return a line for you to continue execution, just like making a decision.
Public class DaysCheckHandler implements DecisionHandler {

@ Override
Public String decide (OpenExecution execution ){
// Add the logic for determining the number of days
String days = execution. getProcessInstance (). getVariable ("days"). toString ();
Float day = Float. parseFloat (days );
If (day> 3 ){
Return "MoreThan3Days ";
} Else {
Return "LessThan3Days ";
}
}
}
Get the previous stream "days" and return the line name. For XML configuration, see the preceding section. so easy.
These two interfaces are still quite common. The method I use is relatively simple, but jbpm is much more flexible than we think, especially AssignmentHandler, which can add permissions, etc, I think a single implementation service can also be implemented by multiple users ~~ The design mode is not well learned. Watch it later !!!

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.