Ejemplo n.º 1
0
  /*
   * Helper methods
   */
  public static Activity activity(Process process, ProcessInstance instance, Task task)
      throws StatusCodeError {
    Activity activity = null;
    if (process.isAllowPerInstanceActivities()
        && task != null
        && task.getTaskDefinitionKey() != null
        && instance != null) {
      Map<String, Activity> activityMap = instance.getActivityMap();
      if (activityMap != null) activity = activityMap.get(task.getTaskDefinitionKey());

      if (activity != null) return activity;
    }

    ProcessDeployment deployment = process.getDeployment();
    if (deployment == null)
      throw new InternalServerError(Constants.ExceptionCodes.process_is_misconfigured);

    String activityKey = deployment.getStartActivityKey();
    if (task != null) activityKey = task.getTaskDefinitionKey();

    if (activityKey != null) activity = deployment.getActivity(activityKey);

    if (activity != null) return activity;

    throw new InternalServerError(Constants.ExceptionCodes.process_is_misconfigured);
  }
  @Cacheable("processDefinitionIdMap")
  public ManyMap<String, Process> getProcessDefinitionIdMap(Set<Process> processes) {
    ManyMap<String, Process> processDefinitionKeyMap = new ManyMap<String, Process>();
    for (Process process : processes) {
      ProcessDeployment deployment = process.getDeployment();
      if (deployment != null
          && deployment.getEngine() != null
          && getKey() != null
          && deployment.getEngine().equals(getKey()))
        processDefinitionKeyMap.putOne(deployment.getEngineProcessDefinitionKey(), process);
    }

    ManyMap<String, Process> map = new ManyMap<String, Process>();
    for (ProcessDefinition processDefinition :
        processEngine.getRepositoryService().createProcessDefinitionQuery().list()) {
      List<Process> matchingProcesses = processDefinitionKeyMap.get(processDefinition.getKey());
      if (matchingProcesses != null && !matchingProcesses.isEmpty())
        map.put(processDefinition.getId(), matchingProcesses);
    }

    return map;
  }