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;
}
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;
}
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());
}
}
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;
}
Aggregations