protected internal virtual ProcessDefinitionInfoCacheObject RetrieveProcessDefinitionInfoCacheObject(string processDefinitionId, ICommandContext commandContext)
        {
            IProcessDefinitionInfoEntityManager infoEntityManager = commandContext.ProcessDefinitionInfoEntityManager;
            ObjectMapper objectMapper = commandContext.ProcessEngineConfiguration.ObjectMapper;

            ProcessDefinitionInfoCacheObject cacheObject = cache.GetOrCreate(processDefinitionId, (key) => new ProcessDefinitionInfoCacheObject()
            {
                Revision = 0,
                InfoNode = objectMapper.CreateObjectNode()
            });

            IProcessDefinitionInfoEntity infoEntity = infoEntityManager.FindProcessDefinitionInfoByProcessDefinitionId(processDefinitionId);

            if (infoEntity != null && infoEntity.Revision != cacheObject.Revision)
            {
                cacheObject.Revision = infoEntity.Revision;
                if (infoEntity.InfoJsonId is object)
                {
                    byte[] infoBytes = infoEntityManager.FindInfoJsonById(infoEntity.InfoJsonId);
                    try
                    {
                        JToken infoNode = objectMapper.ReadTree(infoBytes);
                        cacheObject.InfoNode = infoNode;
                    }
                    catch (Exception e)
                    {
                        throw new ActivitiException("Error reading json info node for process definition " + processDefinitionId, e);
                    }
                }
            }
            else if (infoEntity == null)
            {
                cacheObject.Revision = 0;
                cacheObject.InfoNode = objectMapper.CreateObjectNode();
            }

            return(cacheObject);
        }
Beispiel #2
0
        protected internal virtual void AddDefinitionInfoToCache(IProcessDefinitionEntity processDefinition, ProcessEngineConfigurationImpl processEngineConfiguration, ICommandContext commandContext)
        {
            if (!processEngineConfiguration.EnableProcessDefinitionInfoCache)
            {
                return;
            }

            DeploymentManager deploymentManager = processEngineConfiguration.DeploymentManager;
            IProcessDefinitionInfoEntityManager definitionInfoEntityManager = commandContext.ProcessDefinitionInfoEntityManager;
            ObjectMapper objectMapper = commandContext.ProcessEngineConfiguration.ObjectMapper;
            IProcessDefinitionInfoEntity definitionInfoEntity = definitionInfoEntityManager.FindProcessDefinitionInfoByProcessDefinitionId(processDefinition.Id);

            JToken infoNode = null;

            if (definitionInfoEntity is object && definitionInfoEntity.InfoJsonId is object)
            {
                byte[] infoBytes = definitionInfoEntityManager.FindInfoJsonById(definitionInfoEntity.InfoJsonId);
                if (infoBytes != null)
                {
                    try
                    {
                        infoNode = objectMapper.ReadTree(infoBytes);
                    }
                    catch (Exception)
                    {
                        throw new ActivitiException("Error deserializing json info for process definition " + processDefinition.Id);
                    }
                }
            }

            ProcessDefinitionInfoCacheObject definitionCacheObject = new ProcessDefinitionInfoCacheObject();

            if (definitionInfoEntity == null)
            {
                definitionCacheObject.Revision = 0;
            }
            else
            {
                definitionCacheObject.Id       = definitionInfoEntity.Id;
                definitionCacheObject.Revision = definitionInfoEntity.Revision;
            }

            if (infoNode == null)
            {
                infoNode = objectMapper.CreateObjectNode();
            }
            definitionCacheObject.InfoNode = infoNode;

            deploymentManager.ProcessDefinitionInfoCache.Add(processDefinition.Id, definitionCacheObject);
        }