Package org.fireflow.engine

Examples of org.fireflow.engine.EngineException


      return taskInstanceCompletionEvaluator.taskInstanceCanBeCompleted(
          currentSession, runtimeContext, processInstance,
          taskInstance);
    } else {
      WorkflowProcess process = taskInstance.getWorkflowProcess();
      throw new EngineException(taskInstance.getProcessInstanceId(),
          process, taskInstance.getTaskId(),
          "无法获取TaskInstanceCompletionEvaluator,TaskId="
              + task.getId() + ", taskType="
              + taskInstance.getTaskType());
    }
View Full Code Here


        || taskInstance.getState() == ITaskInstance.CANCELED) {
      return;
    }
    if (taskInstance.getState() == ITaskInstance.INITIALIZED) {
      WorkflowProcess process = taskInstance.getWorkflowProcess();
      throw new EngineException(taskInstance.getProcessInstanceId(),
          process, taskInstance.getTaskId(),
          "Complete task insatance failed.The state of the task insatnce[id="
              + taskInstance.getId() + "] is "
              + taskInstance.getState());
    }
    if (taskInstance.isSuspended()) {
      WorkflowProcess process = taskInstance.getWorkflowProcess();
      throw new EngineException(taskInstance.getProcessInstanceId(),
          process, taskInstance.getTaskId(),
          "Complete task insatance failed. The task instance [id="
              + taskInstance.getId() + "] is suspended");
    }

    if (targetActivityInstance != null) {
      ((TaskInstance) taskInstance)
          .setTargetActivityId(targetActivityInstance.getActivity()
              .getId());
    }

    IPersistenceService persistenceService = this.rtCtx
        .getPersistenceService();

    // 第一步,首先结束当前taskInstance
    if (!this.taskInstanceCanBeCompleted(currentSession, this.rtCtx,
        processInstance, taskInstance)) {
      return;
    }
    ((TaskInstance) taskInstance).setState(ITaskInstance.COMPLETED);
    ((TaskInstance) taskInstance).setCanBeWithdrawn(Boolean.FALSE);
    ((TaskInstance) taskInstance).setEndTime(rtCtx.getCalendarService()
        .getSysDate());
    persistenceService.saveOrUpdateTaskInstance(taskInstance);
    // 触发相应的事件
    TaskInstanceEvent e = new TaskInstanceEvent();
    e.setSource(taskInstance);
    e.setWorkflowSession(currentSession);
    e.setProcessInstance(processInstance);
    e.setEventType(TaskInstanceEvent.AFTER_TASK_INSTANCE_COMPLETE);
    if (this.defaultTaskInstanceEventListener != null) {
      this.defaultTaskInstanceEventListener.onTaskInstanceEventFired(e);
    }

    this.fireTaskInstanceEvent(taskInstance, e);

    // 第二步,检查ActivityInstance是否可以结束
    if (!activityInstanceCanBeCompleted(taskInstance)) {
      return;
    }

    // 第三步,尝试结束对应的activityInstance
    List<IToken> tokens = persistenceService.findTokensForProcessInstance(
        taskInstance.getProcessInstanceId(), taskInstance
            .getActivityId());
    // System.out.println("Inside TaskInstance.complete(targetActivityInstance):: tokens.size is "+tokens.size());
    if (tokens == null || tokens.size() == 0) {
      return;// 表明activityInstance已经结束了。
    }
    if (tokens.size() > 1) {
      WorkflowProcess process = taskInstance.getWorkflowProcess();
      throw new EngineException(taskInstance.getProcessInstanceId(),
          process, taskInstance.getTaskId(), "与activityId="
              + taskInstance.getActivityId() + "对应的token数量(="
              + tokens.size() + ")不正确,正确只能为1,因此无法完成complete操作");
    }
    IToken token = tokens.get(0);
    // stepNumber不相等,不允许执行结束操作。
    if (token.getStepNumber().intValue() != taskInstance.getStepNumber()
        .intValue()) {
      return;
    }
    if (token.isAlive() == false) {
      WorkflowProcess process = taskInstance.getWorkflowProcess();
      throw new EngineException(taskInstance.getProcessInstanceId(),
          process, taskInstance.getTaskId(), "与activityId="
              + taskInstance.getActivityId()
              + "对应的token.alive=false,因此无法完成complete操作");
    }

    INetInstance netInstance = rtCtx.getKernelManager().getNetInstance(
        taskInstance.getProcessId(), taskInstance.getVersion());
    Object obj = netInstance.getWFElementInstance(taskInstance
        .getActivityId());
    if (obj == null) {
      WorkflowProcess process = taskInstance.getWorkflowProcess();
      throw new EngineException(taskInstance.getProcessInstanceId(),
          process, taskInstance.getTaskId(), "系统没有找到与activityId="
              + taskInstance.getActivityId()
              + "对应activityInstance,无法执行complete操作。");
    }
View Full Code Here

    // "Complete task insatance failed.The state of the task insatnce[id=" +
    // taskInstance.getId() + "] is " + taskInstance.getState());
    // }
    if (taskInstance.isSuspended()) {
      WorkflowProcess process = taskInstance.getWorkflowProcess();
      throw new EngineException(taskInstance.getProcessInstanceId(),
          process, taskInstance.getTaskId(),
          "Abort task insatance failed. The task instance [id="
              + taskInstance.getId() + "] is suspended");
    }

    // 1)检查是否在同一个“执行线”上

    WorkflowProcess workflowProcess = taskInstance.getWorkflowProcess();
    if (targetActivityId != null) {
      String thisActivityId = taskInstance.getActivityId();
      boolean isInSameLine = workflowProcess.isInSameLine(thisActivityId,
          targetActivityId);
      if (!isInSameLine) {
        throw new EngineException(
            taskInstance.getProcessInstanceId(),
            taskInstance.getWorkflowProcess(),
            taskInstance.getTaskId(),
            "Jumpto refused because of the current activitgy and the target activity are NOT in the same 'Execution Thread'.");
      }
    }

    INetInstance netInstance = rtCtx.getKernelManager().getNetInstance(
        workflowProcess.getId(), taskInstance.getVersion());
    IActivityInstance targetActivityInstance = (IActivityInstance) netInstance
        .getWFElementInstance(targetActivityId);

    IActivityInstance thisActivityInstance = (IActivityInstance) netInstance
        .getWFElementInstance(taskInstance.getActivityId());
    if (thisActivityInstance == null) {
      WorkflowProcess process = taskInstance.getWorkflowProcess();
      throw new EngineException(taskInstance.getProcessInstanceId(),
          process, taskInstance.getTaskId(), "系统没有找到与activityId="
              + taskInstance.getActivityId()
              + "对应activityInstance,无法执行abort操作。");
    }

    if (targetActivityInstance != null) {
      ((TaskInstance) taskInstance)
          .setTargetActivityId(targetActivityInstance.getActivity()
              .getId());
    }

    IPersistenceService persistenceService = this.rtCtx
        .getPersistenceService();

    // 第一步,首先Abort当前taskInstance
    persistenceService.abortTaskInstance((TaskInstance) taskInstance);

    // 触发相应的事件
    TaskInstanceEvent e = new TaskInstanceEvent();
    e.setSource(taskInstance);
    e.setWorkflowSession(currentSession);
    e.setProcessInstance(processInstance);
    e.setEventType(TaskInstanceEvent.AFTER_TASK_INSTANCE_COMPLETE);
    if (this.defaultTaskInstanceEventListener != null) {
      this.defaultTaskInstanceEventListener.onTaskInstanceEventFired(e);
    }

    this.fireTaskInstanceEvent(taskInstance, e);

    // 第二步,检查ActivityInstance是否可以结束
    if (!activityInstanceCanBeCompleted(taskInstance)) {
      return;
    }

    // 第三步,尝试结束对应的activityInstance
    List<IToken> tokens = persistenceService.findTokensForProcessInstance(
        taskInstance.getProcessInstanceId(), taskInstance
            .getActivityId());
    // System.out.println("Inside TaskInstance.complete(targetActivityInstance):: tokens.size is "+tokens.size());
    if (tokens == null || tokens.size() == 0) {
      return;// 表明activityInstance已经结束了。
    }
    if (tokens.size() > 1) {
      WorkflowProcess process = taskInstance.getWorkflowProcess();
      throw new EngineException(taskInstance.getProcessInstanceId(),
          process, taskInstance.getTaskId(), "与activityId="
              + taskInstance.getActivityId() + "对应的token数量(="
              + tokens.size() + ")不正确,正确只能为1,因此无法完成complete操作");
    }
    IToken token = tokens.get(0);
    // stepNumber不相等,不允许执行结束操作。
    if (token.getStepNumber().intValue() != taskInstance.getStepNumber()
        .intValue()) {
      return;
    }
    if (token.isAlive() == false) {
      WorkflowProcess process = taskInstance.getWorkflowProcess();
      throw new EngineException(taskInstance.getProcessInstanceId(),
          process, taskInstance.getTaskId(), "与activityId="
              + taskInstance.getActivityId()
              + "对应的token.alive=false,因此无法完成complete操作");
    }
View Full Code Here

    // "Complete task insatance failed.The state of the task insatnce[id=" +
    // taskInstance.getId() + "] is " + taskInstance.getState());
    // }
    if (thisTaskInst.isSuspended()) {
      WorkflowProcess process = thisTaskInst.getWorkflowProcess();
      throw new EngineException(thisTaskInst.getProcessInstanceId(),
          process, thisTaskInst.getTaskId(),
          "Abort task insatance failed. The task instance [id="
              + thisTaskInst.getId() + "] is suspended");
    }

    //
    IPersistenceService persistenceService = this.rtCtx.getPersistenceService();
    WorkflowProcess workflowProcess = thisTaskInst.getWorkflowProcess();
    List<IToken> allTokens = null;
    List<String> aliveActivityIdsAfterJump = new ArrayList<String>();
    if (targetActivityId != null) {     
      String thisActivityId = thisTaskInst.getActivityId();
      boolean isInSameLine = workflowProcess.isInSameLine(thisActivityId,
          targetActivityId);
     
      if (isInSameLine){
        this.abortTaskInstance(currentSession, processInstance, thisTaskInst, targetActivityId);
      }
     
      //合法性检查
      allTokens = persistenceService.findTokensForProcessInstance(thisTaskInst.getProcessInstanceId(), null);

      aliveActivityIdsAfterJump.add(targetActivityId);
     
      for (int i=0;allTokens!=null && i<allTokens.size();i++){
        IToken tokenTmp = allTokens.get(i);
        IWFElement workflowElement = workflowProcess.findWFElementById(tokenTmp.getNodeId());
        if ((workflowElement instanceof Activity) && !workflowElement.getId().equals(thisActivityId)){
         
          aliveActivityIdsAfterJump.add(workflowElement.getId());
         
          if (workflowProcess.isReachable(targetActivityId, workflowElement.getId())
            || workflowProcess.isReachable(workflowElement.getId(), targetActivityId)){
            throw new EngineException(
                thisTaskInst.getProcessInstanceId(),
                thisTaskInst.getWorkflowProcess(),
                thisTaskInst.getTaskId(),
                "Abort refused because of the business-logic conflict!");

          }
        }
      }     
     
      //1)检查是否在同一个“执行线”上(不做该检查,20091008) 
//      if (!isInSameLine) {
//        throw new EngineException(
//            taskInstance.getProcessInstanceId(),
//            taskInstance.getWorkflowProcess(),
//            taskInstance.getTaskId(),
//            "Jumpto refused because of the current activitgy and the target activity are NOT in the same 'Execution Thread'.");
//      }
    }

    INetInstance netInstance = rtCtx.getKernelManager().getNetInstance(
        workflowProcess.getId(), thisTaskInst.getVersion());
    IActivityInstance targetActivityInstance = null;
    if (targetActivityId!=null){
      targetActivityInstance = (IActivityInstance) netInstance
        .getWFElementInstance(targetActivityId);
    }

    IActivityInstance thisActivityInstance = (IActivityInstance) netInstance
        .getWFElementInstance(thisTaskInst.getActivityId());
    if (thisActivityInstance == null) {
      WorkflowProcess process = thisTaskInst.getWorkflowProcess();
      throw new EngineException(thisTaskInst.getProcessInstanceId(),
          process, thisTaskInst.getTaskId(), "系统没有找到与activityId="
              + thisTaskInst.getActivityId()
              + "对应activityInstance,无法执行abort操作。");
    }

    if (targetActivityInstance != null) {
      ((TaskInstance) thisTaskInst)
          .setTargetActivityId(targetActivityInstance.getActivity()
              .getId());
    }


    // 第一步,首先Abort当前taskInstance
    persistenceService.abortTaskInstance((TaskInstance) thisTaskInst);

    // 触发相应的事件
    TaskInstanceEvent e = new TaskInstanceEvent();
    e.setSource(thisTaskInst);
    e.setWorkflowSession(currentSession);
    e.setProcessInstance(processInstance);
    e.setEventType(TaskInstanceEvent.AFTER_TASK_INSTANCE_COMPLETE);
    if (this.defaultTaskInstanceEventListener != null) {
      this.defaultTaskInstanceEventListener.onTaskInstanceEventFired(e);
    }

    this.fireTaskInstanceEvent(thisTaskInst, e);

    // 第二步,检查ActivityInstance是否可以结束
    if (!activityInstanceCanBeCompleted(thisTaskInst)) {
      return;
    }

    // 第三步,尝试结束对应的activityInstance
    List<IToken> tokens = persistenceService.findTokensForProcessInstance(
        thisTaskInst.getProcessInstanceId(), thisTaskInst
            .getActivityId());
    // System.out.println("Inside TaskInstance.complete(targetActivityInstance):: tokens.size is "+tokens.size());
    if (tokens == null || tokens.size() == 0) {
      return;// 表明activityInstance已经结束了。
    }
    if (tokens.size() > 1) {
      WorkflowProcess process = thisTaskInst.getWorkflowProcess();
      throw new EngineException(thisTaskInst.getProcessInstanceId(),
          process, thisTaskInst.getTaskId(), "与activityId="
              + thisTaskInst.getActivityId() + "对应的token数量(="
              + tokens.size() + ")不正确,正确只能为1,因此无法完成complete操作");
    }
    IToken token = tokens.get(0);
    // stepNumber不相等,不允许执行结束操作。
    if (token.getStepNumber().intValue() != thisTaskInst.getStepNumber()
        .intValue()) {
      return;
    }
    if (token.isAlive() == false) {
      WorkflowProcess process = thisTaskInst.getWorkflowProcess();
      throw new EngineException(thisTaskInst.getProcessInstanceId(),
          process, thisTaskInst.getTaskId(), "与activityId="
              + thisTaskInst.getActivityId()
              + "对应的token.alive=false,因此无法完成complete操作");
    }
View Full Code Here

      return null;

    if (workItem.getState().intValue() != IWorkItem.INITIALIZED) {
      TaskInstance thisTaskInst = (TaskInstance) workItem
          .getTaskInstance();
      throw new EngineException(thisTaskInst.getProcessInstanceId(),
          thisTaskInst.getWorkflowProcess(),
          thisTaskInst.getTaskId(),
          "Claim work item failed. The state of the work item is "
              + workItem.getState());
    }
    if (workItem.getTaskInstance().getState().intValue() != ITaskInstance.INITIALIZED
        && workItem.getTaskInstance().getState().intValue() != ITaskInstance.RUNNING) {
      TaskInstance thisTaskInst = (TaskInstance) workItem
          .getTaskInstance();
      throw new EngineException(thisTaskInst.getProcessInstanceId(),
          thisTaskInst.getWorkflowProcess(),
          thisTaskInst.getTaskId(),
          "Claim work item failed .The state of the correspond task instance is "
              + workItem.getTaskInstance().getState());
    }

    if (workItem.getTaskInstance().isSuspended()) {
      TaskInstance thisTaskInst = (TaskInstance) workItem
          .getTaskInstance();
      throw new EngineException(thisTaskInst.getProcessInstanceId(),
          thisTaskInst.getWorkflowProcess(),
          thisTaskInst.getTaskId(),
          "Claim work item failed .The  correspond task instance is suspended");
    }
View Full Code Here

      throws EngineException, KernelException {
    if (workItem.getState().intValue() != IWorkItem.RUNNING) {
      TaskInstance thisTaskInst = (TaskInstance) workItem
          .getTaskInstance();
      // System.out.println("WorkItem的当前状态为"+this.getState()+",不可以执行complete操作。");
      throw new EngineException(thisTaskInst.getProcessInstanceId(),
          thisTaskInst.getWorkflowProcess(),
          thisTaskInst.getTaskId(),
          "Complete work item failed . The state of the work item [id="
              + workItem.getId() + "] is " + workItem.getState());
    }

    if (workItem.getTaskInstance().isSuspended()) {
      TaskInstance thisTaskInst = (TaskInstance) workItem
          .getTaskInstance();
      WorkflowProcess process = thisTaskInst.getWorkflowProcess();
      throw new EngineException(thisTaskInst.getProcessInstanceId(),
          process, thisTaskInst.getTaskId(),
          "Complete work item failed. The correspond task instance [id="
              + thisTaskInst.getId() + "] is suspended");
    }
View Full Code Here

    String thisActivityId = workItem.getTaskInstance().getActivityId();
    boolean isInSameLine = workflowProcess.isInSameLine(thisActivityId,
        targetActivityId);
    TaskInstance thisTaskInst = (TaskInstance) workItem.getTaskInstance();
    if (!isInSameLine) {
      throw new EngineException(
          thisTaskInst.getProcessInstanceId(),
          thisTaskInst.getWorkflowProcess(),
          thisTaskInst.getTaskId(),
          "Jumpto refused because of the current activitgy and the target activity are NOT in the same 'Execution Thread'.");
    }

    // 2)检查目标Activity Form Task的数量(暂时关闭该检查项目)
    // Activity targetActivity =
    // (Activity)workflowProcess.findWFElementById(activityId);
    // int count = getFormTaskCount(targetActivity);
    // if (count!=1){
    // if (!isInSameLine) throw new
    // EngineException("Jumpto refused because of the  FORM-type-task count of the target activitgy  is NOT 1; the count is "+count);
    // }

    // 3)检查当前的 taskinstance是否可以结束
    IPersistenceService persistenceService = rtCtx.getPersistenceService();

    Integer aliveWorkItemCount = persistenceService
        .getAliveWorkItemCountForTaskInstance(thisTaskInst.getId());
    if (aliveWorkItemCount != null && aliveWorkItemCount > 1) {
      throw new EngineException(
          thisTaskInst.getProcessInstanceId(),
          thisTaskInst.getWorkflowProcess(),
          thisTaskInst.getTaskId(),
          "Jumpto refused because of current taskinstance can NOT be completed. some workitem of this taskinstance is in runing state or initialized state");

    }

    // 4)检查当前的activity instance是否可以结束
    if (Activity.ALL.equals(workItem.getTaskInstance().getActivity()
        .getCompletionStrategy())) {

      Integer aliveTaskInstanceCount4ThisActivity = persistenceService
          .getAliveTaskInstanceCountForActivity(workItem
              .getTaskInstance().getProcessInstanceId(), workItem
              .getTaskInstance().getActivityId());
      if (aliveTaskInstanceCount4ThisActivity.intValue() > 1) {// 大于2表明当前Activity不可以complete
        throw new EngineException(
            thisTaskInst.getProcessInstanceId(),
            thisTaskInst.getWorkflowProcess(),
            thisTaskInst.getTaskId(),
            "Jumpto refused because of current activity instance can NOT be completed. some task instance of this activity instance is in runing state or initialized state");
      }
    }

    INetInstance netInstance = rtCtx.getKernelManager().getNetInstance(
        workflowProcess.getId(),
        workItem.getTaskInstance().getVersion());
    if (netInstance == null) {
      throw new EngineException(thisTaskInst.getProcessInstanceId(),
          thisTaskInst.getWorkflowProcess(),
          thisTaskInst.getTaskId(),
          "Not find the net instance for workflow process [id="
              + workflowProcess.getId() + ", version="
              + workItem.getTaskInstance().getVersion() + "]");
    }
    Object obj = netInstance.getWFElementInstance(targetActivityId);
    IActivityInstance targetActivityInstance = (IActivityInstance) obj;
    if (targetActivityInstance == null) {
      throw new EngineException(thisTaskInst.getProcessInstanceId(),
          thisTaskInst.getWorkflowProcess(),
          thisTaskInst.getTaskId(),
          "Not find the activity instance  for activity[process id="
              + workflowProcess.getId() + ", version="
              + workItem.getTaskInstance().getVersion()
View Full Code Here

    IPersistenceService persistenceService = rtCtx.getPersistenceService();

    Integer aliveWorkItemCount = persistenceService
        .getAliveWorkItemCountForTaskInstance(thisTaskInst.getId());
    if (aliveWorkItemCount != null && aliveWorkItemCount > 1) {
      throw new EngineException(
          thisTaskInst.getProcessInstanceId(),
          thisTaskInst.getWorkflowProcess(),
          thisTaskInst.getTaskId(),
          "Jumpto refused because of current taskinstance can NOT be completed. some workitem of this taskinstance is in runing state or initialized state");

    }

    // 4)检查当前的activity instance是否可以结束
    if (Activity.ALL.equals(workItem.getTaskInstance().getActivity().getCompletionStrategy())) {

      Integer aliveTaskInstanceCount4ThisActivity = persistenceService
          .getAliveTaskInstanceCountForActivity(workItem
              .getTaskInstance().getProcessInstanceId(), workItem
              .getTaskInstance().getActivityId());
      if (aliveTaskInstanceCount4ThisActivity.intValue() > 1) {// 大于1表明当前Activity不可以complete
        throw new EngineException(
            thisTaskInst.getProcessInstanceId(),
            thisTaskInst.getWorkflowProcess(),
            thisTaskInst.getTaskId(),
            "Jumpto refused because of current activity instance can NOT be completed. some task instance of this activity instance is in runing state or initialized state");
      }
    }
   
    //4)首先检查目标状态M是否存在冲突,如果存在冲突则不允许跳转;如果不存在冲突,则需要调整token
    List<IToken> allTokens = persistenceService.findTokensForProcessInstance(thisTaskInst.getProcessInstanceId(), null);
    WorkflowProcess thisProcess = thisTaskInst.getWorkflowProcess();//找到当前的工作里模型
    List<String> aliveActivityIdsAfterJump = new ArrayList<String>();//计算跳转后,哪些activity节点复活
    aliveActivityIdsAfterJump.add(targetActivityId);
   
    for (int i=0;allTokens!=null && i<allTokens.size();i++){
      IToken tokenTmp = allTokens.get(i);
      IWFElement workflowElement = thisProcess.findWFElementById(tokenTmp.getNodeId()); //找到拥有此token的工作流元素
      if ((workflowElement instanceof Activity) && !workflowElement.getId().equals(thisActivityId)){
        //注意:不能自己跳转到自己,同时此工作流元素是activity类型
        aliveActivityIdsAfterJump.add(workflowElement.getId());
       
        if (thisProcess.isReachable(targetActivityId, workflowElement.getId())
          || thisProcess.isReachable(workflowElement.getId(), targetActivityId)){
          throw new EngineException(
              thisTaskInst.getProcessInstanceId(),
              thisTaskInst.getWorkflowProcess(),
              thisTaskInst.getTaskId(),
              "Jumpto refused because of the business-logic conflict!");

        }
      }
    }

    //所有检查结束,开始执行跳转操作
   
    INetInstance netInstance = rtCtx.getKernelManager().getNetInstance(
        workflowProcess.getId(),
        workItem.getTaskInstance().getVersion());
    if (netInstance == null) {
      throw new EngineException(thisTaskInst.getProcessInstanceId(),
          thisTaskInst.getWorkflowProcess(),
          thisTaskInst.getTaskId(),
          "Not find the net instance for workflow process [id="
              + workflowProcess.getId() + ", version="
              + workItem.getTaskInstance().getVersion() + "]");
    }
    Object obj = netInstance.getWFElementInstance(targetActivityId);
    IActivityInstance targetActivityInstance = (IActivityInstance) obj;
    if (targetActivityInstance == null) {
      throw new EngineException(thisTaskInst.getProcessInstanceId(),
          thisTaskInst.getWorkflowProcess(),
          thisTaskInst.getTaskId(),
          "Not find the activity instance  for activity[process id="
              + workflowProcess.getId() + ", version="
              + workItem.getTaskInstance().getVersion()
View Full Code Here

      throws EngineException, KernelException {
    Activity thisActivity = workItem.getTaskInstance().getActivity();
    TaskInstance thisTaskInstance = (TaskInstance) workItem
        .getTaskInstance();
    if (workItem.getState() > 5 || workItem.getTaskInstance().isSuspended()) {// 处于非活动状态,或者被挂起,则不允许reject
      throw new EngineException(
          thisTaskInstance.getProcessInstanceId(),
          thisTaskInstance.getWorkflowProcess(),
          thisTaskInstance.getTaskId(),
          "Reject operation refused!Current work item is completed or the correspond task instance is suspended!!");
    }
    // 当前Activity只允许一个Form类型的Task
    if (thisActivity.getTasks().size() > 1) {
      throw new EngineException(thisTaskInstance.getProcessInstanceId(),
          thisTaskInstance.getWorkflowProcess(), thisTaskInstance
              .getTaskId(),
          "Reject operation refused!The correspond activity has more than 1 tasks");
    }
    // 汇签Task不允许Reject
    if (FormTask.ALL.equals(thisTaskInstance.getAssignmentStrategy())) {
      throw new EngineException(thisTaskInstance.getProcessInstanceId(),
          thisTaskInstance.getWorkflowProcess(), thisTaskInstance
              .getTaskId(),
          "Reject operation refused!The assignment strategy is 'ALL'");
    }
        //----added by wmj2003 20090915 ---start---
        //处理拒收的边界问题
        if(thisTaskInstance.getFromActivityId().equals(IToken.FROM_START_NODE)){
                throw new EngineException(
                                thisTaskInstance.getProcessInstanceId(),
                                thisTaskInstance.getWorkflowProcess(),
                                thisTaskInstance.getTaskId(),
                                "Reject operation refused!Because the from activityId equals "+IToken.FROM_START_NODE );
        }
        //----added by wmj2003 20090915 ---end---
    IPersistenceService persistenceService = this.rtCtx
        .getPersistenceService();
    List<ITaskInstance> siblingTaskInstancesList = null;

    siblingTaskInstancesList = persistenceService
        .findTaskInstancesForProcessInstanceByStepNumber(workItem
            .getTaskInstance().getProcessInstanceId(),
            thisTaskInstance.getStepNumber());

    // 如果执行了split操作,则不允许reject
    if (siblingTaskInstancesList.size() > 1) {
      throw new EngineException(
          thisTaskInstance.getProcessInstanceId(),
          thisTaskInstance.getWorkflowProcess(),
          thisTaskInstance.getTaskId(),
          "Reject operation refused!Because the process instance has taken a split operation.");
    }

    // 检查From Activity中是否有ToolTask和SubflowTask
    List<String> fromActivityIdList = new ArrayList<String>();
    StringTokenizer tokenizer = new StringTokenizer(thisTaskInstance
        .getFromActivityId(), IToken.FROM_ACTIVITY_ID_SEPARATOR);
    while (tokenizer.hasMoreTokens()) {
      fromActivityIdList.add(tokenizer.nextToken());
    }
    WorkflowProcess workflowProcess = workItem.getTaskInstance()
        .getWorkflowProcess();
    for (int i = 0; i < fromActivityIdList.size(); i++) {
      String fromActivityId = (String) fromActivityIdList.get(i);
      Activity fromActivity = (Activity) workflowProcess
          .findWFElementById(fromActivityId);
      List<Task> fromTaskList = fromActivity.getTasks();
      for (int j = 0; j < fromTaskList.size(); j++) {
        Task task =  fromTaskList.get(j);
        if (Task.TOOL.equals(task.getType())
            || Task.SUBFLOW.equals(task.getType())) {
          throw new EngineException(
              thisTaskInstance.getProcessInstanceId(),
              thisTaskInstance.getWorkflowProcess(),
              thisTaskInstance.getTaskId(),
              "Reject operation refused!The previous activity contains tool-task or subflow-task");

        }
      }
    }
    // 恢复所有的FromTaskInstance
    INetInstance netInstance = rtCtx.getKernelManager().getNetInstance(
        workflowProcess.getId(),
        workItem.getTaskInstance().getVersion());
    if (netInstance == null) {
      throw new EngineException(thisTaskInstance.getProcessInstanceId(),
          thisTaskInstance.getWorkflowProcess(), thisTaskInstance
              .getTaskId(),
          "Not find the net instance for workflow process [id="
              + workflowProcess.getId() + ", version="
              + workItem.getTaskInstance().getVersion() + "]");
View Full Code Here

      throws EngineException, KernelException {
    Activity thisActivity = workItem.getTaskInstance().getActivity();
    TaskInstance thisTaskInstance = (TaskInstance) workItem
        .getTaskInstance();
    if (workItem.getState() < 5) {// 小于5的状态为活动状态
      throw new EngineException(thisTaskInstance.getProcessInstanceId(),
          thisTaskInstance.getWorkflowProcess(), thisTaskInstance
              .getTaskId(),
          "Withdraw operation is refused! Current workitem is in running state!!");
    }
    // 当前Activity只允许一个Form类型的Task
    if (thisActivity.getTasks().size() > 1) {
      throw new EngineException(thisTaskInstance.getProcessInstanceId(),
          thisTaskInstance.getWorkflowProcess(), thisTaskInstance
              .getTaskId(),
          "Withdraw operation is refused! The activity[id="
              + thisActivity.getId() + "] has more than 1 tasks");
    }

    // 汇签Task不允许撤销
    if (FormTask.ALL.equals(thisTaskInstance.getAssignmentStrategy())) {
      throw new EngineException(thisTaskInstance.getProcessInstanceId(),
          thisTaskInstance.getWorkflowProcess(), thisTaskInstance
              .getTaskId(),
          "Withdraw operation is refused! The assignment strategy for activity[id="
              + thisActivity.getId() + "] is 'ALL'");
    }

    IPersistenceService persistenceService = this.rtCtx
        .getPersistenceService();
    List<ITaskInstance> targetTaskInstancesList = null;
    targetTaskInstancesList = persistenceService
        .findTaskInstancesForProcessInstanceByStepNumber(
            thisTaskInstance.getProcessInstanceId(),
            thisTaskInstance.getStepNumber() + 1);

    // 如果targetTaskInstancesList为空或size 等于0,则表示流程实例执行了汇聚操作。
    if (targetTaskInstancesList == null
        || targetTaskInstancesList.size() == 0) {
      throw new EngineException(
          thisTaskInstance.getProcessInstanceId(),
          thisTaskInstance.getWorkflowProcess(),
          thisTaskInstance.getTaskId(),
          "Withdraw operation is refused!Because the process instance has taken a join operation after this activity[id="
              + thisActivity.getId() + "].");
    } else {
      TaskInstance taskInstance = (TaskInstance) targetTaskInstancesList
          .get(0);
      if (!taskInstance.getFromActivityId().equals(
          thisTaskInstance.getActivityId())) {
        throw new EngineException(
            thisTaskInstance.getProcessInstanceId(),
            thisTaskInstance.getWorkflowProcess(),
            thisTaskInstance.getTaskId(),
            "Withdraw operation is refused!Because the process instance has taken a join operation after this activity[id="
                + thisActivity.getId() + "].");
      }
    }

    for (int i = 0; targetTaskInstancesList != null
        && i < targetTaskInstancesList.size(); i++) {
      TaskInstance targetTaskInstanceTmp = (TaskInstance) targetTaskInstancesList
          .get(i);
      if (!targetTaskInstanceTmp.getCanBeWithdrawn()) {
        // 说明已经有某些WorkItem处于已签收状态,或者已经处于完毕状态,此时不允许退回
        throw new EngineException(thisTaskInstance
            .getProcessInstanceId(), thisTaskInstance
            .getWorkflowProcess(), thisTaskInstance.getTaskId(),
            "Withdraw operation is refused! Some task instances of the  next activity[id="
                + targetTaskInstanceTmp.getActivityId()
                + "] are not in 'Initialized' state");
      }
    }

    INetInstance netInstance = rtCtx.getKernelManager().getNetInstance(
        thisTaskInstance.getProcessId(),
        workItem.getTaskInstance().getVersion());
    if (netInstance == null) {
      throw new EngineException(thisTaskInstance.getProcessInstanceId(),
          thisTaskInstance.getWorkflowProcess(), thisTaskInstance
              .getTaskId(),
          "Withdraw operation failed.Not find the net instance for workflow process [id="
              + thisTaskInstance.getProcessId() + ", version="
              + workItem.getTaskInstance().getVersion() + "]");
    }
    Object obj = netInstance.getWFElementInstance(thisTaskInstance
        .getActivityId());
    IActivityInstance thisActivityInstance = (IActivityInstance) obj;

    // 一切检查通过之后进行“收回”处理

    IWorkflowSession session = ((IWorkflowSessionAware) workItem)
        .getCurrentWorkflowSession();
    session.setWithdrawOrRejectOperationFlag(true);
    int newStepNumber = thisTaskInstance.getStepNumber() + 2;
    try {
      DynamicAssignmentHandler dynamicAssignmentHandler = new DynamicAssignmentHandler();
      List<String> actorIds = new ArrayList<String>();
      actorIds.add(workItem.getActorId());
      dynamicAssignmentHandler.setActorIdsList(actorIds);
      ((WorkflowSession) session)
          .setCurrentDynamicAssignmentHandler(dynamicAssignmentHandler);

      // 1、首先将后续环节的TaskInstance极其workItem变成Canceled状态
      List<String> targetActivityIdList = new ArrayList<String>();
      StringBuffer theFromActivityIds = new StringBuffer("");
      for (int i = 0; i < targetTaskInstancesList.size(); i++) {
        TaskInstance taskInstTemp = (TaskInstance) targetTaskInstancesList
            .get(i);

        persistenceService.abortTaskInstance(taskInstTemp);

        if (!targetActivityIdList
            .contains(taskInstTemp.getActivityId())) {
          targetActivityIdList.add(taskInstTemp.getActivityId());
          if (theFromActivityIds.length() == 0) {
            theFromActivityIds.append(taskInstTemp.getActivityId());
          } else {
            theFromActivityIds.append(
                IToken.FROM_ACTIVITY_ID_SEPARATOR).append(
                taskInstTemp.getActivityId());
          }
        }
      }

      persistenceService.deleteTokensForNodes(thisTaskInstance
          .getProcessInstanceId(), targetActivityIdList);

      if (rtCtx.isEnableTrace()) {
        for (int i = 0; targetActivityIdList != null
            && i < targetActivityIdList.size(); i++) {
          String tmpActId = (String) targetActivityIdList.get(i);
          ProcessInstanceTrace trace = new ProcessInstanceTrace();
          trace.setProcessInstanceId(thisTaskInstance
              .getProcessInstanceId());
          trace.setStepNumber(newStepNumber);
          trace.setType(ProcessInstanceTrace.WITHDRAW_TYPE);
          trace.setFromNodeId(tmpActId);
          trace.setToNodeId(thisActivity.getId());
          trace.setEdgeId("");
          rtCtx.getPersistenceService()
              .saveOrUpdateProcessInstanceTrace(trace);
        }
      }

      ITransitionInstance thisLeavingTransitionInstance = (ITransitionInstance) thisActivityInstance
          .getLeavingTransitionInstances().get(0);
      ISynchronizerInstance synchronizerInstance = (ISynchronizerInstance) thisLeavingTransitionInstance
          .getLeavingNodeInstance();
      if (synchronizerInstance.getEnteringTransitionInstances().size() > 1) {
        Token supplementToken = new Token();
        ((Token) supplementToken).setAlive(false);
        ((Token) supplementToken).setNodeId(synchronizerInstance
            .getSynchronizer().getId());
        supplementToken.setProcessInstanceId(thisTaskInstance
            .getProcessInstanceId());
        supplementToken
            .setProcessInstance(((TaskInstance) thisTaskInstance)
                .getAliveProcessInstance());
        supplementToken.setFromActivityId("Empty(created by withdraw)");
        supplementToken.setStepNumber(newStepNumber);
        supplementToken.setValue(synchronizerInstance.getVolume()
            - thisLeavingTransitionInstance.getWeight());
        persistenceService.saveOrUpdateToken(supplementToken);
      }

      Token newToken = new Token();
      ((Token) newToken).setAlive(true);
      ((Token) newToken).setNodeId(workItem.getTaskInstance()
          .getActivityId());
      newToken.setProcessInstanceId(thisTaskInstance
          .getProcessInstanceId());
      newToken.setProcessInstance(((TaskInstance) thisTaskInstance)
          .getAliveProcessInstance());
      newToken.setFromActivityId(theFromActivityIds.toString());
      newToken.setStepNumber(newStepNumber);
      newToken.setValue(0);
      persistenceService.saveOrUpdateToken(newToken);

      this.createTaskInstances(newToken, thisActivityInstance);

      List<IWorkItem>  workItems = persistenceService.findTodoWorkItems(workItem
          .getActorId(), workItem.getTaskInstance().getProcessId(),
          workItem.getTaskInstance().getTaskId());
      if (workItems == null || workItems.size() == 0) {
        throw new EngineException(thisTaskInstance
            .getProcessInstanceId(), thisTaskInstance
            .getWorkflowProcess(), thisTaskInstance.getTaskId(),
            "Withdraw operation failed.No work item has been created for Task[id="
                + thisTaskInstance.getTaskId() + "]");
      }
      if (workItems.size() > 1) {
        throw new EngineException(
            thisTaskInstance.getProcessInstanceId(),
            thisTaskInstance.getWorkflowProcess(),
            thisTaskInstance.getTaskId(),
            "Withdraw operation failed.More than one work item have been created for Task[id="
                + thisTaskInstance.getTaskId() + "]");
View Full Code Here

TOP

Related Classes of org.fireflow.engine.EngineException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.