Activiti node listeners combined with business usage (let business and process completely separate)

Source: Internet
Author: User

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///
'

Related Article

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.