public virtual object  Execute(ICommandContext commandContext)
        {
            if (ReferenceEquals(deploymentId, null))
            {
                throw new ActivitiIllegalArgumentException("Deployment id is null");
            }

            IDeploymentEntity deployment = commandContext.DeploymentEntityManager.FindById <IDeploymentEntity>(deploymentId);

            if (deployment == null)
            {
                throw new ActivitiObjectNotFoundException("No deployment found for id = '" + deploymentId + "'", typeof(IDeployment));
            }

            // Update category
            deployment.Category = category;

            if (commandContext.ProcessEngineConfiguration.EventDispatcher.Enabled)
            {
                commandContext.ProcessEngineConfiguration.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_UPDATED, deployment));
            }

            return(null);
        }
Exemple #2
0
        public virtual void RemoveDeployment(string deploymentId, bool cascade)
        {
            IDeploymentEntity deployment = deploymentEntityManager.FindById <IDeploymentEntity>(new KeyValuePair <string, object>("id", deploymentId));

            if (deployment == null)
            {
                throw new ActivitiObjectNotFoundException("Could not find a deployment with id '" + deploymentId + "'.", typeof(IDeploymentEntity));
            }

            // Remove any process definition from the cache
            IList <IProcessDefinition> processDefinitions = (new ProcessDefinitionQueryImpl()).SetDeploymentId(deploymentId).List();
            IActivitiEventDispatcher   eventDispatcher    = Context.ProcessEngineConfiguration.EventDispatcher;

            foreach (IProcessDefinition processDefinition in processDefinitions)
            {
                // Since all process definitions are deleted by a single query, we should dispatch the events in this loop
                if (eventDispatcher.Enabled)
                {
                    eventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_DELETED, processDefinition));
                }
            }

            // Delete data
            deploymentEntityManager.DeleteDeployment(deploymentId, cascade);

            // Since we use a delete by query, delete-events are not automatically dispatched
            if (eventDispatcher.Enabled)
            {
                eventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_DELETED, deployment));
            }

            foreach (IProcessDefinition processDefinition in processDefinitions)
            {
                processDefinitionCache.Remove(processDefinition.Id);
            }
        }
Exemple #3
0
        protected internal virtual IDeployment ExecuteSave(ICommandContext commandContext)
        {
            IDeploymentEntity deployment = deploymentBuilder.Deployment;

            deployment.Unrunable();

            deployment.DeploymentTime = commandContext.ProcessEngineConfiguration.Clock.CurrentTime;

            commandContext.DeploymentEntityManager.SaveDraft(deployment);

            //if (deploymentBuilder.DuplicateFilterEnabled)
            //{
            //    IList<IDeployment> existingDeployments = new List<IDeployment>();
            //    if (ReferenceEquals(deployment.TenantId, null) || ProcessEngineConfiguration.NO_TENANT_ID.Equals(deployment.TenantId))
            //    {
            //        IDeploymentEntity existingDeployment = commandContext.DeploymentEntityManager.findLatestDeploymentByName(deployment.Name);
            //        if (existingDeployment != null)
            //        {
            //            existingDeployments.Add(existingDeployment);
            //        }
            //    }
            //    else
            //    {
            //        IList<IDeployment> deploymentList = commandContext.ProcessEngineConfiguration.RepositoryService.createDeploymentQuery().deploymentName(deployment.Name).deploymentTenantId(deployment.TenantId).orderByDeploymentId().desc().list();

            //        if (deploymentList.Count > 0)
            //        {
            //            ((List<IDeployment>)existingDeployments).AddRange(deploymentList);
            //        }
            //    }

            //    {
            //        IDeploymentEntity existingDeployment = null;
            //        if (existingDeployments.Count > 0)
            //        {
            //            existingDeployment = (IDeploymentEntity)existingDeployments[0];
            //        }

            //        if ((existingDeployment != null) && !deploymentsDiffer(deployment, existingDeployment))
            //        {
            //            return existingDeployment;
            //        }
            //    }
            //}

            //deployment.New = true;

            //// Save the data
            //commandContext.DeploymentEntityManager.insert(deployment);

            if (commandContext.ProcessEngineConfiguration.EventDispatcher.Enabled)
            {
                commandContext.ProcessEngineConfiguration.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_CREATED, deployment));
            }

            // Deployment settings
            IDictionary <string, object> deploymentSettings = new Dictionary <string, object>
            {
                [DeploymentSettingsFields.IS_BPMN20_XSD_VALIDATION_ENABLED] = deploymentBuilder.Bpmn20XsdValidationEnabled,
                [DeploymentSettingsFields.IS_PROCESS_VALIDATION_ENABLED]    = deploymentBuilder.ProcessValidationEnabled
            };

            // Actually deploy
            commandContext.ProcessEngineConfiguration.DeploymentManager.Deploy(deployment, deploymentSettings);

            if (deploymentBuilder.ProcessDefinitionsActivationDate != null)
            {
                ScheduleProcessDefinitionActivation(commandContext, deployment);
            }

            if (commandContext.ProcessEngineConfiguration.EventDispatcher.Enabled)
            {
                commandContext.ProcessEngineConfiguration.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, deployment));
            }

            return(deployment);
        }
Exemple #4
0
        protected internal virtual void ScheduleProcessDefinitionActivation(ICommandContext commandContext, IDeploymentEntity deployment)
        {
            foreach (IProcessDefinitionEntity processDefinitionEntity in deployment.GetDeployedArtifacts <IProcessDefinitionEntity>())
            {
                // If activation date is set, we first suspend all the process
                // definition
                SuspendProcessDefinitionCmd suspendProcessDefinitionCmd = new SuspendProcessDefinitionCmd(processDefinitionEntity, false, null, deployment.TenantId);
                suspendProcessDefinitionCmd.Execute(commandContext);

                // And we schedule an activation at the provided date
                ActivateProcessDefinitionCmd activateProcessDefinitionCmd = new ActivateProcessDefinitionCmd(processDefinitionEntity, false, deploymentBuilder.ProcessDefinitionsActivationDate, deployment.TenantId);
                activateProcessDefinitionCmd.Execute(commandContext);
            }
        }
Exemple #5
0
        protected internal virtual bool DeploymentsDiffer(IDeploymentEntity deployment, IDeploymentEntity saved)
        {
            if (deployment.GetResources() == null || saved.GetResources() == null)
            {
                return(true);
            }

            IDictionary <string, IResourceEntity> resources      = deployment.GetResources();
            IDictionary <string, IResourceEntity> savedResources = saved.GetResources();

            foreach (string resourceName in resources.Keys)
            {
                IResourceEntity savedResource = savedResources[resourceName];

                if (savedResource == null)
                {
                    return(true);
                }

                if (!savedResource.Generated)
                {
                    IResourceEntity resource = resources[resourceName];

                    byte[] bytes      = resource.Bytes;
                    byte[] savedBytes = savedResource.Bytes;
                    if (!StructuralComparisons.StructuralEqualityComparer.Equals(bytes, savedBytes))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #6
0
 public virtual void Deploy(IDeploymentEntity deployment)
 {
     Deploy(deployment, null);
 }
 public ParsedDeploymentBuilder(IDeploymentEntity deployment, BpmnParser bpmnParser, IDictionary <string, object> deploymentSettings)
 {
     this.deployment         = deployment;
     this.bpmnParser         = bpmnParser;
     this.deploymentSettings = deploymentSettings;
 }
Exemple #8
0
        protected internal virtual IDeployment ExecuteDeploy(ICommandContext commandContext)
        {
            lock (syncRoot)
            {
                IDeploymentEntity deployment = deploymentBuilder.Deployment;

                deployment.Runable();

                deployment.DeploymentTime = commandContext.ProcessEngineConfiguration.Clock.CurrentTime;

                IDictionary <string, IResourceEntity> resources = this.deploymentBuilder.Deployment.GetResources();

                deployment.DeployExecutionBehavior();

                if (deploymentBuilder.DuplicateFilterEnabled)
                {
                    IList <IDeployment> existingDeployments = new List <IDeployment>();
                    if (deployment.TenantId is null || ProcessEngineConfiguration.NO_TENANT_ID.Equals(deployment.TenantId))
                    {
                        IDeploymentEntity existingDeployment = commandContext.DeploymentEntityManager.FindLatestDeploymentByName(deployment.Name);
                        if (existingDeployment != null)
                        {
                            existingDeployments.Add(existingDeployment);
                        }
                    }
                    else
                    {
                        //按部署时间倒序排序,始终与最后一次部署做比较
                        IList <IDeployment> deploymentList = commandContext.ProcessEngineConfiguration.RepositoryService.CreateDeploymentQuery()
                                                             .SetDeploymentName(deployment.Name)
                                                             .SetDeploymentTenantId(deployment.TenantId)
                                                             .SetOrderByDeploymenTime()
                                                             .Desc()
                                                             .List();

                        if (deploymentList.Count > 0)
                        {
                            ((List <IDeployment>)existingDeployments).AddRange(deploymentList);
                        }
                    }

                    {
                        IDeploymentEntity existingDeployment = null;
                        if (existingDeployments.Count > 0)
                        {
                            existingDeployment = (IDeploymentEntity)existingDeployments[0];
                        }

                        if ((existingDeployment != null) && !DeploymentsDiffer(deployment, existingDeployment))
                        {
                            commandContext.ProcessEngineConfiguration.DeploymentEntityManager.RemoveDrafts(deployment.TenantId, deployment.Name);

                            return(existingDeployment);
                        }
                    }
                }

                deployment.New = true;

                // Save the data
                commandContext.DeploymentEntityManager.Insert(deployment);

                if (commandContext.ProcessEngineConfiguration.EventDispatcher.Enabled)
                {
                    commandContext.ProcessEngineConfiguration.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_CREATED, deployment));
                }

                // Deployment settings
                IDictionary <string, object> deploymentSettings = new Dictionary <string, object>
                {
                    [DeploymentSettingsFields.IS_BPMN20_XSD_VALIDATION_ENABLED] = deploymentBuilder.Bpmn20XsdValidationEnabled,
                    [DeploymentSettingsFields.IS_PROCESS_VALIDATION_ENABLED]    = deploymentBuilder.ProcessValidationEnabled
                };

                // Actually deploy
                commandContext.ProcessEngineConfiguration.DeploymentManager.Deploy(deployment, deploymentSettings);

                if (deploymentBuilder.ProcessDefinitionsActivationDate != null)
                {
                    ScheduleProcessDefinitionActivation(commandContext, deployment);
                }

                if (commandContext.ProcessEngineConfiguration.EventDispatcher.Enabled)
                {
                    commandContext.ProcessEngineConfiguration.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, deployment));
                }

                commandContext.ProcessEngineConfiguration.DeploymentEntityManager.RemoveDrafts(deployment.TenantId, deployment.Name);

                return(deployment);
            }
 public DeploymentBuilderImpl(RepositoryServiceImpl repositoryService)
 {
     this.repositoryService     = repositoryService;
     this.deployment            = Context.ProcessEngineConfiguration.DeploymentEntityManager.Create();
     this.resourceEntityManager = Context.ProcessEngineConfiguration.ResourceEntityManager;
 }
Exemple #10
0
 public virtual ParsedDeploymentBuilder GetBuilderForDeploymentAndSettings(IDeploymentEntity deployment, IDictionary <string, object> deploymentSettings)
 {
     return(new ParsedDeploymentBuilder(deployment, bpmnParser, deploymentSettings));
 }
Exemple #11
0
 public virtual ParsedDeploymentBuilder GetBuilderForDeployment(IDeploymentEntity deployment)
 {
     return(GetBuilderForDeploymentAndSettings(deployment, null));
 }