Activiti activity name support expression in process history

Source: Internet
Author: User

In Activiti, the task name supports the Juel expression, but when the task is executed and saved to the Process history table, the activity name here does not support the expression, and he saves the expression string to the table, which should be a bug.

Can you solve it? The next step is to study the Activiti code and see if we can find the appropriate extension point to solve the problem.

After research, found the extension point, developed or relatively convenient, the following detailed description, note that the development of this article based on the Activiti5.15.1 version, the general sweep the code, the updated version 5.17 has this problem, but has not been tested.

The history of the process in Activiti is saved in the Act_hi_actinst table, and the code that saves the Act_hi_actinst table when the task is finished is executed in the Defaulthistorymanager class. Recordactivitystart method, so we just have to find a way to inherit this class, and then overwrite this method, and Defaulthistorymanager creation, is in Defaulthistorymanagersessionfactory, and Defaulthistorymanagersessionfactory is initialized, is in the Processengineconfigurationimpl in the Initsessionfactories method, find here, the idea has been very clear, need to write code not much.

One, extended Processengineconfigurationimpl, if using spring integration, inherit the Springprocessengineconfiguration class, overwrite the Initsessionfactories method , call the Addsessionfactory method in the method to add a new custom defaulthistorymanagersessionfactory;

Second, extend the defaulthistorymanagersessionfactory, overwrite the Opensession method, and create a new Defaulthistorymanager in the method;

Third, extend the Defaulthistorymanager, overwrite the Recordactivitystart method, here the key is to get the expression of the parser, and then parse it;

The specific code looks like this:

Import Org.activiti.spring.springprocessengineconfiguration;public class Processengineconfiguration extends springprocessengineconfiguration {@Override protected void initsessionfactories () {Super.initsessionfactori        ES ();    Super.addsessionfactory (New Processhistorymanagersessionfactory ()); }}

Import Org.activiti.engine.impl.interceptor.session;import Org.activiti.engine.impl.persistence.defaulthistorymanagersessionfactory;public class Processhistorymanagersessionfactory extends Defaulthistorymanagersessionfactory {@Override public Session Opensessi    On () {return new Processhistorymanager (); }}

public class processhistorymanager extends defaulthistorymanager {     public void recordactivitystart (executionentity executionentity)  {         if (Ishistorylevelatleast (historylevel.activity))  {             if (Executionentity.getactivity ()  != null)  {                 idgenerator  idgenerator = context.getprocessengineconfiguration (). Getidgenerator ();                                  String processDefinitionId =  Executionentity.getprocessdefinitionid ();                  String processinstanceid = executionentity.getprocessinstanceid ();                 String executionId =  Executionentity.getid ();                                  historicactivityinstanceentity historicactivityinstance = new  Historicactivityinstanceentity ();                 historicactivityinstance.setid (Idgenerator.getnextid ());                  Historicactivityinstance.setprocessdefinitionid (Processdefinitionid);                 historicactivityinstance.setprocessinstancEId (Processinstanceid);                 historicactivityinstance.setexecutionid (Executionid);                 historicactivityinstance.setactivityid ( Executionentity.getactivityid ());                                  expressionmanager expressionmanager = context.getprocessengineconfiguration (). Getexpressionmanager ();                 expression exp = expressionmanager.createexpression (String)   Executionentity.getactivity (). GetProperty ("name"));                     &nbsP;           historicactivityinstance.setactivityname (( String) Exp.getvalue (executionentity));                 historicactivityinstance.setactivitytype (String)  executionentity.getactivity (). GetProperty ("type"));                 historicactivityinstance.setstarttime (Context.getprocessengineconfiguration (). GetClock (). GetCurrentTime ());                                 //  inherit tenant id  (if applicable)                  if  (Executionentity.gettenantid ()  != null)  {                      Historicactivityinstance.settenantid (Executionentity.gettenantid ());                 }                                  getdbsqlsession (). Insert (historicactivityinstance);             }        }       }}


Activiti activity name support expression in process history

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.