Jbpm整合Spring3+Struts2

一. 编写Reimbursement.jpdl.xml,以及整合Jbpm与Spring3,Struts2。

Reimbursement.jpdl.xml

View Code
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 
 3 <process name="Reimbursement" xmlns="http://jbpm.org/4.3/jpdl">
 4     <start g="371,21,48,48" name="start1">
 5         <transition g="11,-8" name="to SubmitAnApplication" to="SubmitAnApplication" />
 6     </start>
 7     <task assignee="User" form="User.jsp" g="333,109,123,52" name="SubmitAnApplication">
 8         <transition g="14,-9" name="to Manager" to="Manager" />
 9     </task>
10     <task assignee="Manager" form="Manager.jsp" g="333,215,123,52"
11         name="Manager">
12         <transition g="586,242;585,134:6,-8" name="to Refuse"
13             to="SubmitAnApplication" />
14         <transition name="to exclusive1" to="exclusive1" g="8,-7" />
15     </task>
16     <decision expr="#{money > 2000 ? 'to Deputy': 'to end1'}" g="371,309,48,48"
17         name="exclusive1">
18         <transition name="to Deputy" to="Deputy" g="-14,-20" />
19         <transition name="to end1" to="end1" g="23,-9" />
20     </decision>
21     <task assignee="Deputy" form="Manager.jsp" g="180,309,123,52"
22         name="Deputy">
23         <transition g="-58,-13" name="to Refuse" to="SubmitAnApplication" />
24         <transition g="11,-3" name="to GeneralManager" to="GeneralManager" />
25     </task>
26     <task assignee="GeneralManager" form="Manager.jsp" g="180,422,123,52"
27         name="GeneralManager">
28         <transition g="-16,-19" name="to end1" to="end1" />
29         <transition g="119,449;116,320;114,191;113,136:10,-1" name="to Refuse"
30             to="SubmitAnApplication" />
31     </task>
32     <end g="371,426,48,48" name="end1" />
33 
34 </process>

web.xml

View Code
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
 5     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 6 
 7     <listener>
 8         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 9     </listener>
10     <context-param>
11         <param-name>contextConfigLocation</param-name>
12         <param-value>/WEB-INF/applicationContext.xml</param-value>
13     </context-param>
14     
15     <filter>
16         <filter-name>struts2</filter-name>
17         <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
18     </filter>
19     <filter-mapping>
20         <filter-name>struts2</filter-name>
21         <url-pattern>/*</url-pattern>
22     </filter-mapping>
23 
24     <welcome-file-list>
25         <welcome-file>index.jsp</welcome-file>
26     </welcome-file-list>
27 </web-app>

jbpm.cfg.xml

View Code
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 
 3 <jbpm-configuration>
 4 
 5     <import resource="jbpm.default.cfg.xml" />
 6     <import resource="jbpm.tx.spring.cfg.xml" />
 7     <import resource="jbpm.jpdl.cfg.xml" />
 8     <import resource="jbpm.bpmn.cfg.xml" />
 9     <import resource="jbpm.identity.cfg.xml" />
10     <import resource="jbpm.businesscalendar.cfg.xml" />
11     <import resource="jbpm.console.cfg.xml" />
12 
13     <!--   这一句会会导致启动服务器后定时发出查询JBPM4_JOB的sql语句 -->
14     <!--<import resource="jbpm.jobexecutor.cfg.xml" /> -->
15  
16     <process-engine-context>
17         <string name="spring.cfg" value="/WEB-INF/applicationContext.xml" />
18     </process-engine-context>
19 
20 </jbpm-configuration>

applicationContext.xml

View Code
  1 <?xml version="1.0" encoding="UTF-8"?>
  2 
  3 <beans xmlns="http://www.springframework.org/schema/beans"
  4     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
  5     xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  6     xsi:schemaLocation="
  7           http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  8           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
  9           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
 10           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
 11 
 12     <!--定义DataSource-->
 13     <bean id="dataSource"
 14         class="org.springframework.jdbc.datasource.DriverManagerDataSource">
 15         <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
 16         <property name="url" value="jdbc:oracle:thin:@localhost:1521:ARIMADIS" />
 17         <property name="username" value="scott" />
 18         <property name="password" value="tiger" />
 19     </bean>
 20 
 21     <!--定义SessionFactory-->
 22     <bean id="sessionFactory"
 23         class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
 24         <property name="dataSource" ref="dataSource" />
 25         <property name="hibernateProperties">
 26             <props>
 27                 <prop key="javax.persistence.validation.mode">none</prop>
 28                 <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
 29                 <prop key="hibernate.show_sql">true</prop>
 30                 <prop key="hibernate.format_sql">true</prop>
 31                 <prop key="hibernate.hbm2ddl.auto">none</prop>
 32             </props>
 33         </property>
 34 
 35         <property name="mappingResources">
 36             <list>
 37                 <value>jbpm.repository.hbm.xml</value>
 38                 <value>jbpm.execution.hbm.xml</value>
 39                 <value>jbpm.history.hbm.xml</value>
 40                 <value>jbpm.task.hbm.xml</value>
 41                 <value>jbpm.identity.hbm.xml</value>
 42             </list>
 43         </property>
 44     </bean>
 45 
 46     <!--定义TransactionManager-->
 47     <bean id="transactionManager"
 48         class="org.springframework.orm.hibernate3.HibernateTransactionManager">
 49         <property name="sessionFactory" ref="sessionFactory" />
 50         <property name="dataSource" ref="dataSource" />
 51     </bean>
 52 
 53     <!--定义SpringHelper该类可以产生ProcessEngine-->
 54     <bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper" />
 55 
 56     <!--产生ProcessEngine-->
 57     <bean id="processEngine" factory-bean="springHelper"
 58         factory-method="createProcessEngine" />
 59 
 60     <!--产生 *UserLoginAction-->
 61     <bean id="UserLogin" class="com.demo.reimbursement.UserLoginAction"
 62         scope="prototype"></bean>
 63 
 64     <bean id="ListProcess" class="com.demo.reimbursement.ListProcessAction"
 65         scope="prototype">
 66         <property name="processEngine" ref="processEngine"></property>
 67     </bean>
 68 
 69     <bean id="DeployProcess" class="com.demo.reimbursement.DeployProcessAction"
 70         scope="prototype">
 71         <property name="processEngine" ref="processEngine"></property>
 72     </bean>
 73 
 74     <bean id="StartProcessDefinition" class="com.demo.reimbursement.StartProcessDefinitionAction"
 75         scope="prototype">
 76         <property name="processEngine" ref="processEngine"></property>
 77     </bean>
 78 
 79     <bean id="DeleteProcessDefinitionCascade"
 80         class="com.demo.reimbursement.DeleteProcessDefinitionCascadeAction"
 81         scope="prototype">
 82         <property name="processEngine" ref="processEngine"></property>
 83     </bean>
 84 
 85     <bean id="ViewCurrentTask" class="com.demo.reimbursement.ViewCurrentTaskAction"
 86         scope="prototype">
 87         <property name="processEngine" ref="processEngine"></property>
 88     </bean>
 89 
 90     <bean id="SubmitApplication" class="com.demo.reimbursement.SubmitApplicationAction"
 91         scope="prototype">
 92         <property name="processEngine" ref="processEngine"></property>
 93     </bean>
 94 
 95     <bean id="AssessmentApplication" class="com.demo.reimbursement.AssessmentApplicationAction"
 96         scope="prototype">
 97         <property name="processEngine" ref="processEngine"></property>
 98     </bean>
 99 
100     <bean id="GetProcessImage" class="com.demo.reimbursement.GetProcessImageAction"
101         scope="prototype">
102         <property name="processEngine" ref="processEngine"></property>
103     </bean>
104 
105     <bean id="ViewDirectionOfCurrentProcessInstance"
106         class="com.demo.reimbursement.ViewDirectionOfCurrentProcessInstanceAction"
107         scope="prototype">
108         <property name="processEngine" ref="processEngine"></property>
109     </bean>
110 
111 </beans>

二. 编写前台页面

Login.jsp

View Code
 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <%@ taglib prefix="s" uri="/struts-tags"%>
 3 <%
 4     String path = request.getContextPath();
 5     String basePath = request.getScheme() + "://"
 6             + request.getServerName() + ":" + request.getServerPort()
 7             + path + "/";
 8 %>
 9 
10 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
11 <html>
12     <head>
13         <base href="<%=basePath%>">
14 
15         <title>用户登录</title>
16 
17         <meta http-equiv="pragma" content="no-cache">
18         <meta http-equiv="cache-control" content="no-cache">
19         <meta http-equiv="expires" content="0">
20         <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
21         <meta http-equiv="description" content="This is my page">
22         <!--
23     <link rel="stylesheet" type="text/css" href="styles.css">
24     -->
25 
26     </head>
27 
28     <body>
29         <form action="Reimbursement/UserLoginAction.action" method="POST">
30             用户名:
31             <input type="text" name="userName" />
32             <br />
33             密码:
34             <input type="password" name="password" />
35             <br />
36             <input type="submit" value="登录" />
37         </form>
38     </body>
39 </html>

Manager.jsp

View Code
 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <%@taglib prefix="s" uri="/struts-tags"%>
 3 <%
 4     String path = request.getContextPath();
 5     String basePath = request.getScheme() + "://"
 6             + request.getServerName() + ":" + request.getServerPort()
 7             + path + "/";
 8 %>
 9 
10 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
11 <html>
12     <head>
13         <base href="<%=basePath%>">
14 
15         <title>申请审批</title>
16 
17         <meta http-equiv="pragma" content="no-cache">
18         <meta http-equiv="cache-control" content="no-cache">
19         <meta http-equiv="expires" content="0">
20         <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
21         <meta http-equiv="description" content="This is my page">
22         <!--
23     <link rel="stylesheet" type="text/css" href="styles.css">
24     -->
25 
26     </head>
27 
28     <body>
29         <center>
30             <h2>
31                 审核:
32             </h2>
33         </center>
34 
35         <form action="Reimbursement/AssessmentApplicationAction.action"
36             method="post">
37 
38             <input type="hidden" name="taskId"
39                 value="<s:property value='taskId'/>">
40 
41             报销数额:
42             <s:property value="money" />
43             <br>
44 
45             批准:
46             <input type="radio" name="result" value="1">
47             &nbsp;&nbsp;拒绝
48             <input type="radio" name="result" value="2">
49             <br>
50 
51             <input type="submit" value="提交">
52 
53         </form>
54 
55     </body>
56 </html>

Success.jsp

View Code
  1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  2 <%@ taglib prefix="s" uri="/struts-tags"%>
  3 <%
  4     String path = request.getContextPath();
  5     String basePath = request.getScheme() + "://"
  6             + request.getServerName() + ":" + request.getServerPort()
  7             + path + "/";
  8 %>
  9 
 10 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 11 <html>
 12     <head>
 13         <base href="<%=basePath%>">
 14 
 15         <title>流程相关内容列表</title>
 16 
 17         <meta http-equiv="pragma" content="no-cache">
 18         <meta http-equiv="cache-control" content="no-cache">
 19         <meta http-equiv="expires" content="0">
 20         <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 21         <meta http-equiv="description" content="This is my page">
 22         <!--
 23     <link rel="stylesheet" type="text/css" href="styles.css">
 24     -->
 25 
 26     </head>
 27 
 28     <body>
 29         <center>
 30             <h2>
 31                 流程相关内容列表
 32             </h2>
 33         </center>
 34         <table width="80%" align="center">
 35             <tr>
 36                 <td width="100%">
 37                     <b><font color="red">待处理任务列表</font> </b>
 38                 </td>
 39             </tr>
 40         </table>
 41         <table cellpadding="3" cellspacing="1" border="0" align="center"
 42             class="table" width="80%">
 43             <tr class="tr">
 44                 <td align="center" bgcolor="#78A1E6" nowrap="nowrap">
 45                     序号
 46                 </td>
 47                 <td align="center" bgcolor="#78A1E6" nowrap="nowrap">
 48                     名称
 49                 </td>
 50                 <td align="center" bgcolor="#78A1E6" nowrap="nowrap">
 51                     状态
 52                 </td>
 53                 <td align="center" bgcolor="#78A1E6" nowrap="nowrap">
 54                     任务详情
 55                 </td>
 56             </tr>
 57             <s:iterator value="tasks">
 58                 <tr class="tr">
 59                     <td align="center" bgcolor="#E6ECF9">
 60                         <s:property value="id" />
 61                     </td>
 62                     <td align="center" bgcolor="#E6ECF9">
 63                         <s:property value="name" />
 64                     </td>
 65                     <td align="center" bgcolor="#E6ECF9">
 66                         <s:property value="state" />
 67                     </td> 
 68                     <td align="center" bgcolor="#E6ECF9">
 69                         <a href="Reimbursement/ViewCurrentTaskAction.action?taskId=<s:property value='id' />&formResourceName=/<s:property value='formResourceName'/>" />查看</a>
 70                     </td>
 71                 </tr>
 72             </s:iterator>
 73         </table>
 74 
 75         <table width="80%" align="center">
 76             <tr>
 77                 <td width="100%">
 78                     <b><font color="red">流程实例列表</font> </b>
 79                 </td>
 80             </tr>
 81         </table>
 82         <table cellpadding="3" cellspacing="1" border="0" align="center"
 83             class="table" width="80%">
 84             <tr class="tr">
 85                 <td align="center" bgcolor="#78A1E6" nowrap="nowrap">
 86                     序号
 87                 </td>
 88                 <td align="center" bgcolor="#78A1E6" nowrap="nowrap">
 89                     状态
 90                 </td>
 91                 <td align="center" bgcolor="#78A1E6" nowrap="nowrap">
 92                     实例详情
 93                 </td>
 94             </tr>
 95             <s:iterator value="processInstances">
 96                 <tr class="tr">
 97                     <td align="center" bgcolor="#E6ECF9">
 98                         <s:property value="id" />
 99                     </td>
100                     <td align="center" bgcolor="#E6ECF9">
101                         <s:property value="state" />
102                     </td>
103                     <td align="center" bgcolor="#E6ECF9">
104                         <a href="Reimbursement/ViewDirectionOfCurrentProcessInstanceAction.action?processInstanceId=<s:property value='id' />" />查看</a>
105                     </td>
106                 </tr>
107             </s:iterator>
108         </table>
109 
110         <table width="80%" align="center">
111             <tr>
112                 <td width="100%">
113                     <b><font color="red">流程定义列表</font> </b>
114                 </td>
115             </tr>
116         </table>
117         <table cellpadding="3" cellspacing="1" border="0" align="center"
118             class="table" width="80%">
119             <tr class="tr">
120                 <td align="center" bgcolor="#78A1E6" nowrap="nowrap">
121                     序号
122                 </td>
123                 <td align="center" bgcolor="#78A1E6" nowrap="nowrap">
124                     名称
125                 </td>
126                 <td align="center" bgcolor="#78A1E6" nowrap="nowrap">
127                     版本号
128                 </td>
129                 <td align="center" bgcolor="#78A1E6" nowrap="nowrap">
130                     开启流程
131                 </td>
132                 <td align="center" bgcolor="#78A1E6" nowrap="nowrap">
133                     删除
134                 </td>
135             </tr>
136             <s:iterator value="processDefinitions">
137                 <tr class="tr">
138                     <td align="center" bgcolor="#E6ECF9">
139                         <s:property value="id" />
140                     </td>
141                     <td align="center" bgcolor="#E6ECF9">
142                         <s:property value="name" />
143                     </td>
144                     <td align="center" bgcolor="#E6ECF9">
145                         <s:property value="version" />
146                     </td>
147                     <td align="center" bgcolor="#E6ECF9">
148                         <a
149                             href="Reimbursement/StartProcessDefinitionAction.action?processDefinitionId=<s:property value='id' />" />开启</a>
150                     </td>
151                     <td align="center" bgcolor="#E6ECF9">
152                         <a
153                             href="Reimbursement/DeleteProcessDefinitionCascadeAction.action?deploymentId=<s:property value='deploymentId' />" />删除</a>
154                     </td>
155                 </tr>
156             </s:iterator>
157         </table>
158 
159 
160 
161 
162         <center>
163             用户:
164             <font color="red"><s:property value="userName" /> </font>
165             &nbsp;&nbsp;&nbsp;
166             <a href="Reimbursement/DeployProcessAction.action">部署流程</a>
167             &nbsp;&nbsp;&nbsp;
168             <a href="/jbpm/Login.jsp">重新登录</a>
169         </center>
170     </body>
171 </html>

User.jsp

View Code
 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <%@taglib prefix="s" uri="/struts-tags" %>
 3 <%
 4     String path = request.getContextPath();
 5     String basePath = request.getScheme() + "://"
 6             + request.getServerName() + ":" + request.getServerPort()
 7             + path + "/";
 8 %>
 9 
10 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
11 <html>
12     <head>
13         <base href="<%=basePath%>">
14 
15         <title>提交报销申请</title>
16 
17         <meta http-equiv="pragma" content="no-cache">
18         <meta http-equiv="cache-control" content="no-cache">
19         <meta http-equiv="expires" content="0">
20         <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
21         <meta http-equiv="description" content="This is my page">
22         <!--
23     <link rel="stylesheet" type="text/css" href="styles.css">
24     -->
25 
26     </head>
27 
28     <body>
29         <center>
30             <h2>
31                 报销申请:
32             </h2>
33         </center>
34 
35         <form action="Reimbursement/SubmitApplicationAction.action" method="post">
36 
37             <input type="hidden" name="taskId" value="<s:property value='taskId'/>">
38 
39             报销金额:
40             <input type="text" name="money">
41             <br>
42             <input type="submit" value="提交">
43 
44         </form>
45         
46     </body>
47 </html>

ViewProcess.jsp

View Code
 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <%@taglib prefix="s" uri="/struts-tags"%>
 3 <%
 4     String path = request.getContextPath();
 5     String basePath = request.getScheme() + "://"
 6             + request.getServerName() + ":" + request.getServerPort()
 7             + path + "/";
 8 %>
 9 
10 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
11 <html>
12     <head>
13         <base href="<%=basePath%>">
14 
15         <title>查看流程图</title>
16 
17         <meta http-equiv="pragma" content="no-cache">
18         <meta http-equiv="cache-control" content="no-cache">
19         <meta http-equiv="expires" content="0">
20         <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
21         <meta http-equiv="description" content="This is my page">
22         <!--
23     <link rel="stylesheet" type="text/css" href="styles.css">
24     -->
25 
26     </head>
27 
28     <body>
29         <img
30             src="Reimbursement/GetProcessImageAction.action?processInstanceId=<s:property value='processInstanceId'/>"
31             style="position: absolute; left: 0; top: 0">
32         <div
33             style="position: absolute; border: 2px dashed blue; left:<s:property value='x'/>; top:<s:property value='y'/>; 
34                 <s:property value='width'/>; height:<s:property value='height'/>"></div>
35     </body>
36 </html>

三. 编写Action

AssessmentApplicationAction.java

View Code
 1 package com.demo.reimbursement;
 2 
 3 import org.jbpm.api.ProcessEngine;
 4 import org.jbpm.api.TaskService;
 5 
 6 import com.opensymphony.xwork2.ActionContext;
 7 import com.opensymphony.xwork2.ActionSupport;
 8 
 9 public class AssessmentApplicationAction extends ActionSupport
10 {
11     private String taskId;
12     private ProcessEngine processEngine;
13     private Integer result;
14 
15     public String getTaskId()
16     {
17         return taskId;
18     }
19 
20     public void setTaskId(String taskId)
21     {
22         this.taskId = taskId;
23     }
24 
25     public ProcessEngine getProcessEngine()
26     {
27         return processEngine;
28     }
29 
30     public void setProcessEngine(ProcessEngine processEngine)
31     {
32         this.processEngine = processEngine;
33     }
34 
35     public Integer getResult()
36     {
37         return result;
38     }
39 
40     public void setResult(Integer result)
41     {
42         this.result = result;
43     }
44 
45     public String execute() throws Exception
46     {
47         TaskService taskService = this.processEngine.getTaskService();
48         String loginUserName = (String) ActionContext.getContext().getSession()
49                 .get("userName");
50         if ("Manager".equals(loginUserName))
51         {
52             if (1 == this.result)
53             {
54                 taskService.completeTask(this.taskId, "to exclusive1");
55             }
56             else
57             {
58                 taskService.completeTask(this.taskId, "to Refuse");
59             }
60         }
61         else if ("Deputy".equals(loginUserName))
62         {
63             if (1 == this.result)
64             {
65                 taskService.completeTask(this.taskId, "to GeneralManager");
66             }
67             else
68             {
69                 taskService.completeTask(this.taskId, "to Refuse");
70             }
71         }
72         else
73         {
74             if (1 == this.result)
75             {
76                 taskService.completeTask(this.taskId, "to end1");
77             }
78             else
79             {
80                 taskService.completeTask(this.taskId, "to Refuse");
81             }
82         }
83 
84         return SUCCESS;
85     }
86 }

DeleteProcessDefinitionCascadeAction.java

View Code
 1 package com.demo.reimbursement;
 2 
 3 import org.jbpm.api.ProcessEngine;
 4 import org.jbpm.api.RepositoryService;
 5 
 6 import com.opensymphony.xwork2.ActionSupport;
 7 
 8 public class DeleteProcessDefinitionCascadeAction extends ActionSupport
 9 {
10     private ProcessEngine processEngine;
11     private String deploymentId;
12 
13     public ProcessEngine getProcessEngine()
14     {
15         return processEngine;
16     }
17 
18     public void setProcessEngine(ProcessEngine processEngine)
19     {
20         this.processEngine = processEngine;
21     }
22 
23     public String getDeploymentId()
24     {
25         return deploymentId;
26     }
27 
28     public void setDeploymentId(String deploymentId)
29     {
30         this.deploymentId = deploymentId;
31     }
32 
33     public String execute() throws Exception
34     {
35         RepositoryService repositoryService = this.processEngine
36                 .getRepositoryService();
37         repositoryService.deleteDeploymentCascade(this.deploymentId);
38         return SUCCESS;
39     }
40 }

DeployProcessAction.java

View Code
 1 package com.demo.reimbursement;
 2 
 3 import java.io.IOException;
 4 import java.util.zip.ZipInputStream;
 5 
 6 import org.jbpm.api.ProcessEngine;
 7 
 8 import com.opensymphony.xwork2.ActionSupport;
 9 
10 public class DeployProcessAction extends ActionSupport
11 {
12     private ProcessEngine processEngine;
13 
14     public ProcessEngine getProcessEngine()
15     {
16         return processEngine;
17     }
18 
19     public void setProcessEngine(ProcessEngine processEngine)
20     {
21         this.processEngine = processEngine;
22     }
23 
24     public String execute()
25     {
26         ZipInputStream zipInputStream = null;
27 
28         zipInputStream = new ZipInputStream(this.getClass()
29                 .getResourceAsStream("/Reimbursement.zip"));
30         this.processEngine.getRepositoryService().createDeployment()
31                 .addResourcesFromZipInputStream(zipInputStream).deploy();
32         try
33         {
34             zipInputStream.close();
35         }
36         catch (IOException e)
37         {
38             e.printStackTrace();
39         }
40 
41         return SUCCESS;
42     }
43 }

GetProcessImageAction.java

View Code
 1 package com.demo.reimbursement;
 2 
 3 import java.io.InputStream;
 4 import java.io.OutputStream;
 5 
 6 import org.apache.struts2.ServletActionContext;
 7 import org.jbpm.api.ExecutionService;
 8 import org.jbpm.api.ProcessDefinition;
 9 import org.jbpm.api.ProcessEngine;
10 import org.jbpm.api.ProcessInstance;
11 import org.jbpm.api.RepositoryService;
12 
13 import com.opensymphony.xwork2.ActionSupport;
14 
15 public class GetProcessImageAction extends ActionSupport
16 {
17     private ProcessEngine processEngine;
18     private String processInstanceId;
19 
20     public ProcessEngine getProcessEngine()
21     {
22         return processEngine;
23     }
24 
25     public void setProcessEngine(ProcessEngine processEngine)
26     {
27         this.processEngine = processEngine;
28     }
29 
30     public String getProcessInstanceId()
31     {
32         return processInstanceId;
33     }
34 
35     public void setProcessInstanceId(String processInstanceId)
36     {
37         this.processInstanceId = processInstanceId;
38     }
39 
40     public String execute() throws Exception
41     {
42         RepositoryService repositoryService = this.processEngine
43                 .getRepositoryService();
44 
45         ExecutionService executionService = this.processEngine
46                 .getExecutionService();
47         ProcessInstance processInstance = executionService
48                 .findProcessInstanceById(this.processInstanceId);
49 
50         String processDefinitionId = processInstance.getProcessDefinitionId();
51         ProcessDefinition processDefinition = repositoryService
52                 .createProcessDefinitionQuery().processDefinitionId(
53                         processDefinitionId).uniqueResult();
54 
55         InputStream imageInputStream = repositoryService.getResourceAsStream(
56                 processDefinition.getDeploymentId(), "Reimbursement.png");
57         OutputStream out = ServletActionContext.getResponse().getOutputStream();
58 
59         byte buffer[] = new byte[1024];
60         int length = 0;
61         while ((length = imageInputStream.read(buffer)) != -1)
62         {
63             out.write(buffer, 0, length);
64         }
65         imageInputStream.close();
66         out.close();
67         return null;
68 
69     }
70 }

ListProcessAction.java

View Code
 1 package com.demo.reimbursement;
 2 
 3 import java.util.List;
 4 
 5 import org.jbpm.api.ExecutionService;
 6 import org.jbpm.api.ProcessDefinition;
 7 import org.jbpm.api.ProcessEngine;
 8 import org.jbpm.api.ProcessInstance;
 9 import org.jbpm.api.RepositoryService;
10 import org.jbpm.api.TaskService;
11 import org.jbpm.api.task.Task;
12 
13 import com.opensymphony.xwork2.ActionContext;
14 import com.opensymphony.xwork2.ActionSupport;
15 
16 public class ListProcessAction extends ActionSupport
17 {
18     private ProcessEngine processEngine;
19     private List<Task> tasks;
20     private List<ProcessDefinition> processDefinitions;
21     private List<ProcessInstance> processInstances;
22     private String userName;
23 
24     public List<Task> getTasks()
25     {
26         return tasks;
27     }
28 
29     public void setTasks(List<Task> tasks)
30     {
31         this.tasks = tasks;
32     }
33 
34     public List<ProcessDefinition> getProcessDefinitions()
35     {
36         return processDefinitions;
37     }
38 
39     public void setProcessDefinitions(List<ProcessDefinition> processDefinitions)
40     {
41         this.processDefinitions = processDefinitions;
42     }
43 
44     public List<ProcessInstance> getProcessInstances()
45     {
46         return processInstances;
47     }
48 
49     public void setProcessInstances(List<ProcessInstance> processInstances)
50     {
51         this.processInstances = processInstances;
52     }
53 
54     public ProcessEngine getProcessEngine()
55     {
56         return processEngine;
57     }
58 
59     public void setProcessEngine(ProcessEngine processEngine)
60     {
61         this.processEngine = processEngine;
62     }
63 
64     public String getUserName()
65     {
66         return userName;
67     }
68 
69     public void setUserName(String userName)
70     {
71         this.userName = userName;
72     }
73 
74     public String execute() throws Exception
75     {
76         this.userName = (String) ActionContext.getContext().getSession().get(
77                 "userName");
78 
79         RepositoryService repositoryService = this.processEngine
80                 .getRepositoryService();
81         this.processDefinitions = repositoryService
82                 .createProcessDefinitionQuery().list();
83 
84         ExecutionService executionService = this.processEngine
85                 .getExecutionService();
86         this.processInstances = executionService.createProcessInstanceQuery()
87                 .list();
88 
89         TaskService taskService = this.processEngine.getTaskService();
90         this.tasks = taskService.findPersonalTasks(this.userName);
91 
92         return SUCCESS;
93     }
94 }

StartProcessDefinitionAction.java

View Code
 1 package com.demo.reimbursement;
 2 
 3 import org.jbpm.api.ExecutionService;
 4 import org.jbpm.api.ProcessEngine;
 5 
 6 import com.opensymphony.xwork2.ActionSupport;
 7 
 8 public class StartProcessDefinitionAction extends ActionSupport
 9 {
10     private ProcessEngine processEngine;
11     private String processDefinitionId;
12 
13     public ProcessEngine getProcessEngine()
14     {
15         return processEngine;
16     }
17 
18     public void setProcessEngine(ProcessEngine processEngine)
19     {
20         this.processEngine = processEngine;
21     }
22 
23     public String getProcessDefinitionId()
24     {
25         return processDefinitionId;
26     }
27 
28     public void setProcessDefinitionId(String processDefinitionId)
29     {
30         this.processDefinitionId = processDefinitionId;
31     }
32 
33     public String execute() throws Exception
34     {
35         ExecutionService executionService = this.processEngine
36                 .getExecutionService();
37         executionService.startProcessInstanceById(this.processDefinitionId);
38         return SUCCESS;
39     }
40 }

SubmitApplicationAction.java

View Code
 1 package com.demo.reimbursement;
 2 
 3 import java.util.HashMap;
 4 import java.util.Map;
 5 
 6 import org.jbpm.api.ProcessEngine;
 7 import org.jbpm.api.TaskService;
 8 
 9 import com.opensymphony.xwork2.ActionSupport;
10 
11 public class SubmitApplicationAction extends ActionSupport
12 {
13     private String taskId;
14     private String money;
15     private ProcessEngine processEngine;
16 
17     public String getTaskId()
18     {
19         return taskId;
20     }
21 
22     public void setTaskId(String taskId)
23     {
24         this.taskId = taskId;
25     }
26 
27     public String getMoney()
28     {
29         return money;
30     }
31 
32     public void setMoney(String money)
33     {
34         this.money = money;
35     }
36 
37     public ProcessEngine getProcessEngine()
38     {
39         return processEngine;
40     }
41 
42     public void setProcessEngine(ProcessEngine processEngine)
43     {
44         this.processEngine = processEngine;
45     }
46 
47     public String execute() throws Exception
48     {
49         TaskService taskService = this.processEngine.getTaskService();
50         Map<String, Object> mp = new HashMap<String, Object>();
51         mp.put("money", this.money);
52         taskService.completeTask(this.taskId, "to Manager", mp);
53 
54         return SUCCESS;
55     }
56 }

UserLoginAction.java

View Code
 1 package com.demo.reimbursement;
 2 
 3 
 4 import com.opensymphony.xwork2.ActionContext;
 5 import com.opensymphony.xwork2.ActionSupport;
 6 
 7 public class UserLoginAction extends ActionSupport
 8 {
 9     private String userName;
10     private String password;
11 
12     public String getUserName()
13     {
14         return userName;
15     }
16 
17     public void setUserName(String userName)
18     {
19         this.userName = userName;
20     }
21 
22     public String getPassword()
23     {
24         return password;
25     }
26 
27     public void setPassword(String password)
28     {
29         this.password = password;
30     }
31 
32     public String execute() throws Exception
33     {
34         ActionContext.getContext().getSession().put("userName", this.userName);
35 
36         return SUCCESS;
37     }
38 }

ViewCurrentTaskAction.java

View Code
 1 package com.demo.reimbursement;
 2 
 3 import org.jbpm.api.ProcessEngine;
 4 import org.jbpm.api.TaskService;
 5 
 6 import com.opensymphony.xwork2.ActionSupport;
 7 
 8 public class ViewCurrentTaskAction extends ActionSupport
 9 {
10     private String taskId;
11     private String formResourceName;
12     private ProcessEngine processEngine;
13     private Integer money;
14 
15     public ProcessEngine getProcessEngine()
16     {
17         return processEngine;
18     }
19 
20     public void setProcessEngine(ProcessEngine processEngine)
21     {
22         this.processEngine = processEngine;
23     }
24 
25     public Integer getMoney()
26     {
27         return money;
28     }
29 
30     public void setMoney(Integer money)
31     {
32         this.money = money;
33     }
34 
35     public String getTaskId()
36     {
37         return taskId;
38     }
39 
40     public void setTaskId(String taskId)
41     {
42         this.taskId = taskId;
43     }
44 
45     public String getFormResourceName()
46     {
47         return formResourceName;
48     }
49 
50     public void setFormResourceName(String formResourceName)
51     {
52         this.formResourceName = formResourceName;
53     }
54 
55     public String execute() throws Exception
56     {
57         TaskService taskService = this.processEngine.getTaskService();
58         if (null != taskService.getVariable(this.taskId, "money"))
59         {
60             this.money = Integer.parseInt((String) taskService.getVariable(
61                     taskId, "money"));
62         }
63         return SUCCESS;
64     }
65 }

ViewDirectionOfCurrentProcessInstanceAction.java

View Code
  1 package com.demo.reimbursement;
  2 
  3 import java.util.Set;
  4 
  5 import org.jbpm.api.ExecutionService;
  6 import org.jbpm.api.ProcessEngine;
  7 import org.jbpm.api.ProcessInstance;
  8 import org.jbpm.api.RepositoryService;
  9 import org.jbpm.api.model.ActivityCoordinates;
 10 
 11 import com.opensymphony.xwork2.ActionSupport;
 12 
 13 public class ViewDirectionOfCurrentProcessInstanceAction extends ActionSupport
 14 {
 15     private ProcessEngine processEngine;
 16     private String processInstanceId;
 17     private int x;
 18     private int y;
 19     private int width;
 20     private int height;
 21 
 22     public ProcessEngine getProcessEngine()
 23     {
 24         return processEngine;
 25     }
 26 
 27     public void setProcessEngine(ProcessEngine processEngine)
 28     {
 29         this.processEngine = processEngine;
 30     }
 31 
 32     public String getProcessInstanceId()
 33     {
 34         return processInstanceId;
 35     }
 36 
 37     public void setProcessInstanceId(String processInstanceId)
 38     {
 39         this.processInstanceId = processInstanceId;
 40     }
 41 
 42     public int getX()
 43     {
 44         return x;
 45     }
 46 
 47     public void setX(int x)
 48     {
 49         this.x = x;
 50     }
 51 
 52     public int getY()
 53     {
 54         return y;
 55     }
 56 
 57     public void setY(int y)
 58     {
 59         this.y = y;
 60     }
 61 
 62     public int getWidth()
 63     {
 64         return width;
 65     }
 66 
 67     public void setWidth(int width)
 68     {
 69         this.width = width;
 70     }
 71 
 72     public int getHeight()
 73     {
 74         return height;
 75     }
 76 
 77     public void setHeight(int height)
 78     {
 79         this.height = height;
 80     }
 81 
 82     public String execute() throws Exception
 83     {
 84         RepositoryService repositoryService = this.processEngine
 85                 .getRepositoryService();
 86         ExecutionService executionService = this.processEngine
 87                 .getExecutionService();
 88         ProcessInstance processInstance = executionService
 89                 .findProcessInstanceById(this.processInstanceId);
 90 
 91         Set<String> activeActivityNames = processInstance
 92                 .findActiveActivityNames();
 93         ActivityCoordinates activityCoordinates = repositoryService
 94                 .getActivityCoordinates(processInstance
 95                         .getProcessDefinitionId(), activeActivityNames
 96                         .iterator().next());
 97         this.x = activityCoordinates.getX();
 98         this.y = activityCoordinates.getY();
 99         this.width = activityCoordinates.getWidth();
100         this.height = activityCoordinates.getHeight();
101         return SUCCESS;
102     }
103 }

四. 编写struts.xml

View Code
 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
 3 <struts>
 4 
 5     <!-- <constant name="struts.i18n.encoding" value="GBK"></constant> -->
 6 
 7     <package name="Reimbursement" extends="struts-default"
 8         namespace="/Reimbursement">
 9         <action name="UserLoginAction" class="UserLogin">
10             <result name="success" type="redirectAction">
11                 <param name="actionName">ListProcessAction</param>
12             </result>
13         </action>
14 
15         <action name="ListProcessAction" class="ListProcess">
16             <result name="success">/Success.jsp</result>
17         </action>
18 
19         <action name="DeployProcessAction" class="DeployProcess">
20             <result name="success" type="redirectAction">
21                 <param name="actionName">ListProcessAction</param>
22             </result>
23         </action>
24 
25         <action name="StartProcessDefinitionAction" class="StartProcessDefinition">
26             <result name="success" type="redirectAction">
27                 <param name="actionName">ListProcessAction</param>
28             </result>
29         </action>
30 
31         <action name="DeleteProcessDefinitionCascadeAction" class="DeleteProcessDefinitionCascade">
32             <result name="success" type="redirectAction">
33                 <param name="actionName">ListProcessAction</param>
34             </result>
35         </action>
36 
37         <action name="ViewCurrentTaskAction" class="ViewCurrentTask">
38             <result name="success">/${formResourceName}</result>
39         </action>
40 
41         <action name="SubmitApplicationAction" class="SubmitApplication">
42             <result name="success" type="redirectAction">
43                 <param name="actionName">ListProcessAction</param>
44             </result>
45         </action>
46 
47         <action name="AssessmentApplicationAction" class="AssessmentApplication">
48             <result name="success" type="redirectAction">
49                 <param name="actionName">ListProcessAction</param>
50             </result>
51         </action>
52 
53         <action name="GetProcessImageAction" class="GetProcessImage">
54         </action>
55 
56         <action name="ViewDirectionOfCurrentProcessInstanceAction"
57             class="ViewDirectionOfCurrentProcessInstance">
58             <result name="success">/ViewProcess.jsp</result>
59         </action>
60 
61 
62 
63     </package>
64 </struts>    

五. 打包Reimbursement.jpdl.xml,Reimbursement.png,测试

原文地址:https://www.cnblogs.com/xiongyu/p/2600915.html