Package org.fireflow.model.net

Examples of org.fireflow.model.net.Activity


        assertEquals(8, result.getTransitions().size());
       
        Task task = result.getTasks().get(0);
        assertEquals("Goods_Deliver_Process.PrepareGoodsTask",task.getId());

        Activity paymentActivity = (Activity) result.findWFElementById(PaymentActivity_ID);
        assertNotNull(paymentActivity);
        assertEquals(1, paymentActivity.getTasks().size());
        assertEquals(1, paymentActivity.getInlineTasks().size());

        Activity prepareGoodsActivity = (Activity) result.findWFElementById(PrepareGoodsActivity_ID);
        assertNotNull(prepareGoodsActivity);
        assertEquals(1, prepareGoodsActivity.getTasks().size());
        assertEquals(1, prepareGoodsActivity.getTaskRefs().size());
    }
View Full Code Here


        assertEquals(8, result.getTransitions().size());
       
        Task task = result.getTasks().get(0);
        assertEquals("Goods_Deliver_Process.PrepareGoodsTask",task.getId());
       
        Activity paymentActivity = (Activity) result.findWFElementById(PaymentActivity_ID);
        assertNotNull(paymentActivity);
        assertEquals(1, paymentActivity.getTasks().size());
        assertEquals(1, paymentActivity.getInlineTasks().size());

        Activity prepareGoodsActivity = (Activity) result.findWFElementById(PrepareGoodsActivity_ID);
        assertNotNull(prepareGoodsActivity);
        assertEquals(1, prepareGoodsActivity.getTasks().size());
        assertEquals(1, prepareGoodsActivity.getTaskRefs().size());
    }
View Full Code Here

   */
  public final void createTaskInstances(IToken token,
      IActivityInstance activityInstance) throws EngineException,
      KernelException {
   
    Activity activity = activityInstance.getActivity();
    IPersistenceService persistenceService = rtCtx.getPersistenceService();
    ICalendarService calService = rtCtx.getCalendarService();

    IProcessInstance processInstance = token.getProcessInstance();
    WorkflowSession workflowSession = (WorkflowSession) ((IWorkflowSessionAware) processInstance)
        .getCurrentWorkflowSession();

    if (workflowSession == null) {
      throw new EngineException(token.getProcessInstance(),
          activityInstance.getActivity(),
          "The workflow session in process instance can NOT be null");
    }

    int createdTaskInstanceCount = 0;
    for (int i = 0; i < activity.getTasks().size(); i++) {
      Task task = activity.getTasks().get(i);
      // 1、创建Task实例,并设置工作流系统定义的属性
      ITaskInstance taskInstance = this.createTaskInstance(
          workflowSession, processInstance, task, activity);

      if (taskInstance == null) {
        continue;
      }
      createdTaskInstanceCount = createdTaskInstanceCount + 1;

      String taskType = task.getType();
      ((TaskInstance) taskInstance).setTaskType(taskType);
      ((TaskInstance) taskInstance).setStepNumber(token.getStepNumber());
      // ((TaskInstance) taskInstance).setTokenId(token.getId());
      ((TaskInstance) taskInstance).setProcessInstanceId(processInstance
          .getId());
      ((TaskInstance) taskInstance).setProcessId(processInstance
          .getProcessId());
      ((TaskInstance) taskInstance).setVersion(processInstance
          .getVersion());
      ((TaskInstance) taskInstance).setActivityId(activity.getId());
      if (Task.FORM.equals(taskType)) {
        ((TaskInstance) taskInstance)
            .setAssignmentStrategy(((FormTask) task)
                .getAssignmentStrategy());
        ((TaskInstance) taskInstance).setCanBeWithdrawn(true);
View Full Code Here

   */
  protected boolean activityInstanceCanBeCompleted(ITaskInstance taskInstance)
      throws EngineException {
    IPersistenceService persistenceService = this.rtCtx
        .getPersistenceService();
    Activity thisActivity = (Activity) taskInstance.getActivity();
    // 检查是否有尚未创建的TaskInstance
    if (thisActivity.getTasks().size() > 1) {
      List<ITaskInstance> taskInstanceList = persistenceService
          .findTaskInstancesForProcessInstanceByStepNumber(
              taskInstance.getProcessInstanceId(), taskInstance
                  .getStepNumber());
      if (taskInstanceList == null
          || taskInstanceList.size() < thisActivity.getTasks().size()) {
        return false;
      }
    }
    if (thisActivity.getCompletionStrategy().equals(Activity.ALL)) {
      Integer aliveTaskInstanceCount4ThisActivity = persistenceService
          .getAliveTaskInstanceCountForActivity(taskInstance
              .getProcessInstanceId(), taskInstance
              .getActivityId());

View Full Code Here

  /* (non-Javadoc)
   * @see org.fireflow.engine.taskinstance.ITaskInstanceManager#rejectWorkItem(org.fireflow.engine.IWorkItem, java.lang.String)
   */
  public void rejectWorkItem(IWorkItem workItem, String comments)
      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(
View Full Code Here

  /* (non-Javadoc)
   * @see org.fireflow.engine.taskinstance.ITaskInstanceManager#withdrawWorkItem(org.fireflow.engine.IWorkItem)
   */
  public IWorkItem withdrawWorkItem(IWorkItem workItem)
      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);
        }
      }
View Full Code Here

TOP

Related Classes of org.fireflow.model.net.Activity

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.