您的位置:首页 > 其它

Task任务驳回到指定节点

2017-02-22 07:20 281 查看
把Task任务驳回到指定节点

public class FlowServiceTest2 {
ProcessEngine processEngine;
String jdplPath;
String pdKey;

@Before
public void setUp() throws Exception {
processEngine = Configuration.getProcessEngine();// 获取流程引擎
//jdplPath = "F:/workspace/jdome/jbpm_dome/src/main/resource/jpdl/reject.jpdl.xml";
//pdKey = "reject";
jdplPath = "F:/workspace/jdome/jbpm_dome/src/main/resource/jpdl/reject3.jpdl.xml";
pdKey = "reject3";
}

/**
* @description 发布流程 no.1
*/
@Test
public void deploy() {
try {
RepositoryService repositoryService = processEngine.getRepositoryService();
File file = new File(jdplPath);
repositoryService.createDeployment().addResourceFromFile(file).deploy();

} catch (Exception e) {

e.printStackTrace();
throw new RuntimeException();
}

}

/**
* @description 提交申请 no.2
*/
@Test
public void testApply() {
Map<String, Object> values = new HashMap<String, Object>();
List<Integer> deptIds = new ArrayList<Integer>();
deptIds.add(1);
deptIds.add(2);

values.put("deptIds", deptIds);
values.put("deptIdsLenght", deptIds.size());

ExecutionService executionService = processEngine.getExecutionService();
executionService.startProcessInstanceByKey(pdKey, values);
}

/**
* @description 完成任务 no.3
*/
@Test
public void takeTask() {
String taskId = "10005"; //直接接查数据库任务表获取

TaskService taskService = processEngine.getTaskService();
taskService.completeTask(taskId);
}

/**
* 把任务20001驳回到 task0节点 http://blog.csdn.net/xxb2008 */
@Test
public void takeTaskForkOut () {

processEngine.execute(new Command<Object>() {

@Override
public Object execute(Environment environment) throws Exception {
String taskId = "20001"; //直接接查数据库任务表获取
String activityName = "task0"; //需要驳回到的指定节点名称

TaskService taskService = environment.get(TaskService.class);
RepositoryService repositoryService = (RepositoryServiceImpl) environment.get(RepositoryServiceImpl.class);

TaskImpl task = (TaskImpl) taskService.getTask(taskId);
ExecutionImpl processInstance = task.getExecution();
ExecutionImpl execution = processInstance;
ProcessDefinitionImpl procDefi = (ProcessDefinitionImpl) repositoryService.createProcessDefinitionQuery().
processDefinitionId(execution.getProcessDefinitionId()).uniqueResult();

ActivityImpl activity = execution.getActivity();
TransitionImpl transition = activity.createOutgoingTransition();
transition.setSource(activity);
transition.setDestination(procDefi.getActivity(activityName));
String transitionName = "" + new Date().getTime(); //随便取个不重复的名字
transition.setName(transitionName);
activity.setDefaultOutgoingTransition(transition);

if (execution.getIsProcessInstance()) { //主实际,不是fork\foreach分支出来的实例
task.take("feifei");//指定当前任务人
task.complete(transitionName);
}else{ //fork\foreach分支出来的实例,往外驳出
processInstance = execution.getProcessInstance();
processInstance.setState(ExecutionImpl.STATE_ACTIVE_ROOT);

processInstance.setTransition(transition);
processInstance.setActivity(activity);
processInstance.take(transition);

Collection<ExecutionImpl> executions = processInstance.getExecutions();
ExecutionImpl[] executionArray = new ExecutionImpl[executions.size()];
executions.toArray(executionArray);
for (ExecutionImpl e : executionArray) {
e.end();
}
}
return null;
}
});
}

}


流程定义文件

<?xml version="1.0" encoding="UTF-8"?>

<process name="reject3" key="reject3" xmlns="http://jbpm.org/4.4/jpdl">
<start name="start1" g="314,45,48,48">
<transition to="task0"/>
</start>

<task name="task0" g="295,389,92,52" assignee="task0">
<transition to="task1"/>
</task>

<task name="task1" g="295,389,92,52" assignee="task1">
<transition to="fork1"/>
</task>

<fork name="fork1" g="317,127,48,48">
<transition to="task2"/>
<transition to="task4"/>
</fork>

<task name="task2" g="205,206,92,52" assignee="task2">
<transition to="task3"/>
</task>

<task name="task3" g="205,206,92,52" assignee="task3">
<transition to="join1"/>
</task>

<task name="task4" g="392,212,92,52" assignee="task4">
<transition to="join1"/>
</task>

<join name="join1" g="314,311,48,48" multiplicity="2">
<transition to="end1"/>
</join>

<end name="end1" g="319,472,48,48"/>
</process>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: