工作流中的UEL表达式的使用

公共spring配置文件:





  
    
    
    
    
  
 
  
    
  

  
  
    
  
    
    
    
    
    
    
     
    
    
      
        
      
    
  
  
  
  
    
  
  
  
  
  
  
  

package com.easyway.workflow.activiti;
/**
 *
 *  工作流中的activiti中的UEL的两种用法要求:
 *  1.UEL使用的bean必须为spring暴露给activiti的bean。
 *  2.如果采用方法必须为public
 *   
 *   
 *  3.如果采用属性方位则必须为属性提供getter/setter方法
 *     
 *    
 *    
 *    
 * @author longgangbai
 * 
 * 2011-12-18  下午09:48:36
 */
public class SentenceGenerator {
  
  private String level;
  
	/**
	 * @return the level
	 */
	public String getLevel() {
		return level;
	}
	
	/**
	 * @param level the level to set
	 */
	public void setLevel(String level) {
		this.level = level;
	}
	
	public String getSentence() {
	    return "Activiti BPMN 2.0 process engine";
	  }

}

  

 

实例一:

 

配置:




  
     
    
    
        可以理解为多种方式都可以达到目的地,但是适合自己的只有一条
    
     
     
     
     
       
    ${paymentReceived == false} 
     
     
    ${shipOrder == true} 
    
     
     
       
     
     
      
     
     
     
     
     
     
    
           
       
        user(kermit), group(management) 
       
     
      
    
      
     
     
      
    
  
  

 

代码:

package com.easyway.workflow.activiti;

import java.util.HashMap;

/**
 * 
 *   
 *  可以理解为多种方式都可以达到目的地,但是适合自己的只有一条
 *  
 *      
    
           
       
        user(kermit), group(management) 
       
     
 *  
 *  
 *  全局属性的使用
 *  
 *  
 * @author longgangbai
 * 
 * 2011-12-18  下午10:33:15
 */
public class SpringExclusiveGateway {
	public static void main(String[] args) {
		//加载spring配置和工作流流程处理配置
		ApplicationContext ctx=new ClassPathXmlApplicationContext("application-context-expression.xml");
		//工作流相关的各种服务
		HistoryService historyService=(HistoryService)ctx.getBean("historyService");
		RuntimeService runtimeService=(RuntimeService)ctx.getBean("runtimeService");
		TaskService taskService=(TaskService)ctx.getBean("taskService");
        //设置调用流程过程中使用的参数
		HashMap variableMap = new HashMap(); 
        variableMap.put("paymentReceived", true); 
        variableMap.put("shipOrder", true); 
        //流程实例对象
        ProcessInstance pi = runtimeService.startProcessInstanceByKey("springexclusiveGateway",variableMap); 
        TaskQuery query = taskService.createTaskQuery() 
                       .processInstanceId(pi.getId()) 
                       .orderByTaskName() 
                       .asc(); 

		List tasks = query.list(); 
		System.out.println("tasksize ="+tasks.size());
		
		Task task = tasks.get(0); 
		System.out.println("Ship Order ="+task.getName());

	}

}

 

 

实例二:

配置:




  
  
    
    
   
    
    
    
    
    
     
    
    
    
    
    
    
     
    
    
  

 

代码:

/**
package com.easyway.workflow.activiti;

import java.util.List;

/**
 * 测试工作流中的UEL表达式的使用
 * 
 * @author longgangbai
 * 
 * 2011-12-18  下午07:35:29
 */
public class SpringLimitedExpressionActiviti {
	public static void main(String[] args) throws InterruptedException {
		//加载spring配置和工作流流程处理配置
		ApplicationContext ctx=new ClassPathXmlApplicationContext("application-context-expression.xml");
		//工作流相关的各种服务
		HistoryService historyService=(HistoryService)ctx.getBean("historyService");
		RuntimeService runtimeService=(RuntimeService)ctx.getBean("runtimeService");
		TaskService taskService=(TaskService)ctx.getBean("taskService");
		//流程实例对象
		ProcessInstance processInstance=runtimeService.startProcessInstanceByKey("limitedExpressionProcess");
		//查询当前任务数据
		System.out.println("处理任务之前:"+runtimeService.createProcessInstanceQuery().count());
		List taskList=taskService.createTaskQuery().list();
        //手动分配代办任务
		for (Task task : taskList) {
			taskService.claim(task.getId(), "kermit");
		}
		//手动处理完成任务
		for (Task task : taskList) {
			taskService.complete(task.getId());
		}
		//检查剩余任务数
		System.out.println("处理任务之前:"+taskService.createTaskQuery().count());
		 // verify that the process is actually finished 
		//验证流程是否处理完毕
	    HistoricProcessInstance historicProcessInstance =  
	      historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getProcessInstanceId()).singleResult(); 
	    System.out.println("Process instance end time: " + historicProcessInstance.getEndTime());
	    //6分钟时间等待第二次执行
	    Thread.sleep(6*60*1000);
	    
	}

}

 

实例三

配置:



  
	 
	     
	     
	    
	        理解为多种方式都可以到达目的地,并行的互不干涉,进度
	    
	     
	     
	     
	     
	    
	        
		       
		        kermit 
		       
		     
	    
	       
	     
	     
	      
	     
	     
	     
	     
	     
	      
	     
	     
	    
    
  
  

 

 

代码:

 

/**
package com.easyway.workflow.activiti;

import java.util.List;

/**
 * 测试工作流中的UEL表达式的使用
 * 
 *      
 *     理解为多种方式都可以到达目的地,并行的互不干涉,进度
 *     
 *     
	    
	        
		       
		        kermit 
		       
		     
	    
	    
 * 
 * @author longgangbai
 * 
 * 2011-12-18  下午07:35:29
 */
public class SpringParallelExpressionActiviti {
	public static void main(String[] args) throws InterruptedException {
		//加载spring配置和工作流流程处理配置
		ApplicationContext ctx=new ClassPathXmlApplicationContext("application-context-expression.xml");
		//工作流相关的各种服务
		HistoryService historyService=(HistoryService)ctx.getBean("historyService");
		RuntimeService runtimeService=(RuntimeService)ctx.getBean("runtimeService");
		TaskService taskService=(TaskService)ctx.getBean("taskService");
		//流程实例对象
		ProcessInstance processInstance=runtimeService.startProcessInstanceByKey("springparallelGateway");
		TaskQuery query = taskService.createTaskQuery() 
		                         .processInstanceId(processInstance.getId()) 
		                         .orderByTaskName() 
		                         .asc(); 
		 
		List tasks = query.list(); 
		System.out.println(tasks.size()); 

		Task task1 = tasks.get(0); 
		System.out.println("Receive Payment ="+ task1.getName()); 
		Task task2 = tasks.get(1); 
		System.out.println("Ship Order"+task2.getName());
		//查看指定人的任务
		List kermittasks = taskService.createTaskQuery().taskAssignee("kermit").list();
		System.out.println("kermit task number  ="+ kermittasks.size()); 
		 
	    
	}

}

 

 

你可能感兴趣的:(java,数据库)