Пример #1
0
        protected internal virtual IHistoricActivityInstanceEntity CreateHistoricActivityInstanceEntity(IExecutionEntity execution)
        {
            IIdGenerator idGenerator = ProcessEngineConfiguration.IdGenerator;

            string processDefinitionId = execution.ProcessDefinitionId;
            string processInstanceId   = execution.ProcessInstanceId;

            IHistoricActivityInstanceEntity historicActivityInstance = HistoricActivityInstanceEntityManager.Create();

            historicActivityInstance.Id = idGenerator.GetNextId();
            historicActivityInstance.ProcessDefinitionId = processDefinitionId;
            historicActivityInstance.ProcessInstanceId   = processInstanceId;
            historicActivityInstance.ExecutionId         = execution.Id;
            historicActivityInstance.ActivityId          = execution.ActivityId;
            if (execution.CurrentFlowElement != null)
            {
                historicActivityInstance.ActivityName = execution.CurrentFlowElement.Name;
                historicActivityInstance.ActivityType = ParseActivityType(execution.CurrentFlowElement);
            }
            DateTime now = Clock.CurrentTime;

            historicActivityInstance.StartTime = now;

            // Inherit tenant id (if applicable)
            if (execution.TenantId is object)
            {
                historicActivityInstance.TenantId = execution.TenantId;
            }

            HistoricActivityInstanceEntityManager.Insert(historicActivityInstance);
            return(historicActivityInstance);
        }
        public override void Delete(KeyValuePair <string, object> id)
        {
            string historicProcessInstanceId = id.Value?.ToString();

            if (HistoryManager.HistoryEnabled)
            {
                if (historicProcessInstanceId == null)
                {
                    return;
                }

                IHistoricProcessInstanceEntity historicProcessInstance = FindById <IHistoricProcessInstanceEntity>(new KeyValuePair <string, object>("id", historicProcessInstanceId));

                HistoricDetailEntityManager.DeleteHistoricDetailsByProcessInstanceId(historicProcessInstanceId);
                HistoricVariableInstanceEntityManager.DeleteHistoricVariableInstanceByProcessInstanceId(historicProcessInstanceId);
                HistoricActivityInstanceEntityManager.DeleteHistoricActivityInstancesByProcessInstanceId(historicProcessInstanceId);
                HistoricTaskInstanceEntityManager.DeleteHistoricTaskInstancesByProcessInstanceId(historicProcessInstanceId);
                HistoricIdentityLinkEntityManager.DeleteHistoricIdentityLinksByProcInstance(historicProcessInstanceId);
                CommentEntityManager.DeleteCommentsByProcessInstanceId(historicProcessInstanceId);

                Delete(historicProcessInstance, false);

                // Also delete any sub-processes that may be active (ACT-821)

                IList <IHistoricProcessInstanceEntity> selectList = historicProcessInstanceDataManager.FindHistoricProcessInstancesBySuperProcessInstanceId(historicProcessInstanceId);
                foreach (IHistoricProcessInstanceEntity child in selectList)
                {
                    Delete(new KeyValuePair <string, object>("id", child.Id)); // NEEDS to be by id, to come again through this method!
                }
            }
        }
Пример #3
0
        public virtual IHistoricActivityInstanceEntity FindActivityInstance(IExecutionEntity execution, string activityId, bool createOnNotFound, bool endTimeMustBeNull)
        {
            // No use looking for the HistoricActivityInstance when no activityId is provided.
            if (activityId is null)
            {
                return(null);
            }

            string executionId = execution.Id;

            // Check the cache
            IHistoricActivityInstanceEntity historicActivityInstanceEntityFromCache = GetHistoricActivityInstanceFromCache(executionId, activityId, endTimeMustBeNull);

            if (historicActivityInstanceEntityFromCache != null)
            {
                return(historicActivityInstanceEntityFromCache);
            }

            // If the execution was freshly created, there is no need to check the database,
            // there can never be an entry for a historic activity instance with this execution id.
            if (!execution.Inserted && !execution.ProcessInstanceType)
            {
                // Check the database
                IList <IHistoricActivityInstanceEntity> historicActivityInstances = HistoricActivityInstanceEntityManager.FindUnfinishedHistoricActivityInstancesByExecutionAndActivityId(executionId, activityId);

                if (historicActivityInstances.Count > 0)
                {
                    return(historicActivityInstances[0]);
                }
            }

            if (execution.ParentId is object)
            {
                IHistoricActivityInstanceEntity historicActivityInstanceFromParent = FindActivityInstance(execution.Parent, activityId, false, endTimeMustBeNull); // always false for create, we only check if it can be found
                if (historicActivityInstanceFromParent != null)
                {
                    return(historicActivityInstanceFromParent);
                }
            }

            if (createOnNotFound && activityId is object && ((execution.CurrentFlowElement != null && execution.CurrentFlowElement is FlowNode) || execution.CurrentFlowElement == null))
            {
                return(CreateHistoricActivityInstanceEntity(execution));
            }

            return(null);
        }