Package org.fireflow.kernel

Examples of org.fireflow.kernel.IActivityInstance


      }
    }

    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操作");
    }

    token.setProcessInstance(processInstance);

    thisActivityInstance.complete(token, targetActivityInstance);

  }
View Full Code Here


//      }
    }

    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操作");
    }

    token.setProcessInstance(processInstance);

    //调整token布局
    if (targetActivityId != null) {
      List<Synchronizer> allSynchronizersAndEnds = new ArrayList<Synchronizer>();
      allSynchronizersAndEnds.addAll(workflowProcess.getSynchronizers());
      allSynchronizersAndEnds.addAll(workflowProcess.getEndNodes());
      for (int i=0;i<allSynchronizersAndEnds.size();i++){
        Synchronizer synchronizer = allSynchronizersAndEnds.get(i);
        if (synchronizer.getName().equals("Synchronizer4")){
          System.out.println(synchronizer.getName());
        }
        int volumn = 0;
        if (synchronizer instanceof EndNode){
          volumn = synchronizer.getEnteringTransitions().size();
        }else{
          volumn = synchronizer.getEnteringTransitions().size()*synchronizer.getLeavingTransitions().size();
        }     
        IToken tokenTmp =  new Token();
        tokenTmp.setNodeId(synchronizer.getId());
        tokenTmp.setAlive(false);
        tokenTmp.setProcessInstanceId(thisTaskInst.getProcessInstanceId());
        tokenTmp.setStepNumber(-1);

        List<String> incomingTransitionIds = new ArrayList<String>();
        boolean reachable = false;
        List<Transition> enteringTrans = synchronizer.getEnteringTransitions();     
        for (int m=0;m<aliveActivityIdsAfterJump.size();m++){
          String aliveActivityId = aliveActivityIdsAfterJump.get(m);
          if (workflowProcess.isReachable(aliveActivityId, synchronizer.getId())){         
            Transition trans = null;
            reachable = true;
            for (int j=0;j<enteringTrans.size();j++){
              trans = enteringTrans.get(j);
              Node fromNode = (Node)trans.getFromNode();
              if (workflowProcess.isReachable(aliveActivityId, fromNode.getId())){
                if (!incomingTransitionIds.contains(trans.getId())){
                  incomingTransitionIds.add(trans.getId());
                }
              }
            }     
          }
        }
        if (reachable){
          tokenTmp.setValue(volumn-(incomingTransitionIds.size()*volumn/enteringTrans.size()))
         
          IToken virtualToken = getJoinInfo(allTokens,synchronizer.getId());
         
          if (virtualToken!=null){
            persistenceService.deleteTokensForNode(thisTaskInst.getProcessInstanceId(), synchronizer.getId());
          }
         
          if (tokenTmp.getValue()!=0){
            tokenTmp.setProcessInstance(processInstance);
            persistenceService.saveOrUpdateToken(tokenTmp);
          }
        }
      }
    }
    thisActivityInstance.complete(token, targetActivityInstance);

  }
View Full Code Here

          "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="
View Full Code Here

          "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="
View Full Code Here

      // 删除本环节的token
      persistenceService.deleteTokensForNode(thisTaskInstance
          .getProcessInstanceId(), thisTaskInstance.getActivityId());

      IActivityInstance fromActivityInstance = null;
      for (int i = 0; i < fromActivityIdList.size(); i++) {
        String fromActivityId = (String) fromActivityIdList.get(i);
        Object obj = netInstance.getWFElementInstance(fromActivityId);
        fromActivityInstance = (IActivityInstance) obj;
        Token newToken = new Token();
        ((Token) newToken).setAlive(true);
        ((Token) newToken).setNodeId(fromActivityId);
        newToken.setProcessInstanceId(thisTaskInstance
            .getProcessInstanceId());
        newToken.setProcessInstance(((TaskInstance) thisTaskInstance)
            .getAliveProcessInstance());
        newToken.setFromActivityId(thisTaskInstance.getActivityId());
        newToken.setStepNumber(newStepNumber);
        newToken.setValue(0);
        persistenceService.saveOrUpdateToken(newToken);

        this.createTaskInstances(newToken, fromActivityInstance);

        if (rtCtx.isEnableTrace()) {
          ProcessInstanceTrace trace = new ProcessInstanceTrace();
          trace.setProcessInstanceId(thisTaskInstance
              .getProcessInstanceId());
          trace.setStepNumber(newStepNumber);
          trace.setType(ProcessInstanceTrace.REJECT_TYPE);
          trace.setFromNodeId(thisActivity.getId());
          trace.setToNodeId(fromActivityId);
          trace.setEdgeId("");
          rtCtx.getPersistenceService()
              .saveOrUpdateProcessInstanceTrace(trace);
        }
      }

      ITransitionInstance theLeavingTransitionInstance = (ITransitionInstance) fromActivityInstance
          .getLeavingTransitionInstances().get(0);
      ISynchronizerInstance synchronizerInstance = (ISynchronizerInstance) theLeavingTransitionInstance
          .getLeavingNodeInstance();
      if (synchronizerInstance.getEnteringTransitionInstances().size() > fromActivityIdList
          .size()) {
View Full Code Here

              + 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();
View Full Code Here

TOP

Related Classes of org.fireflow.kernel.IActivityInstance

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.