Examples of IPersistenceService


Examples of org.fireflow.engine.persistence.IPersistenceService

     */
    public void abort() throws EngineException {
        if (this.state.intValue() == IProcessInstance.COMPLETED || this.state.intValue() == IProcessInstance.CANCELED) {
            throw new EngineException(this, this.getWorkflowProcess(), "The process instance can not be aborted,the state of this process instance is " + this.getState());
        }
        IPersistenceService persistenceService = rtCtx.getPersistenceService();
        persistenceService.abortProcessInstance(this);
    }
View Full Code Here

Examples of org.fireflow.engine.persistence.IPersistenceService

            throw new EngineException(this, this.getWorkflowProcess(), "The process instance can not be suspended,the state of this process instance is " + this.state);
        }
        if (this.isSuspended()) {
            return;
        }
        IPersistenceService persistenceService = this.rtCtx.getPersistenceService();
        persistenceService.suspendProcessInstance(this);
    }
View Full Code Here

Examples of org.fireflow.engine.persistence.IPersistenceService

        }
        if (!this.isSuspended()) {
            return;
        }

        IPersistenceService persistenceService = this.rtCtx.getPersistenceService();
        persistenceService.restoreProcessInstance(this);

    }
View Full Code Here

Examples of org.fireflow.engine.persistence.IPersistenceService

  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);
      } else {
        ((TaskInstance) taskInstance).setCanBeWithdrawn(false);
      }
      ((TaskInstance) taskInstance).setCreatedTime(calService
          .getSysDate());
      ((TaskInstance) taskInstance).setDisplayName(task.getDisplayName());
      ((TaskInstance) taskInstance).setName(task.getName());

      ((TaskInstance) taskInstance).setState(TaskInstance.INITIALIZED);

      ((TaskInstance) taskInstance).setTaskId(task.getId());

      ((TaskInstance) taskInstance).setFromActivityId(token
          .getFromActivityId());

      ((IRuntimeContextAware) taskInstance).setRuntimeContext(rtCtx);
      ((IWorkflowSessionAware) taskInstance)
          .setCurrentWorkflowSession(workflowSession);
      // 计算超时
      Duration duration = task.getDuration();

      if (duration != null && calService != null) {
        ((TaskInstance) taskInstance).setExpiredTime(calService
            .dateAfter(calService.getSysDate(), duration));
      }

      // 2、保存实例taskInstance
      persistenceService.saveOrUpdateTaskInstance(taskInstance);

      // 3、启动实例
      this.startTaskInstance(workflowSession, processInstance,
          taskInstance);
View Full Code Here

Examples of org.fireflow.engine.persistence.IPersistenceService

   */
  public ITaskInstance createTaskInstance(IWorkflowSession currentSession,
      IProcessInstance processInstance, Task task, Activity activity)
      throws EngineException {
    // 如果loopStrategy为SKIP且Task被执行过,则直接返回null;
    IPersistenceService persistenceService = this.rtCtx
        .getPersistenceService();
    String loopStrategy = task.getLoopStrategy();
    if (loopStrategy != null && Task.SKIP.equals(loopStrategy)
        && !currentSession.isInWithdrawOrRejectOperation()) {
      // 检查是否已经执行过的task instance
      Integer count = persistenceService
          .getCompletedTaskInstanceCountForTask(processInstance
              .getId(), task.getId());
      if (count > 0) {
        return null;
      }
View Full Code Here

Examples of org.fireflow.engine.persistence.IPersistenceService

   * @return
   * @throws EngineException
   */
  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());

      if (aliveTaskInstanceCount4ThisActivity.intValue() > 0) {
View Full Code Here

Examples of org.fireflow.engine.persistence.IPersistenceService

      ((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已经结束了。
View Full Code Here

Examples of org.fireflow.engine.persistence.IPersistenceService

      ((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已经结束了。
View Full Code Here

Examples of org.fireflow.engine.persistence.IPersistenceService

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

    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

Examples of org.fireflow.engine.persistence.IPersistenceService

   * @see org.fireflow.engine.taskinstance.ITaskInstanceManager#createWorkItem(org.fireflow.engine.IWorkflowSession, org.fireflow.engine.IProcessInstance, org.fireflow.engine.ITaskInstance, java.lang.String)
   */
  public final WorkItem createWorkItem(IWorkflowSession currentSession,
      IProcessInstance processInstance, ITaskInstance taskInstance,
      String actorId) throws EngineException {
    IPersistenceService persistenceService = rtCtx.getPersistenceService();

    WorkItem wi = new WorkItem();
    wi.setTaskInstance(taskInstance);
    wi.setActorId(actorId);
    wi.setState(IWorkItem.INITIALIZED);
    wi.setCreatedTime(rtCtx.getCalendarService().getSysDate());
    wi.setRuntimeContext(rtCtx);
    wi.setCurrentWorkflowSession(currentSession);
    // 保存到数据库
    persistenceService.saveOrUpdateWorkItem(wi);

    // 触发事件
    // 触发相应的事件
    TaskInstanceEvent e = new TaskInstanceEvent();
    e.setSource(taskInstance);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.