之前的博文中有讲到怎么单独的配置工作流工程。现在就接着说如何将工作流程图与Web整合。在整合Web首先就
来与Spring进行整合。
整合spring有一下些操作步骤:
1.复制整合包spring-modules-jbpm31.jar
2.把Action三大接口类配置在spring的applicationContext.xml
如:
<!-- action 动作接口-->
<bean id="endAction" class="com.jbpm.action.EndAction"></bean>
<bean id="startAction" class="com.jbpm.action.StartAction"></bean>
<!-- assignment 委类接口-->
<bean id="bossAssignment" class="com.jbpm.assignment.BossAssignment"></bean>
<bean id="managerAssignment" class="com.jbpm.assignment.ManagerAssignment"></bean>
<bean id="writerAssignment" class="com.jbpm.assignment.WriterAssignment"></bean>
<!-- 判定 接口-->
<bean id="moneyDecision" class="com.jbpm.decision.MoneyDecision"></bean>
3在applicationContext.xml配置一个读取jbpm配置文件类
如:
<bean id="jbpmConfig" class="org.springmodules.workflow.jbpm31.LocalJbpmConfigurationFactoryBean">
<property name="sessionFactory" ref="sessionFactory"></property>
<property name="configuration" value="classpath:org/jbpm/default.jbpm.cfg.xml"></property>
</bean>
//org/jbpm/default.jbpm.cfg.xml 为jbpm.cfg.xml 文件中的
4.把jbpm设计图关联图中的动作、事件类全部改为代理JbpmHandlerProxy
在。org.springmodules.workflow.jbpm31.JbpmHandlerProxy
类型改为bean,注入配置文件类和aciton类
//下面的这两个属性需要在配置文件(processdefinition.xml)中代码中手动添加
<factoryKey>jbpmConfig</factoryKey>
<targetBean>bossAction</targetBean>
如:<start-state name="开始">
<transition name="" to="写报销单"></transition>
<event type="node-leave">
<action name="开始" class="org.springmodules.workflow.jbpm31.JbpmHandlerProxy" config-type="bean">
<factoryKey>jbpmConfig</factoryKey>
<targetBean>startAction</targetBean>
</action>
</event>
</start-state>
//jbpmConfig :步骤3中所配置的 id值 startAction:步骤1中所对应的动作接口 id值
5.把测试类继承为JbpmDaoSupport类
并把测试类在applicationContext.xml中配置bean
如:<!-- 测试类 -->
<bean id="jbpmTest" class="com.test.Test">
<property name="jbpmConfiguration" ref="jbpmConfig"></property>
</bean>
6.测试
测试类在整合spring之后与web的关联操作。
如下:
//读取配置文件
private JbpmConfiguration getConfig(){
return super.getJbpmConfiguration();
}
//读取上下文件
private JbpmContext getContext(){
JbpmContext context = getConfig().getCurrentJbpmContext();
if (context==null)
context = getConfig().createJbpmContext();
return context;
}
//建表
private void createTable(){
getConfig().createSchema();
}
//发布
private void deployProcessionDefintion(){
ProcessDefinition pd = ProcessDefinition.parseXmlResource("simple/processdefinition.xml");
pd.setName("s09报销单");
getContext().deployProcessDefinition(pd);
getContext().close();
}
//开启流程实例
private void createInstance(String pname,String name){
ProcessDefinition pd = getContext().getGraphSession().findLatestProcessDefinition("s09报销单");
ProcessInstance pi = pd.createProcessInstance();
pi.getContextInstance().setVariable("start", name);
pi.signal();
getContext().close();
}
//写报销单
private void writer(String name,float money,String msg){
Session session = getContext().getSession();
String hql = "from TaskInstance where ACTORID_=? and END_ is null";
Query query = session.createQuery(hql);
query.setParameter(0, name);
List<TaskInstance> list =query.list();// getContext().getTaskList(name);
//System.out.println(list.size());
if (list!=null)
for (TaskInstance ti : list) {
if (ti.getName().equals("写报销单")){
//System.out.println("进来了没有");
ti.setVariable("money", money);
ti.setVariable("msg", msg);
ti.end();
break;
}
}
getContext().close();
}
// 领导审批
private void agree(int tid,boolean agree){
TaskInstance ti = getContext().getTaskInstance(tid);
if (ti!=null){
String old = (String) ti.getVariable("status");
if (agree)
{
ti.setVariable("status", old+"(同意)");
ti.end("同意");
}
else{
ti.setVariable("status", old+"(不同意)");
ti.end("不同意");
}
getContext().close();
}
}
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
Test test = (Test) context.getBean("jbpmTest");
//test.createTable();
//test.deployProcessionDefintion();
//test.createInstance("s09报销单", "小李子");
//test.writer("小李子", 3000, "坐车");
//test.agree(6, false);
}