public class JumpTask implements Command<Void> {
protected String executionId;
protected ActivityImpl desActivity;
protected Map<String, Object> paramvar;
protected ActivityImpl currentActivity;
//獲取默認的流程引擎
protected static ProcessEngine pe = ProcessEngines.getDefaultProcessEngine();
public static void main(String[] args) {
Map<String, Object> map = new HashMap<String, Object>();
// String[] v = { "shareniu1", "shareniu2", "shareniu3", "shareniu4" };
// vars.put("assigneeList", Arrays.asList(v));
map.put("leader", "hty");
map.put("day", "7");
RepositoryService repositoryService = pe.getRepositoryService();
ReadOnlyProcessDefinition processDefinitionEntity = (ReadOnlyProcessDefinition) repositoryService
.getProcessDefinition("StaffLeaveProcess:4:42504");
// 目標節點
ActivityImpl destinationActivity = (ActivityImpl) processDefinitionEntity
.findActivity("usertask4");
String executionId = "45001";
// 當前節點
ActivityImpl currentActivity = (ActivityImpl)processDefinitionEntity
.findActivity("usertask1");
pe.getManagementService().executeCommand(
new JumpTask(executionId, destinationActivity, map,
currentActivity));
}併發
public Void execute(CommandContext commandContext) {
ExecutionEntityManager executionEntityManager = Context
.getCommandContext().getExecutionEntityManager();
// 獲取當前流程的executionId,由於在併發的狀況下executionId是惟一的。
ExecutionEntity executionEntity = executionEntityManager
.findExecutionById(executionId);
executionEntity.setVariables(paramvar);
executionEntity.setEventSource(this.currentActivity);
executionEntity.setActivity(this.currentActivity);
// 根據executionId 獲取Task
Iterator<TaskEntity> localIterator = Context.getCommandContext()
.getTaskEntityManager()
.findTasksByExecutionId(this.executionId).iterator();
while (localIterator.hasNext()) {
TaskEntity taskEntity = (TaskEntity) localIterator.next();
// 觸發任務監聽
taskEntity.fireEvent("complete");
// taskEntity.setAssignee("hty");
// 刪除任務的緣由
Context.getCommandContext().getTaskEntityManager()
.deleteTask(taskEntity, "completed", false);
}
executionEntity.executeActivity(this.desActivity);
return null;
}
/**
* 構造參數 能夠根據本身的業務須要添加更多的字段
* @param executionId
* @param desActivity
* @param paramvar
* @param currentActivity
*/
public JumpTask(String executionId, ActivityImpl desActivity,
Map<String, Object> paramvar, ActivityImpl currentActivity) {
this.executionId = executionId;
this.desActivity = desActivity;
this.paramvar = paramvar;
this.currentActivity = currentActivity;
} this