"Integration" Activiti business and Process Integration Inquiry (II.)

Source: Internet
Author: User

Following the previous blog: "Integration" JBPM4.4 business and Process integration query application The second way: the request entity to add the required corresponding workflow properties

Package Com.tgb.itoo.basic.entity;import Java.util.date;import Java.util.hashset;import java.util.Map;import Java.util.set;import Javax.persistence.cascadetype;import Javax.persistence.column;import Javax.persistence.entity;import Javax.persistence.fetchtype;import Javax.persistence.joincolumn;import Javax.persistence.manytoone;import Javax.persistence.onetomany;import Javax.persistence.table;import Javax.persistence.temporal;import Javax.persistence.temporaltype;import Javax.persistence.transient;import Org.activiti.engine.history.historicprocessinstance;import org.activiti.engine.repository.ProcessDefinition; Import Org.activiti.engine.runtime.processinstance;import Org.activiti.engine.task.task;import Org.codehaus.jackson.annotate.jsonignore;import org.springframework.format.annotation.datetimeformat;/** * Entity : Leave * * @author Hejingyuan IdEntity implements Serializable */@Entity @table (name = "Oa_leave") public class Leave Exte NDS IdEntity {/** * */private static final lonG Serialversionuid = 1l;private String Processinstanceid;    Private String userId;    Private String TestID;    Private String Oldcourse;    Private String Applycourse; @Column public String Getapplycourse () {return applycourse;} public void Setapplycourse (String applycourse) {this.applycourse = Applycourse;} @Column public String Getoldcourse () {return oldcourse;} public void Setoldcourse (String oldcourse) {this.oldcourse = Oldcourse;} @Columnpublic String Getnewcourse () {return newcourse;} public void Setnewcourse (String newcourse) {this.newcourse = Newcourse;}       Private String Newcourse; @Column public String Gettestid () {return testid;} public void Settestid (String testid) {this.testid = TestID;}    @DateTimeFormat (pattern = "Yyyy-mm-dd hh:mm") Private Date startTime;   @DateTimeFormat (pattern = "Yyyy-mm-dd hh:mm") Private Date endTime;    /* @DateTimeFormat (Pattern = "Yyyy-mm-dd hh:mm") Private Date realitystarttime; @DateTimeFormat (pattern = "Yyyy-mm-dd hh:mm")   Private date realityendtime;*/private date applytime;    Private String Leavetype;    Private String reason;    --Temporary attribute--////Process Task Private task task;    Private map<string, object> variables;    Running process instance private ProcessInstance processinstance;    History of the process instance private historicprocessinstance historicprocessinstance;    Process definition private processdefinition processdefinition;    @Column public String Getprocessinstanceid () {return processinstanceid;    } public void Setprocessinstanceid (String processinstanceid) {This.processinstanceid = Processinstanceid;    } @Column Public String getUserId () {return userId;    } public void Setuserid (String userId) {this.userid = UserId; } @Temporal (Temporaltype.timestamp) @Column (name = "Start_time") public Date GetStartTime () {return START    time;    } public void Setstarttime (Date startTime) {this.starttime = StartTime; } @Temporal (TemporaLtype.timestamp) @Column (name = "End_time") public Date Getendtime () {return endTime;    } public void Setendtime (Date endTime) {this.endtime = EndTime;    } @Column @Temporal (temporaltype.timestamp) public Date getapplytime () {return applytime;    } public void Setapplytime (Date applytime) {this.applytime = Applytime;    } @Column Public String Getleavetype () {return leavetype;    } public void Setleavetype (String leavetype) {this.leavetype = Leavetype;    } @Column Public String GetReason () {return reason;    } public void Setreason (String reason) {This.reason = reason; }/** * Student basic information */@ManyToOne (cascade = cascadetype.all, fetch = Fetchtype.eager, targetentity = Studentcourseinfo.cla    SS) @JoinColumn (name = "Studentcourseinfoid", nullable = True) private Studentcourseinfo studentcourseinfo; Public Studentcourseinfo Getstudentcourseinfo () {return studentcourseinfo;} Public VOID setstudentcourseinfo (studentcourseinfo studentcourseinfo) {this.studentcourseinfo = StudentCourseInfo;}    @Transient Public Task Gettask () {return task;    public void Settask (Task Task) {this.task = task;    } @Transient public map<string, object> Getvariables () {return variables;    } public void Setvariables (map<string, object> variables) {this.variables = variables;    } @Transient Public ProcessInstance getprocessinstance () {return processinstance;    } public void Setprocessinstance (ProcessInstance processinstance) {this.processinstance = ProcessInstance;    } @Transient Public Historicprocessinstance gethistoricprocessinstance () {return historicprocessinstance; } public void Sethistoricprocessinstance (Historicprocessinstance historicprocessinstance) {This.historicproce    Ssinstance = historicprocessinstance; } @Transient Public ProcessDefinition GetprocessdefinItion () {return processdefinition; } public void Setprocessdefinition (ProcessDefinition processdefinition) {this.processdefinition = ProcessDefini    tion; }}


let's start with a brief introduction to the actual application Activiti Medium ratio JBPM4.4 one of the optimizations.

in the Activiti , it provides us with a Businesskey field.

When The process is started , a record is added to the process instance, and there is a businesskey field in the Process instance table ,String businesskey = Leave.getid (). toString (); in this way, our process table will always have a business ID , and we can re-query when we need it again.




The following examples illustrate:

/**     * Task List error [stderr] (http-localhost/127.0.0.1:8080-3) Scriptenginemanager Providers.next (): Javax.script.ScriptEngineFactory:Provider com.sun.script.javascript.RhinoScriptEngineFactory not found     *     * @param leave     *    /@RequestMapping (value = "List/task") public    Modelandview TaskList (HttpSession session, HttpServletRequest request) {    list<leave> results = new arraylist<leave> ();    String userId = userutil.getuserfromsession (session). GetId ();    Results=abstracttasklist (userId);        return new Modelandview ("/oa/leave/tasklist", "results", results);                                         }

/** * Abstract View task list, unrelated to basic business * * @param userId User ID * @return */public list<leave> abstracttasklist (String userId)     {list<leave> results = new arraylist<leave> ();             Query Taskquery taskquery = Taskservice.createtaskquery (), based on the ID of the current person. taskcandidateorassigned (userId);          list<task> tasks = Taskquery.list ();          int i=0;         Queries the entity based on the business ID of the process and associates a for (Task task:tasks) {String Processinstanceid = Task.getprocessinstanceid (); ProcessInstance processinstance = Runtimeservice.createprocessinstancequery (). Processinstanceid (processInstanceId         ). Active (). Singleresult ();         String Businesskey = Processinstance.getbusinesskey ();         if (Businesskey = = null) {continue;         } Leave leave=updateentity (Processinstance,task,businesskey);          Results.add (leave);     i=i+1; }return results;}

Update entity public    Leave updateentity (processinstance processinstance,task task,string businesskey) {   Leave Leave = Leavebean.findentitybyid (Businesskey);   Leave.setprocessinstance (ProcessInstance); Leave.setprocessdefinition (Getprocessdefinition ( Processinstance.getprocessdefinitionid ()));                Leave.settask (Task); return leave;   }


Contrast:

before the JBPM operation, the business data is stored in the process variables when the process is started, the data is taken out of the process variables when the query is needed, and the values that are taken out are assigned to our combined entities. The disadvantage of this is that the data may be out of sync, but it should not be a rare occurrence.

In fact, even if you add the properties of the workflow at the entity level, but you don't need to add the corresponding fields to the actual database tables, where is the convenience? In fact, this is mainly to make us return to the foreground data is more convenient, we just need to return an entity. But what is the disadvantage, is that the business entity needs to know some of the properties of the workflow.

and the downside is that in large systems, the entity layer needs to join all of the dependent workflows Jar package, if this entity also needs to be dependent on other systems, then all systems will have workflow dependencies, the problem we have encountered is that when we in the current system of physical projects When joining a workflow dependency, because other systems also rely on our entity, all systems are paralyzed , and JBoss does not start normally, and it does not recognize the class of the workflow. This effect is far-reaching, so we have to achieve or decoupling.


Continue to the next article




"Integration" Activiti business and Process Integration Inquiry (II.)

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.