Package org.fireflow.engine.impl

Examples of org.fireflow.engine.impl.TaskInstance


    {
      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

    {
      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

    {
      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

   * @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(
              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() + "]");
    }

    // 执行reject操作。

    IWorkflowSession session = ((IWorkflowSessionAware) workItem)
        .getCurrentWorkflowSession();
    session.setWithdrawOrRejectOperationFlag(true);
    int newStepNumber = thisTaskInstance.getStepNumber() + 1;
    try {
      // 首先将本WorkItem和TaskInstance cancel掉。
      workItem.setComments(comments);
      ((WorkItem) workItem).setState(IWorkItem.CANCELED);
      ((WorkItem) workItem).setEndTime(rtCtx.getCalendarService()
          .getSysDate());
      rtCtx.getPersistenceService().saveOrUpdateWorkItem(workItem);

      persistenceService.abortTaskInstance(thisTaskInstance);

      // 删除本环节的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()) {
        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 reject)");
        supplementToken
            .setStepNumber(thisTaskInstance.getStepNumber() + 1);
        supplementToken.setValue(synchronizerInstance.getVolume()
            - theLeavingTransitionInstance.getWeight()
            * fromActivityIdList.size());
        persistenceService.saveOrUpdateToken(supplementToken);
      }
 
View Full Code Here

   * @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
View Full Code Here

     */
    public ITaskInstance createTaskInstance(IWorkflowSession currentSession,
            RuntimeContext runtimeContxt, IProcessInstance processInstance,
            Task task, Activity activity) throws EngineException{

        TaskInstance taskInstance = new TaskInstance();

        return taskInstance;

    }
View Full Code Here

* @author wmj2003
*/
public class TaskInstanceRowMapper implements RowMapper {

  public Object mapRow(ResultSet rs, int rowNum) throws SQLException  {
    TaskInstance taskInstance = new TaskInstance();
    taskInstance.setId(rs.getString("id"));
    // 20090922 wmj2003 没有给biz_type赋值 是否需要给基于jdbc的数据增加 setBizType()方法?
    taskInstance.setTaskId(rs.getString("task_id"));
    taskInstance.setActivityId(rs.getString("activity_id"));
    taskInstance.setName(rs.getString("name"));

    taskInstance.setDisplayName(rs.getString("display_name"));
    taskInstance.setState(rs.getInt("state"));
    taskInstance.setSuspended(rs.getInt("suspended") == 1 ? true : false);
    taskInstance.setTaskType(rs.getString("task_type"));
    taskInstance.setCreatedTime(rs.getTimestamp("created_time"));

    taskInstance.setStartedTime(rs.getTimestamp("started_time"));
    taskInstance.setEndTime(rs.getTimestamp("end_time"));
    taskInstance.setAssignmentStrategy(rs.getString("assignment_strategy"));
    taskInstance.setProcessInstanceId(rs.getString("processinstance_id"));
    taskInstance.setProcessId(rs.getString("process_id"));

    taskInstance.setVersion(rs.getInt("version"));
    taskInstance.setTargetActivityId(rs.getString("target_activity_id"));
    taskInstance.setFromActivityId(rs.getString("from_activity_id"));
    taskInstance.setStepNumber(rs.getInt("step_number"));
    taskInstance.setCanBeWithdrawn(rs.getInt("can_be_withdrawn") == 1 ? true : false);

    return taskInstance;
  }
View Full Code Here

     */
    List<String> actorIdsList = null;
   
    public void assign(IAssignable asignable, String performerName) throws EngineException, KernelException {
        if (actorIdsList==null || actorIdsList.size()==0){
            TaskInstance taskInstance = (TaskInstance)asignable;
            throw new EngineException(taskInstance.getProcessInstanceId(),taskInstance.getWorkflowProcess(),
                    taskInstance.getTaskId(),"actorIdsList can not be empty");
        }

        List<IWorkItem> workItems = asignable.assignToActors(actorIdsList);
       
        ITaskInstance taskInst = (ITaskInstance)asignable;
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.