Package org.fireflow.engine.impl

Examples of org.fireflow.engine.impl.TaskInstance


    if (workItem == null)
      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");
    }

    // 0、首先修改workitem的状态
    ((WorkItem) workItem).setState(IWorkItem.RUNNING);
    ((WorkItem) workItem).setClaimedTime(rtCtx.getCalendarService()
        .getSysDate());
    persistenceService.saveOrUpdateWorkItem(workItem);

    // 1、如果不是会签,则删除其他的workitem
    if (FormTask.ANY.equals(workItem.getTaskInstance()
        .getAssignmentStrategy())) {
      persistenceService.deleteWorkItemsInInitializedState(workItem
          .getTaskInstance().getId());
    }

    // 2、将TaskInstance的canBeWithdrawn字段改称false。即不允许被撤销
    TaskInstance taskInstance = (TaskInstance) workItem.getTaskInstance();
    taskInstance.setCanBeWithdrawn(false);
    persistenceService.saveOrUpdateTaskInstance(taskInstance);

    return workItem;

  }
View Full Code Here


   */
  public void completeWorkItem(IWorkItem workItem,
      IActivityInstance targetActivityInstance, String comments)
      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");
    }

    IPersistenceService persistenceService = rtCtx.getPersistenceService();

    ((WorkItem) workItem).setComments(comments);
View Full Code Here

    WorkflowProcess workflowProcess = workItem.getTaskInstance()
        .getWorkflowProcess();
    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()
              + ",activity id=" + targetActivityId + "]");
    }
View Full Code Here

   
    // 首先检查是否可以正确跳转 

    WorkflowProcess workflowProcess = workItem.getTaskInstance().getWorkflowProcess();
    String thisActivityId = workItem.getTaskInstance().getActivityId();
    TaskInstance thisTaskInst = (TaskInstance) workItem.getTaskInstance();
    //如果是在同一条执行线上,那么可以直接跳过去,只是重复判断了是否在同一条执行线上
    boolean isInSameLine = workflowProcess.isInSameLine(thisActivityId,targetActivityId)
    if (isInSameLine){
      this.completeWorkItemAndJumpTo(workItem, targetActivityId, comments);
      return;
    }
   
    // 1)检查是否在同一个“执行线”上(关闭该检查,20091002)   
//    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) {// 大于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()
              + ",activity id=" + targetActivityId + "]");
    }

    if (rtCtx.isEnableTrace()) {

      ProcessInstanceTrace trace = new ProcessInstanceTrace();
      trace.setProcessInstanceId(workItem.getTaskInstance()
          .getProcessInstanceId());
      trace.setStepNumber(workItem.getTaskInstance().getStepNumber() + 1);
      trace.setType(ProcessInstanceTrace.JUMPTO_TYPE);
      trace.setFromNodeId(workItem.getTaskInstance().getActivityId());
      trace.setToNodeId(targetActivityId);
      trace.setEdgeId("");
      rtCtx.getPersistenceService().saveOrUpdateProcessInstanceTrace(
          trace);
    }

    //调整token布局
    List<Synchronizer> allSynchronizersAndEnds = new ArrayList<Synchronizer>();
    allSynchronizersAndEnds.addAll(thisProcess.getSynchronizers());
    allSynchronizersAndEnds.addAll(thisProcess.getEndNodes());
    for (int i=0;i<allSynchronizersAndEnds.size();i++){
      Synchronizer synchronizer = allSynchronizersAndEnds.get(i);

      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 (thisProcess.isReachable(aliveActivityId, synchronizer.getId())){         
          Transition trans = null;
          reachable = true;
          for (int j=0;j<enteringTrans.size();j++){
            trans = enteringTrans.get(j);
            Node fromNode = trans.getFromNode();
            if (thisProcess.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()); //获取一个虚拟的综合性token
       
        if (virtualToken!=null){
          persistenceService.deleteTokensForNode(thisTaskInst.getProcessInstanceId(), synchronizer.getId());
        }
       
        if (tokenTmp.getValue()!=0){
          tokenTmp.setProcessInstance(thisTaskInst.getAliveProcessInstance());
          persistenceService.saveOrUpdateToken(tokenTmp);
        }
      }
    }
   
View Full Code Here

  }

  public void lockTaskInstance(String taskInstanceId)
  {
    // hibernate:LockMode.UPGRADE 相当于jpa:LockModeType.READ
    TaskInstance taskInstance = this.em.find(TaskInstance.class, taskInstanceId);
    this.em.lock(taskInstance, LockModeType.READ);
  }
View Full Code Here

    String workItemSql = " select * from t_ff_rt_workitem where id=? ";

    WorkItem workItem = (WorkItem) super.getJdbcTemplate().queryForObject(workItemSql, new Object[] { id },
        new WorkItemRowMapper());
    String taskInstanceSql = "select * from t_ff_rt_taskinstance where id=? ";
    TaskInstance taskInstance = (TaskInstance) super.getJdbcTemplate().queryForObject(taskInstanceSql,
        new Object[] { workItem.getTaskInstanceId() }, new TaskInstanceRowMapper());
    workItem.setTaskInstance(taskInstance);
    return workItem;
  }
View Full Code Here

    String sql = " select * from t_ff_rt_workitem where taskinstance_id=? and state=" + IWorkItem.COMPLETED;

    List<IWorkItem> l = (List<IWorkItem>) super.getJdbcTemplate().query(sql, new Object[] { taskInstanceId },
        new WorkItemRowMapper());
    String taskInstanceSql = "select * from t_ff_rt_taskinstance where id=? ";
    TaskInstance taskInstance = (TaskInstance) super.getJdbcTemplate().queryForObject(taskInstanceSql,
        new Object[] { taskInstanceId }, new TaskInstanceRowMapper());
    if (l == null)
    {
      return null;
    }
View Full Code Here

    String sql = " select * from t_ff_rt_workitem where taskinstance_id=? ";

    List<IWorkItem> l = (List<IWorkItem>) super.getJdbcTemplate().query(sql, new Object[] { taskInstanceId },
        new WorkItemRowMapper());
    String taskInstanceSql = "select * from t_ff_rt_taskinstance where id=? ";
    TaskInstance taskInstance = (TaskInstance) super.getJdbcTemplate().queryForObject(taskInstanceSql,
        new Object[] { taskInstanceId }, new TaskInstanceRowMapper());
    if (l == null)
    {
      return null;
    }
View Full Code Here

    {
      String taskInstanceSql = "select * from t_ff_rt_taskinstance where id=? ";

      for (IWorkItem workItem : l)
      {
        TaskInstance taskInstance = (TaskInstance) super.getJdbcTemplate().queryForObject(taskInstanceSql,
            new Object[] { ((WorkItem) workItem).getTaskInstanceId() }, new TaskInstanceRowMapper());

        ((WorkItem) workItem).setTaskInstance(taskInstance);
      }
      return l;
View Full Code Here

    {
      String taskInstanceSql = "select * from t_ff_rt_taskinstance where id=? ";

      for (IWorkItem workItem : l)
      {
        TaskInstance taskInstance = (TaskInstance) super.getJdbcTemplate().queryForObject(taskInstanceSql,
            new Object[] { ((WorkItem) workItem).getTaskInstanceId() }, new TaskInstanceRowMapper());

        ((WorkItem) workItem).setTaskInstance(taskInstance);
      }
      return l;
View Full Code Here

TOP

Related Classes of org.fireflow.engine.impl.TaskInstance

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.