/* (non-Javadoc) * @see org.fireflow.engine.ITaskInstance#abortEx(java.lang.String, org.fireflow.engine.taskinstance.DynamicAssignmentHandler) */ public void abortEx(String targetActivityId, DynamicAssignmentHandler dynamicAssignmentHandler) { if (this.CurrentWorkflowSession == null) { new EngineException(this.ProcessInstanceId, this.WorkflowProcess, this.TaskId, "The current workflow session is null."); } if (this.RuntimeContext == null) { new EngineException(this.ProcessInstanceId, this.WorkflowProcess, this.TaskId, "The current runtime context is null."); } if ((this.State == TaskInstanceStateEnum.COMPLETED) || (this.State == TaskInstanceStateEnum.CANCELED)) { throw new EngineException(this.ProcessInstanceId, this.WorkflowProcess, this.TaskId, "Abort task instance failed . The state of the task instance [id=" + this.Id + "] is " + this.State); } if (dynamicAssignmentHandler != null) { this.CurrentWorkflowSession.setDynamicAssignmentHandler(dynamicAssignmentHandler); } ITaskInstanceManager taskInstanceMgr = this.RuntimeContext.TaskInstanceManager; taskInstanceMgr.abortTaskInstanceEx(this.CurrentWorkflowSession, this.AliveProcessInstance, this, targetActivityId); }
public /*final*/ void start() { ITaskInstanceManager taskInstanceMgr = this.RuntimeContext.TaskInstanceManager; taskInstanceMgr.startTaskInstance(this.CurrentWorkflowSession, this.AliveProcessInstance, this); // taskInstanceMgr.startTaskInstance(this); }
public void complete(IActivityInstance targetActivityInstance) { ITaskInstanceManager taskInstanceMgr = this.RuntimeContext.TaskInstanceManager; taskInstanceMgr.completeTaskInstance(this.CurrentWorkflowSession, this.AliveProcessInstance, this, targetActivityInstance); // taskInstanceMgr.completeTaskInstance(this, targetActivityInstance); }
public IWorkItem assignToActor(String id)// throws EngineException, KernelException { ITaskInstanceManager taskInstanceMgr = this.RuntimeContext.TaskInstanceManager; WorkItem wi = taskInstanceMgr.createWorkItem(this.CurrentWorkflowSession, this.AliveProcessInstance, this, id); return(wi); }
/// <summary>签收</summary> /// <returns></returns> public IWorkItem claim() { if (this._workflowSession == null) { new EngineException(this.TaskInstance.ProcessInstanceId, this.TaskInstance.WorkflowProcess, this.TaskInstance.TaskId, "The current workflow session is null."); } if (this.RuntimeContext == null) { new EngineException(this.TaskInstance.ProcessInstanceId, this.TaskInstance.WorkflowProcess, this.TaskInstance.TaskId, "The current runtime context is null."); } ITaskInstanceManager taskInstanceMgr = RuntimeContext.TaskInstanceManager; IWorkItem newWorkItem = taskInstanceMgr.claimWorkItem(this.Id, this.TaskInstance.Id); if (newWorkItem != null) { this.State = newWorkItem.State; this.ClaimedTime = newWorkItem.ClaimedTime; ((IRuntimeContextAware)newWorkItem).RuntimeContext = this.RuntimeContext; ((IWorkflowSessionAware)newWorkItem).CurrentWorkflowSession = this._workflowSession; } else { this.State = WorkItemEnum.CANCELED; } return(newWorkItem); }
/// <summary> /// <para>结束当前WorkItem;并由工作流引擎根据流程定义决定下一步操作。引擎的执行规则如下</para> /// <para>1、工作流引擎首先判断该WorkItem对应的TaskInstance是否可以结束。</para> /// <para> 如果TaskInstance的assignment策略为ANY,或者,assignment策略为ALL且它所有的WorkItem都已经完成</para> /// <para> 则结束当前TaskInstance</para> /// <para>2、判断TaskInstance对应的ActivityInstance是否可以结束。如果ActivityInstance的complete strategy为ANY,</para> /// <para> 或者,complete strategy为ALL且他的所有的TaskInstance都已经结束,则结束当前ActivityInstance</para> /// <para>3、根据流程定义,启动下一个Activity,并创建相关的TaskInstance和WorkItem</para> /// </summary> /// <param name="dynamicAssignmentHandler">通过动态分配句柄指定下一个环节的操作者。</param> /// <param name="comments">备注信息</param> public void complete(DynamicAssignmentHandler dynamicAssignmentHandler, String comments) { if (this._workflowSession == null) { new EngineException(this.TaskInstance.ProcessInstanceId, this.TaskInstance.WorkflowProcess, this.TaskInstance.TaskId, "The current workflow session is null."); } if (this.RuntimeContext == null) { new EngineException(this.TaskInstance.ProcessInstanceId, this.TaskInstance.WorkflowProcess, this.TaskInstance.TaskId, "The current runtime context is null."); } if (this.State != WorkItemEnum.RUNNING) { TaskInstance thisTaskInst = (TaskInstance)this.TaskInstance; // System.out.println("WorkItem的当前状态为"+this.State+",不可以执行complete操作。"); throw new EngineException(thisTaskInst.ProcessInstanceId, thisTaskInst.WorkflowProcess, thisTaskInst.TaskId, "Complete work item failed . The state of the work item [id=" + this.Id + "] is " + this.State); } if (dynamicAssignmentHandler != null) { this._workflowSession.setDynamicAssignmentHandler(dynamicAssignmentHandler); } ITaskInstanceManager taskInstanceManager = this.RuntimeContext.TaskInstanceManager; taskInstanceManager.completeWorkItem(this, null, comments); }
public List <IWorkItem> assignToActors(List <String> ids)// throws EngineException, KernelException { //task应该有一个标志(asignToEveryone),表明asign的规则 List <IWorkItem> workItemList = new List <IWorkItem>(); for (int i = 0; ids != null && i < ids.Count; i++) { ITaskInstanceManager taskInstanceMgr = this.RuntimeContext.TaskInstanceManager; WorkItem wi = taskInstanceMgr.createWorkItem(this.CurrentWorkflowSession, this.AliveProcessInstance, this, ids[i]); wi.CurrentWorkflowSession = this.CurrentWorkflowSession; workItemList.Add(wi); } return(workItemList); }
public void run(IWorkflowSession currentSession, RuntimeContext runtimeContext, IProcessInstance processInstance, ITaskInstance taskInstance)// throws EngineException, KernelException { if (taskInstance.TaskType != TaskTypeEnum.TOOL) { throw new EngineException(processInstance, taskInstance.Activity, "DefaultToolTaskInstanceRunner:TaskInstance的任务类型错误,只能为TOOL类型"); } Task task = taskInstance.Task; if (task == null) { WorkflowProcess process = taskInstance.WorkflowProcess; throw new EngineException(taskInstance.ProcessInstanceId, process, taskInstance.TaskId, "The Task is null,can NOT start the taskinstance,"); } if (((ToolTask)task).Application == null || ((ToolTask)task).Application.Handler == null) { WorkflowProcess process = taskInstance.WorkflowProcess; throw new EngineException(taskInstance.ProcessInstanceId, process, taskInstance.TaskId, "The task.Application is null or task.Application.Handler is null,can NOT start the taskinstance,"); } Object obj = runtimeContext.getBeanByName(((ToolTask)task).Application.Handler); if (obj == null || !(obj is IApplicationHandler)) { WorkflowProcess process = taskInstance.WorkflowProcess; throw new EngineException(taskInstance.ProcessInstanceId, process, taskInstance.TaskId, "Run tool task instance error! Not found the instance of " + ((ToolTask)task).Application.Handler + " or the instance not implements IApplicationHandler"); } try { ((IApplicationHandler)obj).execute(taskInstance); } catch (Exception) {//TODO wmj2003 对tool类型的task抛出的错误应该怎么处理? 这个时候引擎会如何?整个流程是否还可以继续? throw new EngineException(processInstance, taskInstance.Activity, "DefaultToolTaskInstanceRunner:TaskInstance的任务执行失败!"); } ITaskInstanceManager taskInstanceManager = runtimeContext.TaskInstanceManager; taskInstanceManager.completeTaskInstance(currentSession, processInstance, taskInstance, null); }
public void reject(String comments) { if (this._workflowSession == null) { new EngineException(this.TaskInstance.ProcessInstanceId, this.TaskInstance.WorkflowProcess, this.TaskInstance.TaskId, "The current workflow session is null."); } if (this.RuntimeContext == null) { new EngineException(this.TaskInstance.ProcessInstanceId, this.TaskInstance.WorkflowProcess, this.TaskInstance.TaskId, "The current runtime context is null."); } ITaskInstanceManager taskInstanceMgr = this.RuntimeContext.TaskInstanceManager; taskInstanceMgr.rejectWorkItem(this, comments); }
public IWorkItem withdraw() { if (this._workflowSession == null) { new EngineException(this.TaskInstance.ProcessInstanceId, this.TaskInstance.WorkflowProcess, this.TaskInstance.TaskId, "The current workflow session is null."); } if (this.RuntimeContext == null) { new EngineException(this.TaskInstance.ProcessInstanceId, this.TaskInstance.WorkflowProcess, this.TaskInstance.TaskId, "The current runtime context is null."); } ITaskInstanceManager taskInstanceMgr = this.RuntimeContext.TaskInstanceManager; return(taskInstanceMgr.withdrawWorkItem(this)); }
public IWorkItem reassignTo(String actorId, String comments) { if (this._workflowSession == null) { new EngineException(this.TaskInstance.ProcessInstanceId, this.TaskInstance.WorkflowProcess, this.TaskInstance.TaskId, "The current workflow session is null."); } if (this.RuntimeContext == null) { new EngineException(this.TaskInstance.ProcessInstanceId, this.TaskInstance.WorkflowProcess, this.TaskInstance.TaskId, "The current runtime context is null."); } ITaskInstanceManager manager = this.RuntimeContext.TaskInstanceManager; return(manager.reasignWorkItemTo(this, actorId, comments)); }
public void jumpToEx(String targetActivityId, DynamicAssignmentHandler dynamicAssignmentHandler, String comments) { if (this._workflowSession == null) { new EngineException(this.TaskInstance.ProcessInstanceId, this.TaskInstance.WorkflowProcess, this.TaskInstance.TaskId, "The current workflow session is null."); } if (this.RuntimeContext == null) { new EngineException(this.TaskInstance.ProcessInstanceId, this.TaskInstance.WorkflowProcess, this.TaskInstance.TaskId, "The current runtime context is null."); } if (dynamicAssignmentHandler != null) { this._workflowSession.setDynamicAssignmentHandler(dynamicAssignmentHandler); } ITaskInstanceManager taskInstanceManager = this.RuntimeContext.TaskInstanceManager; taskInstanceManager.completeWorkItemAndJumpToEx(this, targetActivityId, comments); }
/// <summary>分配, 按照当前任务的参与者插入工单</summary> /// <param name="currentSession"></param> /// <param name="processInstance"></param> /// <param name="runtimeContext"></param> /// <param name="taskInstance"></param> /// <param name="formTask"></param> /// <param name="part"></param> /// <param name="dynamicAssignmentHandler"></param> protected void assign(IWorkflowSession currentSession, IProcessInstance processInstance, RuntimeContext runtimeContext, ITaskInstance taskInstance, FormTask formTask, Participant part, DynamicAssignmentHandler dynamicAssignmentHandler)// throws EngineException, KernelException { //如果有指定的Actor,则按照指定的Actor分配任务 if (dynamicAssignmentHandler != null) { dynamicAssignmentHandler.assign((IAssignable)taskInstance, part.Name); } else { IPersistenceService persistenceService = runtimeContext.PersistenceService; List <ITaskInstance> taskInstanceList = persistenceService.FindTaskInstancesForProcessInstance(taskInstance.ProcessInstanceId, taskInstance.ActivityId); ITaskInstance theLastCompletedTaskInstance = null; for (int i = 0; taskInstanceList != null && i < taskInstanceList.Count; i++) { ITaskInstance tmp = (ITaskInstance)taskInstanceList[i]; if (tmp.Id.Equals(taskInstance.Id)) { continue; } if (!tmp.TaskId.Equals(taskInstance.TaskId)) { continue; } if (tmp.State != TaskInstanceStateEnum.COMPLETED) { continue; } if (theLastCompletedTaskInstance == null) { theLastCompletedTaskInstance = tmp; } else { if (theLastCompletedTaskInstance.StepNumber < tmp.StepNumber) { theLastCompletedTaskInstance = tmp; } } } //如果是循环且LoopStrategy==REDO,则分配个上次完成该工作的操作员 if (theLastCompletedTaskInstance != null && (LoopStrategyEnum.REDO == formTask.LoopStrategy || currentSession.isInWithdrawOrRejectOperation())) { List <IWorkItem> workItemList = persistenceService.FindCompletedWorkItemsForTaskInstance(theLastCompletedTaskInstance.Id); ITaskInstanceManager taskInstanceMgr = runtimeContext.TaskInstanceManager; for (int k = 0; k < workItemList.Count; k++) { IWorkItem completedWorkItem = (IWorkItem)workItemList[k]; IWorkItem newFromWorkItem = taskInstanceMgr.createWorkItem(currentSession, processInstance, taskInstance, completedWorkItem.ActorId); newFromWorkItem.claim();//并自动签收 } } else { IBeanFactory beanFactory = runtimeContext.BeanFactory; //从spring中获取到对应任务的Performer,创建工单 //201004 add lwz 参与者通过业务接口实现默认获取用户 switch (part.AssignmentType) { case AssignmentTypeEnum.Current: runtimeContext.AssignmentBusinessHandler.assignCurrent( currentSession, processInstance, (IAssignable)taskInstance); break; case AssignmentTypeEnum.Role: runtimeContext.AssignmentBusinessHandler.assignRole( currentSession, processInstance, (IAssignable)taskInstance, part.PerformerValue); break; case AssignmentTypeEnum.Agency: runtimeContext.AssignmentBusinessHandler.assignAgency( currentSession, processInstance, (IAssignable)taskInstance, part.PerformerValue); break; case AssignmentTypeEnum.Fixed: runtimeContext.AssignmentBusinessHandler.assignFixed( currentSession, processInstance, (IAssignable)taskInstance, part.PerformerValue); break; case AssignmentTypeEnum.Superiors: runtimeContext.AssignmentBusinessHandler.assignSuperiors( currentSession, processInstance, (IAssignable)taskInstance); break; default: IAssignmentHandler assignmentHandler = (IAssignmentHandler)beanFactory.GetBean(part.AssignmentHandler); //modified by wangmj 20090904 ((IAssignmentHandler)assignmentHandler).assign((IAssignable)taskInstance, part.PerformerValue); break; } } } }