`
wwwxxx286
  • 浏览: 50377 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

Activiti Work Flow Engine

阅读更多
public class TestActivitiFlow {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext(
				"classpath:activiti/activiti-context.xml");
//		ProcessEngine processEngine = (ProcessEngine) context.getBean("processEngine");
		BizActiviti bizActiviti = (BizActiviti) context.getBean("bizActiviti");
		ProcessEngine processEngine = bizActiviti.getProcessEngine();
		RuntimeService runtimeService;
		RepositoryService repositoryService;
		TaskService taskService;
		repositoryService = processEngine.getRepositoryService();
		runtimeService = processEngine.getRuntimeService();
		taskService = processEngine.getTaskService();
		repositoryService.createDeployment().addClasspathResource("activiti/createcase-context.bpmn20.xml").deploy();
		String proId = runtimeService.startProcessInstanceByKey("createcasebyactiviti").getId();
		System.out.println("process id: " + proId);
		
		List<Task> tasks = null;
		tasks = taskService.createTaskQuery().taskCandidateGroup("io").list(); 
	    for (Task task : tasks) { 
	      System.out.println("Following task is available for io group: " + task.getName()); 
	      taskService.claim(task.getId(), "io"); 
//	      taskService.setAssignee(task.getId(), "hiss");
	    } 
	    
	 // Verify hiss can now retrieve the task 
	    tasks = taskService.createTaskQuery().taskAssignee("io").list(); 
	    for (Task task : tasks) { 
	      System.out.println("Task for io: " + task.getName()); 
	      taskService.complete(task.getId());
	      System.out.println("now status is: " + task.getDescription());
//	      System.out.println(runtimeService.getVariables("nextstatus"));
	    } 
	    
	    tasks = taskService.createTaskQuery().taskCandidateGroup("hiss").list(); 
	    for (Task task : tasks) { 
	      System.out.println("Following task is available for hiss group: " + task.getName()); 
	      taskService.claim(task.getId(), "hiss"); 
	    } 
	    
	    tasks = taskService.createTaskQuery().taskAssignee("hiss").list(); 
	    for (Task task : tasks) { 
	      System.out.println("Task for hiss: " + task.getName()); 
	      taskService.complete(task.getId()); 
	      System.out.println("now status is: " + task.getDescription());
	    } 
	    
	    tasks = taskService.createTaskQuery().taskCandidateGroup("hunit").list(); 
	    for (Task task : tasks) { 
	      System.out.println("Following task is available for hunit group: " + task.getName()); 
	      taskService.claim(task.getId(), "hunit"); 
	    } 
	    
	    tasks = taskService.createTaskQuery().taskAssignee("hunit").list(); 
	    for (Task task : tasks) { 
	      System.out.println("Task for hunit: " + task.getName()); 
	      taskService.complete(task.getId()); 
	      System.out.println("now status is: " + task.getDescription());
	    } 

	    HistoryService historyService = processEngine.getHistoryService(); 
	    HistoricProcessInstance historicProcessInstance =  
	      historyService.createHistoricProcessInstanceQuery().processInstanceId(proId).singleResult(); 
	    System.out.println("Process instance end time: " + historicProcessInstance.getEndTime()); 

	}


custom-persistence.xml
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
     version="1.0"
>
  <persistence-unit name="activiti-jpa-pu">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    
    <class>org.activiti.spring.test.jpa.LoanRequest</class>    
    
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
    
     <properties>
      <property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO"/>
      <property name="openjpa.LockTimeout " value="30000"/>
      <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(SchemaAction='add,deleteTableContents')"/>
    </properties>
    
  </persistence-unit>
</persistence>


activiti-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="oracle.jdbc.OracleDriver" />
    <property name="url" value="jdbc:oracle:thin:@//***" />
    <property name="username" value="***" />
    <property name="password" value="***" />
  </bean>
  
  <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
  </bean>
  
  <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
	  <property name="dataSource" ref="dataSource"/>
	  <property name="persistenceXmlLocation">
	      <value>classpath:activiti/custom-persistence.xml</value>
	  </property>
	  <property name="jpaVendorAdapter">
		  <bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">
			  <property name="databasePlatform" value="org.apache.openjpa.jdbc.sql.OracleDictionary" />
		  </bean>
	  </property>
  </bean>

 <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
    <property name="dataSource" ref="dataSource" />
    <property name="transactionManager" ref="transactionManager" />
    <property name="jpaEntityManagerFactory" ref="entityManagerFactory" />
    <property name="databaseSchemaUpdate" value="true" />
    <property name="mailServerHost" value="192.168***" />
    <property name="mailServerPort" value="**" />
    <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="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" />

  <bean id="userBean" class="com.ncs.UserBean"/>  
  <bean id="bizActiviti" class="com.ncs.BizActiviti">
  	<property name="processEngine" ref="processEngine"/> 
  	<property name="userBean" ref="userBean"/>
  </bean>
</beans>


createcase-context.bpmn20.xml
<?xml version="1.0" encoding="UTF-8"?>

<definitions id="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"
  targetNamespace="test">
  
  <process id="createcasebyactiviti">
  
    <startEvent id="start" />
    <sequenceFlow id="flow1" sourceRef="start" targetRef="createfirstinfo" />
    
    <userTask id="createfirstinfo" name="create first information">
		<documentation>1</documentation>
		<potentialOwner>
			<resourceAssignmentExpression>
				<formalExpression>io</formalExpression>
			</resourceAssignmentExpression>
		</potentialOwner>
	</userTask>
	
	<sequenceFlow id="flow11" sourceRef="createfirstinfo" targetRef="egtask" />
	
	<exclusiveGateway id="egtask" name="exclusive gateway task"/>
	
    <sequenceFlow id="flow2" sourceRef="egtask" targetRef="verifyfirstinfo" >
    	<conditionExpression xsi:type="tFormalExpression">
    		${userBean.userId != ''}
    	</conditionExpression>
    </sequenceFlow>
	    <userTask id="verifyfirstinfo" name="verify first information">
			<documentation>3</documentation>
			<potentialOwner>
				<resourceAssignmentExpression>
					<formalExpression>hiss</formalExpression>
				</resourceAssignmentExpression>
			</potentialOwner>
		</userTask>
		
	<sequenceFlow id="flow21" sourceRef="verifyfirstinfo" targetRef="end" />
	
	<sequenceFlow id="flow3" sourceRef="egtask" targetRef="approvefirstinfo" >
    	<conditionExpression xsi:type="tFormalExpression">
    		${userBean.userId == ''}
    	</conditionExpression>
    </sequenceFlow>
	    <userTask id="approvefirstinfo" name="approve first information, generate ip">
			<documentation>5</documentation>
			<potentialOwner>
				<resourceAssignmentExpression>
					<formalExpression>hunit</formalExpression>
				</resourceAssignmentExpression>
			</potentialOwner>
		</userTask>
    <sequenceFlow id="flow31" sourceRef="approvefirstinfo" targetRef="end" />
    <endEvent id="end" />
    
  </process>

</definitions>
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics