activiti 定时边界相关

在activiti开发中经常会碰到节点之间互相跳转的需求,正常的跳转,用下面代码即可完成:

public class JumpCmd implements Command<Object> {

    private String            activityId;
    private String            processInstanceId;

    @Autowired
    private ManagementService managementService;
    @Autowired
    private RuntimeService    runtimeService;

    public JumpCmd(String processInstanceId, String activityId){
        this.activityId = activityId;
        this.processInstanceId = processInstanceId;
    }

    public Object execute(CommandContext commandContext) {

        List executionList = runtimeService.createExecutionQuery().executionId(processInstanceId).list();
        for (Execution execution : executionList) {
            String executionId = execution.getId();
            managementService.executeCommand(new EndEntityCmd(processInstanceId, executionId, null));
        }

        ExecutionEntity executionEntity = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);
        ProcessDefinitionImpl processDefinition = executionEntity.getProcessDefinition();
        ActivityImpl activity = processDefinition.findActivity(activityId);

        executionEntity.executeActivity(activity);

        return null;
    }
}

但是这里会有个问题 ,当跳转到带有定时边界任务的task时,定时job没有在job表中生成,做下面修改后即可:

 public Object execute(CommandContext commandContext) {

        List executionList = ActivitiUtil.runtimeService.createExecutionQuery().processInstanceId(processInstanceId).list();
        for (Execution execution : executionList) {
            String executionId = execution.getId();
            ActivitiUtil.managementService.executeCommand(new EndEntityCmd(processInstanceId, executionId, null));
        }

        ExecutionEntity executionEntity = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);
        ProcessDefinitionImpl processDefinition = executionEntity.getProcessDefinition();
        ActivityImpl activity = processDefinition.findActivity(activityId);

        InterpretableExecution propagatingExecution = null;
        if (activity.isScope()) {
          propagatingExecution = (InterpretableExecution) executionEntity.createExecution();
          propagatingExecution.setActivity(activity);
          propagatingExecution.setTransition(executionEntity.getTransition());
          executionEntity.setTransition(null);
          executionEntity.setActivity(null);
          executionEntity.setActive(false);
          propagatingExecution.initialize();

          propagatingExecution.performOperation(AtomicOperation.TRANSITION_NOTIFY_LISTENER_START);

        } else {
//          propagatingExecution = executionEntity;
            executionEntity.executeActivity(activity);
        }

//        propagatingExecution.performOperation(AtomicOperation.TRANSITION_NOTIFY_LISTENER_START);

        return null;
    }

你可能感兴趣的:(activiti)