* 任务活动分配
* 1.使用流程变量: assignee="#{manager}" 在Expression设置#{manager}
* 2.使用类处理AssignmentHandler :assignable.setAssignee(userId);
* 3.TaskService.assignTask(taskId,userId);
流程配置文件test.jpdl.xml
任务分配类:
* 1.使用流程变量: assignee="#{manager}" 在Expression设置#{manager}
* 2.使用类处理AssignmentHandler :assignable.setAssignee(userId);
* 3.TaskService.assignTask(taskId,userId);
Java Code :
package cn.edu.zust.itee.task;
import java.io.InputStream;
import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.ProcessInstance;
import org.junit.Test;
/**
* @author 郑勇
* 2013-7-10 16:26
* 任务活动分配
* 1.使用流程变量: assignee="#{manager}" 在Expression设置#{manager}
* 2.使用类处理AssignmentHandler :assignable.setAssignee(userId);
* 3.TaskService.assignTask(taskId,userId);
*/
public class TaskVariable {
ProcessEngine processEngine= Configuration.getProcessEngine();
@Test
public void testTaskActivity(){
//部署流程定义
//获得当前包中的文件
InputStream in = this.getClass().getResourceAsStream("test.jpdl.xml");
processEngine.getRepositoryService()
.createDeployment()
.addResourceFromInputStream("test.jpdl.xml", in)
.deploy();
//设置流程变量
/**
方法一:设置占位参数:
Map<String,Object> mapVariable = new HashMap<String,Object> ();
mapVariable.put("manager", "丽水3");
ProcessInstance pi = processEngine.getExecutionService().startProcessInstanceByKey("test", mapVariable);
在配置文件xml中配置占位参数: <task g="312,60,92,52" name="task1" assignee="#{manager}">
*/
//方法二:实现AssignmentHandler接口,并在配置文件xml中声明
// 如下:<assignment-handler class="cn.edu.zust.itee.task.AssignmentHandlerImpl"></assignment-handler>
//启动流程实例
ProcessInstance pi = processEngine.getExecutionService().startProcessInstanceByKey("test");
System.out.println("processIntenceId="+pi.getId());
}
@Test
public void signal(){
//让指定的Execution(即:ProcessInstance)向后执行一步
//(excutionId对应jbpm4_execution表中的“ID_”字段)
String excutionId = "test.360007";
processEngine.getExecutionService().signalExecutionById(excutionId);
}
}
流程配置文件test.jpdl.xml
<?xml version="1.0" encoding="UTF-8"?>
<process name="test" xmlns="http://jbpm.org/4.4/jpdl">
<start name="start1" g="149,64,48,48">
<transition name="to task1" to="task1" g="-52,-22"/>
</start>
<task name="task1" g="312,60,92,52">
<assignment-handler class="cn.edu.zust.itee.task.AssignmentHandlerImpl"></assignment-handler>
<transition name="to end1" to="end1" g="-50,-22"/>
</task>
<end name="end1" g="501,81,48,48"/>
</process>
任务分配类:
/**
*
*/
package cn.edu.zust.itee.task;
import org.jbpm.api.model.OpenExecution;
import org.jbpm.api.task.Assignable;
import org.jbpm.api.task.AssignmentHandler;
/**
* @author 郑勇
* 2013-7-10
*/
public class AssignmentHandlerImpl implements AssignmentHandler {
@Override
public void assign(Assignable assignable, OpenExecution execution) throws Exception {
System.out.println("进入了--------AssignmentHandlerImpl");
//计算出任务的办理人
// String userId =execution.getVariable(key);
// String userId =hibernateSession.createQuery(hql).uniqueResult();
//指定当前任务办理人(任务分配)
String userId = "王五";
assignable.setAssignee(userId);
}
}