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

Source: Internet
Author: User


Following the top two blogs: applying the Third Way

Entities do not need to introduce any workflow-related properties, simply do their own! For example, the following applicant entity (Leave):

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;    Private Date Applytime;    Private String Leavetype;    Private String reason; --Temporary properties--//private map<string, object> variables;    @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;    } @Transient public map<string, object> Getvariables () {return variables;    } public void Setvariables (map<string, object> variables) {this.variables = variables; }}

So how do you integrate with your workflow when querying?


Let's look at the task node:


 /** * Task List error [stderr] (http-localhost/127.0.0.1:8080-3) Scriptenginemanager providers.next (): Javax.script.ScriptE Nginefactory:provider com.sun.script.javascript.RhinoScriptEngineFactory not found * * @param leave */@Re Questmapping (value = "List/task") public Modelandview TaskList (HttpSession session, HttpServletRequest request) {Li    St<map<string, object>> results = new arraylist<map<string, object>> ();    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<map<string, Obje     Ct>> 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;     list<map<string, object>> maplist = new arraylist<map<string, object>> ();         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;                  } map<string, object> Map = new hashmap<string, object> ();                               Leave Leave = Leavebean.findentitybyid (Businesskey); Map.put ("Leave", leave);//Deposit "Application Information" Map.put ("task", Task); Map.put ("ProcessDefinition", Getprocessdefinition (Processinstance.getprocessdefinitionid ())); Map.put ("ProcessInstance", processinstance);//Deposit "process instance" Maplist.add (map);         /*leave leave=updateentity (Processinstance,task,businesskey); Results.add (leave);     */i=i+1; }return Maplist;}

the way we do this is by using Businesskey , does not use the business data stored in the process variables, but directly to the business table to query, avoid the situation of the different steps, and the return value is used Map in the form of a business entity that does not need to add additional attributes, away from what we say AOP A step closer.

These methods are also in the practice of accumulation, do a summary record!




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

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.