Search in sources :

Example 1 with ProcessDefinitionQueryImpl

use of org.activiti.engine.impl.ProcessDefinitionQueryImpl in project Activiti by Activiti.

the class AbstractSetProcessDefinitionStateCmd method findProcessDefinition.

protected List<ProcessDefinitionEntity> findProcessDefinition(CommandContext commandContext) {
    // we don't need to do an extra database fetch and we can simply return it, wrapped in a list
    if (processDefinitionEntity != null) {
        return Arrays.asList(processDefinitionEntity);
    }
    // Validation of input parameters
    if (processDefinitionId == null && processDefinitionKey == null) {
        throw new ActivitiIllegalArgumentException("Process definition id or key cannot be null");
    }
    List<ProcessDefinitionEntity> processDefinitionEntities = new ArrayList<ProcessDefinitionEntity>();
    ProcessDefinitionEntityManager processDefinitionManager = commandContext.getProcessDefinitionEntityManager();
    if (processDefinitionId != null) {
        ProcessDefinitionEntity processDefinitionEntity = processDefinitionManager.findProcessDefinitionById(processDefinitionId);
        if (processDefinitionEntity == null) {
            throw new ActivitiObjectNotFoundException("Cannot find process definition for id '" + processDefinitionId + "'", ProcessDefinition.class);
        }
        processDefinitionEntities.add(processDefinitionEntity);
    } else {
        ProcessDefinitionQueryImpl query = new ProcessDefinitionQueryImpl(commandContext).processDefinitionKey(processDefinitionKey);
        if (tenantId == null || ProcessEngineConfiguration.NO_TENANT_ID.equals(tenantId)) {
            query.processDefinitionWithoutTenantId();
        } else {
            query.processDefinitionTenantId(tenantId);
        }
        List<ProcessDefinition> processDefinitions = query.list();
        if (processDefinitions.isEmpty()) {
            throw new ActivitiException("Cannot find process definition for key '" + processDefinitionKey + "'");
        }
        for (ProcessDefinition processDefinition : processDefinitions) {
            processDefinitionEntities.add((ProcessDefinitionEntity) processDefinition);
        }
    }
    return processDefinitionEntities;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ProcessDefinitionEntityManager(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntityManager) ProcessDefinitionQueryImpl(org.activiti.engine.impl.ProcessDefinitionQueryImpl) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ArrayList(java.util.ArrayList) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 2 with ProcessDefinitionQueryImpl

use of org.activiti.engine.impl.ProcessDefinitionQueryImpl in project Activiti by Activiti.

the class DeploymentEntityManager method findNewLatestProcessDefinitionAfterRemovalOf.

protected ProcessDefinition findNewLatestProcessDefinitionAfterRemovalOf(ProcessDefinition processDefinitionToBeRemoved) {
    // The latest process definition is not necessarily the one with 'version -1' (some versions could have been deleted)
    // Hence, the following logic
    ProcessDefinitionQueryImpl query = new ProcessDefinitionQueryImpl();
    query.processDefinitionKey(processDefinitionToBeRemoved.getKey());
    if (processDefinitionToBeRemoved.getTenantId() != null && !ProcessEngineConfiguration.NO_TENANT_ID.equals(processDefinitionToBeRemoved.getTenantId())) {
        query.processDefinitionTenantId(processDefinitionToBeRemoved.getTenantId());
    } else {
        query.processDefinitionWithoutTenantId();
    }
    query.processDefinitionVersionLowerThan(processDefinitionToBeRemoved.getVersion());
    query.orderByProcessDefinitionVersion().desc();
    List<ProcessDefinition> processDefinitions = getProcessDefinitionManager().findProcessDefinitionsByQueryCriteria(query, new Page(0, 1));
    if (processDefinitions != null && processDefinitions.size() > 0) {
        return processDefinitions.get(0);
    }
    return null;
}
Also used : ProcessDefinitionQueryImpl(org.activiti.engine.impl.ProcessDefinitionQueryImpl) Page(org.activiti.engine.impl.Page) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition)

Example 3 with ProcessDefinitionQueryImpl

use of org.activiti.engine.impl.ProcessDefinitionQueryImpl 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 4 with ProcessDefinitionQueryImpl

use of org.activiti.engine.impl.ProcessDefinitionQueryImpl in project Activiti by Activiti.

the class ProcessDefinitionEntityManager method findProcessDefinitionByKeyAndVersion.

public ProcessDefinition findProcessDefinitionByKeyAndVersion(String processDefinitionKey, Integer processDefinitionVersion) {
    ProcessDefinitionQueryImpl processDefinitionQuery = new ProcessDefinitionQueryImpl().processDefinitionKey(processDefinitionKey).processDefinitionVersion(processDefinitionVersion);
    List<ProcessDefinition> results = findProcessDefinitionsByQueryCriteria(processDefinitionQuery, null);
    if (results.size() == 1) {
        return results.get(0);
    } else if (results.size() > 1) {
        throw new ActivitiException("There are " + results.size() + " process definitions with key = '" + processDefinitionKey + "' and version = '" + processDefinitionVersion + "'.");
    }
    return null;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ProcessDefinitionQueryImpl(org.activiti.engine.impl.ProcessDefinitionQueryImpl) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition)

Aggregations

ProcessDefinitionQueryImpl (org.activiti.engine.impl.ProcessDefinitionQueryImpl)4 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)4 ActivitiException (org.activiti.engine.ActivitiException)2 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)2 ArrayList (java.util.ArrayList)1 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 ActivitiEventDispatcher (org.activiti.engine.delegate.event.ActivitiEventDispatcher)1 Page (org.activiti.engine.impl.Page)1 DeploymentEntity (org.activiti.engine.impl.persistence.entity.DeploymentEntity)1 DeploymentEntityManager (org.activiti.engine.impl.persistence.entity.DeploymentEntityManager)1 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)1 ProcessDefinitionEntityManager (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntityManager)1