예제 #1
0
        /// <summary>验证workflow process是否完整正确。</summary>
        /// <returns>null表示流程正确;否则表示流程错误,返回值是错误原因</returns>
        public String validate()
        {
            String errHead = "Workflow process is invalid:";

            if (this.StartNode == null)
            {
                return(errHead + "must have one start node");
            }
            if (this.StartNode.LeavingTransitions.Count == 0)
            {
                return(errHead + "start node must have leaving transitions.");
            }


            List <Activity> activities = this.Activities;

            for (int i = 0; i < activities.Count; i++)
            {
                Activity activity = activities[i];
                String   theName  = (String.IsNullOrEmpty(activity.DisplayName)) ? activity.Name : activity.DisplayName;
                if (activity.EnteringTransition == null)
                {
                    return(errHead + "activity[" + theName + "] must have entering transition.");
                }
                if (activity.LeavingTransition == null)
                {
                    return(errHead + "activity[" + theName + "] must have leaving transition.");
                }

                //check tasks
                List <Task> taskList = activity.getTasks();
                for (int j = 0; j < taskList.Count; j++)
                {
                    Task task = (Task)taskList[j];
                    if (task.TaskType == TaskTypeEnum.FORM)
                    {
                        FormTask formTask = (FormTask)task;
                        if (formTask.Performer == null)
                        {
                            return(errHead + "FORM-task[id=" + task.Id + "] must has a performer.");
                        }
                    }
                    else if (task.TaskType == TaskTypeEnum.TOOL)
                    {
                        ToolTask toolTask = (ToolTask)task;
                        if (toolTask.Application == null)
                        {
                            return(errHead + "TOOL-task[id=" + task.Id + "] must has a application.");
                        }
                    }
                    else if (task.TaskType == TaskTypeEnum.SUBFLOW)
                    {
                        SubflowTask subflowTask = (SubflowTask)task;
                        if (subflowTask.SubWorkflowProcess == null)
                        {
                            return(errHead + "SUBFLOW-task[id=" + task.Id + "] must has a subflow.");
                        }
                    }
                    else
                    {
                        return(errHead + " unknown task type of task[" + task.Id + "]");
                    }
                }
            }

            List <Synchronizer> synchronizers = this.Synchronizers;

            for (int i = 0; i < synchronizers.Count; i++)
            {
                Synchronizer synchronizer = synchronizers[i];
                String       theName      = (synchronizer.DisplayName == null || synchronizer.DisplayName.Equals("")) ? synchronizer.Name : synchronizer.DisplayName;
                if (synchronizer.EnteringTransitions.Count == 0)
                {
                    return(errHead + "synchronizer[" + theName + "] must have entering transition.");
                }
                if (synchronizer.LeavingTransitions.Count == 0)
                {
                    return(errHead + "synchronizer[" + theName + "] must have leaving transition.");
                }
            }

            List <EndNode> endnodes = this.EndNodes;

            for (int i = 0; i < endnodes.Count; i++)
            {
                EndNode endnode = endnodes[i];
                String  theName = (endnode.DisplayName == null || endnode.DisplayName.Equals("")) ? endnode.Name : endnode.DisplayName;
                if (endnode.EnteringTransitions.Count == 0)
                {
                    return(errHead + "end node[" + theName + "] must have entering transition.");
                }
            }

            List <Transition> transitions = this.Transitions;

            for (int i = 0; i < transitions.Count; i++)
            {
                Transition transition = transitions[i];
                String     theName    = (transition.DisplayName == null || transition.DisplayName.Equals("")) ? transition.Name : transition.DisplayName;
                if (transition.FromNode == null)
                {
                    return(errHead + "transition[" + theName + "] must have from node.");
                }
                if (transition.ToNode == null)
                {
                    return(errHead + "transition[" + theName + "] must have to node.");
                }
            }

            //check datafield 不再需要 DataType不肯能为空
            //List<DataField> dataFieldList = this.DataFields;
            //for (int i = 0; i < dataFieldList.Count; i++)
            //{
            //    DataField df = dataFieldList[i];
            //    if (df.DataType == DataTypeEnum. null)
            //    {
            //        return errHead + "unknown data type of datafield[" + df.Id + "]";
            //    }
            //}

            return(null);
        }
        // throws EngineException, KernelException
        /// <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)
        {
            //如果有指定的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;
                    }
                }
            }
        }