/// <summary>
     /// 插入或者更新ProcessInstance流程实例
     /// </summary>
     public bool SaveOrUpdateProcessInstance(IProcessInstance processInstance)
     {
         if (String.IsNullOrEmpty(processInstance.Id))
         {
             processInstance.Id = Guid.NewGuid().ToString("N");
             return SaveProcessInstance(processInstance);
         }
         else
         {
            string update = "UPDATE T_FF_RT_PROCESSINSTANCE SET "+
                 "PROCESS_ID=:2, VERSION=:3, NAME=:4, DISPLAY_NAME=:5, STATE=:6, "+
                 "SUSPENDED=:7, CREATOR_ID=:8, CREATED_TIME=:9, STARTED_TIME=:10, EXPIRED_TIME=:11, "+
                 "END_TIME=:12, PARENT_PROCESSINSTANCE_ID=:13, PARENT_TASKINSTANCE_ID=:14 WHERE ID=:1";
 			OracleParameter[] updateParms = { 
 				OracleHelper.NewOracleParameter(":2", OracleType.VarChar, 100, processInstance.ProcessId), 
 				OracleHelper.NewOracleParameter(":3", OracleType.Int32, processInstance.Version), 
 				OracleHelper.NewOracleParameter(":4", OracleType.VarChar, 100, processInstance.Name), 
 				OracleHelper.NewOracleParameter(":5", OracleType.VarChar, 128, processInstance.DisplayName), 
 				OracleHelper.NewOracleParameter(":6", OracleType.Int32, (int)processInstance.State), 
 				OracleHelper.NewOracleParameter(":7", OracleType.Int16, OracleHelper.OraBit(processInstance.Suspended)), 
 				OracleHelper.NewOracleParameter(":8", OracleType.VarChar, 50, processInstance.CreatorId), 
 				OracleHelper.NewOracleParameter(":9", OracleType.DateTime, 11, processInstance.CreatedTime), 
 				OracleHelper.NewOracleParameter(":10", OracleType.DateTime, 11, processInstance.StartedTime), 
 				OracleHelper.NewOracleParameter(":11", OracleType.DateTime, 11, processInstance.ExpiredTime), 
 				OracleHelper.NewOracleParameter(":12", OracleType.DateTime, 11, processInstance.EndTime), 
 				OracleHelper.NewOracleParameter(":13", OracleType.VarChar, 50, processInstance.ParentProcessInstanceId), 
 				OracleHelper.NewOracleParameter(":14", OracleType.VarChar, 50, processInstance.ParentTaskInstanceId),
 				OracleHelper.NewOracleParameter(":1", OracleType.VarChar, 50, processInstance.Id)
 			};
 			if (OracleHelper.ExecuteNonQuery(connectionString, CommandType.Text, update, updateParms) != 1)
 				return false;
 			else return true;
         }
     }
        /******************************************************************************/
        /************                                                        **********/
        /************            Process instance 相关的持久化方法            **********/
        /************            Persistence methods for process instance    **********/
        /************                                                        **********/
        /******************************************************************************/
        /// <summary>
        /// 插入或者更新ProcessInstance流程实例
        /// </summary>
        public bool SaveProcessInstance(IProcessInstance processInstance)
        {
            if (String.IsNullOrEmpty(processInstance.Id))
                return false;

            string insert = "INSERT INTO T_FF_RT_PROCESSINSTANCE (" +
                    "ID, PROCESS_ID, VERSION, NAME, DISPLAY_NAME, " +
                    "STATE, SUSPENDED, CREATOR_ID, CREATED_TIME, STARTED_TIME, " +
                    "EXPIRED_TIME, END_TIME, PARENT_PROCESSINSTANCE_ID, PARENT_TASKINSTANCE_ID" +
                    ") VALUES(:1,:2,:3,:4,:5, :6,:7,:8,:9,:10, :11,:12,:13,:14)";
            OracleParameter[] insertParms = { 
    				OracleHelper.NewOracleParameter(":1", OracleType.VarChar, 50, processInstance.Id), 
    				OracleHelper.NewOracleParameter(":2", OracleType.VarChar, 100, processInstance.ProcessId), 
    				OracleHelper.NewOracleParameter(":3", OracleType.Int32, processInstance.Version), 
    				OracleHelper.NewOracleParameter(":4", OracleType.VarChar, 100, processInstance.Name), 
    				OracleHelper.NewOracleParameter(":5", OracleType.VarChar, 128, processInstance.DisplayName), 
    				OracleHelper.NewOracleParameter(":6", OracleType.Int32, (int)processInstance.State), 
    				OracleHelper.NewOracleParameter(":7", OracleType.Int16, OracleHelper.OraBit(processInstance.Suspended)), 
    				OracleHelper.NewOracleParameter(":8", OracleType.VarChar, 50, processInstance.CreatorId), 
    				OracleHelper.NewOracleParameter(":9", OracleType.DateTime, 11, processInstance.CreatedTime), 
    				OracleHelper.NewOracleParameter(":10", OracleType.DateTime, 11, processInstance.StartedTime), 
    				OracleHelper.NewOracleParameter(":11", OracleType.DateTime, 11, processInstance.ExpiredTime), 
    				OracleHelper.NewOracleParameter(":12", OracleType.DateTime, 11, processInstance.EndTime), 
    				OracleHelper.NewOracleParameter(":13", OracleType.VarChar, 50, processInstance.ParentProcessInstanceId), 
    				OracleHelper.NewOracleParameter(":14", OracleType.VarChar, 50, processInstance.ParentTaskInstanceId)
    			};
            if (OracleHelper.ExecuteNonQuery(connectionString, CommandType.Text, insert, insertParms) != 1)
                return false;
            else return true;
        }
예제 #3
0
 public TaskInstance(ProcessInstance workflowProcessInsatnce)
 {
     this.State = TaskInstanceStateEnum.INITIALIZED;
     this.Suspended = false;
     this.CanBeWithdrawn = true;
     this.processInsatance = workflowProcessInsatnce;
 }
        /******************************************************************************/
        /************                                                        **********/
        /************            Process instance 相关的持久化方法            **********/
        /************            Persistence methods for process instance    **********/
        /************                                                        **********/
        /******************************************************************************/
       
         /// <summary>
        /// 插入或者更新ProcessInstance流程实例
        /// </summary>
        public bool SaveProcessInstance(IProcessInstance processInstance)
        {
            if (String.IsNullOrEmpty(processInstance.Id))
                return false;

            string insert = "INSERT INTO T_FF_RT_PROCESSINSTANCE (" +
                    "ID, PROCESS_ID, VERSION, NAME, DISPLAY_NAME, " +
                    "STATE, SUSPENDED, CREATOR_ID, CREATED_TIME, STARTED_TIME, " +
                    "EXPIRED_TIME, END_TIME, PARENT_PROCESSINSTANCE_ID, PARENT_TASKINSTANCE_ID" +
                    ") VALUES(@1,@2,@3,@4,@5, @6,@7,@8,@9,@10, @11,@12,@13,@14)";
            SqlParameter[] insertParms = { 
    				SqlServerHelper.NewSqlParameter("@1", SqlDbType.VarChar, 50, processInstance.Id), 
    				SqlServerHelper.NewSqlParameter("@2", SqlDbType.VarChar, 100, processInstance.ProcessId), 
    				SqlServerHelper.NewSqlParameter("@3", SqlDbType.Int, processInstance.Version), 
    				SqlServerHelper.NewSqlParameter("@4", SqlDbType.VarChar, 100, processInstance.Name), 
    				SqlServerHelper.NewSqlParameter("@5", SqlDbType.VarChar, 128, processInstance.DisplayName), 
    				SqlServerHelper.NewSqlParameter("@6", SqlDbType.Int, (int)processInstance.State), 
    				SqlServerHelper.NewSqlParameter("@7", SqlDbType.SmallInt, SqlServerHelper.OraBit(processInstance.Suspended)), 
    				SqlServerHelper.NewSqlParameter("@8", SqlDbType.VarChar, 50, processInstance.CreatorId), 
    				SqlServerHelper.NewSqlParameter("@9", SqlDbType.DateTime, 11, processInstance.CreatedTime), 
    				SqlServerHelper.NewSqlParameter("@10", SqlDbType.DateTime, 11, processInstance.StartedTime), 
    				SqlServerHelper.NewSqlParameter("@11", SqlDbType.DateTime, 11, processInstance.ExpiredTime), 
    				SqlServerHelper.NewSqlParameter("@12", SqlDbType.DateTime, 11, processInstance.EndTime), 
    				SqlServerHelper.NewSqlParameter("@13", SqlDbType.VarChar, 50, processInstance.ParentProcessInstanceId), 
    				SqlServerHelper.NewSqlParameter("@14", SqlDbType.VarChar, 50, processInstance.ParentTaskInstanceId)
    			};
            if (SqlServerHelper.ExecuteNonQuery(connectionString, CommandType.Text, insert, insertParms) != 1)
                return false;
            else return true;
        }
예제 #5
0
		public ActivityFormImpl(FlowImpl flow, IList fields, IDictionary attributeValues)
		{
			this._flow = flow;
			this._processInstance = flow.ProcessInstance;
			this._processDefinition = _processInstance.ProcessDefinition;
			this._activityState = (IActivityState) flow.Node;
			this._fields = fields;
			this._attributeValues = attributeValues;
			InitTransitionNames(flow.Node);
		}
예제 #6
0
        public ITaskInstance createTaskInstance(IWorkflowSession currentSession, RuntimeContext runtimeContxt, IProcessInstance processInstance, Task task, Activity activity)
        {
            LoanTaskInstance taskInstance = new LoanTaskInstance();
            taskInstance.Sn=(String)processInstance.getProcessInstanceVariable("sn");
            taskInstance.ApplicantName=(String)processInstance.getProcessInstanceVariable("applicantName");
            taskInstance.LoanValue=(int)processInstance.getProcessInstanceVariable("loanValue");
            taskInstance.RiskFlag=(Boolean)processInstance.getProcessInstanceVariable("RiskFlag");
            taskInstance.Decision=(Boolean)processInstance.getProcessInstanceVariable("Decision");

            return taskInstance;
        }
예제 #7
0
 public FlowImpl(String name, FlowImpl parent, ProcessBlockImpl processBlock)
 {
     this._name = name;
     this._start = DateTime.Now;
     this._processInstance = parent.ProcessInstance;
     this._subProcessInstances = null;
     this._parent = parent;
     this._children = null;
     this._logs = new ListSet();
     this._parentReactivation = true;
     CreateAttributeInstances(processBlock.Attributes);
 }
예제 #8
0
파일: PPMEComp.cs 프로젝트: qwinner/NetBPM
		private void WriteProcess(StreamWriter xmlwriter, IProcessInstance processInstance)
		{
			xmlwriter.WriteLine("<!--");
			xmlwriter.WriteLine("ProcessDefinition.Name: "+processInstance.ProcessDefinition.Name);
			xmlwriter.WriteLine("ProcessDefinition.Version: "+processInstance.ProcessDefinition.Version);
			xmlwriter.WriteLine("-->");
			xmlwriter.WriteLine("	<graph id=\"" +processInstance.ProcessDefinition.Name + " - " +
				processInstance.RootFlow.Id+"\" xml:lang=\"en\">");
			WriterAttributes(processInstance.RootFlow,xmlwriter);
			WriterNodes(processInstance.RootFlow,xmlwriter);
			
			xmlwriter.WriteLine("	</graph>");
		}
 //throws EngineException ,KernelException
 public Boolean taskInstanceCanBeCompleted(IWorkflowSession currentSession, RuntimeContext runtimeContext,
     IProcessInstance processInstance, ITaskInstance taskInstance)
 {
     IPersistenceService persistenceService = runtimeContext.PersistenceService;
     Int32 aliveWorkItemCount = persistenceService.GetAliveWorkItemCountForTaskInstance(taskInstance.Id);
     if (aliveWorkItemCount == 0)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
예제 #10
0
        public virtual void testTerminateWithSubProcess()
        {
            IProcessInstance pi = runtimeService.StartProcessInstanceByKey("terminateEndEventExample");

            // should terminate the process and
            long executionEntities = runtimeService.CreateExecutionQuery(c => c.ProcessInstanceId == pi.Id).Count();

            Assert.AreEqual(4, executionEntities);

            ITask task = taskService.CreateTaskQuery(c => c.ProcessInstanceId == pi.Id && c.TaskDefinitionKey == "preTerminateEnd").First();

            taskService.Complete(task.Id);

            AssertProcessEnded(pi.Id);
        }
예제 #11
0
        public virtual void testTerminateInCallActivityConcurrentMulitInstance()
        {
            IProcessInstance pi = runtimeService.StartProcessInstanceByKey("terminateEndEventExample");

            // should terminate the called process and continue the parent
            long executionEntities = runtimeService.CreateExecutionQuery().Count();

            Assert.AreEqual(1, executionEntities);

            ITask task = taskService.CreateTaskQuery(c => c.ProcessInstanceId == pi.Id && c.TaskDefinitionKey == "preNormalEnd").First();

            taskService.Complete(task.Id);

            AssertProcessEnded(pi.Id);
        }
예제 #12
0
        public virtual void CreateIncident()
        {
            //given
            testRule.DeployAndGetDefinition(ProcessModels.TwoTasksProcess);

            IProcessInstance processInstance = engineRule.RuntimeService.StartProcessInstanceByKey("Process");
            ExecutionEntity  execution       = (ExecutionEntity)engineRule.RuntimeService.CreateExecutionQuery(c => c.IsActive).First();

            authRule.Init(scenario).WithUser("userId").BindResource("processInstance", processInstance.Id).BindResource("processDefinition", "Process").Start();

            engineRule.RuntimeService.CreateIncident("foo", execution.Id, execution.ActivityId, "bar");

            // then
            authRule.AssertScenario(scenario);
        }
예제 #13
0
        public virtual void TestMessageThrowEvent()
        {
            IProcessInstance processInstance = runtimeService.StartProcessInstanceByKey("testProcess");

            // input mapping
            IDictionary <string, object> mappedVariables = VariableLogDelegate.LOCAL_VARIABLES;

            Assert.AreEqual(1, mappedVariables.Count);
            Assert.AreEqual("mappedValue", ((PrimitiveTypeValueImpl <string>)mappedVariables["mappedVariable"]).Value);

            // output mapping
            string variable = (string)runtimeService.GetVariableLocal(processInstance.Id, "outVariable");

            Assert.AreEqual("mappedValue", variable);
        }
        public virtual void startProcessInstanceWithTenantId()
        {
            testRule.DeployForTenant(TENANT_ONE, PROCESS);

            IJob job = managementService.CreateJobQuery().First();

            Assert.That(job.TenantId, Is.EqualTo(TENANT_ONE));

            managementService.ExecuteJob(job.Id);

            IProcessInstance processInstance = runtimeService.CreateProcessInstanceQuery().First();

            Assert.That(processInstance != null);
            Assert.That(processInstance.TenantId, Is.EqualTo(TENANT_ONE));
        }
예제 #15
0
        public virtual void ResolveIncident()
        {
            // given
            Deploy(ProcessModels.TwoTasksProcess);
            IProcessInstance processInstance = runtimeService.StartProcessInstanceByKey("Process");
            IIncident        incident        = runtimeService.CreateIncident("foo", processInstance.Id, "userTask1", "bar");

            // when
            runtimeService.ResolveIncident(incident.Id);

            // then
            IIncident incident2 = runtimeService.CreateIncidentQuery(c => c.ExecutionId == processInstance.Id).FirstOrDefault();

            Assert.Null(incident2);
        }
예제 #16
0
 public FlowImpl(String actorId, ProcessInstanceImpl processInstance)
 {
     ProcessDefinitionImpl processDefinition = (ProcessDefinitionImpl) processInstance.ProcessDefinition;
     this._name = "root";
     this._actorId = actorId;
     this._start = DateTime.Now;
     this._node = processDefinition.StartState;
     this._processInstance = processInstance;
     this._subProcessInstances = null;
     this._parent = null;
     this._children = null;
     this._logs = new ListSet();
     this._parentReactivation = true;
     CreateAttributeInstances(processDefinition.Attributes);
 }
        public virtual void testConcurrentExclusiveCorrelationToDifferentExecutions()
        {
            InvocationLogListener.reset();

            // given a process instance
            IProcessInstance instance1 = runtimeService.StartProcessInstanceByKey("testProcess");
            IProcessInstance instance2 = runtimeService.StartProcessInstanceByKey("testProcess");

            // and two threads correlating in parallel to each of the two instances
            ThreadControl thread1 = ExecuteControllableCommand(new ControllableMessageCorrelationCommand("Message", instance1.Id, true));

            thread1.ReportInterrupts();
            ThreadControl thread2 = ExecuteControllableCommand(new ControllableMessageCorrelationCommand("Message", instance2.Id, true));

            thread2.ReportInterrupts();

            // both threads open a transaction and wait before correlating the message
            thread1.WaitForSync();
            thread2.WaitForSync();

            // thread one correlates and acquires the exclusive lock on the event subscription of instance1
            thread1.MakeContinue();
            thread1.WaitForSync();

            // the service task was executed once
            Assert.AreEqual(1, InvocationLogListener.Invocations);

            // thread two correlates and acquires the exclusive lock on the event subscription of instance2
            // depending on the database and locking used, this may block thread2
            thread2.MakeContinue();

            // thread 1 completes successfully
            thread1.WaitUntilDone();
            Assert.IsNull(thread1.Exception);

            // thread2 should be able to continue at least after thread1 has finished and released its lock
            thread2.WaitForSync();

            // the service task was executed the second time
            Assert.AreEqual(2, InvocationLogListener.Invocations);

            // thread 2 completes successfully
            thread2.WaitUntilDone();
            Assert.IsNull(thread2.Exception);

            // the follow-up task was reached in both instances
            Assert.AreEqual(2, taskService.CreateTaskQuery(c => c.TaskDefinitionKey == "afterMessageUserTask").Count());
        }
        public virtual void deployProcessesAndCreateMigrationPlan()
        {
            IProcessDefinition sourceDefinition = testHelper.DeployAndGetDefinition(ProcessModels.OneTaskProcess);
            IProcessDefinition targetDefinition = testHelper.DeployAndGetDefinition(ProcessModels.OneTaskProcess);

            migrationPlan = engineRule.RuntimeService.CreateMigrationPlan(sourceDefinition.Id, targetDefinition.Id).MapEqualActivities().Build();

            IProcessInstance pi = engineRule.RuntimeService.StartProcessInstanceById(sourceDefinition.Id);

            batch1 = engineRule.RuntimeService.NewMigration(migrationPlan).ProcessInstanceIds((pi.Id)).ExecuteAsync();

            ESS.FW.Bpm.Engine.Runtime.IJob seedJob = engineRule.ManagementService.CreateJobQuery().First();
            engineRule.ManagementService.ExecuteJob(seedJob.Id);

            batch2 = engineRule.RuntimeService.NewMigration(migrationPlan).ProcessInstanceIds((pi.Id)).ExecuteAsync();
        }
예제 #19
0
        public static ProcessInstanceModel Create(IProcessInstance instance)
        {
            var model = new ProcessInstanceModel();

            model.Id            = instance.Id;
            model.Key           = instance.Key;
            model.Name          = instance.Name;
            model.State         = (int)instance.State;
            model.StateName     = instance.State.ToString();
            model.Initiator     = instance.Initiator;
            model.StartTime     = instance.StartTime;
            model.LastStateTime = instance.LastStateTime;
            model.Description   = instance.Description;

            return(model);
        }
        protected internal virtual IList<string> setupFailedJobs()
        {
            IList<string> jobIds = new List<string>();

            IDeployment deploy = testHelper.Deploy(JOB_EXCEPTION_DEFINITION_XML);
            IProcessDefinition sourceDefinition = engineRule.RepositoryService.CreateProcessDefinitionQuery(c=> c.DeploymentId == deploy.Id).First();
            processInstance = engineRule.RuntimeService.StartProcessInstanceById(sourceDefinition.Id);

            IList<ESS.FW.Bpm.Engine.Runtime.IJob> jobs = managementService.CreateJobQuery(c=>c.ProcessInstanceId== processInstance.Id)
                .ToList();
            foreach (ESS.FW.Bpm.Engine.Runtime.IJob job in jobs)
            {
                jobIds.Add(job.Id);
            }
            return jobIds;
        }
        [Test]   public virtual void testGetIdentityLinkWithTenantIdForCandidateGroup()
        {
            // given
            IBpmnModelInstance oneTaskProcess = ESS.FW.Bpm.Model.Bpmn.Bpmn.CreateExecutableProcess("testProcess").StartEvent().UserTask("task").CamundaCandidateGroups("aGroupId").EndEvent().Done();

            DeploymentForTenant("tenant", oneTaskProcess);

            IProcessInstance tenantProcessInstance = runtimeService.CreateProcessInstanceByKey("testProcess").SetProcessDefinitionTenantId("tenant").Execute();

            ITask tenantTask = taskService.CreateTaskQuery(c => c.ProcessInstanceId == tenantProcessInstance.Id).First();

            IList <IIdentityLink> identityLinks = taskService.GetIdentityLinksForTask(tenantTask.Id);

            Assert.AreEqual(identityLinks.Count, 1);
            Assert.AreEqual(identityLinks[0].TenantId, "tenant");
        }
예제 #22
0
        public virtual void ResolveIncidentWithIncidentHandler()
        {
            // given
            Deploy(ProcessModels.TwoTasksProcess);
            IProcessInstance processInstance = runtimeService.StartProcessInstanceByKey("Process");

            runtimeService.CreateIncident("custom", processInstance.Id, "configuration");
            IIncident incident = runtimeService.CreateIncidentQuery().FirstOrDefault();

            // when
            runtimeService.ResolveIncident(incident.Id);

            // then
            incident = runtimeService.CreateIncidentQuery().First();
            Assert.Null(incident);
        }
예제 #23
0
        public FlowImpl(String actorId, ProcessInstanceImpl processInstance)
        {
            ProcessDefinitionImpl processDefinition = (ProcessDefinitionImpl)processInstance.ProcessDefinition;

            this._name                = "root";
            this._actorId             = actorId;
            this._start               = DateTime.Now;
            this._node                = processDefinition.StartState;
            this._processInstance     = processInstance;
            this._subProcessInstances = null;
            this._parent              = null;
            this._children            = null;
            this._logs                = new ListSet();
            this._parentReactivation  = true;
            CreateAttributeInstances(processDefinition.Attributes);
        }
예제 #24
0
        public virtual void testRepeatingTimerWithCancelActivity()
        {
            IProcessInstance processInstance = runtimeService.StartProcessInstanceByKey("repeatingTimerAndCallActivity");

            Assert.AreEqual(1, managementService.CreateJobQuery().Count());
            Assert.AreEqual(1, taskService.CreateTaskQuery().Count());

            // Firing job should cancel the IUser task, destroy the scope,
            // re-enter the task and recreate the task. A new timer should also be created.
            // This didn't happen before 5.11 (new jobs kept being created). See ACT-1427
            IJob job = managementService.CreateJobQuery().First();

            managementService.ExecuteJob(job.Id);
            Assert.AreEqual(1, managementService.CreateJobQuery().Count());
            Assert.AreEqual(1, taskService.CreateTaskQuery().Count());
        }
예제 #25
0
        public virtual void testTerminateInSubProcessMultiInstance()
        {
            serviceTaskInvokedCount = 0;

            IProcessInstance pi = runtimeService.StartProcessInstanceByKey("terminateEndEventExample");

            long executionEntities = runtimeService.CreateExecutionQuery().Count();

            Assert.AreEqual(1, executionEntities);

            ITask task = taskService.CreateTaskQuery(c => c.ProcessInstanceId == pi.Id && c.TaskDefinitionKey == "preNormalEnd").First();

            taskService.Complete(task.Id);

            AssertProcessEnded(pi.Id);
        }
        public virtual void testUserTaskFollowUpDateStringExtension()
        {
            IDictionary <string, object> variables = new Dictionary <string, object>();

            variables["dateVariable"] = "2015-01-01T12:10:00";

            // Start process-instance, passing date that should be used as followUpDate
            IProcessInstance processInstance = runtimeService.StartProcessInstanceByKey("process", variables);

            ITask task = taskService.CreateTaskQuery(c => c.ProcessInstanceId == processInstance.Id).First();

            Assert.NotNull(task.FollowUpDate);
            DateTime date = DateTime.Parse("2015-01-01 12:10:00");

            Assert.AreEqual(date, task.FollowUpDate);
        }
        public virtual void testNoSignalEventSubscriptionWithExecutionId()
        {
            Deployment(ESS.FW.Bpm.Model.Bpmn.Bpmn.CreateExecutableProcess("noSignal").StartEvent().UserTask().EndEvent().Done());

            IProcessInstance processInstance = runtimeService.StartProcessInstanceByKey("noSignal");
            string           ExecutionId     = processInstance.Id;

            try
            {
                runtimeService.CreateSignalEvent("signal").SetExecutionId(ExecutionId).Send();
            }
            catch (ProcessEngineException e)
            {
                Assert.That(e.Message, Does.Contain("IExecution '" + ExecutionId + "' has not subscribed to a signal event with name 'signal'"));
            }
        }
예제 #28
0
        [Test]   public virtual void testEvaluateDecisionWithLatestBindingDifferentVersions()
        {
            IBpmnModelInstance process = ESS.FW.Bpm.Model.Bpmn.Bpmn.CreateExecutableProcess("process").StartEvent().BusinessRuleTask().CamundaDecisionRef("decision").CamundaDecisionRefBinding("latest").CamundaMapDecisionResult("singleEntry").CamundaResultVariable("decisionVar").CamundaAsyncAfter().EndEvent().Done();

            DeploymentForTenant(TENANT_ONE, DMN_FILE, process);

            DeploymentForTenant(TENANT_TWO, DMN_FILE, process);
            DeploymentForTenant(TENANT_TWO, DMN_FILE_VERSION_TWO);

            IProcessInstance processInstanceOne = runtimeService.CreateProcessInstanceByKey("process").SetVariable("status", "gold").SetProcessDefinitionTenantId(TENANT_ONE).Execute();

            IProcessInstance processInstanceTwo = runtimeService.CreateProcessInstanceByKey("process").SetVariable("status", "gold").SetProcessDefinitionTenantId(TENANT_TWO).Execute();

            Assert.That((string)runtimeService.GetVariable(processInstanceOne.Id, "decisionVar"), Is.EqualTo(RESULT_OF_VERSION_ONE));
            Assert.That((string)runtimeService.GetVariable(processInstanceTwo.Id, "decisionVar"), Is.EqualTo(RESULT_OF_VERSION_TWO));
        }
예제 #29
0
        public virtual void testEnableQueryOfProcessDefinitionAddModelInstancesToDeploymentCache()
        {
            // given
            deploy(ProcessModels.OneTaskProcessWithDocumentation);
            processEngineConfiguration.EnableFetchProcessDefinitionDescription = true;
            IProcessInstance pi = runtimeService.StartProcessInstanceByKey(ProcessModels.ProcessKey);

            // when
            var id = repositoryService.CreateProcessDefinitionQuery(c => c.Key == ProcessModels.ProcessKey).First().Id;

            // then
            DeploymentCache    deploymentCache = processEngineConfiguration.DeploymentCache;
            IBpmnModelInstance modelInstance   = deploymentCache.BpmnModelInstanceCache.Get(pi.ProcessDefinitionId);

            Assert.NotNull(modelInstance);
        }
예제 #30
0
        public void  TestGroupAssignmentToGroupA()
        {
            IDictionary attributeValues = CreateProcessAttributes();

            // start group assignment process instance
            // activity assigned to group A
            IProcessInstance processInstance    = StartGroupAssignmentProcessInstance("uaoga", attributeValues);
            IList            uaogaGroupTaskList = GetGroupTaskList("uaoga");

            Assert.IsFalse(uaogaGroupTaskList.Count == 0);

            IList ubogaGroupTaskList = GetGroupTaskList("uboga");

            Assert.IsFalse(ubogaGroupTaskList.Count == 0);
            IList ucogaGroupTaskList = GetGroupTaskList("ucoga");

            Assert.IsFalse(ucogaGroupTaskList.Count == 0);
            IList uaogbGroupTaskList = GetGroupTaskList("uaogb");

            Assert.IsFalse(uaogbGroupTaskList.Count == 0);
            IList ubogbGroupTaskList = GetGroupTaskList("ubogb");

            Assert.IsFalse(ubogbGroupTaskList.Count == 0);
            IList ucogbGroupTaskList = GetGroupTaskList("ucogb");

            Assert.IsFalse(ucogbGroupTaskList.Count == 0);
            IList uaogcGroupTaskList = GetGroupTaskList("uaogc");

            Assert.IsFalse(uaogcGroupTaskList.Count == 0);
            IList ubogcGroupTaskList = GetGroupTaskList("ubogc");

            Assert.IsFalse(ubogcGroupTaskList.Count == 0);
            IList ucogcGroupTaskList = GetGroupTaskList("ucogc");

            Assert.IsFalse(ucogcGroupTaskList.Count == 0);
            IList uaogdGroupTaskList = GetGroupTaskList("uaogd");

            Assert.IsFalse(uaogdGroupTaskList.Count == 0);
            IList ubogdGroupTaskList = GetGroupTaskList("ubogd");

            Assert.IsFalse(ubogdGroupTaskList.Count == 0);
            IList ucogdGroupTaskList = GetGroupTaskList("ucogd");

            Assert.IsFalse(ucogdGroupTaskList.Count == 0);

            CancelProcessInstance("uaoga", processInstance.Id);
        }
예제 #31
0
        private void Resolve(FlowImpl flow, Relations relations, DbSession dbSession)
        {
            // resolve the flow
            if (relations != null)
            {
                log.Debug("resolving relations : '" + relations + "' on flow '" + flow + "'");
                relations.Resolve(flow);
            }

            // resolve the flow-details
            IEnumerator iter = flow.Logs.GetEnumerator();

            while (iter.MoveNext())
            {
                LogImpl     logImpl     = (LogImpl)iter.Current;
                IEnumerator detailsIter = logImpl.Details.GetEnumerator();
                while (detailsIter.MoveNext())
                {
                    LogDetailImpl LogDetailImpl = (LogDetailImpl)detailsIter.Current;
                    LogDetailImpl.Resolve(dbSession);
                }
            }

            // resolve the attribute values
            iter = flow.AttributeInstances.GetEnumerator();
            while (iter.MoveNext())
            {
                AttributeInstanceImpl attributeInstance = (AttributeInstanceImpl)iter.Current;
                log.Debug("resolving attribute instance : " + attributeInstance.GetValue());
            }

            // resolve the child-flows
            iter = flow.Children.GetEnumerator();
            while (iter.MoveNext())
            {
                FlowImpl subFlow = (FlowImpl)iter.Current;
                Resolve(subFlow, relations, dbSession);
            }

            // resolve the sub-process-flows
            IProcessInstance subProcessInstance = flow.GetSubProcessInstance();

            if (subProcessInstance != null)
            {
                Resolve((FlowImpl)subProcessInstance.RootFlow, relations, dbSession);
            }
        }
        //throws EngineException ,KernelException
        /// <summary>
        /// 判断任务实例是否可以终止
        /// </summary>
        /// <param name="currentSession"></param>
        /// <param name="runtimeContext"></param>
        /// <param name="processInstance"></param>
        /// <param name="taskInstance"></param>
        /// <returns>true表示可以终止,false不能终止</returns>
        public Boolean taskInstanceCanBeCompleted(IWorkflowSession currentSession, RuntimeContext runtimeContext,
            IProcessInstance processInstance, ITaskInstance taskInstance)
        {
            //在Fire Workflow 中,系统默认每个子流程仅创建一个实例,所以当子流程实例完成后,SubflowTaskInstance都可以被completed
            //所以,应该直接返回true;
            return true;

            //如果系统动态创建了多个并发子流程实例,则需要检查是否存在活动的子流程实例,如果存在则返回false,否则返回true。
            //可以用下面的代码实现
            //        IPersistenceService persistenceService = runtimeContext.PersistenceService;
            //        Int32 count = persistenceService.getAliveProcessInstanceCountForParentTaskInstance(taskInstance.Id);
            //        if (count>0){
            //            return false;
            //        }else{
            //            return true;
            //        }
        }
예제 #33
0
        public virtual void canMigrateSharedInstanceWithNoTenant()
        {
            // given
            IProcessDefinition sourceDefinition = testHelper.DeployAndGetDefinition(ProcessModels.OneTaskProcess);
            IProcessDefinition targetDefinition = testHelper.DeployAndGetDefinition(ProcessModels.OneTaskProcess);

            IMigrationPlan migrationPlan = engineRule.RuntimeService.CreateMigrationPlan(sourceDefinition.Id, targetDefinition.Id).MapEqualActivities().Build();

            IProcessInstance processInstance = engineRule.RuntimeService.StartProcessInstanceById(sourceDefinition.Id);

            // when
            engineRule.IdentityService.SetAuthentication("user", null, null);
            engineRule.RuntimeService.NewMigration(migrationPlan).ProcessInstanceIds((processInstance.Id)).Execute();

            // then
            AssertMigratedTo(processInstance, targetDefinition);
        }
예제 #34
0
        public virtual void testResolvesVariablesFromDifferentScopes()
        {
            IDictionary <string, object> variables = new Dictionary <string, object>();

            variables["assignee"] = "michael";

            runtimeService.StartProcessInstanceByKey("oneTaskProcess", variables);
            ITask task = taskService.CreateTaskQuery().First();

            Assert.AreEqual("michael", task.Assignee);

            variables["assignee"] = "johnny";
            IProcessInstance secondInstance = runtimeService.StartProcessInstanceByKey("oneTaskProcess", variables);

            task = taskService.CreateTaskQuery(c => c.ProcessInstanceId == secondInstance.Id).First();
            Assert.AreEqual("johnny", task.Assignee);
        }
예제 #35
0
        public virtual void testSupportsLegacySignalingOnSingleReceiveTask()
        {
            // given: a process instance waiting in the receive task
            IProcessInstance processInstance = runtimeService.StartProcessInstanceByKey("testProcess");

            // expect: there is a message event subscription for the task
            Assert.AreEqual(1, EventSubscriptionList.Count);

            // then: we can signal the waiting receive task
            runtimeService.Signal(getExecutionId(processInstance.Id, "waitState"));

            // expect: subscription is removed
            Assert.AreEqual(0, EventSubscriptionList.Count);

            // expect: this ends the process instance
            AssertProcessEnded(processInstance.Id);
        }
예제 #36
0
 public void WriteToFile(IProcessInstance proc, FinalFile file)
 {
     if (proc.CurrentDictionnaire.IsString(this.stringName))
     {
         if (proc.CurrentScope.Exists(this.varName))
         {
             IData d = proc.CurrentScope.GetVariable(this.varName);
             d.Value        = proc.CurrentDictionnaire.GetString(this.stringName);
             d.IsComputable = false;
         }
         else
         {
             proc.CurrentScope.Add(this.varName, proc.CurrentDictionnaire.GetString(this.stringName), proc.Name, false);
             proc.CurrentProject.Add(new ProjectItem(proc.Name, proc.CurrentPositionExecution, "dictionary string", this.varName, this.stringName));
         }
     }
 }
        [Test]   public virtual void testGetStartFormWithAuthenticatedTenant()
        {
            testRule.DeployForTenant(TENANT_ONE, "resources/api/authorization/formKeyProcess.bpmn20.xml");

            IProcessInstance instance = runtimeService.StartProcessInstanceByKey(PROCESS_DEFINITION_KEY);

            identityService.SetAuthentication("aUserId", null, new List <string>()
            {
                TENANT_ONE
            });

            IStartFormData startFormData = formService.GetStartFormData(instance.ProcessDefinitionId);

            // then
            Assert.NotNull(startFormData);
            Assert.AreEqual("aStartFormKey", startFormData.FormKey);
        }
예제 #38
0
        public virtual void  TestSchedulerThread()
        {
            servicelocator.Scheduler.Start();

            IProcessInstance processInstance = StartNewSchedulerSample1("cg", null);

            System.Int64 flowId = processInstance.RootFlow.Id;
            //sleep 10 seconds to give the scheduler the chance to complete the work
            Thread.Sleep(10000);

            //now ae 'do bloody thing'
            testUtil.PerformActivity("ae", flowId, 0, null, executionComponent);

            //to next activity "do clean thing".
            testUtil.PerformActivity("cg", flowId, 0, null, executionComponent);
            servicelocator.Scheduler.Stop();
        }
예제 #39
0
        public virtual void testAsyncAfterServiceWrappedInParallelMultiInstance()
        {
            // start process instance
            IProcessInstance pi = runtimeService.StartProcessInstanceByKey("testProcess");

            // listeners and behavior should be invoked by now
            AssertListenerStartInvoked(pi);
            AssertBehaviorInvoked(pi, 5);
            AssertListenerEndInvoked(pi);

            // the process should Wait *after* execute each service task wrapped in the multi-instance body
            Assert.AreEqual(5L, managementService.CreateJobQuery().Count());
            // execute all jobs - one for each service task
            ExecuteAvailableJobs(5);

            AssertProcessEnded(pi.Id);
        }
        /// <summary>
        /// 判断任务实例是否可以终止
        /// </summary>
        /// <param name="currentSession"></param>
        /// <param name="runtimeContext"></param>
        /// <param name="processInstance"></param>
        /// <param name="taskInstance"></param>
        /// <returns>true表示可以终止,false不能终止</returns>
        public Boolean taskInstanceCanBeCompleted(IWorkflowSession currentSession, RuntimeContext runtimeContext,
                                                  IProcessInstance processInstance, ITaskInstance taskInstance)//throws EngineException ,KernelException
        {
            //在Fire Workflow 中,系统默认每个子流程仅创建一个实例,所以当子流程实例完成后,SubflowTaskInstance都可以被completed
            //所以,应该直接返回true;
            return(true);

            //如果系统动态创建了多个并发子流程实例,则需要检查是否存在活动的子流程实例,如果存在则返回false,否则返回true。
            //可以用下面的代码实现
            //        IPersistenceService persistenceService = runtimeContext.PersistenceService;
            //        Int32 count = persistenceService.getAliveProcessInstanceCountForParentTaskInstance(taskInstance.Id);
            //        if (count>0){
            //            return false;
            //        }else{
            //            return true;
            //        }
        }
예제 #41
0
//JAVA TO C# CONVERTER TODO Resources.Task: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Deployment public void testGroovyScriptExecution()
        public virtual void testGroovyScriptExecution()
        {
            try
            {
                processEngineConfiguration.IsAutoStoreScriptVariables = true;
                int[]            inputArray = new int[] { 1, 2, 3, 4, 5 };
                IProcessInstance pi         = runtimeService.StartProcessInstanceByKey("scriptExecution"
                                                                                       , CollectionUtil.SingletonMap("inputArray", inputArray));

                int?result = (int?)runtimeService.GetVariable(pi.Id, "sum");
                Assert.AreEqual(15, result.Value);
            }
            finally
            {
                processEngineConfiguration.IsAutoStoreScriptVariables = false;
            }
        }
        // throws EngineException, KernelException
        public void run(IWorkflowSession currentSession, RuntimeContext runtimeContext, IProcessInstance processInstance, ITaskInstance taskInstance)
        {
            if (taskInstance.TaskType!= TaskTypeEnum.FORM)//!Task.FORM.Equals(taskInstance.TaskType))
            {
                throw new EngineException(processInstance, taskInstance.Activity,
                        "DefaultFormTaskInstanceRunner:TaskInstance的任务类型错误,只能为FORM类型");
            }

            DynamicAssignmentHandler dynamicAssignmentHandler = ((WorkflowSession)currentSession).consumeCurrentDynamicAssignmentHandler();
            FormTask task = (FormTask)taskInstance.Task;
            // performer(id,name,type,handler)
            Participant performer = task.Performer;
            if (performer == null || performer.AssignmentHandler.Trim().Equals(""))
            {
                throw new EngineException(processInstance, taskInstance.Activity,
                        "流程定义错误,Form类型的 task必须指定performer及其AssignmentHandler");
            }
            assign(currentSession, processInstance, runtimeContext, taskInstance, task, performer, dynamicAssignmentHandler);
        }
        // throws EngineException, KernelException
        public void run(IWorkflowSession currentSession, RuntimeContext runtimeContext, IProcessInstance processInstance, ITaskInstance taskInstance)
        {
            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 ITaskInstance createTaskInstance(IWorkflowSession currentSession,
            RuntimeContext runtimeContxt, IProcessInstance processInstance,
            Task task, Activity activity)
        {
            GoodsDeliverTaskInstance taskInst = new GoodsDeliverTaskInstance();

            String sn = (String)processInstance.getProcessInstanceVariable("sn");
            taskInst.Sn = sn;

            String customerName = (String)processInstance.getProcessInstanceVariable("customerName");
            taskInst.CustomerName = customerName;

            String goodsName = (String)processInstance.getProcessInstanceVariable("goodsName");
            taskInst.GoodsName = goodsName;

            long quantity = (long)processInstance.getProcessInstanceVariable("quantity");
            taskInst.Quantity = quantity;

            //taskInst.BizInfo=

            return taskInst;
        }
        /// <summary>
        /// 挂起流程实例
        /// </summary>
        public bool SuspendProcessInstance(IProcessInstance processInstance) {
            OracleTransaction transaction = OracleHelper.GetOracleTransaction(this.connectionString);
            try
            {

                String sql = " update t_ff_rt_processinstance set suspended=1 where id=:1 ";
                int count = OracleHelper.ExecuteNonQuery(transaction, CommandType.Text, sql,
                    OracleHelper.NewOracleParameter(":1", OracleType.VarChar, 50, processInstance.Id)
                    );
                if (count <= 0)
                {
                    transaction.Rollback();
                    return false;
                }

                // 挂起对应的TaskInstance
                String sql2 = " update t_ff_rt_taskinstance set suspended=1 where processinstance_id=:1 ";
                count = OracleHelper.ExecuteNonQuery(transaction, CommandType.Text, sql2,
                    OracleHelper.NewOracleParameter(":1", OracleType.VarChar, 50, processInstance.Id)
                    );
                if (count <= 0)
                {
                    transaction.Rollback();
                    return false;
                }

                processInstance.Suspended=true;

                transaction.Commit();
                return true;

            }
            catch
            {
                transaction.Rollback();
                return false;
            }
            finally
            {
                if (transaction.Connection.State != ConnectionState.Closed)
                {
                    transaction.Connection.Close();
                    transaction.Dispose();
                }
            }
        }
 // throws EngineException
 public ITaskInstance createTaskInstance(IWorkflowSession currentSession, RuntimeContext runtimeContxt,
     IProcessInstance processInstance, Task task, Activity activity)
 {
     TaskInstance taskInstance = new TaskInstance();
     return taskInstance;
 }
        /// <summary>
        /// 终止流程实例。将流程实例、活动的TaskInstance、活动的WorkItem的状态设置为CANCELED;并删除所有的token
        /// </summary>
        public bool AbortProcessInstance(IProcessInstance processInstance)
        {
            SqlTransaction transaction = SqlServerHelper.GetSqlTransaction(this.connectionString);
            try
            {
                // 更新流程状态,设置为canceled
                DateTime now = this.RuntimeContext.CalendarService.getSysDate();
                String processSql = "update t_ff_rt_processinstance set state=" + (int)ProcessInstanceEnum.CANCELED
                        + ",end_time=@1 where id=@2 ";
                int count = SqlServerHelper.ExecuteNonQuery(transaction, CommandType.Text, processSql,
                    SqlServerHelper.NewSqlParameter("@1", SqlDbType.DateTime, 11, now),
                    SqlServerHelper.NewSqlParameter("@2", SqlDbType.VarChar, 50, processInstance.Id)
                    );
                if (count <= 0)
                {
                    transaction.Rollback();
                    return false;
                }


                // 更新所有的任务实例状态为canceled
                String taskSql = " update t_ff_rt_taskinstance set state=" + (int)TaskInstanceStateEnum.CANCELED
                        + ",end_time=@1,can_be_withdrawn=0 " + "  where processinstance_id=@2 and (state=0 or state=1)";
                count = SqlServerHelper.ExecuteNonQuery(transaction, CommandType.Text, taskSql,
                    SqlServerHelper.NewSqlParameter("@1", SqlDbType.DateTime, 11, now),
                    SqlServerHelper.NewSqlParameter("@2", SqlDbType.VarChar, 50, processInstance.Id)
                    );
                if (count <= 0)
                {
                    transaction.Rollback();
                    return false;
                }

                // 更新所有工作项的状态为canceled
                String workItemSql = " update t_ff_rt_workitem set state="
                        + (int)WorkItemEnum.CANCELED
                        + ",end_time=@1  "
                        + " where taskinstance_id in (select a.id  from t_ff_rt_taskinstance a,t_ff_rt_workitem b where a.id=b.taskinstance_id and a.processinstance_id=@2 ) and (state=0 or state=1) ";
                count = SqlServerHelper.ExecuteNonQuery(transaction, CommandType.Text, workItemSql,
                    SqlServerHelper.NewSqlParameter("@1", SqlDbType.DateTime, 11, now),
                    SqlServerHelper.NewSqlParameter("@2", SqlDbType.VarChar, 50, processInstance.Id)
                    );
                if (count <= 0)
                {
                    transaction.Rollback();
                    return false;
                }

                // 删除所有的token
                String tokenSql = " delete from t_ff_rt_token where processinstance_id=@1  ";
                count = SqlServerHelper.ExecuteNonQuery(transaction, CommandType.Text, tokenSql,
                    SqlServerHelper.NewSqlParameter("@1", SqlDbType.VarChar, 50, processInstance.Id)
                    );
                if (count <= 0)
                {
                    transaction.Rollback();
                    return false;
                }

                // 数据库操作成功后,更新对象的状态
                processInstance.State = ProcessInstanceEnum.CANCELED;

                transaction.Commit();
                return true;

            }
            catch
            {
                transaction.Rollback();
                return false;
            }
            finally
            {
                if (transaction.Connection.State != ConnectionState.Closed)
                {
                    transaction.Connection.Close();
                    transaction.Dispose();
                }
            }
        }
        /// <summary>
        /// 恢复流程实例
        /// </summary>
        public bool RestoreProcessInstance(IProcessInstance processInstance)
        {
            SqlTransaction transaction = SqlServerHelper.GetSqlTransaction(this.connectionString);
            try
            {
                String sql = " update t_ff_rt_processinstance set suspended=0 where id=@1 ";
                int count = SqlServerHelper.ExecuteNonQuery(transaction, CommandType.Text, sql,
                    SqlServerHelper.NewSqlParameter("@1", SqlDbType.VarChar, 50, processInstance.Id)
                    );
                if (count <= 0)
                {
                    transaction.Rollback();
                    return false;
                }

                // 恢复对应的TaskInstance
                String sql2 = " update t_ff_rt_taskinstance set suspended=0 where processinstance_id=@1";
                count = SqlServerHelper.ExecuteNonQuery(transaction, CommandType.Text, sql2,
                    SqlServerHelper.NewSqlParameter("@1", SqlDbType.VarChar, 50, processInstance.Id)
                    );
                if (count <= 0)
                {
                    transaction.Rollback();
                    return false;
                }

                processInstance.Suspended = false;

                transaction.Commit();
                return true;

            }
            catch
            {
                transaction.Rollback();
                return false;
            }
            finally
            {
                if (transaction.Connection.State != ConnectionState.Closed)
                {
                    transaction.Connection.Close();
                    transaction.Dispose();
                }
            }
        }
예제 #49
0
 public virtual void SetSubProcessInstance(IProcessInstance subProcessInstance)
 {
     _subProcessInstances = new ListSet();
     _subProcessInstances.Add(subProcessInstance);
 }
예제 #50
0
 public void SetProcessInstance(IProcessInstance processInstance)
 {
     this._processInstance = (ProcessInstanceImpl) processInstance;
 }
예제 #51
0
        /// <summary>
        /// 终止当前TaskInstance,检查是否可以中止当前ActivityInstance,如果可以,
        /// 则结束当前ActivityInstance,并触发targetActivityInstance或后继ActivityInstance
        /// </summary>
        /// <param name="currentSession"></param>
        /// <param name="processInstance"></param>
        /// <param name="taskInstance"></param>
        /// <param name="targetActivityInstance"></param>
        public void completeTaskInstance(IWorkflowSession currentSession, IProcessInstance processInstance,
            ITaskInstance taskInstance, IActivityInstance targetActivityInstance)
        {
            //如果TaskInstance处于结束状态,则直接返回
            if (taskInstance.State == TaskInstanceStateEnum.COMPLETED || taskInstance.State == TaskInstanceStateEnum.CANCELED)
            {
                return;
            }
            if (taskInstance.State == TaskInstanceStateEnum.INITIALIZED)
            {
                WorkflowProcess process = taskInstance.WorkflowProcess;
                throw new EngineException(taskInstance.ProcessInstanceId, process,
                        taskInstance.TaskId,
                        "Complete task insatance failed.The state of the task insatnce[id=" + taskInstance.Id + "] is " + taskInstance.State);
            }
            if (taskInstance.IsSuspended())
            {
                WorkflowProcess process = taskInstance.WorkflowProcess;
                throw new EngineException(taskInstance.ProcessInstanceId, process,
                        taskInstance.TaskId,
                        "Complete task insatance failed. The task instance [id=" + taskInstance.Id + "] is suspended");
            }

            if (targetActivityInstance != null)
            {
                ((TaskInstance)taskInstance).TargetActivityId=targetActivityInstance.Activity.Id;
            }

            IPersistenceService persistenceService = this.RuntimeContext.PersistenceService;

            //第一步,首先结束当前taskInstance
            if (!this.taskInstanceCanBeCompleted(currentSession, this.RuntimeContext, processInstance, taskInstance))
            {
                return;
            }
            ((TaskInstance)taskInstance).State=TaskInstanceStateEnum.COMPLETED;
            ((TaskInstance)taskInstance).CanBeWithdrawn=false;
            ((TaskInstance)taskInstance).EndTime=RuntimeContext.CalendarService.getSysDate();
            persistenceService.SaveOrUpdateTaskInstance(taskInstance);
            //触发相应的事件
            TaskInstanceEvent e = new TaskInstanceEvent();
            e.Source=taskInstance;
            e.WorkflowSession=currentSession;
            e.ProcessInstance=processInstance;
            e.EventType = TaskInstanceEventEnum.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.ProcessInstanceId, taskInstance.ActivityId);
            //        System.out.println("Inside TaskInstance.complete(targetActivityInstance):: tokens.size is "+tokens.Count);
            if (tokens == null || tokens.Count == 0)
            {
                return;//表明activityInstance已经结束了。
            }
            if (tokens.Count > 1)
            {
                WorkflowProcess process = taskInstance.WorkflowProcess;
                throw new EngineException(taskInstance.ProcessInstanceId, process, taskInstance.TaskId,
                        "与activityId=" + taskInstance.ActivityId + "对应的token数量(=" + tokens.Count + ")不正确,正确只能为1,因此无法完成complete操作");
            }
            IToken token = tokens[0];
            //stepNumber不相等,不允许执行结束操作。
            if (token.StepNumber != taskInstance.StepNumber)
            {
                return;
            }
            if (token.IsAlive == false)
            {
                WorkflowProcess process = taskInstance.WorkflowProcess;
                throw new EngineException(taskInstance.ProcessInstanceId, process,
                        taskInstance.TaskId,
                        "与activityId=" + taskInstance.ActivityId + "对应的token.alive=false,因此无法完成complete操作");
            }

            INetInstance netInstance = this.RuntimeContext.KernelManager.getNetInstance(taskInstance.ProcessId, taskInstance.Version);
            Object obj = netInstance.getWFElementInstance(taskInstance.ActivityId);
            if (obj == null)
            {
                WorkflowProcess process = taskInstance.WorkflowProcess;
                throw new EngineException(taskInstance.ProcessInstanceId, process, taskInstance.TaskId,
                        "系统没有找到与activityId=" + taskInstance.ActivityId + "对应activityInstance,无法执行complete操作。");
            }

            token.ProcessInstance = processInstance;

            ((IActivityInstance)obj).complete(token, targetActivityInstance);
        }
        // throws EngineException, KernelException
        public void run(IWorkflowSession currentSession, RuntimeContext runtimeContext,
            IProcessInstance processInstance, ITaskInstance taskInstance)
        {
            if (taskInstance.TaskType != TaskTypeEnum.SUBFLOW)
            {
                throw new EngineException(processInstance, taskInstance.Activity,
                        "DefaultSubflowTaskInstanceRunner:TaskInstance的任务类型错误,只能为SUBFLOW类型");
            }
            Task task = taskInstance.Task;
            SubWorkflowProcess Subflow = ((SubflowTask)task).SubWorkflowProcess;

            WorkflowDefinition subWorkflowDef = runtimeContext.DefinitionService.GetTheLatestVersionOfWorkflowDefinition(Subflow.WorkflowProcessId);
            if (subWorkflowDef == null)
            {
                WorkflowProcess parentWorkflowProcess = taskInstance.WorkflowProcess;
                throw new EngineException(taskInstance.ProcessInstanceId, parentWorkflowProcess, taskInstance.TaskId,
                        "系统中没有Id为" + Subflow.WorkflowProcessId + "的流程定义");
            }
            WorkflowProcess subWorkflowProcess = subWorkflowDef.getWorkflowProcess();

            if (subWorkflowProcess == null)
            {
                WorkflowProcess parentWorkflowProcess = taskInstance.WorkflowProcess;
                throw new EngineException(taskInstance.ProcessInstanceId, parentWorkflowProcess, taskInstance.TaskId,
                        "系统中没有Id为" + Subflow.WorkflowProcessId + "的流程定义");
            }

            IPersistenceService persistenceService = runtimeContext.PersistenceService;
            //更改任务的状态和开始时间
            ((TaskInstance)taskInstance).State = TaskInstanceStateEnum.RUNNING;
            ((TaskInstance)taskInstance).StartedTime = runtimeContext.CalendarService.getSysDate();
            persistenceService.SaveOrUpdateTaskInstance(taskInstance);

            IProcessInstance subProcessInstance = currentSession.createProcessInstance(subWorkflowProcess.Name, taskInstance);

            //初始化流程变量,从父实例获得初始值
            Dictionary<String, Object> processVars = ((TaskInstance)taskInstance).AliveProcessInstance.ProcessInstanceVariables;
            List<DataField> datafields = subWorkflowProcess.DataFields;
            for (int i = 0; datafields != null && i < datafields.Count; i++)
            {
                DataField df = (DataField)datafields[i];
                if (df.DataType == DataTypeEnum.STRING)
                {
                    if (processVars[df.Name] != null && (processVars[df.Name] is String))
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, processVars[df.Name]);
                    }
                    else if (df.InitialValue != null)
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, df.InitialValue);
                    }
                    else
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, "");
                    }
                }
                else if (df.DataType == DataTypeEnum.INTEGER)
                {
                    if (processVars[df.Name] != null && (processVars[df.Name] is Int32))
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, processVars[df.Name]);
                    }
                    else if (df.InitialValue != null)
                    {
                        try
                        {
                            Int32 intValue = Int32.Parse(df.InitialValue);
                            subProcessInstance.setProcessInstanceVariable(df.Name, intValue);
                        }
                        catch { }
                    }
                    else
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, (Int32)0);
                    }
                }
                else if (df.DataType == DataTypeEnum.FLOAT)
                {
                    if (processVars[df.Name] != null && (processVars[df.Name] is float))
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, processVars[df.Name]);
                    }
                    else if (df.InitialValue != null)
                    {
                        float floatValue = float.Parse(df.InitialValue);
                        subProcessInstance.setProcessInstanceVariable(df.Name, floatValue);
                    }
                    else
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, (float)0);
                    }
                }
                else if (df.DataType == DataTypeEnum.BOOLEAN)
                {
                    if (processVars[df.Name] != null && (processVars[df.Name] is Boolean))
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, processVars[df.Name]);
                    }
                    else if (df.InitialValue != null)
                    {
                        Boolean booleanValue = Boolean.Parse(df.InitialValue);
                        subProcessInstance.setProcessInstanceVariable(df.Name, booleanValue);
                    }
                    else
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, false);
                    }
                }
                else if (df.DataType == DataTypeEnum.DATETIME)
                {
                    //TODO 需要完善一下 ( 父子流程数据传递——时间类型的数据还未做传递-不知道为什么?)
                    //wmj2003 20090925 补充上了
                    if (processVars[df.Name] != null && (processVars[df.Name] is DateTime))
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, processVars[df.Name]);
                    }
                    else if (df.InitialValue != null)
                    {
                        try
                        {
                            DateTime dateTmp = DateTime.Parse(df.InitialValue);
                            subProcessInstance.setProcessInstanceVariable(df.Name, dateTmp);
                        }
                        catch
                        {
                            subProcessInstance.setProcessInstanceVariable(df.Name, null);
                        }
                    }
                }
                //TODO 应将下面这句删除!这里还需要吗?应该直接subProcessInstance.run()就可以了。
                runtimeContext.PersistenceService.SaveOrUpdateProcessInstance(subProcessInstance);
                subProcessInstance.run();
            }
        }
예제 #53
0
        /// <summary>
        /// 中止当前的TaskInstance,并使得流程流转到指定的环节。
        /// </summary>
        /// <param name="currentSession"></param>
        /// <param name="processInstance"></param>
        /// <param name="taskInstance"></param>
        /// <param name="targetActivityId"></param>
        public void abortTaskInstance(IWorkflowSession currentSession,
            IProcessInstance processInstance, ITaskInstance taskInstance,
            String targetActivityId)
        {
            // 如果TaskInstance处于结束状态,则直接返回
            if (taskInstance.State == TaskInstanceStateEnum.COMPLETED || taskInstance.State == TaskInstanceStateEnum.CANCELED)
            {
                return;
            }
            // Initialized状态的TaskInstance也可以中止,20090830
            // if (taskInstance.State == ITaskInstance.INITIALIZED) {
            // WorkflowProcess process = taskInstance.getWorkflowProcess();
            // throw new EngineException(taskInstance.getProcessInstanceId(),
            // process,
            // taskInstance.getTaskId(),
            // "Complete task insatance failed.The state of the task insatnce[id=" +
            // taskInstance.getId() + "] is " + taskInstance.State);
            // }
            if (taskInstance.IsSuspended())
            {
                WorkflowProcess process = taskInstance.WorkflowProcess;
                throw new EngineException(taskInstance.ProcessInstanceId,
                        process, taskInstance.TaskId,
                        "Abort task insatance failed. The task instance [id="
                                + taskInstance.Id + "] is suspended");
            }

            // 1)检查是否在同一个“执行线”上
            WorkflowProcess workflowProcess = taskInstance.WorkflowProcess;
            if (targetActivityId != null)
            {
                String thisActivityId = taskInstance.ActivityId;
                Boolean isInSameLine = workflowProcess.isInSameLine(thisActivityId,
                        targetActivityId);
                if (!isInSameLine)
                {
                    throw new EngineException(
                            taskInstance.ProcessInstanceId,
                            taskInstance.WorkflowProcess,
                            taskInstance.TaskId,
                            "Jumpto refused because of the current activitgy and the target activity are NOT in the same 'Execution Thread'.");
                }
            }

            INetInstance netInstance = this.RuntimeContext.KernelManager.getNetInstance(workflowProcess.Id, taskInstance.Version);
            IActivityInstance targetActivityInstance = (IActivityInstance)netInstance.getWFElementInstance(targetActivityId);

            IActivityInstance thisActivityInstance = (IActivityInstance)netInstance.getWFElementInstance(taskInstance.ActivityId);
            if (thisActivityInstance == null)
            {
                WorkflowProcess process = taskInstance.WorkflowProcess;
                throw new EngineException(taskInstance.ProcessInstanceId, process, taskInstance.TaskId,
                    "系统没有找到与activityId=" + taskInstance.ActivityId + "对应activityInstance,无法执行abort操作。");
            }

            if (targetActivityInstance != null)
            {
                ((TaskInstance)taskInstance).TargetActivityId=targetActivityInstance.Activity.Id;
            }

            IPersistenceService persistenceService = this.RuntimeContext.PersistenceService;

            // 第一步,首先Abort当前taskInstance
            persistenceService.AbortTaskInstance((TaskInstance)taskInstance);

            // 触发相应的事件
            TaskInstanceEvent e = new TaskInstanceEvent();
            e.Source=taskInstance;
            e.WorkflowSession=currentSession;
            e.ProcessInstance=processInstance;
            e.EventType = TaskInstanceEventEnum.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.ProcessInstanceId, taskInstance.ActivityId);
            // System.out.println("Inside TaskInstance.complete(targetActivityInstance):: tokens.size is "+tokens.size());
            if (tokens == null || tokens.Count == 0)
            {
                return;// 表明activityInstance已经结束了。
            }
            if (tokens.Count > 1)
            {
                WorkflowProcess process = taskInstance.WorkflowProcess;
                throw new EngineException(taskInstance.ProcessInstanceId, process, taskInstance.TaskId,
                    "与activityId=" + taskInstance.ActivityId + "对应的token数量(=" + tokens.Count + ")不正确,正确只能为1,因此无法完成complete操作");
            }
            IToken token = tokens[0];
            // stepNumber不相等,不允许执行结束操作。
            if (token.StepNumber != taskInstance.StepNumber)
            {
                return;
            }
            if (token.IsAlive == false)
            {
                WorkflowProcess process = taskInstance.WorkflowProcess;
                throw new EngineException(taskInstance.ProcessInstanceId, process, taskInstance.TaskId,
                    "与activityId=" + taskInstance.ActivityId + "对应的token.alive=false,因此无法完成complete操作");
            }

            token.ProcessInstance = processInstance;

            thisActivityInstance.complete(token, targetActivityInstance);
        }
예제 #54
0
        public WorkItem createWorkItem(IWorkflowSession currentSession, IProcessInstance processInstance, ITaskInstance taskInstance, String actorId)
        {
            IPersistenceService persistenceService = this.RuntimeContext.PersistenceService;

            WorkItem wi = new WorkItem();
            wi.TaskInstance=taskInstance;
            wi.ActorId=actorId;
            wi.State=WorkItemEnum.INITIALIZED;
            wi.CreatedTime = this.RuntimeContext.CalendarService.getSysDate();
            wi.RuntimeContext = this.RuntimeContext;
            wi.CurrentWorkflowSession=currentSession;
            //保存到数据库
            persistenceService.SaveOrUpdateWorkItem(wi);

            //触发事件
            //触发相应的事件
            TaskInstanceEvent e = new TaskInstanceEvent();
            e.Source=taskInstance;
            e.WorkItem=wi;
            e.WorkflowSession=currentSession;
            e.ProcessInstance=processInstance;

            e.EventType = TaskInstanceEventEnum.AFTER_WORKITEM_CREATED;
            if (this.DefaultTaskInstanceEventListener != null)
            {
                this.DefaultTaskInstanceEventListener.onTaskInstanceEventFired(e);
            }
            this.fireTaskInstanceEvent(taskInstance, e);

            return wi;
        }
예제 #55
0
        /// <summary>
        /// 启动TaskInstance。
        /// 该方法定义为final,不允许子类扩展。
        /// </summary>
        public void startTaskInstance(IWorkflowSession currentSession, IProcessInstance processInstance, ITaskInstance taskInstance)
        {
            //触发事件
            TaskInstanceEvent e = new TaskInstanceEvent();
            e.Source=taskInstance;
            e.WorkflowSession=currentSession;
            e.ProcessInstance=processInstance;
            e.EventType = TaskInstanceEventEnum.BEFORE_TASK_INSTANCE_START;
            if (DefaultTaskInstanceEventListener != null)
            {
                DefaultTaskInstanceEventListener.onTaskInstanceEventFired(e);
            }
            this.fireTaskInstanceEvent(taskInstance, e);

            ((TaskInstance)taskInstance).State=TaskInstanceStateEnum.RUNNING;
            ((TaskInstance)taskInstance).StartedTime=this.RuntimeContext.CalendarService.getSysDate();
            this.RuntimeContext.PersistenceService.SaveOrUpdateTaskInstance(taskInstance);

            Task task = taskInstance.Task;
            String taskInstanceRunnerName = null;
            ITaskInstanceRunner taskInstanceRunner = null;

            TaskTypeEnum taskType = task.TaskType;

            taskInstanceRunnerName = task.TaskInstanceRunner;
            if (!String.IsNullOrEmpty(taskInstanceRunnerName.Trim()))
            {
                IBeanFactory beanFactory = this.RuntimeContext.BeanFactory;
                taskInstanceRunner = (ITaskInstanceRunner)beanFactory.GetBean(taskInstanceRunnerName);
            }

            if (taskInstanceRunner == null)
            {
                if (TaskTypeEnum.FORM == taskType)
                {
                    taskInstanceRunnerName = processInstance.WorkflowProcess.FormTaskInstanceRunner;
                }
                else if (TaskTypeEnum.TOOL == taskType)
                {
                    taskInstanceRunnerName = processInstance.WorkflowProcess.ToolTaskInstanceRunner;
                }
                else if (TaskTypeEnum.SUBFLOW == taskType)
                {
                    taskInstanceRunnerName = processInstance.WorkflowProcess.SubflowTaskInstanceRunner;
                }
                if (!String.IsNullOrEmpty(taskInstanceRunnerName.Trim()))
                {
                    IBeanFactory beanFactory = this.RuntimeContext.BeanFactory;
                    taskInstanceRunner = (ITaskInstanceRunner)beanFactory.GetBean(taskInstanceRunnerName);
                }
            }

            if (taskInstanceRunner == null)
            {
                if (TaskTypeEnum.FORM == taskType)
                {
                    taskInstanceRunner = DefaultFormTaskInstanceRunner;
                }
                else if (TaskTypeEnum.TOOL == taskType)
                {
                    taskInstanceRunner = DefaultToolTaskInstanceRunner;
                }
                else if (TaskTypeEnum.SUBFLOW == taskType)
                {
                    taskInstanceRunner = DefaultSubflowTaskInstanceRunner;
                }
            }
            if (taskInstanceRunner != null)
            {
                taskInstanceRunner.run(currentSession, this.RuntimeContext, processInstance, taskInstance);
            }
            else
            {
                WorkflowProcess process = taskInstance.WorkflowProcess;
                throw new EngineException(taskInstance.ProcessInstanceId, process,
                        taskInstance.TaskId,
                        "无法获取TaskInstanceRunner,TaskId=" + task.Id + ", taskType=" + taskInstance.TaskType);
            }
        }
예제 #56
0
        /// <summary>
        /// 判断TaskInstance是否可以结束,缺省的判断规则是:没有活动的WorkItem即可结束。
        /// 业务代码可以重载该函数,对特定的Task采取特殊的判断规则。
        /// </summary>
        /// <param name="currentSession"></param>
        /// <param name="runtimeContext"></param>
        /// <param name="processInstance"></param>
        /// <param name="taskInstance"></param>
        /// <returns></returns>
        protected Boolean taskInstanceCanBeCompleted(IWorkflowSession currentSession, RuntimeContext runtimeContext,
            IProcessInstance processInstance, ITaskInstance taskInstance)
        {
            Task task = taskInstance.Task;
            String taskInstanceCompletionEvaluatorName = null;
            ITaskInstanceCompletionEvaluator taskInstanceCompletionEvaluator = null;

            TaskTypeEnum taskType = task.TaskType;

            taskInstanceCompletionEvaluatorName = task.TaskInstanceCompletionEvaluator;
            if (!String.IsNullOrEmpty(taskInstanceCompletionEvaluatorName.Trim()))
            {
                IBeanFactory beanFactory = runtimeContext.BeanFactory;
                taskInstanceCompletionEvaluator = (ITaskInstanceCompletionEvaluator)beanFactory.GetBean(taskInstanceCompletionEvaluatorName);
            }

            if (taskInstanceCompletionEvaluator == null)
            {
                if (TaskTypeEnum.FORM == taskType)
                {
                    taskInstanceCompletionEvaluatorName = processInstance.WorkflowProcess.FormTaskInstanceCompletionEvaluator;
                }
                else if (TaskTypeEnum.TOOL == taskType)
                {
                    taskInstanceCompletionEvaluatorName = processInstance.WorkflowProcess.ToolTaskInstanceCompletionEvaluator;
                }
                else if (TaskTypeEnum.SUBFLOW == taskType)
                {
                    taskInstanceCompletionEvaluatorName = processInstance.WorkflowProcess.SubflowTaskInstanceCompletionEvaluator;
                }
                if (!String.IsNullOrEmpty(taskInstanceCompletionEvaluatorName.Trim()))
                {
                    IBeanFactory beanFactory = runtimeContext.BeanFactory;
                    taskInstanceCompletionEvaluator = (ITaskInstanceCompletionEvaluator)beanFactory.GetBean(taskInstanceCompletionEvaluatorName);
                }
            }

            if (taskInstanceCompletionEvaluator == null)
            {
                if (TaskTypeEnum.FORM == taskType)
                {
                    taskInstanceCompletionEvaluator = this.DefaultFormTaskInstanceCompletionEvaluator;
                }
                else if (TaskTypeEnum.TOOL == taskType)
                {
                    taskInstanceCompletionEvaluator = this.DefaultToolTaskInstanceCompletionEvaluator;
                }
                else if (TaskTypeEnum.SUBFLOW == taskType)
                {
                    taskInstanceCompletionEvaluator = this.DefaultSubflowTaskInstanceCompletionEvaluator;
                }
            }
            if (taskInstanceCompletionEvaluator != null)
            {
                return taskInstanceCompletionEvaluator.taskInstanceCanBeCompleted(currentSession, runtimeContext, processInstance, taskInstance);
            }
            else
            {
                WorkflowProcess process = taskInstance.WorkflowProcess;
                throw new EngineException(taskInstance.ProcessInstanceId, process, taskInstance.TaskId,
                        "无法获取TaskInstanceCompletionEvaluator,TaskId=" + task.Id + ", taskType=" + taskInstance.TaskType);
            }
        }
예제 #57
0
        // throws EngineException
        public ITaskInstance createTaskInstance(IWorkflowSession currentSession, IProcessInstance processInstance, Task task,
            Activity activity)
        {
            //如果loopStrategy为SKIP且Task被执行过,则直接返回null;
            IPersistenceService persistenceService = this.RuntimeContext.PersistenceService;
            LoopStrategyEnum loopStrategy = task.LoopStrategy;
            if (LoopStrategyEnum.SKIP == loopStrategy && !currentSession.isInWithdrawOrRejectOperation())
            {
                //检查是否已经执行过的task instance
                Int32 count = persistenceService.GetCompletedTaskInstanceCountForTask(processInstance.Id, task.Id);
                if (count > 0)
                {
                    return null;
                }
            }

            String taskInstanceCreatorName = null;
            ITaskInstanceCreator taskInstanceCreator = null;

            //首先查找Task级别的TaskInstanceCreator
            taskInstanceCreatorName = task.TaskInstanceCreator;
            if (!String.IsNullOrEmpty(taskInstanceCreatorName.Trim()))
            {
                IBeanFactory beanFactory = this.RuntimeContext.BeanFactory;
                taskInstanceCreator = (ITaskInstanceCreator)beanFactory.GetBean(taskInstanceCreatorName);
            }
            //如果没有,则查询流程级别的TaskInstanceCreator
            if (taskInstanceCreator == null)
            {
                taskInstanceCreatorName = processInstance.WorkflowProcess.TaskInstanceCreator;
                if (!String.IsNullOrEmpty(taskInstanceCreatorName.Trim()))
                {
                    IBeanFactory beanFactory = this.RuntimeContext.BeanFactory;
                    taskInstanceCreator = (ITaskInstanceCreator)beanFactory.GetBean(taskInstanceCreatorName);
                }
            }

            //如果流程定义中也没有指定TaskInstanceCreator,则用缺省的
            if (taskInstanceCreator == null)
            {
                taskInstanceCreator = DefaultTaskInstanceCreator;
            }

            return taskInstanceCreator.createTaskInstance(currentSession, RuntimeContext, processInstance, task, activity);
        }
     /// <summary>
     /// 插入或者更新ProcessInstance流程实例
     /// </summary>
     public bool SaveOrUpdateProcessInstance(IProcessInstance processInstance)
     {
         if (String.IsNullOrEmpty(processInstance.Id))
         {
             processInstance.Id = Guid.NewGuid().ToString("N");
             return SaveProcessInstance(processInstance);
         }
         else
         {
             string update = "UPDATE T_FF_RT_PROCESSINSTANCE SET " +
                  "PROCESS_ID=@2, VERSION=@3, NAME=@4, DISPLAY_NAME=@5, STATE=@6, " +
                  "SUSPENDED=@7, CREATOR_ID=@8, CREATED_TIME=@9, STARTED_TIME=@10, EXPIRED_TIME=@11, " +
                  "END_TIME=@12, PARENT_PROCESSINSTANCE_ID=@13, PARENT_TASKINSTANCE_ID=@14 WHERE ID=@1";
             SqlParameter[] updateParms = { 
 				SqlServerHelper.NewSqlParameter("@2", SqlDbType.VarChar, 100, processInstance.ProcessId), 
 				SqlServerHelper.NewSqlParameter("@3", SqlDbType.Int, processInstance.Version), 
 				SqlServerHelper.NewSqlParameter("@4", SqlDbType.VarChar, 100, processInstance.Name), 
 				SqlServerHelper.NewSqlParameter("@5", SqlDbType.VarChar, 128, processInstance.DisplayName), 
 				SqlServerHelper.NewSqlParameter("@6", SqlDbType.Int, (int)processInstance.State), 
 				SqlServerHelper.NewSqlParameter("@7", SqlDbType.SmallInt, SqlServerHelper.OraBit(processInstance.Suspended)), 
 				SqlServerHelper.NewSqlParameter("@8", SqlDbType.VarChar, 50, processInstance.CreatorId), 
 				SqlServerHelper.NewSqlParameter("@9", SqlDbType.DateTime, 11, processInstance.CreatedTime), 
 				SqlServerHelper.NewSqlParameter("@10", SqlDbType.DateTime, 11, processInstance.StartedTime), 
 				SqlServerHelper.NewSqlParameter("@11", SqlDbType.DateTime, 11, processInstance.ExpiredTime), 
 				SqlServerHelper.NewSqlParameter("@12", SqlDbType.DateTime, 11, processInstance.EndTime), 
 				SqlServerHelper.NewSqlParameter("@13", SqlDbType.VarChar, 50, processInstance.ParentProcessInstanceId), 
 				SqlServerHelper.NewSqlParameter("@14", SqlDbType.VarChar, 50, processInstance.ParentTaskInstanceId),
 				SqlServerHelper.NewSqlParameter("@1", SqlDbType.VarChar, 50, processInstance.Id)
 			};
             if (SqlServerHelper.ExecuteNonQuery(connectionString, CommandType.Text, update, updateParms) != 1)
                 return false;
             else return true;
         }
     }
예제 #59
0
        public void run(IProcessInstance processInstance)
        {
            if (StartNodeInstance == null)
            {
                KernelException exception = new KernelException(processInstance,
                        this.WorkflowProcess,
                        "Error:NetInstance is illegal ,the startNodeInstance can NOT be NULL ");
                throw exception;
            }

            Token token = new Token();//初始化token
            token.IsAlive = true;//活动的
            token.ProcessInstance = processInstance;//对应流程实例
            token.Value = StartNodeInstance.Volume;//token容量
            token.StepNumber = 0;//步骤号,开始节点的第一步默认为0
            token.FromActivityId = TokenFrom.FROM_START_NODE;//从哪个节点来 "FROM_START_NODE" 规定的节点。

            //注意这里并没有保存token
            StartNodeInstance.fire(token);//启动开始节点
        }
예제 #60
0
        public void abortTaskInstanceEx(IWorkflowSession currentSession, IProcessInstance processInstance, 
            ITaskInstance thisTaskInst, String targetActivityId)
        {
            // 如果TaskInstance处于结束状态,则直接返回
            if (thisTaskInst.State == TaskInstanceStateEnum.COMPLETED || thisTaskInst.State == TaskInstanceStateEnum.CANCELED)
            {
                return;
            }

            // Initialized状态的TaskInstance也可以中止,20090830
            // if (taskInstance.State == ITaskInstance.INITIALIZED) {
            // WorkflowProcess process = taskInstance.getWorkflowProcess();
            // throw new EngineException(taskInstance.getProcessInstanceId(),
            // process,
            // taskInstance.getTaskId(),
            // "Complete task insatance failed.The state of the task insatnce[id=" +
            // taskInstance.getId() + "] is " + taskInstance.State);
            // }
            if (thisTaskInst.IsSuspended())
            {
                WorkflowProcess process = thisTaskInst.WorkflowProcess;
                throw new EngineException(thisTaskInst.ProcessInstanceId,
                        process, thisTaskInst.TaskId,
                        "Abort task insatance failed. The task instance [id="
                                + thisTaskInst.Id + "] is suspended");
            }

            //
            IPersistenceService persistenceService = this.RuntimeContext.PersistenceService;
            WorkflowProcess workflowProcess = thisTaskInst.WorkflowProcess;
            List<IToken> allTokens = null;
            List<String> aliveActivityIdsAfterJump = new List<String>();
            if (targetActivityId != null)
            {
                String thisActivityId = thisTaskInst.ActivityId;
                Boolean isInSameLine = workflowProcess.isInSameLine(thisActivityId, targetActivityId);

                if (isInSameLine)
                {
                    this.abortTaskInstance(currentSession, processInstance, thisTaskInst, targetActivityId);
                }

                //合法性检查
                allTokens = persistenceService.FindTokensForProcessInstance(thisTaskInst.ProcessInstanceId, null);

                aliveActivityIdsAfterJump.Add(targetActivityId);

                for (int i = 0; allTokens != null && i < allTokens.Count; i++)
                {
                    IToken tokenTmp = allTokens[i];
                    IWFElement workflowElement = workflowProcess.findWFElementById(tokenTmp.NodeId);
                    if ((workflowElement is Activity) && !workflowElement.Id.Equals(thisActivityId))
                    {
                        aliveActivityIdsAfterJump.Add(workflowElement.Id);

                        if (workflowProcess.isReachable(targetActivityId, workflowElement.Id)
                            || workflowProcess.isReachable(workflowElement.Id, targetActivityId))
                        {
                            throw new EngineException(
                                    thisTaskInst.ProcessInstanceId,
                                    thisTaskInst.WorkflowProcess,
                                    thisTaskInst.TaskId,
                                    "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 = this.RuntimeContext.KernelManager.getNetInstance(workflowProcess.Id, thisTaskInst.Version);
            IActivityInstance targetActivityInstance = null;
            if (targetActivityId != null)
            {
                targetActivityInstance = (IActivityInstance)netInstance.getWFElementInstance(targetActivityId);
            }

            IActivityInstance thisActivityInstance = (IActivityInstance)netInstance.getWFElementInstance(thisTaskInst.ActivityId);
            if (thisActivityInstance == null)
            {
                WorkflowProcess process = thisTaskInst.WorkflowProcess;
                throw new EngineException(thisTaskInst.ProcessInstanceId, process, thisTaskInst.TaskId,
                    "系统没有找到与activityId=" + thisTaskInst.ActivityId + "对应activityInstance,无法执行abort操作。");
            }

            if (targetActivityInstance != null)
            {
                ((TaskInstance)thisTaskInst).TargetActivityId=targetActivityInstance.Activity.Id;
            }

            // 第一步,首先Abort当前taskInstance
            persistenceService.AbortTaskInstance((TaskInstance)thisTaskInst);

            // 触发相应的事件
            TaskInstanceEvent e = new TaskInstanceEvent();
            e.Source=thisTaskInst;
            e.WorkflowSession=currentSession;
            e.ProcessInstance=processInstance;
            e.EventType = TaskInstanceEventEnum.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.ProcessInstanceId, thisTaskInst.ActivityId);
            // System.out.println("Inside TaskInstance.complete(targetActivityInstance):: tokens.size is "+tokens.size());
            if (tokens == null || tokens.Count == 0)
            {
                return;// 表明activityInstance已经结束了。
            }
            if (tokens.Count > 1)
            {
                WorkflowProcess process = thisTaskInst.WorkflowProcess;
                throw new EngineException(thisTaskInst.ProcessInstanceId, process, thisTaskInst.TaskId,
                    "与activityId=" + thisTaskInst.ActivityId + "对应的token数量(=" + tokens.Count + ")不正确,正确只能为1,因此无法完成complete操作");
            }
            IToken token = tokens[0];
            // stepNumber不相等,不允许执行结束操作。
            if (token.StepNumber != thisTaskInst.StepNumber)
            {
                return;
            }
            if (token.IsAlive == false)
            {
                WorkflowProcess process = thisTaskInst.WorkflowProcess;
                throw new EngineException(thisTaskInst.ProcessInstanceId, process, thisTaskInst.TaskId,
                    "与activityId=" + thisTaskInst.ActivityId + "对应的token.alive=false,因此无法完成complete操作");
            }

            token.ProcessInstance = processInstance;

            //调整token布局
            if (targetActivityId != null)
            {
                List<Synchronizer> allSynchronizersAndEnds = new List<Synchronizer>();
                allSynchronizersAndEnds.AddRange(workflowProcess.Synchronizers);
                allSynchronizersAndEnds.AddRange((IEnumerable<Synchronizer>)workflowProcess.EndNodes.ToArray());
                //allSynchronizersAndEnds.AddRange((List<Synchronizer>));
                for (int i = 0; i < allSynchronizersAndEnds.Count; i++)
                {
                    Synchronizer synchronizer = allSynchronizersAndEnds[i];
                    if (synchronizer.Name.Equals("Synchronizer4"))
                    {
                        //System.out.println(synchronizer.Name);
                    }
                    int volumn = 0;
                    if (synchronizer is EndNode)
                    {
                        volumn = synchronizer.EnteringTransitions.Count;
                    }
                    else
                    {
                        volumn = synchronizer.EnteringTransitions.Count * synchronizer.LeavingTransitions.Count;
                    }
                    IToken tokenTmp = new Token();
                    tokenTmp.NodeId = synchronizer.Id;
                    tokenTmp.IsAlive = false;
                    tokenTmp.ProcessInstanceId = thisTaskInst.ProcessInstanceId;
                    tokenTmp.StepNumber = -1;

                    List<String> incomingTransitionIds = new List<String>();
                    Boolean reachable = false;
                    List<Transition> enteringTrans = synchronizer.EnteringTransitions;
                    for (int m = 0; m < aliveActivityIdsAfterJump.Count; m++)
                    {
                        String aliveActivityId = aliveActivityIdsAfterJump[m];
                        if (workflowProcess.isReachable(aliveActivityId, synchronizer.Id))
                        {
                            Transition trans = null;
                            reachable = true;
                            for (int j = 0; j < enteringTrans.Count; j++)
                            {
                                trans = enteringTrans[j];
                                Node fromNode = (Node)trans.FromNode;
                                if (workflowProcess.isReachable(aliveActivityId, fromNode.Id))
                                {
                                    if (!incomingTransitionIds.Contains(trans.Id))
                                    {
                                        incomingTransitionIds.Add(trans.Id);
                                    }
                                }
                            }
                        }
                    }
                    if (reachable)
                    {
                        tokenTmp.Value = volumn - (incomingTransitionIds.Count * volumn / enteringTrans.Count);

                        IToken virtualToken = getJoinInfo(allTokens, synchronizer.Id);

                        if (virtualToken != null)
                        {
                            persistenceService.DeleteTokensForNode(thisTaskInst.ProcessInstanceId, synchronizer.Id);
                        }

                        if (tokenTmp.Value != 0)
                        {
                            tokenTmp.ProcessInstance = processInstance;
                            persistenceService.SaveOrUpdateToken(tokenTmp);
                        }
                    }
                }
            }
            thisActivityInstance.complete(token, targetActivityInstance);
        }