Activity工作流

论坛 期权论坛 脚本     
匿名网站用户   2020-12-20 06:05   11   0

工作流模拟程序员面试过程情景如下:
1.开发知识面试或者笔试
2.人事面试

流程图:

流程配置:

Xml代码 收藏代码
  1. <?xmlversion="1.0"encoding="UTF-8"?>
  2. <definitionsxmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:activiti="http://activiti.org/bpmn"xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"typeLanguage="http://www.w3.org/2001/XMLSchema"expressionLanguage="http://www.w3.org/1999/XPath"targetNamespace="http://www.activiti.org/test">
  3. <processid="DeveloperWorkExam"name="DeveloperWorkExam">
  4. <startEventid="startevent1"name="准备面试"></startEvent>
  5. <endEventid="endevent1"name="面试通过"></endEvent>
  6. <receiveTaskid="receivetask1"name="笔试以及面试通过">
  7. <extensionElements>
  8. <activiti:executionListenerevent="start"class="com.easyway.workflow.activiti.exam.DeveloperKnowledgeExamListener"></activiti:executionListener>
  9. </extensionElements>
  10. </receiveTask>
  11. <receiveTaskid="receivetask2"name="人事面试">
  12. <extensionElements>
  13. <activiti:executionListenerevent="start"class="com.easyway.workflow.activiti.exam.HumanResourceExamListener"></activiti:executionListener>
  14. </extensionElements>
  15. </receiveTask>
  16. <sequenceFlowid="flow1"name=""sourceRef="startevent1"targetRef="receivetask1"></sequenceFlow>
  17. <sequenceFlowid="flow2"name=""sourceRef="receivetask1"targetRef="receivetask2"></sequenceFlow>
  18. <sequenceFlowid="flow3"name=""sourceRef="receivetask2"targetRef="endevent1"></sequenceFlow>
  19. <sequenceFlowid="flow4"name=""sourceRef="receivetask1"targetRef="endevent1"></sequenceFlow>
  20. </process>
  21. </definitions>

spring配置application-context-standalone.xml如下:

Xml代码 收藏代码
  1. <?xmlversion="1.0"encoding="UTF-8"?>
  2. <beansxmlns="http://www.springframework.org/schema/beans"
  3. xmlns:context="http://www.springframework.org/schema/context"
  4. xmlns:tx="http://www.springframework.org/schema/tx"
  5. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd
  7. http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsd
  8. http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
  9. <!--创建数据源-->
  10. <beanid="dataSource"class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
  11. <propertyname="driverClass"value="org.h2.Driver"/>
  12. <propertyname="url"value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000"/>
  13. <propertyname="username"value="sa"/>
  14. <propertyname="password"value=""/>
  15. </bean>
  16. <!--创建事务管理器-->
  17. <beanid="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  18. <propertyname="dataSource"ref="dataSource"/>
  19. </bean>
  20. <!--创建流程引擎配置对象-->
  21. <beanid="processEngineConfiguration"class="org.activiti.spring.SpringProcessEngineConfiguration">
  22. <propertyname="dataSource"ref="dataSource"/>
  23. <propertyname="transactionManager"ref="transactionManager"/>
  24. <propertyname="databaseSchemaUpdate"value="true"/>
  25. <propertyname="mailServerHost"value="localhost"/>
  26. <propertyname="mailServerPort"value="5025"/>
  27. <propertyname="jpaHandleTransaction"value="true"/>
  28. <propertyname="jpaCloseEntityManager"value="true"/>
  29. <propertyname="jobExecutorActivate"value="false"/>
  30. </bean>
  31. <!--创建流程引擎对象-->
  32. <beanid="processEngine"class="org.activiti.spring.ProcessEngineFactoryBean">
  33. <propertyname="processEngineConfiguration"ref="processEngineConfiguration"/>
  34. </bean>
  35. <beanid="identityService"factory-bean="processEngine"factory-method="getIdentityService"/>
  36. <beanid="formService"factory-bean="processEngine"factory-method="getFormService"/>
  37. <beanid="repositoryService"factory-bean="processEngine"factory-method="getRepositoryService"/>
  38. <beanid="runtimeService"factory-bean="processEngine"factory-method="getRuntimeService"/>
  39. <beanid="taskService"factory-bean="processEngine"factory-method="getTaskService"/>
  40. <beanid="historyService"factory-bean="processEngine"factory-method="getHistoryService"/>
  41. <beanid="managementService"factory-bean="processEngine"factory-method="getManagementService"/>
  42. </beans>

application-context.xml

Xml代码 收藏代码
  1. <?xmlversion="1.0"encoding="UTF-8"?>
  2. <beansxmlns="http://www.springframework.org/schema/beans"
  3. xmlns:context="http://www.springframework.org/schema/context"
  4. xmlns:tx="http://www.springframework.org/schema/tx"
  5. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd
  7. http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsd
  8. http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
  9. <!--创建数据源-->
  10. <beanid="dataSource"class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
  11. <propertyname="driverClass"value="org.h2.Driver"/>
  12. <propertyname="url"value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000"/>
  13. <propertyname="username"value="sa"/>
  14. <propertyname="password"value=""/>
  15. </bean>
  16. <!--创建事务管理器-->
  17. <beanid="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  18. <propertyname="dataSource"ref="dataSource"/>
  19. </bean>
  20. <!--创建流程引擎配置对象-->
  21. <beanid="processEngineConfiguration"class="org.activiti.spring.SpringProcessEngineConfiguration">
  22. <propertyname="dataSource"ref="dataSource"/>
  23. <propertyname="transactionManager"ref="transactionManager"/>
  24. <propertyname="databaseSchemaUpdate"value="true"/>
  25. <propertyname="mailServerHost"value="localhost"/>
  26. <propertyname="mailServerPort"value="5025"/>
  27. <propertyname="jpaHandleTransaction"value="true"/>
  28. <propertyname="jpaCloseEntityManager"value="true"/>
  29. <propertyname="jobExecutorActivate"value="false"/>
  30. <!--使用spring的自动资源加载部署方式部署-->
  31. <propertyname="deploymentResources"value="classpath*:diagrams/*.bpmn20.xml"/>
  32. </bean>
  33. <!--创建流程引擎对象-->
  34. <beanid="processEngine"class="org.activiti.spring.ProcessEngineFactoryBean">
  35. <propertyname="processEngineConfiguration"ref="processEngineConfiguration"/>
  36. </bean>
  37. <beanid="identityService"factory-bean="processEngine"factory-method="getIdentityService"/>
  38. <beanid="formService"factory-bean="processEngine"factory-method="getFormService"/>
  39. <beanid="repositoryService"factory-bean="processEngine"factory-method="getRepositoryService"/>
  40. <beanid="runtimeService"factory-bean="processEngine"factory-method="getRuntimeService"/>
  41. <beanid="taskService"factory-bean="processEngine"factory-method="getTaskService"/>
  42. <beanid="historyService"factory-bean="processEngine"factory-method="getHistoryService"/>
  43. <beanid="managementService"factory-bean="processEngine"factory-method="getManagementService"/>
  44. </beans>

代码实现:

Java代码 收藏代码
  1. /**
  2. packagecom.easyway.workflow.activiti.exam;
  3. importjava.util.Map;
  4. /**
  5. *
  6. *工作流中配置如下:
  7. *<receiveTaskid="receivetask1"name="笔试以及面试通过">
  8. <extensionElements>
  9. <activiti:executionListenerevent="start"class="com.easyway.workflow.activiti.exam.DeveloperKnowledgeExamListener"/>
  10. </extensionElements>
  11. </receiveTask>
  12. *@authorlonggangbai
  13. *
  14. *2011-12-18上午12:38:24
  15. */
  16. publicclassDeveloperKnowledgeExamListenerimplementsJavaDelegate{
  17. privateLoggerlogger=Logger.getLogger(DeveloperKnowledgeExamListener.class.getName());
  18. /*(non-Javadoc)
  19. *@seeorg.activiti.engine.delegate.JavaDelegate#execute(org.activiti.engine.delegate.DelegateExecution)
  20. */
  21. @Override
  22. publicvoidexecute(DelegateExecutionexecute)throwsException{
  23. //TODOAuto-generatedmethodstub
  24. logger.info("开始开发知识面试了....");
  25. Map<String,Object>variables=execute.getVariables();
  26. Set<Entry<String,Object>>infos=variables.entrySet();
  27. for(Entry<String,Object>entry:infos){
  28. logger.info(entry.getKey()+""+entry.getValue());
  29. }
  30. logger.info("开始开发知识面试了....");
  31. execute.setVariable("result","该考生开发知识面试通过了....");
  32. }
  33. }

Java代码 收藏代码
  1. /**
  2. packagecom.easyway.workflow.activiti.exam;
  3. importjava.util.Map;
  4. /**
  5. *
  6. *
  7. *工作流中配置如下:
  8. *
  9. *<receiveTaskid="receivetask2"name="人事面试">
  10. <extensionElements>
  11. <activiti:executionListenerevent="start"class="com.easyway.workflow.activiti.exam.HumanResourceExamListener"/>
  12. </extensionElements>
  13. </receiveTask>
  14. *@authorlonggangbai
  15. *
  16. *2011-12-18上午12:37:01
  17. */
  18. publicclassHumanResourceExamListenerimplementsJavaDelegate{
  19. privateLoggerlogger=Logger.getLogger(HumanResourceExamListener.class.getName());
  20. /*(non-Javadoc)
  21. *@seeorg.activiti.engine.delegate.JavaDelegate#execute(org.activiti.engine.delegate.DelegateExecution)
  22. */
  23. @Override
  24. publicvoidexecute(DelegateExecutionexecute)throwsException{
  25. //TODOAuto-generatedmethodstub
  26. //TODOAuto-generatedmethodstub
  27. logger.info("检查该考试是否通过开发知识考试....");
  28. Map<String,Object>variables=execute.getVariables();
  29. Stringreuslt=variables.get("result").toString();
  30. logger.info("开发知识面试结果"+reuslt);
  31. logger.info("开始人事面试了....");
  32. execute.setVariable("result","该考生开发知识面试通过了....");
  33. logger.info("人事面试完毕....等候通知....");
  34. }
  35. }

Java代码 收藏代码
  1. /**
  2. packagecom.easyway.workflow.activiti.exam;
  3. importjava.util.logging.Logger;
  4. /**
  5. *
  6. *工作流模拟程序员面试过程情景如下:
  7. *1.开发知识面试或者笔试
  8. *2.人事面试
  9. *
  10. *在spring3.0.3和activiti5.6整合时候,建议采用activiti-spring-examples中的jar文件。
  11. *如果么有完整的jar文件,可以参考{activiti_home}/setup/files/dependencies/libs.spring.runtime.txt文件
  12. *。(C:\mash_activiti-5.6\setup\files\dependencies)
  13. *
  14. *之所以要采用封装的原因,spring配置文件和activiti的配置文件分开发布部署。
  15. *
  16. *@authorlonggangbai
  17. *
  18. *2011-12-18上午01:32:17
  19. */
  20. @ContextConfiguration("classpath:application-context-standalone.xml")
  21. publicabstractclassAbstractSpringTestextendsAbstractTransactionalJUnit4SpringContextTests{
  22. @SuppressWarnings("unused")
  23. privatefinalLoggerlog=Logger.getLogger(AbstractSpringTest.class.getName());
  24. @SuppressWarnings("unused")
  25. @Autowired
  26. privateProcessEngineprocessEngine;
  27. @Autowired
  28. protectedRepositoryServicerepositoryService;
  29. @Autowired
  30. protectedRuntimeServiceruntimeService;
  31. @Autowired
  32. protectedTaskServicetaskService;
  33. @Autowired
  34. protectedHistoryServicehistoryService;
  35. @Autowired
  36. protectedManagementServicemanagementService;
  37. protectedStringdeploymentId;
  38. publicAbstractSpringTest(){
  39. super();
  40. }
  41. @Before
  42. publicvoidinitialize()throwsException{
  43. beforeTest();
  44. }
  45. @After
  46. publicvoidclean()throwsException{
  47. afterTest();
  48. }
  49. protectedabstractvoidbeforeTest()throwsException;
  50. protectedabstractvoidafterTest()throwsException;
  51. }

Java代码 收藏代码
  1. /**
  2. packagecom.easyway.workflow.activiti.exam;
  3. importjava.util.HashMap;
  4. /**
  5. *我把Activiti5.6默认工程中有关JPA的部分配置删除了,其实通过这个就可以初始化Activiti引擎实例。
  6. *为了测试方便,将获取服务的实现抽象出来,同时使用Spring自带的与JUnit4集成的工具(
  7. *AbstractTransactionalJUnit4SpringContextTests)。
  8. *
  9. *将classpath:activiti-context.xml在测试的时候进行加载,这样,在测试的子类中,只需要将其他的相
  10. *关Spring配置单独加载即可,业务配置与流程配置分开,便于维护。
  11. *@authorlonggangbai
  12. *
  13. *2011-12-18上午01:37:14
  14. */
  15. @ContextConfiguration("classpath:application-context-standalone.xml")
  16. publicclassActivitiWithSpringStandaloneTestextendsAbstractSpringTest{
  17. @Override
  18. protectedvoidbeforeTest()throwsException{
  19. Deploymentdeployment=repositoryService
  20. .createDeployment()
  21. .addClasspathResource(
  22. "diagrams/SprintActiviti56.bpmn20.xml")
  23. .deploy();
  24. deploymentId=deployment.getId();
  25. }
  26. @Override
  27. protectedvoidafterTest()throwsException{
  28. repositoryService.deleteDeployment(deploymentId,true);
  29. }
  30. @Test
  31. publicvoidtriggerMyProcess(){
  32. //preparedatapacket
  33. Map<String,Object>variables=newHashMap<String,Object>();
  34. variables.put("姓名","程序员");
  35. variables.put("职务","高级软件工程师");
  36. variables.put("语言","Java/C#");
  37. variables.put("操作系统","Window,Linux,unix,Aix");
  38. variables.put("工作地点","苏州高新技术软件园");
  39. //startprocessinstance
  40. ProcessInstancepi=runtimeService.startProcessInstanceByKey("DeveloperWorkExam",variables);
  41. assert(pi!=null);
  42. List<Execution>executions=runtimeService.createExecutionQuery().list();
  43. assert(executions.size()==1);
  44. Executionexecution=runtimeService.createExecutionQuery().singleResult();
  45. runtimeService.setVariable(execution.getId(),"type","receiveTask");
  46. runtimeService.signal(execution.getId());
  47. executions=runtimeService.createExecutionQuery().list();
  48. assert(executions.size()==1);
  49. execution=executions.get(0);
  50. runtimeService.setVariable(execution.getId(),"oper","录用此人....");
  51. runtimeService.signal(execution.getId());
  52. }
  53. }

自动部署测试:

Java代码 收藏代码
  1. /**
  2. packagecom.easyway.workflow.activiti.exam;
  3. importjava.util.HashMap;
  4. /**
  5. *
  6. *Activiti5.6与Spring3.0.3整合也比较简单,其基本思想就是,通过Spring的IOC容器来管理Activiti的流程引擎
  7. *实例以及相关服务,可见,主要是基于Activiti在与Spring整合上努力上,做好配置即可。这里基于前面的
  8. *<receiveTask>的例子来进行.
  9. *
  10. *
  11. *为了测试方便,将获取服务的实现抽象出来,同时使用Spring自带的与JUnit4集成的工具(
  12. *AbstractTransactionalJUnit4SpringContextTests)。我们的实现类为AbstractSpringTest,
  13. *
  14. *
  15. *本文采用activiti和spring整合中自动部署资源的功能配置如下:
  16. *<!--创建流程引擎配置对象-->
  17. <beanid="processEngineConfiguration"class="org.activiti.spring.SpringProcessEngineConfiguration">
  18. <propertyname="dataSource"ref="dataSource"/>
  19. <propertyname="transactionManager"ref="transactionManager"/>
  20. <propertyname="databaseSchemaUpdate"value="true"/>
  21. <propertyname="mailServerHost"value="localhost"/>
  22. <propertyname="mailServerPort"value="5025"/>
  23. <propertyname="jpaHandleTransaction"value="true"/>
  24. <propertyname="jpaCloseEntityManager"value="true"/>
  25. <propertyname="jobExecutorActivate"value="false"/>
  26. <!--使用spring的自动资源加载部署方式部署-->
  27. <propertyname="deploymentResources"value="classpath*:diagrams/*.bpmn20.xml"/>
  28. </bean>
  29. *@authorlonggangbai
  30. *
  31. *2011-12-18上午12:58:31
  32. */
  33. @ContextConfiguration("classpath:application-context.xml")
  34. publicclassActivitiWithSpringTestextendsAbstractTransactionalJUnit4SpringContextTests{
  35. @Autowired
  36. privateRuntimeServiceruntimeService;
  37. @Autowired
  38. privateTaskServicetaskService;
  39. @Autowired
  40. privateManagementServicemanagerService;
  41. @Autowired
  42. privateIdentityServiceidentityService;
  43. @Autowired
  44. privateFormServiceformService;
  45. /**
  46. *测试方法
  47. */
  48. @Test
  49. publicvoidtriggerMyProcess(){
  50. //面试题目和答案
  51. Map<String,Object>variables=newHashMap<String,Object>();
  52. variables.put("姓名","程序员");
  53. variables.put("职务","高级软件工程师");
  54. variables.put("语言","Java/C#");
  55. variables.put("操作系统","Window,Linux,unix,Aix");
  56. variables.put("工作地点","苏州高新技术软件园");
  57. //startprocessinstance
  58. //获取创建一个实例
  59. ProcessInstancepi=runtimeService.startProcessInstanceByKey("DeveloperWorkExam",variables);
  60. assert(pi!=null);
  61. List<Execution>executions=runtimeService.createExecutionQuery().list();
  62. assert(executions.size()==1);
  63. //执行开发技术知识面试业务
  64. Executionexecution=runtimeService.createExecutionQuery().singleResult();
  65. runtimeService.setVariable(execution.getId(),"type","receiveTask");
  66. runtimeService.signal(execution.getId());
  67. executions=runtimeService.createExecutionQuery().list();
  68. assert(executions.size()==1);
  69. //执行人事面试业务
  70. execution=executions.get(0);
  71. runtimeService.setVariable(execution.getId(),"oper","录用此人....");
  72. runtimeService.signal(execution.getId());
  73. }
  74. }
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1136255
帖子:227251
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP