In the actual Activiti project development, the task node is often used, today I was in the task node listener groping for a day, although the Internet has data but are all kinds of nodes have not been in depth, I was only today to meet the confusion recorded, Hope to help students learn activiti.
Task node monitoring as long as the implementation of the Tasklistener interface, usually we use the Activiti process and business is definitely separate, it must be necessary to use the node listener, in the node listener we can handle the business, the parameters through
Taskservice.setvariables ("parameter name", parameter map)
passes the argument first to the Activiti act_variable table, and then through the node listener
Object value = Delegatetask.getvariable ("parameter name"); The
takes a parameter to implement a business operation. This, of course, does not conflict with Taskservice.complete (Task.id,var), which is the process variable that is the judge condition of the incoming gateway to complete the task.
usually a business save when the task is completed
So change the event to complete, of course if you want to do it before the node is changed to creat, empathy assign and delete, This is the place where Activiti is flexible.
Remember that adding one listener at a time requires a redeployment before it takes effect.
One of the applications in my project is public string StartTask (string jsonstring) {string processdefinitionkey = "a"; ProcessInstance processinstance = Processengine.getruntimeservice (). Startprocessinstancebykey (
Processdefinitionkey);
String nm_pid = Processinstance.getprocessinstanceid (); Query the task of the escalation role and complete the task list<task> TASKSB = Taskservice.createtaskquery (). Processinstanceid (
Processinstance.getprocessinstanceid ()). Taskcandidategroup ("ROLE_SB"). List ();
System.out.println (TASKSB); if (TASKSB!= null && tasksb.size () > 0) {for (Task task:tasksb) {Map<stri
Ng, object> variables = new hashmap<string, object> ();
Into the business variables, jsonstring is the outside incoming parameters, I directly save to the listener to deal with Variables.put ("jsonstring", jsonstring);
The task is stored in the process variable Taskservice.setvariables (Task.getid (), variables); The gateway condition variable determines where the process goes map<string, object> Map = new Hashmap<strING, object> ();
Map.put ("state", 102206) Taskservice.complete (Task.getid (), map); }
}
}
Here's the listener.
"'
Import Org.activiti.engine.delegate.DelegateTask;
Import Org.activiti.engine.delegate.TaskListener;
Import Cn.com.wavenet.webservices.workflow.activiti.saveData.SaveToDb;
public class Flowtasklistener_report implements tasklistener{
/**
* @return
* @return
*
*/
@Override
public void Notify (Delegatetask delegatetask) {
Receive the parameters that the process passes over
Object value = delegatetask.getvariable ("jsonstring");
Business operations can be done here///
'