@ruoli
2016-08-16T10:06:46.000000Z
字数 1798
阅读 3281
Activiti
package test;
/**
* @author: Ruoli
*/
import org.activiti.engine.ManagementService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.activiti.engine.impl.pvm.process.ActivityImpl;
import org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl;
import org.junit.Test;
/**
* 流程中任意跳跃
* @author Administrator
*
*/
public class JumpActivityCmd implements Command<Object> {
private String activityId;
private String processInstanceId;
private String jumpOrigin;
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
public JumpActivityCmd(){}
public JumpActivityCmd(String processInstanceId, String activityId) {
this(processInstanceId, activityId, "jump");
}
/**
*
* @param processInstanceId 流程实例ID
* @param activityId 跳转目标环节KEY
* @param jumpOrigin 自动完成环节的意见
*/
public JumpActivityCmd(String processInstanceId, String activityId, String jumpOrigin) {
this.activityId = activityId;
this.processInstanceId = processInstanceId;
this.jumpOrigin = jumpOrigin;
}
public Object execute(CommandContext commandContext) {
ExecutionEntity executionEntity = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);
executionEntity.destroyScope(jumpOrigin);
ProcessDefinitionImpl processDefinition = executionEntity.getProcessDefinition();
ActivityImpl activity = processDefinition.findActivity(activityId);
executionEntity.executeActivity(activity);
return executionEntity;
}
@Test
public void testname() {
ManagementService managementService=processEngine.getManagementService();
//第一个参数 流程实例ID,
//第二个参数 跳转目标环节KEY
//第三个参数 自动完成环节的意见
Command<Object> cmdCommand=new JumpActivityCmd("1201","usertask2","强制跳转");
managementService.executeCommand(cmdCommand);
}
}