工作流模擬程序員面試過程情景如下:
1.開發知識面試或者筆試
2.人事面試
流程圖:
流程配置:
- <?xml version="1.0" encoding="UTF-8"?>
- <definitions xmlns="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">
- <process id="DeveloperWorkExam" name="DeveloperWorkExam">
- <startEvent id="startevent1" name="準備面試"></startEvent>
- <endEvent id="endevent1" name="面試通過"></endEvent>
- <receiveTask id="receivetask1" name="筆試以及面試通過">
- <extensionElements>
- <activiti:executionListener event="start" class="com.easyway.workflow.activiti.exam.DeveloperKnowledgeExamListener"></activiti:executionListener>
- </extensionElements>
- </receiveTask>
- <receiveTask id="receivetask2" name="人事面試">
- <extensionElements>
- <activiti:executionListener event="start" class="com.easyway.workflow.activiti.exam.HumanResourceExamListener"></activiti:executionListener>
- </extensionElements>
- </receiveTask>
- <sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="receivetask1"></sequenceFlow>
- <sequenceFlow id="flow2" name="" sourceRef="receivetask1" targetRef="receivetask2"></sequenceFlow>
- <sequenceFlow id="flow3" name="" sourceRef="receivetask2" targetRef="endevent1"></sequenceFlow>
- <sequenceFlow id="flow4" name="" sourceRef="receivetask1" targetRef="endevent1"></sequenceFlow>
- </process>
- </definitions>
spring配置application-context-standalone.xml如下:
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
- <!-- 創建數據源 -->
- <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
- <property name="driverClass" value="org.h2.Driver" />
- <property name="url" value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000" />
- <property name="username" value="sa" />
- <property name="password" value="" />
- </bean>
-
- <!-- 創建事務管理器 -->
- <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource" />
- </bean>
-
- <!-- 創建流程引擎配置對象 -->
- <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
- <property name="dataSource" ref="dataSource" />
- <property name="transactionManager" ref="transactionManager" />
- <property name="databaseSchemaUpdate" value="true" />
- <property name="mailServerHost" value="localhost" />
- <property name="mailServerPort" value="5025" />
- <property name="jpaHandleTransaction" value="true" />
- <property name="jpaCloseEntityManager" value="true" />
- <property name="jobExecutorActivate" value="false" />
- </bean>
-
- <!-- 創建流程引擎對象-->
- <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
- <property name="processEngineConfiguration" ref="processEngineConfiguration" />
- </bean>
- <bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />
-
- <bean id="formService" factory-bean="processEngine" factory-method="getFormService" />
-
- <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
- <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
- <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
- <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
- <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />
-
- </beans>
application-context.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
- <!-- 創建數據源 -->
- <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
- <property name="driverClass" value="org.h2.Driver" />
- <property name="url" value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000" />
- <property name="username" value="sa" />
- <property name="password" value="" />
- </bean>
-
- <!-- 創建事務管理器 -->
- <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource" />
- </bean>
-
- <!-- 創建流程引擎配置對象 -->
- <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
- <property name="dataSource" ref="dataSource" />
- <property name="transactionManager" ref="transactionManager" />
- <property name="databaseSchemaUpdate" value="true" />
- <property name="mailServerHost" value="localhost" />
- <property name="mailServerPort" value="5025" />
- <property name="jpaHandleTransaction" value="true" />
- <property name="jpaCloseEntityManager" value="true" />
- <property name="jobExecutorActivate" value="false" />
- <!-- 使用spring的自動資源加載部署方式部署 -->
- <property name="deploymentResources" value="classpath*:diagrams/*.bpmn20.xml" />
-
- </bean>
-
- <!-- 創建流程引擎對象-->
- <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
- <property name="processEngineConfiguration" ref="processEngineConfiguration" />
- </bean>
- <bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />
-
- <bean id="formService" factory-bean="processEngine" factory-method="getFormService" />
-
- <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
- <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
- <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
- <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
- <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />
-
- </beans>
代碼實現:
- /**
- package com.easyway.workflow.activiti.exam;
-
- import java.util.Map;
-
- /**
- *
- * 工作流中配置如下:
- * <receiveTask id="receivetask1" name="筆試以及面試通過">
- <extensionElements>
- <activiti:executionListener event="start" class="com.easyway.workflow.activiti.exam.DeveloperKnowledgeExamListener"/>
- </extensionElements>
- </receiveTask>
-
- * @author longgangbai
- *
- * 2011-12-18 上午12:38:24
- */
- public class DeveloperKnowledgeExamListener implements JavaDelegate {
- private Logger logger=Logger.getLogger(DeveloperKnowledgeExamListener.class.getName());
- /* (non-Javadoc)
- * @see org.activiti.engine.delegate.JavaDelegate#execute(org.activiti.engine.delegate.DelegateExecution)
- */
- @Override
- public void execute(DelegateExecution execute) throws Exception {
- // TODO Auto-generated method stub
- logger.info("開始開發知識面試了....");
- Map<String,Object> variables= execute.getVariables();
- Set<Entry<String,Object>> infos=variables.entrySet();
- for (Entry<String, Object> entry : infos) {
- logger.info(entry.getKey()+" "+entry.getValue());
- }
- logger.info("開始開發知識面試了....");
- execute.setVariable("result", "該考生開發知識面試通過了....");
-
- }
-
- }
- /**
- package com.easyway.workflow.activiti.exam;
-
- import java.util.Map;
-
- /**
- *
- *
- * 工作流中配置如下:
- *
- * <receiveTask id="receivetask2" name="人事面試">
- <extensionElements>
- <activiti:executionListener event="start" class="com.easyway.workflow.activiti.exam.HumanResourceExamListener"/>
- </extensionElements>
- </receiveTask>
-
- * @author longgangbai
- *
- * 2011-12-18 上午12:37:01
- */
- public class HumanResourceExamListener implements JavaDelegate {
- private Logger logger=Logger.getLogger(HumanResourceExamListener.class.getName());
-
- /* (non-Javadoc)
- * @see org.activiti.engine.delegate.JavaDelegate#execute(org.activiti.engine.delegate.DelegateExecution)
- */
- @Override
- public void execute(DelegateExecution execute) throws Exception {
- // TODO Auto-generated method stub
- // TODO Auto-generated method stub
- logger.info("檢查該考試是否通過開發知識考試....");
- Map<String,Object> variables= execute.getVariables();
- String reuslt=variables.get("result").toString();
- logger.info("開發知識面試結果"+reuslt);
- logger.info("開始人事面試了....");
- execute.setVariable("result", "該考生開發知識面試通過了....");
- logger.info("人事面試完畢....等候通知....");
- }
-
- }
- /**
- package com.easyway.workflow.activiti.exam;
-
- import java.util.logging.Logger;
- /**
- *
- * 工作流模擬程序員面試過程情景如下:
- * 1.開發知識面試或者筆試
- * 2.人事面試
- *
- * 在spring3.0.3和activiti5.6整合時候,建議採用activiti-spring-examples中的jar文件。
- * 如果麼有完整 的jar文件,可以參考{activiti_home}/setup/files/dependencies/libs.spring.runtime.txt文件
- * 。(C:\mash_activiti-5.6\setup\files\dependencies)
- *
- * 之所以要採用封裝的原因,spring配置文件和activiti的配置文件分開發布部署。
- *
- * @author longgangbai
- *
- * 2011-12-18 上午01:32:17
- */
- @ContextConfiguration("classpath:application-context-standalone.xml")
- public abstract class AbstractSpringTest extends AbstractTransactionalJUnit4SpringContextTests {
-
- @SuppressWarnings("unused")
- private final Logger log = Logger.getLogger(AbstractSpringTest.class.getName());
-
- @SuppressWarnings("unused")
- @Autowired
- private ProcessEngine processEngine;
- @Autowired
- protected RepositoryService repositoryService;
- @Autowired
- protected RuntimeService runtimeService;
- @Autowired
- protected TaskService taskService;
- @Autowired
- protected HistoryService historyService;
- @Autowired
- protected ManagementService managementService;
-
- protected String deploymentId;
-
- public AbstractSpringTest() {
- super();
- }
-
- @Before
- public void initialize() throws Exception {
- beforeTest();
- }
-
- @After
- public void clean() throws Exception {
- afterTest();
- }
-
- protected abstract void beforeTest() throws Exception;
-
- protected abstract void afterTest() throws Exception;
- }
- /**
- package com.easyway.workflow.activiti.exam;
-
- import java.util.HashMap;
- /**
- * 我把Activiti 5.6默認工程中有關JPA的部分配置刪除了,其實通過這個就可以初始化Activiti引擎實例。
- * 爲了測試方便,將獲取服務的實現抽象出來,同時使用Spring自帶的與JUnit4集成的工具(
- * AbstractTransactionalJUnit4SpringContextTests)。
- *
- * 將classpath:activiti-context.xml在測試的時候進行加載,這樣,在測試的子類中,只需要將其他的相
- * 關Spring配置單獨加載即可,業務配置與流程配置分開,便於維護。
- * @author longgangbai
- *
- * 2011-12-18 上午01:37:14
- */
- @ContextConfiguration("classpath:application-context-standalone.xml")
- public class ActivitiWithSpringStandaloneTest extends AbstractSpringTest {
-
- @Override
- protected void beforeTest() throws Exception {
- Deployment deployment = repositoryService
- .createDeployment()
- .addClasspathResource(
- "diagrams/SprintActiviti56.bpmn20.xml")
- .deploy();
- deploymentId = deployment.getId();
- }
-
- @Override
- protected void afterTest() throws Exception {
- repositoryService.deleteDeployment(deploymentId, true);
- }
-
- @Test
- public void triggerMyProcess() {
- // prepare data packet
- Map<String, Object> variables = new HashMap<String, Object>();
- variables.put("姓名", "程序員");
- variables.put("職務", "高級軟件工程師");
- variables.put("語言", "Java/C#");
- variables.put("操作系統", "Window,Linux,unix,Aix");
- variables.put("工作地點","蘇州高新技術軟件園");
-
- // start process instance
- ProcessInstance pi = runtimeService.startProcessInstanceByKey("DeveloperWorkExam", variables);
- assert (pi!=null);
-
- List<Execution> executions = runtimeService.createExecutionQuery().list();
- assert (executions.size()==1);
-
- Execution execution = runtimeService.createExecutionQuery().singleResult();
- runtimeService.setVariable(execution.getId(), "type", "receiveTask");
- runtimeService.signal(execution.getId());
-
- executions = runtimeService.createExecutionQuery().list();
- assert (executions.size()==1);
-
- execution = executions.get(0);
- runtimeService.setVariable(execution.getId(), "oper", "錄用此人....");
- runtimeService.signal(execution.getId());
- }
- }
自動部署測試:
- /**
- package com.easyway.workflow.activiti.exam;
-
-
- import java.util.HashMap;
- /**
- *
- * Activiti 5.6與Spring3.0.3整合也比較簡單,其基本思想就是,通過Spring的IOC容器來管理Activiti的流程引擎
- * 實例以及相關服務,可見,主要是基於Activiti在與Spring整合上努力上,做好配置即可。這裏基於前面的
- * <receiveTask>的例子來進行.
- *
- *
- * 爲了測試方便,將獲取服務的實現抽象出來,同時使用Spring自帶的與JUnit4集成的工具(
- * AbstractTransactionalJUnit4SpringContextTests)。我們的實現類爲AbstractSpringTest,
- *
- *
- * 本文采用activiti和spring整合中自動部署資源的功能配置如下:
- * <!-- 創建流程引擎配置對象 -->
- <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
- <property name="dataSource" ref="dataSource" />
- <property name="transactionManager" ref="transactionManager" />
- *
- * 爲了測試方便,將獲取服務的實現抽象出來,同時使用Spring自帶的與JUnit4集成的工具(
- * AbstractTransactionalJUnit4SpringContextTests)。我們的實現類爲AbstractSpringTest,
- *
- *
- * 本文采用activiti和spring整合中自動部署資源的功能配置如下:
- * <!-- 創建流程引擎配置對象 -->
- <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
- <property name="dataSource" ref="dataSource" />
- <property name="transactionManager" ref="transactionManager" />
- <property name="databaseSchemaUpdate" value="true" />
- <property name="mailServerHost" value="localhost" />
- <property name="mailServerPort" value="5025" />
- <property name="jpaHandleTransaction" value="true" />
- <property name="jpaCloseEntityManager" value="true" />
- <property name="jobExecutorActivate" value="false" />
- <!-- 使用spring的自動資源加載部署方式部署 -->ot; value="true" />
- <property name="mailServerHost" value="localhost" />
- <property name="mailServerPort" value="5025" />
- <property name="jpaHandleTransaction" value="true" />
- <property name="jpaCloseEntityManager" value="true" />
- <property name="jobExecutorActivate" value="false" />
- <!-- 使用spring的自動資源加載部署方式部署 -->
- <property name="deploymentResources" value="classpath*:diagrams/*.bpmn20.xml" />
-
- </bean>
- * @author longgangbai
- *
- * 2011-12-18 上午12:58:31
- */
- @ContextConfiguration("classpath:application-context.xml")
- <property name="jpaCloseEntityManager" value="true" />