Jbpm4常用操作

 jbpm4.4 和spring整合起来 .
流程文件如下:
Java代码 复制代码 收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <process name="leave" xmlns="http://jbpm.org/4.4/jpdl">
  3. <start g="196,25,48,48" name="start1">
  4. <transition to="申请"/>
  5. </start>
  6. <task assignee="#{owner}" form="leave.htm?method=toFillForm" g="172,118,92,52" name="申请">
  7. <transition to="managerAudit"/>
  8. </task>
  9. <task assignee="yexs" form="leave.htm?method=toManageAudit" g="175,217,92,52" name="managerAudit">
  10. <transition g="-32,-8" name="批准" to="exclusive1"/>
  11. <transition g="128,221;124,165:-42,-18" name="驳回" to="申请"/>
  12. </task>
  13. <decision expr="#{day > 3 ? '老板审批' : '结束'}" g="200,308,48,48" name="exclusive1">
  14. <transition g="-39,-10" name="结束" to="end1"/>
  15. <transition g="339,342:-71,-17" name="老板审批" to="老板审批"/>
  16. </decision>
  17. <task assignee="laoxin" form="leave.htm?method=toBossAudit" g="294,375,92,52" name="老板审批">
  18. <transition g="339,457:" to="end1"/>
  19. </task>
  20. <end g="199,445,48,48" name="end1"/>
  21. </process>

jbpm.cfg.xml
Java代码 复制代码 收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <jbpm-configuration>
  3. <import resource="jbpm.default.cfg.xml" />
  4. <import resource="jbpm.businesscalendar.cfg.xml" />
  5. <import resource="jbpm.tx.spring.cfg.xml" />
  6. <import resource="jbpm.jpdl.cfg.xml" />
  7. <import resource="jbpm.bpmn.cfg.xml" />
  8. <import resource="jbpm.identity.cfg.xml" />
  9. <!-- Job executor is excluded for running the example test cases. -->
  10. <!-- To enable timers and messages in production use, this should be included. -->
  11. <!--
  12. <import resource="jbpm.jobexecutor.cfg.xml" />
  13. -->
  14. </jbpm-configuration>

applicationContext.xml:
Java代码 复制代码 收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:aop="http://www.springframework.org/schema/aop"
  5. xmlns:tx="http://www.springframework.org/schema/tx"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
  7. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
  8. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
  9. default-autowire="byName">
  10. <bean id="sessionFactory"
  11. class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
  12. <property name="configLocation">
  13. <value>classpath:hibernate.cfg.xml</value>
  14. </property>
  15. </bean>
  16. <!-- Jbpm 服务 -->
  17. <bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper" >
  18. <property name="jbpmCfg" value="jbpm/jbpm.cfg.xml"></property>
  19. </bean>
  20. <bean id="processEngine" factory-bean="springHelper"
  21. factory-method="createProcessEngine" />
  22. <bean id="repositoryService" factory-bean="processEngine"
  23. factory-method="getRepositoryService" />
  24. <bean id="executionService" factory-bean="processEngine"
  25. factory-method="getExecutionService" />
  26. <bean id="taskService" factory-bean="processEngine"
  27. factory-method="getTaskService" />
  28. <bean id="historyService" factory-bean="processEngine"
  29. factory-method="getHistoryService" />
  30. <bean id="managementService" factory-bean="processEngine"
  31. factory-method="getManagementService" />
  32. <!-- 装载spring提供的分发组件 -->
  33. <bean id="paraMethodResolver"
  34. class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
  35. <property name="paramName" value="method" />
  36. <property name="defaultMethodName" value="list" />
  37. </bean>
  38. <!-- 上传文件 -->
  39. <bean id="multipartResolver"
  40. class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
  41. <property name="maxUploadSize">
  42. <value>4000000000</value>
  43. </property>
  44. <property name="maxInMemorySize">
  45. <value>10000000</value>
  46. </property>
  47. <property name="defaultEncoding">
  48. <value>utf-8</value>
  49. </property>
  50. <property name="uploadTempDir">
  51. <value>/temp</value>
  52. </property>
  53. </bean>
  54. <!-- 装载velocity配置文件 -->
  55. <bean id="velocityConfig"
  56. class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
  57. <property name="resourceLoaderPath">
  58. <value>/</value>
  59. </property>
  60. <property name="configLocation">
  61. <value>/WEB-INF/classes/velocity.properties</value>
  62. </property>
  63. </bean>
  64. <!-- 装载spring提供的velocity组建 -->
  65. <bean id="viewResolver"
  66. class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
  67. <property name="requestContextAttribute" value="rc"/>
  68. <property name="exposeSessionAttributes" value="true" />
  69. <property name="suffix" value=".html"></property>
  70. <property name="dateToolAttribute">
  71. <value>dateTool</value>
  72. </property>
  73. <property name="toolboxConfigLocation"><value>/WEB-INF/velocity-toolbox.xml</value> </property>
  74. </bean>
  75. <!-- 接口映射 配置URL请求 -->
  76. <bean id="simpleUrlMapping"
  77. class="com.yb.hrm.baselink.util.UrlHandlerMapping">
  78. <property name="interceptors">
  79. <list>
  80. <ref bean="openSessionInViewInterceptor" />
  81. </list>
  82. </property>
  83. </bean>
  84. <!-- business 服务 -->
  85. <bean id="baseBusiness"
  86. class="com.yb.hrm.baselink.business.BaseBusiness" />
  87. <!-- Service 服务 -->
  88. <bean id="baseService"
  89. class="com.yb.hrm.baselink.service.BaseService" />
  90. <!-- DAO申明 -->
  91. <bean id="baseDAO" class="com.yb.hrm.baselink.dao.BaseDAOImp">
  92. </bean>
  93. <!-- 配置事务管理器 -->
  94. <bean id="transactionManager"
  95. class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  96. <property name="sessionFactory">
  97. <ref local="sessionFactory" />
  98. </property>
  99. </bean>
  100. <!-- 配置事务的传播特性 -->
  101. <tx:advice id="txAdvice" transaction-manager="transactionManager">
  102. <tx:attributes>
  103. <!-- 在开发的时候可以这样定义,但部署的时候一定要详细定义 -->
  104. <tx:method name="*" propagation="REQUIRED" />
  105. <tx:method name="get*" propagation="REQUIRED"
  106. rollback-for="-Exception" read-only="true" />
  107. <tx:method name="test*" propagation="REQUIRED"
  108. rollback-for="-Exception" read-only="true" />
  109. <tx:method name="find*" propagation="REQUIRED"
  110. rollback-for="-Exception" read-only="true" />
  111. <tx:method name="add*" propagation="REQUIRED"
  112. rollback-for="-Exception" />
  113. <tx:method name="update*" propagation="REQUIRED"
  114. rollback-for="-Exception" />
  115. <tx:method name="batch*" propagation="REQUIRED"
  116. rollback-for="-Exception" />
  117. <tx:method name="modify*" propagation="REQUIRED"
  118. rollback-for="-Exception" />
  119. <tx:method name="delete*" propagation="REQUIRED"
  120. rollback-for="-Exception" />
  121. </tx:attributes>
  122. </tx:advice>
  123. <!-- 配置哪些类哪些方法使用事务-->
  124. <aop:config>
  125. <aop:pointcut id="allManagerMethod"
  126. expression="execution(* com.yb.hrm..*.*Business.*(..))" />
  127. <aop:advisor advice-ref="txAdvice"
  128. pointcut-ref="allManagerMethod" />
  129. </aop:config>.....

business 的代码:
Java代码 复制代码 收藏代码
  1. public class LeaveBusiness extends BaseBusiness {
  2. private RepositoryService repositoryService;
  3. private ExecutionService executionService;
  4. private TaskService taskService;
  5. public void setTaskService(TaskService taskService) {
  6. this.taskService = taskService;
  7. }
  8. public void setRepositoryService(RepositoryService repositoryService) {
  9. this.repositoryService = repositoryService;
  10. }
  11. public void setExecutionService(ExecutionService executionService) {
  12. this.executionService = executionService;
  13. }
  14. /**
  15. *部署一个请假流程
  16. */
  17. public void deploy(){
  18. ZipInputStream zis = new ZipInputStream(this.getClass()
  19. .getResourceAsStream("/com/yb/hrm/jbpm/leave/jpdl/leave.zip"));
  20. repositoryService.createDeployment().addResourcesFromZipInputStream(zis).deploy();
  21. }
  22. /**删除流程定义 及其相关数据
  23. * @param deployId
  24. */
  25. public void removeDeploy(String deployId){
  26. repositoryService.deleteDeploymentCascade(deployId);
  27. }
  28. /**生成流程实例
  29. * @param deployId
  30. */
  31. public void startDefine(String deployId,String loginName){
  32. Map map = new HashMap();
  33. map.put("owner", loginName);
  34. executionService.startProcessInstanceByKey("leave", map);
  35. }
  36. /**获取流程定义
  37. * @return
  38. */
  39. public List getDefinition(){
  40. return repositoryService.createProcessDefinitionQuery().list();
  41. }
  42. /**获取流程定义
  43. * @return
  44. */
  45. public ProcessDefinition getDefinitionByPiId(String id){
  46. return repositoryService.createProcessDefinitionQuery().processDefinitionId(id).uniqueResult();
  47. }
  48. /**获取流程实例
  49. * @return
  50. */
  51. public List getInstance(){
  52. return executionService.createProcessInstanceQuery().list();
  53. }
  54. /**获取流程实例
  55. * @return
  56. */
  57. public ProcessInstance getInstanceById(String id){
  58. return executionService.findProcessInstanceById(id);
  59. }
  60. /**查询用户任务
  61. * @param userId
  62. * @return
  63. */
  64. public List getTaskByUserId(String loginName){
  65. return taskService.findPersonalTasks(loginName);
  66. }
  67. /**获取当前节点位置
  68. * @param userId
  69. * @return
  70. */
  71. public ActivityCoordinates getAc(ProcessInstance pi){
  72. return repositoryService.getActivityCoordinates(pi.getProcessDefinitionId(),pi.findActiveActivityNames().iterator().next());
  73. }
  74. /**获取流程图片流
  75. * @param userId
  76. * @return
  77. */
  78. public InputStream getPicStream(ProcessDefinition pd){
  79. return repositoryService.getResourceAsStream(pd.getDeploymentId(), "leave.png");
  80. }
  81. /**提交请假单
  82. * @param userId
  83. * @return
  84. */
  85. public void submitForm(Map map,String taskId){
  86. taskService.completeTask(taskId, map);
  87. }

你可能感兴趣的:(Jbpm4常用操作)