2 ways to bind a corresponding business object to each process by "Activiti"

Source: Internet
Author: User

Mode 1:

When you save each process instance, you set up multiple process variables, filter the process instances that match that combination by combining multiple process variables, and later, when you need to query the process instance that corresponds to the business object, simply query the process instance that contains the value of the process variable.

 Setup process:
Public voidstartprocess (Long id) {Customer cus=get (ID); if(Cus! =NULL) { //Modify the status of a customerCus.setstatus (1); UpdateStatus (cus); // nickname The customer's tracking salesperson into the process variable, which can be used to query the process instance that includes the seller map<string, object> map =NewHashmap<string, object>(); if(Cus.getseller ()! =NULL) {Map.put ("Seller", Cus.getseller (). Getnickname ()); } // put the type and ID of the customer into the process variable, which can be used to query the process instance corresponding to the Customer object for the 2 process variablesString ClassType =Cus.getclass (). Getsimplename (); Map.put ("ClassType", ClassType); Map.put ("ObjId", id); //get Processdefinitionkey, default to type simple name plus flowString Processdefinitionkey = ClassType + "Flow"; //Open Process Instanceworkflowservice.startprocessinstancebykeyandvariables (Processdefinitionkey, map); } }
query process:
/*** Test the corresponding process instance according to the limit of the variable value * *@throwsException*/@Test Public voidTestgetfromvariable ()throwsException {Employee Sller=NewEmployee (); Sller.setnickname ("Staff 2"); Sller.setid (4L); List<ProcessInstance> processinstances =runtimeservice.createprocessinstancequery (). Variablevalueequals ("ClassType", Sller.getclass (). Getsimplename ()). List ();        System.out.println (processinstances);  for(ProcessInstance processinstance:processinstances) {System.out.println (processinstance); }        //=====================================================================================================Customer cus =NewCustomer (); Cus.setid (4L); List<ProcessInstance> processInstances1 =runtimeservice.createprocessinstancequery (). Variablevalueequals ("ClassType", Cus.getclass (). Getsimplename ()). Variablevalueequals ("ObjId", Cus.getid ()). List ();        System.out.println (processinstances);  for(ProcessInstance processinstance:processinstances1) {System.out.println (processinstance); }    }

Mode 2:

Use Businesskey to set Businesskey as the association key for the business object Association Process instance when the process instance is opened

 Setup Process :
/*** Use Businesskey as the Association key of the business object associated with the process instance * *@throwsException*/@Test Public voidTestbuskey ()throwsException {//Set BusinesskeyCustomer customer =NewCustomer (); Customer.setid (2L); //Businesskey format with simple class name + primary keyString Busniesskey = Customer.getclass (). Getsimplename () +Customer.getid (); String Definitionkey= Customer.getclass (). Getsimplename () + "Flow"; Map<string, object> map =NewHashmap<string, object>(); Map.put ("Seller", "admin"); //Open ProcessRuntimeservice.startprocessinstancebykey (Definitionkey, Busniesskey, map); }
Query process:
/** * Use Businesskey to query the process instance of the corresponding business object * @throws Exception */ @Test publicvoidthrows Exception { List <ProcessInstance> processinstances = runtimeservice.createprocessinstancequery () . Processinstancebusinesskey ("Customer2", "Customerflow"). List (); System.out.println (processinstances); }

Activiti 2 ways to bind the corresponding business object for each process

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.