Package org.fireflow.engine

Examples of org.fireflow.engine.IWorkflowSession


              + 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);
      }
    } finally {
      session.setWithdrawOrRejectOperationFlag(false);
    }
  }
View Full Code Here


        .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();
        ((Token) supplementToken).setAlive(false);
        ((Token) supplementToken).setNodeId(synchronizerInstance
            .getSynchronizer().getId());
        supplementToken.setProcessInstanceId(thisTaskInstance
            .getProcessInstanceId());
        supplementToken
            .setProcessInstance(((TaskInstance) thisTaskInstance)
                .getAliveProcessInstance());
        supplementToken.setFromActivityId("Empty(created by withdraw)");
        supplementToken.setStepNumber(newStepNumber);
        supplementToken.setValue(synchronizerInstance.getVolume()
            - thisLeavingTransitionInstance.getWeight());
        persistenceService.saveOrUpdateToken(supplementToken);
      }

      Token newToken = new Token();
      ((Token) newToken).setAlive(true);
      ((Token) newToken).setNodeId(workItem.getTaskInstance()
          .getActivityId());
      newToken.setProcessInstanceId(thisTaskInstance
          .getProcessInstanceId());
      newToken.setProcessInstance(((TaskInstance) thisTaskInstance)
          .getAliveProcessInstance());
      newToken.setFromActivityId(theFromActivityIds.toString());
      newToken.setStepNumber(newStepNumber);
      newToken.setValue(0);
      persistenceService.saveOrUpdateToken(newToken);

      this.createTaskInstances(newToken, thisActivityInstance);

      List<IWorkItem>  workItems = persistenceService.findTodoWorkItems(workItem
          .getActorId(), workItem.getTaskInstance().getProcessId(),
          workItem.getTaskInstance().getTaskId());
      if (workItems == null || workItems.size() == 0) {
        throw new EngineException(thisTaskInstance
            .getProcessInstanceId(), thisTaskInstance
            .getWorkflowProcess(), thisTaskInstance.getTaskId(),
            "Withdraw operation failed.No work item has been created for Task[id="
                + thisTaskInstance.getTaskId() + "]");
      }
      if (workItems.size() > 1) {
        throw new EngineException(
            thisTaskInstance.getProcessInstanceId(),
            thisTaskInstance.getWorkflowProcess(),
            thisTaskInstance.getTaskId(),
            "Withdraw operation failed.More than one work item have been created for Task[id="
                + thisTaskInstance.getTaskId() + "]");

      }

      return (IWorkItem) workItems.get(0);
    } finally {
      session.setWithdrawOrRejectOperationFlag(false);
    }
  }
View Full Code Here

  /* (non-Javadoc)
   * @see org.fireflow.engine.event.ITaskInstanceEventListener#onTaskInstanceEventFired(org.fireflow.engine.event.TaskInstanceEvent)
   */
  public void onTaskInstanceEventFired(TaskInstanceEvent e) throws EngineException {
    IWorkflowSession session = e.getWorkflowSession();
    IProcessInstance proceInst = e.getProcessInstance();
    ITaskInstance taskInst = (ITaskInstance)e.getSource();
    IWorkItem wi = e.getWorkItem();
    if (e.getEventType()==TaskInstanceEvent.BEFORE_TASK_INSTANCE_START){
      beforeTaskInstanceStart(session,proceInst,taskInst);
View Full Code Here

*/
public class CurrentUserAssignmentHandlerMock implements IAssignmentHandler{
    public static final String ACTOR_ID = "Fireflow JUnit Tester";
    public void assign(IAssignable asignable, String performerName) throws EngineException, KernelException {
      TaskInstance taskInstance = (TaskInstance)asignable;
      IWorkflowSession workflowSession = ((IWorkflowSessionAware)taskInstance).getCurrentWorkflowSession();
     
      System.out.println("+++++++++++++Current Workflow Session is "+workflowSession.hashCode());
      System.out.println("+++++++++++ x in current workflow session is "+workflowSession.getAttribute("x"));
        IWorkItem wi = asignable.assignToActor(ACTOR_ID);
        wi.claim();
    }
View Full Code Here

        currentProcessInstance = (IProcessInstance) transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                  //IWorkflowSession是流程操作的入口,需要从runtimeContext获得。
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                   
                    //创建流程实例
                    IProcessInstance processInstance = workflowSession.createProcessInstance(
                            "LeaveApplicationProcess",CurrentUserAssignmentHandler.APPLICANT);
                   
                    //运行流程实例
                    processInstance.run();
View Full Code Here

    transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                  //IWorkflowSession是流程操作的入口,需要从runtimeContext获得。
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                   
                    List myWorkItemsList = workflowSession.findMyTodoWorkItems(CurrentUserAssignmentHandler.APPLICANT);
                    System.out.println("我(zhang)的待办workitem列表如下:");
                    for (int i=0;myWorkItemsList!=null && i<myWorkItemsList.size();i++){
                      IWorkItem wi = (IWorkItem)myWorkItemsList.get(i);
                      System.out.println("序号:"+i+"; id="+wi.getId()+"; name="+wi.getTaskInstance().getDisplayName()+"; actorId="+wi.getActorId()+"; state="+wi.getState());
                    }
View Full Code Here

    transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                  //IWorkflowSession是流程操作的入口,需要从runtimeContext获得。
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                   
                    List myWorkItemsList = workflowSession.findMyTodoWorkItems(RoleDepartmentBasedAssignmentHandler.DEPARTMENT_MANAGER);
                    System.out.println("我(manager_chen)的待办workitem列表如下:");
                    for (int i=0;myWorkItemsList!=null && i<myWorkItemsList.size();i++){
                      IWorkItem wi = (IWorkItem)myWorkItemsList.get(i);
                      System.out.println("序号:"+i+"; id="+wi.getId()+"; name="+wi.getTaskInstance().getDisplayName()+"; actorId="+wi.getActorId()+"; state="+wi.getState());
                    }
View Full Code Here

TOP

Related Classes of org.fireflow.engine.IWorkflowSession

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.