Java Code Examples for org.activiti.engine.impl.persistence.entity.ExecutionEntity#getProcessInstanceId()

The following examples show how to use org.activiti.engine.impl.persistence.entity.ExecutionEntity#getProcessInstanceId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActivitiProcessStartedEventImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public ActivitiProcessStartedEventImpl(final Object entity, final Map variables, final boolean localScope) {
  super(entity, variables, localScope, ActivitiEventType.PROCESS_STARTED);
  if (entity instanceof ExecutionEntity) {
    ExecutionEntity executionEntity = (ExecutionEntity) entity;
    if (executionEntity.isProcessInstanceType() == false) {
      executionEntity = executionEntity.getParent();
    }
    
    final ExecutionEntity superExecution = executionEntity.getSuperExecution();
    if (superExecution != null) {
      this.nestedProcessDefinitionId = superExecution.getProcessDefinitionId();
      this.nestedProcessInstanceId = superExecution.getProcessInstanceId();
    } else {
      this.nestedProcessDefinitionId = null;
      this.nestedProcessInstanceId = null;
    }
    
  } else {
    this.nestedProcessDefinitionId = null;
    this.nestedProcessInstanceId = null;
  }
}
 
Example 2
Source File: SetProcessInstanceBusinessKeyCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public Void execute(CommandContext commandContext) {
    ExecutionEntityManager executionManager = commandContext.getExecutionEntityManager();
    ExecutionEntity processInstance = executionManager.findExecutionById(processInstanceId);
    if (processInstance == null) {
        throw new ActivitiObjectNotFoundException("No process instance found for id = '" + processInstanceId + "'.", ProcessInstance.class);
    } else if (!processInstance.isProcessInstanceType()) {
        throw new ActivitiIllegalArgumentException(
                "A process instance id is required, but the provided id " +
                        "'" + processInstanceId + "' " +
                        "points to a child execution of process instance " +
                        "'" + processInstance.getProcessInstanceId() + "'. " +
                        "Please invoke the " + getClass().getSimpleName() + " with a root execution id.");
    }

    processInstance.updateProcessBusinessKey(businessKey);

    return null;
}
 
Example 3
Source File: ActivitiProcessStartedEventImpl.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
public ActivitiProcessStartedEventImpl(final Object entity, final Map variables, final boolean localScope) {
    super(entity, variables, localScope, FlowableEngineEventType.PROCESS_STARTED);
    if (entity instanceof ExecutionEntity) {
        final ExecutionEntity superExecution = ((ExecutionEntity) entity).getSuperExecution();
        if (superExecution != null) {
            this.nestedProcessDefinitionId = superExecution.getProcessDefinitionId();
            this.nestedProcessInstanceId = superExecution.getProcessInstanceId();
        } else {
            this.nestedProcessDefinitionId = null;
            this.nestedProcessInstanceId = null;
        }
    } else {
        this.nestedProcessDefinitionId = null;
        this.nestedProcessInstanceId = null;
    }
}
 
Example 4
Source File: SetProcessInstanceBusinessKeyCmd.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public Void execute(CommandContext commandContext) {
  ExecutionEntityManager executionManager = commandContext.getExecutionEntityManager();
  ExecutionEntity processInstance = executionManager.findById(processInstanceId);
  if (processInstance == null) {
    throw new ActivitiObjectNotFoundException("No process instance found for id = '" + processInstanceId + "'.", ProcessInstance.class);
  } else if (!processInstance.isProcessInstanceType()) {
    throw new ActivitiIllegalArgumentException("A process instance id is required, but the provided id " + "'" + processInstanceId + "' " + "points to a child execution of process instance " + "'"
        + processInstance.getProcessInstanceId() + "'. " + "Please invoke the " + getClass().getSimpleName() + " with a root execution id.");
  }
  
  if (Activiti5Util.isActiviti5ProcessDefinitionId(commandContext, processInstance.getProcessDefinitionId())) {
    commandContext.getProcessEngineConfiguration().getActiviti5CompatibilityHandler().updateBusinessKey(processInstanceId, businessKey);
    return null;
  }

  executionManager.updateProcessInstanceBusinessKey(processInstance, businessKey);

  return null;
}
 
Example 5
Source File: InactiveExecutionsInActivityAndProcInstMatcher.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isRetained(ExecutionEntity executionEntity, Object parameter) {
  Map<String, Object> paramMap = (Map<String, Object>) parameter;
  String activityId = (String) paramMap.get("activityId");
  String processInstanceId = (String) paramMap.get("processInstanceId");
  
  return executionEntity.getProcessInstanceId() != null 
      && executionEntity.getProcessInstanceId().equals(processInstanceId) 
      && !executionEntity.isActive() 
      && executionEntity.getActivityId() != null 
      && executionEntity.getActivityId().equals(activityId);
}
 
Example 6
Source File: InactiveExecutionsByProcInstMatcher.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isRetained(ExecutionEntity executionEntity, Object parameter) {
  Map<String, Object> paramMap = (Map<String, Object>) parameter;
  String processInstanceId = (String) paramMap.get("processInstanceId");
  
  return executionEntity.getProcessInstanceId() != null 
      && executionEntity.getProcessInstanceId().equals(processInstanceId) 
      && !executionEntity.isActive();
}
 
Example 7
Source File: ExecutionsByProcessInstanceIdEntityMatcher.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isRetained(ExecutionEntity entity, Object parameter) {
  // parameter = process instance execution id
    return entity.getProcessInstanceId() != null 
        && entity.getProcessInstanceId().equals((String) parameter) 
        && entity.getParentId() != null;
}
 
Example 8
Source File: SetProcessDefinitionVersionCmd.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public Void execute(CommandContext commandContext) {
  // check that the new process definition is just another version of the same
  // process definition that the process instance is using
  ExecutionEntityManager executionManager = commandContext.getExecutionEntityManager();
  ExecutionEntity processInstance = executionManager.findById(processInstanceId);
  if (processInstance == null) {
    throw new ActivitiObjectNotFoundException("No process instance found for id = '" + processInstanceId + "'.", ProcessInstance.class);
  } else if (!processInstance.isProcessInstanceType()) {
    throw new ActivitiIllegalArgumentException("A process instance id is required, but the provided id " + "'" + processInstanceId + "' " + "points to a child execution of process instance " + "'"
        + processInstance.getProcessInstanceId() + "'. " + "Please invoke the " + getClass().getSimpleName() + " with a root execution id.");
  }
  
  DeploymentManager deploymentCache = commandContext.getProcessEngineConfiguration().getDeploymentManager();
  ProcessDefinition currentProcessDefinition = deploymentCache.findDeployedProcessDefinitionById(processInstance.getProcessDefinitionId());

  ProcessDefinition newProcessDefinition = deploymentCache
      .findDeployedProcessDefinitionByKeyAndVersionAndTenantId(currentProcessDefinition.getKey(), processDefinitionVersion, currentProcessDefinition.getTenantId());

  validateAndSwitchVersionOfExecution(commandContext, processInstance, newProcessDefinition);

  // switch the historic process instance to the new process definition version
  commandContext.getHistoryManager().recordProcessDefinitionChange(processInstanceId, newProcessDefinition.getId());

  // switch all sub-executions of the process instance to the new process definition version
  Collection<ExecutionEntity> childExecutions = executionManager.findChildExecutionsByProcessInstanceId(processInstanceId);
  for (ExecutionEntity executionEntity : childExecutions) {
    validateAndSwitchVersionOfExecution(commandContext, executionEntity, newProcessDefinition);
  }

  return null;
}
 
Example 9
Source File: DefaultHistoryManager.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected HistoricActivityInstanceEntity createHistoricActivityInstanceEntity(ExecutionEntity execution) {
  IdGenerator idGenerator = getProcessEngineConfiguration().getIdGenerator();
  
  String processDefinitionId = execution.getProcessDefinitionId();
  String processInstanceId = execution.getProcessInstanceId();
    
  HistoricActivityInstanceEntity historicActivityInstance = getHistoricActivityInstanceEntityManager().create();
  historicActivityInstance.setId(idGenerator.getNextId());
  historicActivityInstance.setProcessDefinitionId(processDefinitionId);
  historicActivityInstance.setProcessInstanceId(processInstanceId);
  historicActivityInstance.setExecutionId(execution.getId());
  historicActivityInstance.setActivityId(execution.getActivityId());
  if (execution.getCurrentFlowElement() != null) {
    historicActivityInstance.setActivityName(execution.getCurrentFlowElement().getName());
    historicActivityInstance.setActivityType(parseActivityType(execution.getCurrentFlowElement()));
  }
  Date now = getClock().getCurrentTime();
  historicActivityInstance.setStartTime(now);
 
  // Inherit tenant id (if applicable)
  if (execution.getTenantId() != null) {
    historicActivityInstance.setTenantId(execution.getTenantId());
  }
  
  getHistoricActivityInstanceEntityManager().insert(historicActivityInstance);
  return historicActivityInstance;
}
 
Example 10
Source File: LogMDC.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static void putMDCExecution(ExecutionEntity e) {
  if (e.getId() != null)
    MDC.put(LOG_MDC_EXECUTION_ID, e.getId());
  if (e.getProcessDefinitionId() != null)
    MDC.put(LOG_MDC_PROCESSDEFINITION_ID, e.getProcessDefinitionId());
  if (e.getProcessInstanceId() != null)
    MDC.put(LOG_MDC_PROCESSINSTANCE_ID, e.getProcessInstanceId());
  if (e.getProcessInstanceBusinessKey() != null)
    MDC.put(LOG_MDC_BUSINESS_KEY, e.getProcessInstanceBusinessKey());

}
 
Example 11
Source File: DefaultHistoryManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void recordActivityStart(ExecutionEntity executionEntity) {
    if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
        if (executionEntity.getActivity() != null) {
            IdGenerator idGenerator = Context.getProcessEngineConfiguration().getIdGenerator();

            String processDefinitionId = executionEntity.getProcessDefinitionId();
            String processInstanceId = executionEntity.getProcessInstanceId();
            String executionId = executionEntity.getId();

            HistoricActivityInstanceEntity historicActivityInstance = new HistoricActivityInstanceEntity();
            historicActivityInstance.setId(idGenerator.getNextId());
            historicActivityInstance.setProcessDefinitionId(processDefinitionId);
            historicActivityInstance.setProcessInstanceId(processInstanceId);
            historicActivityInstance.setExecutionId(executionId);
            historicActivityInstance.setActivityId(executionEntity.getActivityId());
            historicActivityInstance.setActivityName((String) executionEntity.getActivity().getProperty("name"));
            historicActivityInstance.setActivityType((String) executionEntity.getActivity().getProperty("type"));
            historicActivityInstance.setStartTime(Context.getProcessEngineConfiguration().getClock().getCurrentTime());

            // Inherit tenant id (if applicable)
            if (executionEntity.getTenantId() != null) {
                historicActivityInstance.setTenantId(executionEntity.getTenantId());
            }

            getDbSqlSession().insert(historicActivityInstance);

            // Fire event
            ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
            if (config != null && config.getEventDispatcher().isEnabled()) {
                config.getEventDispatcher().dispatchEvent(
                        ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.HISTORIC_ACTIVITY_INSTANCE_CREATED, historicActivityInstance));
            }

        }
    }
}
 
Example 12
Source File: ExecutionByProcessInstanceMatcher.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isRetained(ExecutionEntity entity, Object parameter) {
  return entity.getProcessInstanceId() != null && entity.getProcessInstanceId().equals((String) parameter);
}
 
Example 13
Source File: DefaultHistoryManager.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void recordProcessInstanceStart(ExecutionEntity processInstance) {
    if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricProcessInstanceEntity historicProcessInstance = new HistoricProcessInstanceEntity(processInstance);

        // Insert historic process-instance
        getDbSqlSession().insert(historicProcessInstance);

        // Fire event
        ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
        if (config != null && config.getEventDispatcher().isEnabled()) {
            config.getEventDispatcher().dispatchEvent(
                    ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.HISTORIC_PROCESS_INSTANCE_CREATED, historicProcessInstance));
        }

        // Also record the start-event manually, as there is no "start" activity history listener for this
        IdGenerator idGenerator = Context.getProcessEngineConfiguration().getIdGenerator();

        String processDefinitionId = processInstance.getProcessDefinitionId();
        String processInstanceId = processInstance.getProcessInstanceId();
        String executionId = processInstance.getId();

        HistoricActivityInstanceEntity historicActivityInstance = new HistoricActivityInstanceEntity();
        historicActivityInstance.setId(idGenerator.getNextId());
        historicActivityInstance.setProcessDefinitionId(processDefinitionId);
        historicActivityInstance.setProcessInstanceId(processInstanceId);
        historicActivityInstance.setExecutionId(executionId);
        historicActivityInstance.setActivityId(processInstance.getActivityId());
        historicActivityInstance.setActivityName((String) processInstance.getActivity().getProperty("name"));
        historicActivityInstance.setActivityType((String) processInstance.getActivity().getProperty("type"));
        Date now = Context.getProcessEngineConfiguration().getClock().getCurrentTime();
        historicActivityInstance.setStartTime(now);

        // Inherit tenant id (if applicable)
        if (processInstance.getTenantId() != null) {
            historicActivityInstance.setTenantId(processInstance.getTenantId());
        }

        getDbSqlSession().insert(historicActivityInstance);

        // Fire event
        if (config != null && config.getEventDispatcher().isEnabled()) {
            config.getEventDispatcher().dispatchEvent(
                    ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.HISTORIC_ACTIVITY_INSTANCE_CREATED, historicActivityInstance));
        }

    }
}
 
Example 14
Source File: ExecutionController.java    From activiti-in-action-codes with Apache License 2.0 4 votes vote down vote up
/**
 * 用户参与过的流程
 *
 * @return
 */
@RequestMapping("execution/list")
public ModelAndView list(HttpServletRequest request) {
    ModelAndView mav = new ModelAndView("chapter13/execution-list");
/* 标准查询
List<ProcessInstance> processInstanceList = runtimeService.createProcessInstanceQuery().list();
List<Execution> list = runtimeService.createExecutionQuery().list();
mav.addObject("list", list);
*/

    User user = UserUtil.getUserFromSession(request.getSession());
    Page<Execution> page = new Page<Execution>(PageUtil.PAGE_SIZE);
    int[] pageParams = PageUtil.init(page, request);
    NativeExecutionQuery nativeExecutionQuery = runtimeService.createNativeExecutionQuery();

    // native query
    String sql = "select RES.* from ACT_RU_EXECUTION RES left join ACT_HI_TASKINST ART on ART.PROC_INST_ID_ = RES.PROC_INST_ID_ "
            + " where ART.ASSIGNEE_ = #{userId} and ACT_ID_ is not null and IS_ACTIVE_ = 'TRUE' order by START_TIME_ desc";

    nativeExecutionQuery.parameter("userId", user.getId());

    List<Execution> executionList = nativeExecutionQuery.sql(sql).listPage(pageParams[0], pageParams[1]);

    // 查询流程定义对象
    Map<String, ProcessDefinition> definitionMap = new HashMap<String, ProcessDefinition>();

    // 任务的英文-中文对照
    Map<String, Task> taskMap = new HashMap<String, Task>();

    // 每个Execution的当前活动ID,可能为多个
    Map<String, List<String>> currentActivityMap = new HashMap<String, List<String>>();

    // 设置每个Execution对象的当前活动节点
    for (Execution execution : executionList) {
        ExecutionEntity executionEntity = (ExecutionEntity) execution;
        String processInstanceId = executionEntity.getProcessInstanceId();
        String processDefinitionId = executionEntity.getProcessDefinitionId();

        // 缓存ProcessDefinition对象到Map集合
        definitionCache(definitionMap, processDefinitionId);

        // 查询当前流程的所有处于活动状态的活动ID,如果并行的活动则会有多个
        List<String> activeActivityIds = runtimeService.getActiveActivityIds(execution.getId());
        currentActivityMap.put(execution.getId(), activeActivityIds);

        for (String activityId : activeActivityIds) {

            // 查询处于活动状态的任务
            Task task = taskService.createTaskQuery().taskDefinitionKey(activityId).executionId(execution.getId()).singleResult();

            // 调用活动
            if (task == null) {
                ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
                        .superProcessInstanceId(processInstanceId).singleResult();
                task = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).singleResult();
                definitionCache(definitionMap, processInstance.getProcessDefinitionId());
            }
            taskMap.put(activityId, task);
        }
    }

    mav.addObject("taskMap", taskMap);
    mav.addObject("definitions", definitionMap);
    mav.addObject("currentActivityMap", currentActivityMap);

    page.setResult(executionList);
    page.setTotalCount(nativeExecutionQuery.sql("select count(*) from (" + sql + ")").count());
    mav.addObject("page", page);

    return mav;
}
 
Example 15
Source File: ExecutionController.java    From activiti-in-action-codes with Apache License 2.0 4 votes vote down vote up
/**
 * 用户参与过的流程
 *
 * @return
 */
@RequestMapping("execution/list")
public ModelAndView list(HttpServletRequest request) {
    ModelAndView mav = new ModelAndView("chapter13/execution-list");
/* 标准查询
List<ProcessInstance> processInstanceList = runtimeService.createProcessInstanceQuery().list();
List<Execution> list = runtimeService.createExecutionQuery().list();
mav.addObject("list", list);
*/

    User user = UserUtil.getUserFromSession(request.getSession());
    Page<Execution> page = new Page<Execution>(PageUtil.PAGE_SIZE);
    int[] pageParams = PageUtil.init(page, request);
    NativeExecutionQuery nativeExecutionQuery = runtimeService.createNativeExecutionQuery();

    // native query
    String sql = "select RES.* from ACT_RU_EXECUTION RES left join ACT_HI_TASKINST ART on ART.PROC_INST_ID_ = RES.PROC_INST_ID_ "
            + " where SUSPENSION_STATE_ = '1' and ART.ASSIGNEE_ = #{userId} and ACT_ID_ is not null and IS_ACTIVE_ = 'TRUE' order by START_TIME_ desc";

    nativeExecutionQuery.parameter("userId", user.getId());

    List<Execution> executionList = nativeExecutionQuery.sql(sql).listPage(pageParams[0], pageParams[1]);

    // 查询流程定义对象
    Map<String, ProcessDefinition> definitionMap = new HashMap<String, ProcessDefinition>();

    // 任务的英文-中文对照
    Map<String, Task> taskMap = new HashMap<String, Task>();

    // 每个Execution的当前活动ID,可能为多个
    Map<String, List<String>> currentActivityMap = new HashMap<String, List<String>>();

    // 设置每个Execution对象的当前活动节点
    for (Execution execution : executionList) {
        ExecutionEntity executionEntity = (ExecutionEntity) execution;
        String processInstanceId = executionEntity.getProcessInstanceId();
        String processDefinitionId = executionEntity.getProcessDefinitionId();

        // 缓存ProcessDefinition对象到Map集合
        definitionCache(definitionMap, processDefinitionId);

        // 查询当前流程的所有处于活动状态的活动ID,如果并行的活动则会有多个
        List<String> activeActivityIds = runtimeService.getActiveActivityIds(execution.getId());
        currentActivityMap.put(execution.getId(), activeActivityIds);

        for (String activityId : activeActivityIds) {

            // 查询处于活动状态的任务
            Task task = taskService.createTaskQuery().taskDefinitionKey(activityId).executionId(execution.getId()).singleResult();

            // 调用活动
            if (task == null) {
                ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
                        .superProcessInstanceId(processInstanceId).singleResult();
                if (processInstance != null) {
                    task = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).singleResult();
                    definitionCache(definitionMap, processInstance.getProcessDefinitionId());
                }
            }
            taskMap.put(activityId, task);
        }
    }

    mav.addObject("taskMap", taskMap);
    mav.addObject("definitions", definitionMap);
    mav.addObject("currentActivityMap", currentActivityMap);

    page.setResult(executionList);
    page.setTotalCount(nativeExecutionQuery.sql("select count(*) from (" + sql + ")").count());
    mav.addObject("page", page);

    return mav;
}
 
Example 16
Source File: ExecutionController.java    From activiti-in-action-codes with Apache License 2.0 4 votes vote down vote up
/**
 * 用户参与过的流程
 *
 * @return
 */
@RequestMapping("execution/list")
public ModelAndView list(HttpServletRequest request) {
    ModelAndView mav = new ModelAndView("chapter13/execution-list");
/* 标准查询
List<ProcessInstance> processInstanceList = runtimeService.createProcessInstanceQuery().list();
List<Execution> list = runtimeService.createExecutionQuery().list();
mav.addObject("list", list);
*/

    User user = UserUtil.getUserFromSession(request.getSession());
    Page<Execution> page = new Page<Execution>(PageUtil.PAGE_SIZE);
    int[] pageParams = PageUtil.init(page, request);
    NativeExecutionQuery nativeExecutionQuery = runtimeService.createNativeExecutionQuery();

    // native query
    String sql = "select distinct * from (select RES.* from ACT_RU_EXECUTION RES left join ACT_HI_TASKINST ART on ART.PROC_INST_ID_ = RES.PROC_INST_ID_ "
            + " left join ACT_HI_PROCINST AHP on AHP.PROC_INST_ID_ = RES.PROC_INST_ID_ "
            + " where SUSPENSION_STATE_ = '1' and (ART.ASSIGNEE_ = #{userId} or AHP.START_USER_ID_ = #{userId}) "
            + " and ACT_ID_ is not null and IS_ACTIVE_ = 'TRUE' order by ART.START_TIME_ desc)";

    nativeExecutionQuery.parameter("userId", user.getId());

    List<Execution> executionList = nativeExecutionQuery.sql(sql).listPage(pageParams[0], pageParams[1]);

    // 查询流程定义对象
    Map<String, ProcessDefinition> definitionMap = new HashMap<String, ProcessDefinition>();

    // 任务的英文-中文对照
    Map<String, Task> taskMap = new HashMap<String, Task>();

    // 每个Execution的当前活动ID,可能为多个
    Map<String, List<String>> currentActivityMap = new HashMap<String, List<String>>();

    // 设置每个Execution对象的当前活动节点
    for (Execution execution : executionList) {
        ExecutionEntity executionEntity = (ExecutionEntity) execution;
        String processInstanceId = executionEntity.getProcessInstanceId();
        String processDefinitionId = executionEntity.getProcessDefinitionId();

        // 缓存ProcessDefinition对象到Map集合
        definitionCache(definitionMap, processDefinitionId);

        // 查询当前流程的所有处于活动状态的活动ID,如果并行的活动则会有多个
        List<String> activeActivityIds = runtimeService.getActiveActivityIds(execution.getId());
        currentActivityMap.put(execution.getId(), activeActivityIds);

        for (String activityId : activeActivityIds) {

            // 查询处于活动状态的任务
            Task task = taskService.createTaskQuery().taskDefinitionKey(activityId).executionId(execution.getId()).singleResult();

            // 调用活动
            if (task == null) {
                ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
                        .superProcessInstanceId(processInstanceId).singleResult();
                if (processInstance != null) {
                    task = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).singleResult();
                    definitionCache(definitionMap, processInstance.getProcessDefinitionId());
                }
            }
            taskMap.put(activityId, task);
        }
    }

    mav.addObject("taskMap", taskMap);
    mav.addObject("definitions", definitionMap);
    mav.addObject("currentActivityMap", currentActivityMap);

    page.setResult(executionList);
    page.setTotalCount(nativeExecutionQuery.sql("select count(*) from (" + sql + ")").count());
    mav.addObject("page", page);

    return mav;
}
 
Example 17
Source File: ExecutionController.java    From activiti-in-action-codes with Apache License 2.0 4 votes vote down vote up
/**
 * 用户参与过的流程
 *
 * @return
 */
@RequestMapping("execution/list")
public ModelAndView list(HttpServletRequest request) {
    ModelAndView mav = new ModelAndView("chapter13/execution-list");
/* 标准查询
List<ProcessInstance> processInstanceList = runtimeService.createProcessInstanceQuery().list();
List<Execution> list = runtimeService.createExecutionQuery().list();
mav.addObject("list", list);
*/

    User user = UserUtil.getUserFromSession(request.getSession());
    Page<Execution> page = new Page<Execution>(PageUtil.PAGE_SIZE);
    int[] pageParams = PageUtil.init(page, request);
    NativeExecutionQuery nativeExecutionQuery = runtimeService.createNativeExecutionQuery();

    // native query
    String sql = "select distinct * from (select RES.* from ACT_RU_EXECUTION RES left join ACT_HI_TASKINST ART on ART.PROC_INST_ID_ = RES.PROC_INST_ID_ "
            + " left join ACT_HI_PROCINST AHP on AHP.PROC_INST_ID_ = RES.PROC_INST_ID_ "
            + " where SUSPENSION_STATE_ = '1' and (ART.ASSIGNEE_ = #{userId} or AHP.START_USER_ID_ = #{userId}) "
            + " and ACT_ID_ is not null and IS_ACTIVE_ = 'TRUE' order by ART.START_TIME_ desc)";

    nativeExecutionQuery.parameter("userId", user.getId());

    List<Execution> executionList = nativeExecutionQuery.sql(sql).listPage(pageParams[0], pageParams[1]);

    // 查询流程定义对象
    Map<String, ProcessDefinition> definitionMap = new HashMap<String, ProcessDefinition>();

    // 任务的英文-中文对照
    Map<String, Task> taskMap = new HashMap<String, Task>();

    // 每个Execution的当前活动ID,可能为多个
    Map<String, List<String>> currentActivityMap = new HashMap<String, List<String>>();

    // 设置每个Execution对象的当前活动节点
    for (Execution execution : executionList) {
        ExecutionEntity executionEntity = (ExecutionEntity) execution;
        String processInstanceId = executionEntity.getProcessInstanceId();
        String processDefinitionId = executionEntity.getProcessDefinitionId();

        // 缓存ProcessDefinition对象到Map集合
        definitionCache(definitionMap, processDefinitionId);

        // 查询当前流程的所有处于活动状态的活动ID,如果并行的活动则会有多个
        List<String> activeActivityIds = runtimeService.getActiveActivityIds(execution.getId());
        currentActivityMap.put(execution.getId(), activeActivityIds);

        for (String activityId : activeActivityIds) {

            // 查询处于活动状态的任务
            Task task = taskService.createTaskQuery().taskDefinitionKey(activityId).executionId(execution.getId()).singleResult();

            // 调用活动
            if (task == null) {
                ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
                        .superProcessInstanceId(processInstanceId).singleResult();
                if (processInstance != null) {
                    task = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).singleResult();
                    definitionCache(definitionMap, processInstance.getProcessDefinitionId());
                }
            }
            taskMap.put(activityId, task);
        }
    }

    mav.addObject("taskMap", taskMap);
    mav.addObject("definitions", definitionMap);
    mav.addObject("currentActivityMap", currentActivityMap);

    page.setResult(executionList);
    page.setTotalCount(nativeExecutionQuery.sql("select count(*) from (" + sql + ")").count());
    mav.addObject("page", page);

    return mav;
}
 
Example 18
Source File: ExecutionController.java    From activiti-in-action-codes with Apache License 2.0 4 votes vote down vote up
/**
 * 用户参与过的流程
 *
 * @return
 */
@RequestMapping("execution/list")
public ModelAndView list(HttpServletRequest request) {
    ModelAndView mav = new ModelAndView("chapter13/execution-list");
/* 标准查询
List<ProcessInstance> processInstanceList = runtimeService.createProcessInstanceQuery().list();
List<Execution> list = runtimeService.createExecutionQuery().list();
mav.addObject("list", list);
*/

    User user = UserUtil.getUserFromSession(request.getSession());
    Page<Execution> page = new Page<Execution>(PageUtil.PAGE_SIZE);
    int[] pageParams = PageUtil.init(page, request);
    NativeExecutionQuery nativeExecutionQuery = runtimeService.createNativeExecutionQuery();

    // native query
    String sql = "select distinct * from (select RES.* from ACT_RU_EXECUTION RES left join ACT_HI_TASKINST ART on ART.PROC_INST_ID_ = RES.PROC_INST_ID_ "
            + " left join ACT_HI_PROCINST AHP on AHP.PROC_INST_ID_ = RES.PROC_INST_ID_ "
            + " where SUSPENSION_STATE_ = '1' and (ART.ASSIGNEE_ = #{userId} or AHP.START_USER_ID_ = #{userId}) "
            + " and ACT_ID_ is not null and IS_ACTIVE_ = 'TRUE' order by ART.START_TIME_ desc)";

    nativeExecutionQuery.parameter("userId", user.getId());

    List<Execution> executionList = nativeExecutionQuery.sql(sql).listPage(pageParams[0], pageParams[1]);

    // 查询流程定义对象
    Map<String, ProcessDefinition> definitionMap = new HashMap<String, ProcessDefinition>();

    // 任务的英文-中文对照
    Map<String, Task> taskMap = new HashMap<String, Task>();

    // 每个Execution的当前活动ID,可能为多个
    Map<String, List<String>> currentActivityMap = new HashMap<String, List<String>>();

    // 设置每个Execution对象的当前活动节点
    for (Execution execution : executionList) {
        ExecutionEntity executionEntity = (ExecutionEntity) execution;
        String processInstanceId = executionEntity.getProcessInstanceId();
        String processDefinitionId = executionEntity.getProcessDefinitionId();

        // 缓存ProcessDefinition对象到Map集合
        definitionCache(definitionMap, processDefinitionId);

        // 查询当前流程的所有处于活动状态的活动ID,如果并行的活动则会有多个
        List<String> activeActivityIds = runtimeService.getActiveActivityIds(execution.getId());
        currentActivityMap.put(execution.getId(), activeActivityIds);

        for (String activityId : activeActivityIds) {

            // 查询处于活动状态的任务
            Task task = taskService.createTaskQuery().taskDefinitionKey(activityId).executionId(execution.getId()).singleResult();

            // 调用活动
            if (task == null) {
                ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
                        .superProcessInstanceId(processInstanceId).singleResult();
                if (processInstance != null) {
                    task = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).singleResult();
                    definitionCache(definitionMap, processInstance.getProcessDefinitionId());
                }
            }
            taskMap.put(activityId, task);
        }
    }

    mav.addObject("taskMap", taskMap);
    mav.addObject("definitions", definitionMap);
    mav.addObject("currentActivityMap", currentActivityMap);

    page.setResult(executionList);
    page.setTotalCount(nativeExecutionQuery.sql("select count(*) from (" + sql + ")").count());
    mav.addObject("page", page);

    return mav;
}