Framework day57 BOS Project Exercise (process definition/instance management, BOS user role Synchronization Activiti User Table Group table)

Source: Internet
Author: User
Tags gety md5 encryption

BOS Project Note 11th Day

Content:

1. Provide a new JSON file, modify the System menu (join the Workflow menu)

2. Process definition Management (query, deployment process, view PNG process picture)

3. Process instance Management (query, view running status)

4. Synchronize user data and role data in the BOS system to Activiti user and group tables

1. Provide a new JSON file, modify the System menu (join the Workflow menu)

2. Process definition Management

First step : Create a processdefinitionaction, provide a list method, and inject the process engine object

Inquire

@Controller @scope ("prototype") public class Processdefinitionaction extends Actionsupport {@Resourceprivate Processengine processengine;/** * Query the latest version of the process definition list data */public String list () {Processdefinitionquery query = Processengine.getrepositoryservice (). Createprocessdefinitionquery (); Query.latestversion (); list<processdefinition> list = Query.list ();//press Stack Actioncontext.getcontext (). Getvaluestack (). Set ("List", list) ; return "List";}

Step two : Configure Struts.xml

Step three : Provide processdefinition_list.jsp page to show process definition data

<body class= "Easyui-layout" > <div region= "center" > <table id= "grid" class= "Easyui-datagrid" > <t head> <tr> <th data-options= "field: ' ID '" width= "+" > Process number </th> <th data-options= "field: ' Name ' "width=" > Process name </th> <th data-options= "field: ' Key '" width= "+" > Process key</th> <th data-options= "field: ' Version '" width= "> Version number </th> <th data-options=" field: ' Viewpng ' "width=" + "> View Flowchart </th> </tr> </thead> <tbody> <s:iterator value= "list" var= "ProcessDefinition" > &lt ;!  --During the loop, the ProcessDefinition object is put into root and map-<tr> <td> <s:property value= "id"/> <!--  From root-<%--<s:property value= "#processDefinition. Id"/> <!--from map,--%> </td> <td><s:property value= "name"/> </td> <td><s:property value= "key"/></td> <td& Gt;<s:property value= "Version"/></td>  <td> <a onclick= "window.showModalDialog (' Processdefinitionaction_showpng.action?pdid=${id} ')" Class= " Easyui-linkbutton "data-options=" iconcls: ' Icon-search ' "> View flowchart </a> </td> </tr> </s:iterator > </tbody> </table> </div>

2.1 Deployment of Process definition


First step : Provide the File upload page

<s:form action= "Processdefinitionaction_deploy" theme= "simple" method= "post" enctype= "Multipart/form-data" id= " Uploadform "><table class=" Table-edit "width=" 100% "><tr class=" title "><td colspan=" 2 "> Release new Process </TD></TR><TR><TD width= "$" > Browse process Definition Zip compressed file </td><td><input type= "file" Name= "Deploy"/></td></tr><tr><td colspan= "2" ><a id= "btn" href= "javascript:$ (' # Uploadform '). Submit (); "class=" Easyui-linkbutton "data-options=" iconcls: ' Icon-save ' "> Release new Process </a>  < /td></tr></table></s:form>


Step two : Provide the Deploy method in Processdefinitionaction and provide the property of the file type deploy

Receive uploaded files Private file deploy;//zip file public void Setdeploy (file deploy) {This.deploy = deploy;} /** * Deployment Process Definition *  * @throws Exception */public String Deploy () throws Exception {Deploymentbuilder Deploymentbuilder = pr Ocessengine.getrepositoryservice (). Createdeployment (); Zipinputstream Zipinputstream = new Zipinputstream (new FileInputStream (deploy));d Eploymentbuilder.addzipinputstream (Zipinputstream);d Eploymentbuilder.deploy (); return "ToList";}

Step three : Configure Struts.xml

2.2 Viewing flowchart slices


First Step : Modify the address of the link button in the processdefintion_list.jsp page

  <a onclick= "window.showModalDialog (' Processdefinitionaction_showpng.action?pdid=${id} ')"    class= " Easyui-linkbutton "data-options=" iconcls: ' Icon-search ' "> View flowchart  </a>

Step two : Provide the Showpng method in action to get the input stream for the corresponding PNG image

Receive process definition Idprivate string pdid;public void Setpdid (String pdid) {this.pdid = Pdid;} /** * View png picture */public String showpng () {//processengine.getrepositoryservice (). getResourceAsStream (Deploymentid, resourcename); InputStream pngstream = Processengine.getrepositoryservice (). Getprocessdiagram (PdId); Actioncontext.getcontext (). Getvaluestack (). Set ("Pngstream", pngstream);//use struts2 file download function to show PNG picture return "Showpng" ;}

Step three : Configure Struts.xml

<!--process Definition management action--><action name= "processdefinitionaction_*" class= "processdefinitionaction" method= "{1}" ><result name= "List" >/WEB-INF/pages/workflow/processdefinition_list.jsp</result><!--< Result name= "ToList" type= "redirectaction" > <param name= "namespace" >/</param> <param name= " ActionName ">processDefinitionAction_list</param> </result>--><result name=" toList "type=" Redirectaction ">processdefinitionaction_list</result><result name=" showpng "type=" Stream ">< param name= "ContentType" >image/png</param><param name= "InputName" >pngStream</param><!-- <param name= "contentdisposition" >attachment;filename= "document.pdf" </param><param name= " BufferSize ">1024</param>--></result></action>

3. Process instance Management

3.1 Viewing a running process instance


First step : Create a processinstanceaction, provide a list method, query the process instance list data

@Controller @scope ("prototype") public class Processinstanceaction extends Actionsupport {@Autowiredprivate Processengine processengine;/** * Querying running Process instance data */public String list () {//Process instance query object, query table Act_ru_ Executionprocessinstancequery query = Processengine.getruntimeservice (). Createprocessinstancequery (); Query.orderbyprocessdefinitionkey (). DESC (); list<processinstance> list = Query.list (); Actioncontext.getcontext (). Getvaluestack (). Set ("List", list); return "List";}

Step two : Configure Struts.xml

Step three : Provide processinstance_list.jsp page, show list data

<body class= "Easyui-layout" > <div region= "center" > <table id= "grid" class= "Easyui-datagrid" > & lt;thead> <tr> <th data-options= "field: ' Id '" "width=" > Instance number </th> <th data-options= "field: '  Name ' "width=" > Process definition number </th> <th data-options= "field: ' Activity '" "width=" > which task to run </th> <th data-options= "field: ' Viewruntime '" width= "> Business data </th> <th data-options=" field: ' Viewpng ' "  width= > View flowchart </th> </tr> </thead> <tbody> <s:iterator value= "List" > <tr> <td>${id}</td> <td>${processdefinitionid}</td> <td>${activityid}</td> <td&  Gt <div id= "Div${id}" ></div> <script type= "Text/javascript" >//query process variables According to process instance ID $.post ("${ Pagecontext.request.contextpath}/processinstanceaction_finddata.action ", {" id ": ' ${id} '},function (data) {$ (" #div $  {ID} "). html (data);  }); </script> </td> <td> &Lt;script type= "Text/javascript" > function showpng (ID) {window.showModalDialog ("Processinstanceaction_  Showpng.action?id= "+id); } </script> <a data-options= "iconcls: ' Icon-search '" class= "Easyui-linkbutton" onclick= "Showpng (' ${id} ');" href= "#" > View flowchart </a> </td> </tr> </s:iterator> </tbody> </table> &LT;/DIV&G T;</body>

Fourth Step : Provide the FindData method in action to query the corresponding process variables based on the process instance ID

Receive process instance Idprivate string Id;public void SetId (string id) {this.id = ID;} /** * Query process variables based on process instance ID *  * @throws ioexception */public String findData () throws IOException {map<string, object> variables = Processengine.getruntimeservice (). Getvariables (ID); Servletactioncontext.getresponse (). setContentType ("Text/html;charset=utf-8"); Servletactioncontext.getresponse (). Getwriter (). print (variables); return NONE;}

3.2 Querying the running status of the process instance (picture display)


First step : In the Process Instance list page, modify the address of the link button

Effect


Step two : Provide the Showpng method in action, query the deployment ID, picture name, task coordinates

/** * Process Task get picture data * * @return */public String showpng () {//process instance gets process definition idprocessinstance processinstance = processengine. Getruntimeservice (). Createprocessinstancequery (). Processinstanceid (ID). Singleresult (); String Processdefinitionid = Processinstance.getprocessdefinitionid ();//Gets the process definition object through the process definition ID, Then get the deployment ID and picture name processdefinition processdefinition = Processengine.getrepositoryservice (). Createprocessdefinitionquery (). Processdefinitionid (Processdefinitionid). Singleresult (); String Deploymentid = Processdefinition.getdeploymentid (); String imageName = Processdefinition.getdiagramresourcename ();//Process definition object with the process definition ID for detailed (including coordinates) processdefinitionentity Processdefinitionentity = (processdefinitionentity) processengine.getrepositoryservice (). GetProcessDefinition ( Processdefinitionid); String ActivityID = Processinstance.getactivityid ();//Gets the active (current task) object through the activity id activityimpl Activityimpl = Processdefinitionentity.findactivity (ActivityID);//Get picture parameter int x = ACTIVITYIMPL.GETX (); int y = activityimpl.gety (); int Height= Activityimpl.getheight (); int width = Activityimpl.getwidth ();//Put all parameters on the value stack map<string,object> map=new HashMap <string, Object> (), Map.put ("Deploymentid", Deploymentid), Map.put ("ImageName", ImageName), Map.put ("X", x); Map.put ("Y", y), map.put ("height", height), map.put ("width", width); Actioncontext.getcontext (). Getvaluestack (). push (map); return "image";}

Extraction Tool Class: Activitiutils

public class Activitiutils {public static map<string, object> Finddatabyinstanceid (Processengine processengine, String ID) {//Query deployment ID, PNG picture name, current process task coordinates processinstancequery query = Processengine.getruntimeservice (). Createprocessinstancequery ();//Query Process instance object Query.processinstanceid (ID) based on process instance ID; ProcessInstance processinstance = Query.singleresult ();//query process definition based on Process instance object Idstring Processdefinitionid = Processinstance.getprocessdefinitionid ();//query process definition object based on process definition id processdefinitionquery query2 = Processengine.getrepositoryservice (). Createprocessdefinitionquery (); Query2.processdefinitionid ( Processdefinitionid); ProcessDefinition processdefinition = Query2.singleresult ();//Get the current process instance executed to that task. String ActivityID = Processinstance.getactivityid ();//usertask2//The Process definition object (including coordinate information) is queried based on the process definition ID processdefinitionentity ProcessDefinition2 = (processdefinitionentity) processengine.getrepositoryservice (). Getprocessdefinition ( Processdefinitionid); Activityimpl Activityimpl = processdefinition2.findactivity (ActivityID);int x = ACTIVITYIMPL.GETX (); int y = activityimpl.gety (); int width = activityimpl.getwidth (); int height = Activityimpl.geth Eight (); map<string, object> map = new hashmap<string, object> (); Map.put ("Deploymentid", Processdefinition.getdeploymentid ()); Map.put ("ImageName", Processdefinition.getdiagramresourcename ()); Map.put (" X ", x); Map.put (" Y ", y), map.put (" width ", width), map.put (" height ", height); return map;}}

Step three : Configure Struts.xml

Fourth Step: provide image.jsp page, show pictures and Div

<body><!--1. Get to the rule flowchart--><!--2. Based on the coordinates of the current activity , dynamically draw div--><div style= "position:absolute;border:1px solid red;top:${y-1}px;left:${x-1}px;width:${width}px; height:${height}px; " ></div></body>

Fifth Step : Provide the Viewimage method in action to query the input stream of the PNG image

Receive picture Src pass over the argument string Deploymentid; string imagename;public void Setdeploymentid (String deploymentid) {This.deploymentid = Deploymentid;} public void Setimagename (String imageName) {this.imagename = ImageName;} /** * Query the input stream of the PNG image, display the picture */public String viewimage () {InputStream pngstream = Processengine.getrepositoryservice (). getResourceAsStream (Deploymentid, imageName); Actioncontext.getcontext (). Getvaluestack (). Set ("Pngstream", Pngstream); return "Viewimage";}

Sixth Step : Configure Struts.xml, use file download

<!--process instance management action--><action name= "processinstanceaction_*" class= "processinstanceaction" method= "{1}" > <result name= "list" >/web-inf/pages/workflow/processinstance_list.jsp</result><result name= " Showpng ">//web-inf/pages/workflow/image.jsp</result><result name=" ViewImage "type=" Stream ">< param name= "ContentType" >image/png</param><param name= "InputName" >pngstream</param></ Result></action>

4. Synchronizing users and groups in the BOS system to Activiti

 Synchronizing users

Add user, sync to activiti act_id_user  act_id_mebershippublic void Save (user user, string[] roleids) {String password = User.getpassword ();//use MD5 encryption password = MD5UTILS.MD5 (password); User.setpassword (password); userdao.save (user);// Persistent object//Add Activiti UserEntityorg.activiti.engine.identity.User actUser = new userentity (); Actuser.setid (User.getid ()) ;p Rocessengine.getidentityservice (). Saveuser (ActUser);//Operation Act_id_userfor (String id:roleids) {Role role = Roledao.findbyid (ID);//User Association role User.getroles (). Add (role);//Add the AC user to the AC Group Role.getname () Use the role name as the group ID for easy reading Processengine.getidentityservice (). Createmembership (Actuser.getid (), Role.getname ());}

 Sync Group

Save the role, sync to Activiti act_id_grouppublic void Save (role model, String funcitonids) {roledao.save (model);//Persistent object// Create an AC group and add Group group = new Groupentity (); Group.setid (Model.getname ()); Group.setname (Model.getname ()); Processengine.getidentityservice (). Savegroup (group); string[] ids = Funcitonids.split (","); for (String id:ids) {function function = new Function (); Function.setid (ID); MODEL.G Etfunctions (). Add (function);//Role Association permissions}}

Framework day57 BOS Project Exercise (process definition/instance management, BOS user role Synchronization Activiti User Table Group table)

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.