Search in sources :

Example 1 with DeploymentEntity

use of org.activiti.engine.impl.persistence.entity.DeploymentEntity in project Activiti by Activiti.

the class DeploymentManager method removeDeployment.

public void removeDeployment(String deploymentId, boolean cascade) {
    DeploymentEntityManager deploymentEntityManager = Context.getCommandContext().getDeploymentEntityManager();
    DeploymentEntity deployment = deploymentEntityManager.findDeploymentById(deploymentId);
    if (deployment == null)
        throw new ActivitiObjectNotFoundException("Could not find a deployment with id '" + deploymentId + "'.", DeploymentEntity.class);
    // Remove any process definition from the cache
    List<ProcessDefinition> processDefinitions = new ProcessDefinitionQueryImpl(Context.getCommandContext()).deploymentId(deploymentId).list();
    ActivitiEventDispatcher eventDispatcher = Context.getProcessEngineConfiguration().getEventDispatcher();
    for (ProcessDefinition processDefinition : processDefinitions) {
        // Since all process definitions are deleted by a single query, we should dispatch the events in this loop
        if (eventDispatcher.isEnabled()) {
            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.isEnabled()) {
        eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_DELETED, deployment));
    }
    for (ProcessDefinition processDefinition : processDefinitions) {
        processDefinitionCache.remove(processDefinition.getId());
    }
}
Also used : DeploymentEntityManager(org.activiti.engine.impl.persistence.entity.DeploymentEntityManager) DeploymentEntity(org.activiti.engine.impl.persistence.entity.DeploymentEntity) ProcessDefinitionQueryImpl(org.activiti.engine.impl.ProcessDefinitionQueryImpl) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiEventDispatcher(org.activiti.engine.delegate.event.ActivitiEventDispatcher)

Example 2 with DeploymentEntity

use of org.activiti.engine.impl.persistence.entity.DeploymentEntity in project Activiti by Activiti.

the class RulesHelper method findKnowledgeBaseByDeploymentId.

public static KnowledgeBase findKnowledgeBaseByDeploymentId(String deploymentId) {
    DeploymentCache<Object> knowledgeBaseCache = Context.getProcessEngineConfiguration().getDeploymentManager().getKnowledgeBaseCache();
    KnowledgeBase knowledgeBase = (KnowledgeBase) knowledgeBaseCache.get(deploymentId);
    if (knowledgeBase == null) {
        DeploymentEntity deployment = Context.getCommandContext().getDeploymentEntityManager().findDeploymentById(deploymentId);
        if (deployment == null) {
            throw new ActivitiObjectNotFoundException("no deployment with id " + deploymentId, Deployment.class);
        }
        Context.getProcessEngineConfiguration().getDeploymentManager().deploy(deployment);
        knowledgeBase = (KnowledgeBase) knowledgeBaseCache.get(deploymentId);
        if (knowledgeBase == null) {
            throw new ActivitiException("deployment " + deploymentId + " doesn't contain any rules");
        }
    }
    return knowledgeBase;
}
Also used : DeploymentEntity(org.activiti.engine.impl.persistence.entity.DeploymentEntity) ActivitiException(org.activiti.engine.ActivitiException) KnowledgeBase(org.drools.KnowledgeBase) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 3 with DeploymentEntity

use of org.activiti.engine.impl.persistence.entity.DeploymentEntity in project Activiti by Activiti.

the class ChangeDeploymentTenantIdCmd method execute.

public Void execute(CommandContext commandContext) {
    if (deploymentId == null) {
        throw new ActivitiIllegalArgumentException("deploymentId is null");
    }
    // Update all entities
    DeploymentEntity deployment = commandContext.getDeploymentEntityManager().findDeploymentById(deploymentId);
    if (deployment == null) {
        throw new ActivitiObjectNotFoundException("Could not find deployment with id " + deploymentId, Deployment.class);
    }
    String oldTenantId = deployment.getTenantId();
    deployment.setTenantId(newTenantId);
    // Doing process instances, executions and tasks with direct SQL updates (otherwise would not be performant) 
    commandContext.getProcessDefinitionEntityManager().updateProcessDefinitionTenantIdForDeployment(deploymentId, newTenantId);
    commandContext.getExecutionEntityManager().updateExecutionTenantIdForDeployment(deploymentId, newTenantId);
    commandContext.getTaskEntityManager().updateTaskTenantIdForDeployment(deploymentId, newTenantId);
    commandContext.getJobEntityManager().updateJobTenantIdForDeployment(deploymentId, newTenantId);
    commandContext.getEventSubscriptionEntityManager().updateEventSubscriptionTenantId(oldTenantId, newTenantId);
    // Doing process definitions in memory, cause we need to clear the process definition cache
    List<ProcessDefinition> processDefinitions = commandContext.getDbSqlSession().createProcessDefinitionQuery().deploymentId(deploymentId).list();
    for (ProcessDefinition processDefinition : processDefinitions) {
        commandContext.getProcessEngineConfiguration().getProcessDefinitionCache().remove(processDefinition.getId());
    }
    // Clear process definition cache
    commandContext.getProcessEngineConfiguration().getProcessDefinitionCache().clear();
    return null;
}
Also used : DeploymentEntity(org.activiti.engine.impl.persistence.entity.DeploymentEntity) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 4 with DeploymentEntity

use of org.activiti.engine.impl.persistence.entity.DeploymentEntity in project Activiti by Activiti.

the class DeployCmd method execute.

public Deployment execute(CommandContext commandContext) {
    DeploymentEntity deployment = deploymentBuilder.getDeployment();
    deployment.setDeploymentTime(commandContext.getProcessEngineConfiguration().getClock().getCurrentTime());
    if (deploymentBuilder.isDuplicateFilterEnabled()) {
        List<Deployment> existingDeployments = new ArrayList<Deployment>();
        if (deployment.getTenantId() == null || ProcessEngineConfiguration.NO_TENANT_ID.equals(deployment.getTenantId())) {
            DeploymentEntity existingDeployment = commandContext.getDeploymentEntityManager().findLatestDeploymentByName(deployment.getName());
            if (existingDeployment != null) {
                existingDeployments.add(existingDeployment);
            }
        } else {
            List<Deployment> deploymentList = commandContext.getProcessEngineConfiguration().getRepositoryService().createDeploymentQuery().deploymentName(deployment.getName()).deploymentTenantId(deployment.getTenantId()).orderByDeploymentId().desc().list();
            if (!deploymentList.isEmpty()) {
                existingDeployments.addAll(deploymentList);
            }
        }
        DeploymentEntity existingDeployment = null;
        if (!existingDeployments.isEmpty()) {
            existingDeployment = (DeploymentEntity) existingDeployments.get(0);
        }
        if ((existingDeployment != null) && !deploymentsDiffer(deployment, existingDeployment)) {
            return existingDeployment;
        }
    }
    deployment.setNew(true);
    // Save the data
    commandContext.getDeploymentEntityManager().insertDeployment(deployment);
    if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, deployment));
    }
    // Deployment settings
    Map<String, Object> deploymentSettings = new HashMap<String, Object>();
    deploymentSettings.put(DeploymentSettings.IS_BPMN20_XSD_VALIDATION_ENABLED, deploymentBuilder.isBpmn20XsdValidationEnabled());
    deploymentSettings.put(DeploymentSettings.IS_PROCESS_VALIDATION_ENABLED, deploymentBuilder.isProcessValidationEnabled());
    // Actually deploy
    commandContext.getProcessEngineConfiguration().getDeploymentManager().deploy(deployment, deploymentSettings);
    if (deploymentBuilder.getProcessDefinitionsActivationDate() != null) {
        scheduleProcessDefinitionActivation(commandContext, deployment);
    }
    if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, deployment));
    }
    return deployment;
}
Also used : DeploymentEntity(org.activiti.engine.impl.persistence.entity.DeploymentEntity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Deployment(org.activiti.engine.repository.Deployment)

Example 5 with DeploymentEntity

use of org.activiti.engine.impl.persistence.entity.DeploymentEntity in project Activiti by Activiti.

the class DeploymentManager method resolveProcessDefinition.

public ProcessDefinitionEntity resolveProcessDefinition(ProcessDefinitionEntity processDefinition) {
    String processDefinitionId = processDefinition.getId();
    String deploymentId = processDefinition.getDeploymentId();
    processDefinition = processDefinitionCache.get(processDefinitionId);
    if (processDefinition == null) {
        DeploymentEntity deployment = Context.getCommandContext().getDeploymentEntityManager().findDeploymentById(deploymentId);
        deployment.setNew(false);
        deploy(deployment, null);
        processDefinition = processDefinitionCache.get(processDefinitionId);
        if (processDefinition == null) {
            throw new ActivitiException("deployment '" + deploymentId + "' didn't put process definition '" + processDefinitionId + "' in the cache");
        }
    }
    return processDefinition;
}
Also used : DeploymentEntity(org.activiti.engine.impl.persistence.entity.DeploymentEntity) ActivitiException(org.activiti.engine.ActivitiException)

Aggregations

DeploymentEntity (org.activiti.engine.impl.persistence.entity.DeploymentEntity)9 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ActivitiException (org.activiti.engine.ActivitiException)2 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)2 Deployment (org.activiti.engine.repository.Deployment)2 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)2 List (java.util.List)1 SimulationEvent (org.activiti.crystalball.simulator.SimulationEvent)1 ActivitiEntityEvent (org.activiti.engine.delegate.event.ActivitiEntityEvent)1 ActivitiEventDispatcher (org.activiti.engine.delegate.event.ActivitiEventDispatcher)1 ProcessDefinitionQueryImpl (org.activiti.engine.impl.ProcessDefinitionQueryImpl)1 DeploymentEntityManager (org.activiti.engine.impl.persistence.entity.DeploymentEntityManager)1 KnowledgeBase (org.drools.KnowledgeBase)1 Test (org.junit.Test)1