예제 #1
0
  /**
   * 根据流入任务集合,查询最近一次的流入任务节点
   *
   * @param procInst 流程实例
   * @param tempList 流入任务集合
   * @return
   */
  private ActivityImpl filterNewestActivity(ProcessInstance procInst, List<ActivityImpl> tempList) {
    while (tempList.size() > 0) {
      ActivityImpl activity_ = tempList.get(0);
      HistoricActivityInstance activityInstance_ =
          findHistoricUserTask(procInst, activity_.getId());
      if (activityInstance_ == null) {
        tempList.remove(activity_);
        continue;
      }

      if (tempList.size() > 0) {
        ActivityImpl activity_0 = tempList.get(0);
        HistoricActivityInstance activityInstance_0 =
            findHistoricUserTask(procInst, activity_0.getId());
        if (activityInstance_ == null) {
          tempList.remove(activity_);
          continue;
        }

        if (activityInstance_0.getEndTime().before(activityInstance_0.getEndTime())) {
          tempList.remove(activity_);
        } else {
          tempList.remove(activity_);
        }
      } else {
        break;
      }
    }
    if (tempList.size() > 0) {
      return tempList.get(0);
    }
    return null;
  }
예제 #2
0
 public static void put(String processDefinitionId, ProcessDefinition processDefinition) {
   map.put(processDefinitionId, processDefinition);
   ProcessDefinitionEntity pde = (ProcessDefinitionEntity) processDefinition;
   activities.put(processDefinitionId, pde.getActivities());
   for (ActivityImpl activityImpl : pde.getActivities()) {
     singleActivity.put(processDefinitionId + "_" + activityImpl.getId(), activityImpl);
   }
 }
 /** * 获取跟踪信息 * * @return * @throws Exception */
 public String getProcessMap() throws Exception {
   String procDefId = ""; // request.getParameter("procDefId");
   String proInstId = ""; // request.getParameter("procInstId");
   ProcessDefinition processDefinition =
       repositoryService
           .createProcessDefinitionQuery()
           .processDefinitionId(procDefId)
           .singleResult();
   ProcessDefinitionImpl pdImpl = (ProcessDefinitionImpl) processDefinition;
   String processDefinitionId = pdImpl.getId(); // 流程标识
   ProcessDefinitionEntity def =
       (ProcessDefinitionEntity)
           ((RepositoryServiceImpl) repositoryService)
               .getDeployedProcessDefinition(processDefinitionId);
   List<ActivityImpl> activitiList = def.getActivities();
   // 获得当前任务的所有节点 /****/
   List<String> ActiveActivityIds = runtimeService.getActiveActivityIds(proInstId);
   for (String activeId : ActiveActivityIds) {
     for (ActivityImpl activityImpl : activitiList) {
       String id = activityImpl.getId();
       if (activityImpl.isScope()) {
         if (activityImpl.getActivities().size() > 1) {
           List<ActivityImpl> subAcList = activityImpl.getActivities();
           for (ActivityImpl subActImpl : subAcList) {
             String subid = subActImpl.getId();
             System.out.println("subImpl:" + subid);
             if (activeId.equals(subid)) { // 获得执行到那个节点
               actImpls.add(subActImpl);
               break;
             }
           }
         }
       }
       if (activeId.equals(id)) { // 获得执行到那个节点
         actImpls.add(activityImpl);
         System.out.println(id);
       }
     }
   }
   /** * */
   return "SUCCESS";
 }
  public void handleEvent(
      EventSubscriptionEntity eventSubscription, Object payload, CommandContext commandContext) {

    String configuration = eventSubscription.getConfiguration();
    if (configuration == null) {
      throw new ActivitiException(
          "Compensating execution not set for compensate event subscription with id "
              + eventSubscription.getId());
    }

    ExecutionEntity compensatingExecution =
        commandContext.getExecutionEntityManager().findExecutionById(configuration);

    ActivityImpl compensationHandler = eventSubscription.getActivity();

    if ((compensationHandler.getProperty(BpmnParse.PROPERTYNAME_IS_FOR_COMPENSATION) == null
            || !(Boolean)
                compensationHandler.getProperty(BpmnParse.PROPERTYNAME_IS_FOR_COMPENSATION))
        && compensationHandler.isScope()) {

      // descend into scope:
      List<CompensateEventSubscriptionEntity> eventsForThisScope =
          compensatingExecution.getCompensateEventSubscriptions();
      ScopeUtil.throwCompensationEvent(eventsForThisScope, compensatingExecution, false);

    } else {
      try {

        if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
          commandContext
              .getProcessEngineConfiguration()
              .getEventDispatcher()
              .dispatchEvent(
                  ActivitiEventBuilder.createActivityEvent(
                      ActivitiEventType.ACTIVITY_COMPENSATE,
                      compensationHandler.getId(),
                      compensatingExecution.getId(),
                      compensatingExecution.getProcessInstanceId(),
                      compensatingExecution.getProcessDefinitionId()));
        }
        compensatingExecution.setActivity(compensationHandler);

        // executing the atomic operation makes sure activity start events are fired
        compensatingExecution.performOperation(AtomicOperation.ACTIVITY_START);

      } catch (Exception e) {
        throw new ActivitiException(
            "Error while handling compensation event " + eventSubscription, e);
      }
    }
  }
예제 #5
0
 /**
  * 获取可以驳回的节点。
  *
  * @param wfTaskId String
  * @return List<Map<String,Object>>
  * @throws Exception 异常
  */
 @ResponseBody
 @RequestMapping(value = "taskManage.do", params = "queryBackActivitiNodes")
 public List<Map<String, Object>> queryBackActivitiNodes(String wfTaskId) throws Exception {
   List<Map<String, Object>> returnList = new ArrayList<Map<String, Object>>();
   // 获取可以驳回的节点
   List<ActivityImpl> backActivitiNodes = this.taskManageService.findBackAvtivity(wfTaskId);
   for (ActivityImpl a : backActivitiNodes) {
     Map<String, Object> map = new HashMap<String, Object>();
     map.put("value", a.getId());
     map.put("label", a.getProperties().get("name"));
     returnList.add(map);
   }
   return returnList;
 }
예제 #6
0
  /**
   * 判断是否为第一个初始节点
   *
   * @return
   */
  public boolean isFirstTask() {
    ActivityImpl rootActivity = execution.getProcessDefinition().getInitial();
    List<PvmTransition> transitions = rootActivity.getOutgoingTransitions();

    for (PvmTransition transition : transitions) {
      TransitionImpl transitionImpl = (TransitionImpl) transition;
      ActivityImpl destinationActivity = transitionImpl.getDestination();
      String firstTaskActivityname = destinationActivity.getId();
      String currentActivityName = execution.getActivity().getId();

      return currentActivityName.equals(firstTaskActivityname);
    }

    return false;
  }
예제 #7
0
 /**
  * 根据当前节点,查询输出流向是否为并行终点,如果为并行终点,则拼装对应的并行起点ID
  *
  * @param activityImpl 当前节点
  * @return
  */
 private String findParallelGatewayId(ActivityImpl activityImpl) {
   List<PvmTransition> incomingTransitions = activityImpl.getOutgoingTransitions();
   for (PvmTransition pvmTransition : incomingTransitions) {
     TransitionImpl transitionImpl = (TransitionImpl) pvmTransition;
     activityImpl = transitionImpl.getDestination();
     String type = (String) activityImpl.getProperty("type");
     if ("parallelGateway".equals(type)) { // 并行路线
       String gatewayId = activityImpl.getId();
       String gatewayType = gatewayId.substring(gatewayId.lastIndexOf("_") + 0);
       if ("END".equals(gatewayType.toUpperCase())) {
         return gatewayId.substring(0, gatewayId.lastIndexOf("_")) + "_start";
       }
     }
   }
   return null;
 }
예제 #8
0
  /**
   * 流程跟踪图
   *
   * @param processInstanceId 流程实例ID
   * @return 封装了各种节点信息
   */
  public List<Map<String, Object>> traceProcess(String processInstanceId) throws Exception {
    Execution execution =
        runtimeService.createExecutionQuery().executionId(processInstanceId).singleResult(); // 执行实例
    Object property = PropertyUtils.getProperty(execution, "activityId");
    String activityId = "";
    if (property != null) {
      activityId = property.toString();
    }
    ProcessInstance processInstance =
        runtimeService
            .createProcessInstanceQuery()
            .processInstanceId(processInstanceId)
            .singleResult();
    ProcessDefinitionEntity processDefinition =
        (ProcessDefinitionEntity)
            ((RepositoryServiceImpl) repositoryService)
                .getDeployedProcessDefinition(processInstance.getProcessDefinitionId());
    List<ActivityImpl> activitiList = processDefinition.getActivities(); // 获得当前任务的所有节点

    List<Map<String, Object>> activityInfos = new ArrayList<Map<String, Object>>();
    for (ActivityImpl activity : activitiList) {

      boolean currentActiviti = false;
      String id = activity.getId();

      // 当前节点
      if (id.equals(activityId)) {
        currentActiviti = true;
      }

      Map<String, Object> activityImageInfo =
          packageSingleActivitiInfo(activity, processInstance, currentActiviti);

      activityInfos.add(activityImageInfo);
    }

    return activityInfos;
  }
예제 #9
0
  public void validateExclusiveGateway(ActivityImpl activity, ExclusiveGateway exclusiveGateway) {
    if (activity.getOutgoingTransitions().size() == 0) {
      // TODO: double check if this is valid (I think in Activiti yes, since we need start events we
      // will need an end event as well)
      bpmnModel.addProblem(
          "Exclusive Gateway '" + activity.getId() + "' has no outgoing sequence flows.",
          exclusiveGateway);
    } else if (activity.getOutgoingTransitions().size() == 1) {
      PvmTransition flow = activity.getOutgoingTransitions().get(0);
      Condition condition = (Condition) flow.getProperty(BpmnParse.PROPERTYNAME_CONDITION);
      if (condition != null) {
        bpmnModel.addProblem(
            "Exclusive Gateway '"
                + activity.getId()
                + "' has only one outgoing sequence flow ('"
                + flow.getId()
                + "'). This is not allowed to have a condition.",
            exclusiveGateway);
      }
    } else {
      String defaultSequenceFlow = (String) activity.getProperty("default");
      boolean hasDefaultFlow = StringUtils.isNotEmpty(defaultSequenceFlow);

      ArrayList<PvmTransition> flowsWithoutCondition = new ArrayList<PvmTransition>();
      for (PvmTransition flow : activity.getOutgoingTransitions()) {
        Condition condition = (Condition) flow.getProperty(BpmnParse.PROPERTYNAME_CONDITION);
        boolean isDefaultFlow = flow.getId() != null && flow.getId().equals(defaultSequenceFlow);
        boolean hasConditon = condition != null;

        if (!hasConditon && !isDefaultFlow) {
          flowsWithoutCondition.add(flow);
        }
        if (hasConditon && isDefaultFlow) {
          bpmnModel.addProblem(
              "Exclusive Gateway '"
                  + activity.getId()
                  + "' has outgoing sequence flow '"
                  + flow.getId()
                  + "' which is the default flow but has a condition too.",
              exclusiveGateway);
        }
      }
      if (hasDefaultFlow || flowsWithoutCondition.size() > 1) {
        // if we either have a default flow (then no flows without conditions are valid at all) or
        // if we have more than one flow without condition this is an error
        for (PvmTransition flow : flowsWithoutCondition) {
          bpmnModel.addProblem(
              "Exclusive Gateway '"
                  + activity.getId()
                  + "' has outgoing sequence flow '"
                  + flow.getId()
                  + "' without condition which is not the default flow.",
              exclusiveGateway);
        }
      } else if (flowsWithoutCondition.size() == 1) {
        // Havinf no default and exactly one flow without condition this is considered the default
        // one now (to not break backward compatibility)
        PvmTransition flow = flowsWithoutCondition.get(0);
        bpmnModel.addWarning(
            "Exclusive Gateway '"
                + activity.getId()
                + "' has outgoing sequence flow '"
                + flow.getId()
                + "' without condition which is not the default flow. We assume it to be the default flow, but it is bad modeling practice, better set the default flow in your gateway.",
            exclusiveGateway);
      }
    }
  }
 /** @return */
 @Override
 public String getTaskDefinitionKey() {
   return activityImpl.getId();
 }
 public BoundaryEventActivityBehavior createBoundaryEventActivityBehavior(
     BoundaryEvent boundaryEvent, boolean interrupting, ActivityImpl activity) {
   return new BoundaryEventActivityBehavior(interrupting, activity.getId());
 }
예제 #12
0
  /**
   * 打开任务 传入的request必须有以下参数 taskId:task的Id taskPage:处理task的页面路径 model:业务表类名 formId:业务表id
   * formProperties:控制表单的名称
   *
   * @return
   * @throws Exception
   */
  public String open_task() throws Exception {
    log.debug("open_task()");
    List<String> nextTaskList = new ArrayList<String>();
    String taskId = getpara("taskId");
    String taskPage = getpara("taskPage");
    String modelStr = getpara("model");
    // add by hb for only query user task
    String readonly = getpara("readonly");
    // end
    String formId = (String) infActiviti.getVariableByTaskId(taskId, "formId");
    if (formId == null || formId.equals("") || modelStr == null || "".equals(modelStr)) {
      rhs.put("model", null);
    } else {
      BaseModel model = (BaseModel) baseDao.loadById(modelStr, Long.parseLong(formId));
      rhs.put("model", model);
    }

    /* add by chenzhijian 20130419 -s */
    // 获取 formProperties 配置文件
    String formProperties = getpara("formProperties");
    HashMap<String, String> formPro = new HashMap<String, String>();
    Properties p = new Properties();
    try {
      // String filepath = System.getProperty("webroot", "./src/main/webapp/");
      String filepath = getWebroot();
      // eg: app/manager/wo/wo.properties
      filepath +=
          "/app/manager/" + modelStr.toLowerCase() + "/" + modelStr.toLowerCase() + ".properties";
      FileInputStream in = new FileInputStream(filepath);
      p.load(in);
      in.close();
      Set<String> set = p.stringPropertyNames();
      for (String s : set) {
        if (s.startsWith("default")) {
          formPro.put(s.replace("default.", ""), p.getProperty(s));
        }
      }
      for (String s : set) {
        if (s.startsWith(formProperties)) {
          formPro.put(s.replace(formProperties + ".", ""), p.getProperty(s));
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    rhs.put("formPro", formPro);
    /* add by chenzhijian 20130419 -e */

    Task task = infActiviti.getTaskById(taskId);
    /*add by hb for get next task 20140128 start*/
    String nextTask = "";
    String initiator = (String) infActiviti.getVariableByTaskId(task.getId(), "initiator");
    // 当前任务获取当前流程的流程定义,然后根据流程定义获得所有的节点
    ProcessDefinitionEntity def =
        (ProcessDefinitionEntity)
            ((RepositoryServiceImpl) repositoryService)
                .getDeployedProcessDefinition(task.getProcessDefinitionId());
    List<ActivityImpl> activitiList = def.getActivities();
    // 根据任务获取当前流程执行ID,执行实例以及当前流程节点的ID
    String excId = task.getExecutionId();
    ExecutionEntity execution =
        (ExecutionEntity) runtimeService.createExecutionQuery().executionId(excId).singleResult();
    String activitiId = execution.getActivityId();
    // 循环activitiList 并判断出当前流程所处节点,然后得到当前节点实例,
    // 根据节点实例获取所有从当前节点出发的路径,然后根据路径获得下一个节点实例
    for (ActivityImpl activityImpl : activitiList) {
      String id = activityImpl.getId();
      if (activitiId.equals(id)) {
        log.debug("当前任务:" + activityImpl.getProperty("name"));
        List<PvmTransition> outTransitions =
            activityImpl.getOutgoingTransitions(); // 获取从某个节点出来的所有线路
        for (PvmTransition tr : outTransitions) {
          PvmActivity ac = tr.getDestination(); // 获取线路的终点节点,在这里应该还要加个判断,如果是并行或者相容关口,则需要继续往下找下一个任务。
          if (ac.getProperty("type").equals("parallelGateway")
              || ac.getProperty("type")
                  .equals(
                      "inclusiveGateway")) { // 不能包括互斥关口
                                             // ac.getProperty("type").equals("exclusiveGateway")
            List<PvmTransition> outTransitions2 = ac.getOutgoingTransitions(); // 因为是关口,所以继续往下找任务
            for (PvmTransition pvmTransition : outTransitions2) {
              PvmActivity ac2 = pvmTransition.getDestination();
              nextTask = (String) ac2.getId();
              log.debug("下一个任务----->:" + nextTask);
              nextTaskList.add(nextTask);
            }
          } else {
            nextTask = (String) ac.getId();
            log.debug("下一个任务++++>:" + nextTask);
            nextTaskList.add(nextTask);
          }
        }
        break;
      }
    }

    /*end*/
    rhs.put("task", task);
    rhs.put("initiator", initiator);
    rhs.put("nextTaskList", nextTaskList);
    rhs.put("taskPage", taskPage);
    rhs.put("readonly", readonly);
    getAllUserAndGroupInfo();

    return "success";
  }
예제 #13
0
  /**
   * 迭代循环流程树结构,查询当前节点可驳回的任务节点
   *
   * @param taskId 当前任务ID
   * @param currActivity 当前活动节点
   * @param rtnList 存储回退节点集合
   * @param tempList 临时存储节点集合(存储一次迭代过程中的同级userTask节点)
   * @return 回退节点集合
   */
  private List<ActivityImpl> iteratorBackActivity(
      String taskId,
      ActivityImpl currActivity,
      List<ActivityImpl> rtnList,
      List<ActivityImpl> tempList)
      throws Exception {
    // 查询流程定义,生成流程树结构
    ProcessInstance procInst = this.findProcInsByTaskId(taskId);

    // 当前节点的流入来源
    List<PvmTransition> incomingTransitions = currActivity.getIncomingTransitions();
    // 条件分支节点集合,userTask节点遍历完毕,迭代遍历此集合,查询条件分支对应的userTask节点
    List<ActivityImpl> exclusiveGateways = new ArrayList<ActivityImpl>();
    // 并行节点集合,userTask节点遍历完毕,迭代遍历此集合,查询并行节点对应的userTask节点
    List<ActivityImpl> parallelGateways = new ArrayList<ActivityImpl>();
    // 遍历当前节点所有流入路径
    for (PvmTransition pvmTransition : incomingTransitions) {
      TransitionImpl transitionImpl = (TransitionImpl) pvmTransition;
      ActivityImpl activityImpl = transitionImpl.getSource();
      String type = (String) activityImpl.getProperty("type");
      /**
       * 并行节点配置要求:<br>
       * 必须成对出现,且要求分别配置节点ID为:XXX_start(开始),XXX_end(结束)
       */
      if ("parallelGateway".equals(type)) { // 并行路线
        String gatewayId = activityImpl.getId();
        String gatewayType = gatewayId.substring(gatewayId.lastIndexOf("_") + 0);
        if ("START".equals(gatewayType.toUpperCase())) { // 并行起点,停止递归
          return rtnList;
        } else { // 并行终点,临时存储此节点,本次循环结束,迭代集合,查询对应的userTask节点
          parallelGateways.add(activityImpl);
        }
      } else if ("startEvent".equals(type)) { // 开始节点,停止递归
        return rtnList;
      } else if ("userTask".equals(type)) { // 用户任务
        tempList.add(activityImpl);
      } else if ("exclusiveGateway".equals(type)) { // 分支路线,临时存储此节点,本次循环结束,迭代集合,查询对应的userTask节点
        currActivity = transitionImpl.getSource();
        exclusiveGateways.add(currActivity);
      }
    }

    /** 迭代条件分支集合,查询对应的userTask节点 */
    for (ActivityImpl activityImpl : exclusiveGateways) {
      iteratorBackActivity(taskId, activityImpl, rtnList, tempList);
    }

    /** 迭代并行集合,查询对应的userTask节点 */
    for (ActivityImpl activityImpl : parallelGateways) {
      iteratorBackActivity(taskId, activityImpl, rtnList, tempList);
    }

    /** 根据同级userTask集合,过滤最近发生的节点 */
    currActivity = filterNewestActivity(procInst, tempList);
    if (currActivity != null) {
      // 查询当前节点的流向是否为并行终点,并获取并行起点ID
      String id = findParallelGatewayId(currActivity);
      if (StringUtil.isStrEmpty(id)) { // 并行起点ID为空,此节点流向不是并行终点,符合驳回条件,存储此节点
        rtnList.add(currActivity);
      } else { // 根据并行起点ID查询当前节点,然后迭代查询其对应的userTask任务节点
        currActivity = findActivitiImpl(taskId, id);
      }

      // 清空本次迭代临时集合
      tempList.clear();
      // 执行下次迭代
      iteratorBackActivity(taskId, currActivity, rtnList, tempList);
    }
    return rtnList;
  }
예제 #14
0
 /**
  * 中止流程(特权人直接审批通过等)
  *
  * @param taskId
  */
 @Override
 public void endProcess(String taskId) throws Exception {
   ActivityImpl endActivity = findActivitiImpl(taskId, "end");
   commitProcess(taskId, null, endActivity.getId());
 }