use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.
the class HasTaskVariableCmd method execute.
public Boolean execute(CommandContext commandContext) {
if (taskId == null) {
throw new ActivitiIllegalArgumentException("taskId is null");
}
if (variableName == null) {
throw new ActivitiIllegalArgumentException("variableName is null");
}
TaskEntity task = commandContext.getTaskEntityManager().findTaskById(taskId);
if (task == null) {
throw new ActivitiObjectNotFoundException("task " + taskId + " doesn't exist", Task.class);
}
boolean hasVariable = false;
if (isLocal) {
hasVariable = task.hasVariableLocal(variableName);
} else {
hasVariable = task.hasVariable(variableName);
}
return hasVariable;
}
use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.
the class StartProcessInstanceByMessageCmd method execute.
public ProcessInstance execute(CommandContext commandContext) {
if (messageName == null) {
throw new ActivitiIllegalArgumentException("Cannot start process instance by message: message name is null");
}
MessageEventSubscriptionEntity messageEventSubscription = commandContext.getEventSubscriptionEntityManager().findMessageStartEventSubscriptionByName(messageName, tenantId);
if (messageEventSubscription == null) {
throw new ActivitiObjectNotFoundException("Cannot start process instance by message: no subscription to message with name '" + messageName + "' found.", MessageEventSubscriptionEntity.class);
}
String processDefinitionId = messageEventSubscription.getConfiguration();
if (processDefinitionId == null) {
throw new ActivitiException("Cannot start process instance by message: subscription to message with name '" + messageName + "' is not a message start event.");
}
DeploymentManager deploymentManager = commandContext.getProcessEngineConfiguration().getDeploymentManager();
ProcessDefinitionEntity processDefinition = deploymentManager.findDeployedProcessDefinitionById(processDefinitionId);
if (processDefinition == null) {
throw new ActivitiObjectNotFoundException("No process definition found for id '" + processDefinitionId + "'", ProcessDefinition.class);
}
// Do not start process a process instance if the process definition is suspended
if (deploymentManager.isProcessDefinitionSuspended(processDefinition.getId())) {
throw new ActivitiException("Cannot start process instance. Process definition " + processDefinition.getName() + " (id = " + processDefinition.getId() + ") is suspended");
}
ActivityImpl startActivity = processDefinition.findActivity(messageEventSubscription.getActivityId());
ExecutionEntity processInstance = processDefinition.createProcessInstance(businessKey, startActivity);
if (processVariables != null) {
processInstance.setVariables(processVariables);
}
processInstance.start();
return processInstance;
}
use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.
the class StartProcessInstanceCmd method execute.
public ProcessInstance execute(CommandContext commandContext) {
DeploymentManager deploymentManager = commandContext.getProcessEngineConfiguration().getDeploymentManager();
// Find the process definition
ProcessDefinitionEntity processDefinition = null;
if (processDefinitionId != null) {
processDefinition = deploymentManager.findDeployedProcessDefinitionById(processDefinitionId);
if (processDefinition == null) {
throw new ActivitiObjectNotFoundException("No process definition found for id = '" + processDefinitionId + "'", ProcessDefinition.class);
}
} else if (processDefinitionKey != null && (tenantId == null || ProcessEngineConfiguration.NO_TENANT_ID.equals(tenantId))) {
processDefinition = deploymentManager.findDeployedLatestProcessDefinitionByKey(processDefinitionKey);
if (processDefinition == null) {
throw new ActivitiObjectNotFoundException("No process definition found for key '" + processDefinitionKey + "'", ProcessDefinition.class);
}
} else if (processDefinitionKey != null && tenantId != null && !ProcessEngineConfiguration.NO_TENANT_ID.equals(tenantId)) {
processDefinition = deploymentManager.findDeployedLatestProcessDefinitionByKeyAndTenantId(processDefinitionKey, tenantId);
if (processDefinition == null) {
throw new ActivitiObjectNotFoundException("No process definition found for key '" + processDefinitionKey + "' for tenant identifier " + tenantId, ProcessDefinition.class);
}
} else {
throw new ActivitiIllegalArgumentException("processDefinitionKey and processDefinitionId are null");
}
// Do not start process a process instance if the process definition is suspended
if (deploymentManager.isProcessDefinitionSuspended(processDefinition.getId())) {
throw new ActivitiException("Cannot start process instance. Process definition " + processDefinition.getName() + " (id = " + processDefinition.getId() + ") is suspended");
}
// Start the process instance
ExecutionEntity processInstance = processDefinition.createProcessInstance(businessKey);
// now set the variables passed into the start command
initializeVariables(processInstance);
// now set processInstance name
if (processInstanceName != null) {
processInstance.setName(processInstanceName);
commandContext.getHistoryManager().recordProcessInstanceNameChange(processInstance.getId(), processInstanceName);
}
processInstance.start();
return processInstance;
}
use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.
the class SetDeploymentCategoryCmd method execute.
public Void execute(CommandContext commandContext) {
if (deploymentId == null) {
throw new ActivitiIllegalArgumentException("Deployment id is null");
}
DeploymentEntity deployment = commandContext.getDeploymentEntityManager().findDeploymentById(deploymentId);
if (deployment == null) {
throw new ActivitiObjectNotFoundException("No deployment found for id = '" + deploymentId + "'", Deployment.class);
}
// Update category
deployment.setCategory(category);
if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, deployment));
}
return null;
}
use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.
the class SetProcessDefinitionVersionCmd method execute.
public Void execute(CommandContext commandContext) {
// check that the new process definition is just another version of the same
// process definition that the process instance is using
ExecutionEntityManager executionManager = commandContext.getExecutionEntityManager();
ExecutionEntity processInstance = executionManager.findExecutionById(processInstanceId);
if (processInstance == null) {
throw new ActivitiObjectNotFoundException("No process instance found for id = '" + processInstanceId + "'.", ProcessInstance.class);
} else if (!processInstance.isProcessInstanceType()) {
throw new ActivitiIllegalArgumentException("A process instance id is required, but the provided id " + "'" + processInstanceId + "' " + "points to a child execution of process instance " + "'" + processInstance.getProcessInstanceId() + "'. " + "Please invoke the " + getClass().getSimpleName() + " with a root execution id.");
}
ProcessDefinitionImpl currentProcessDefinitionImpl = processInstance.getProcessDefinition();
DeploymentManager deploymentCache = commandContext.getProcessEngineConfiguration().getDeploymentManager();
ProcessDefinitionEntity currentProcessDefinition;
if (currentProcessDefinitionImpl instanceof ProcessDefinitionEntity) {
currentProcessDefinition = (ProcessDefinitionEntity) currentProcessDefinitionImpl;
} else {
currentProcessDefinition = deploymentCache.findDeployedProcessDefinitionById(currentProcessDefinitionImpl.getId());
}
ProcessDefinitionEntity newProcessDefinition = deploymentCache.findDeployedProcessDefinitionByKeyAndVersion(currentProcessDefinition.getKey(), processDefinitionVersion);
validateAndSwitchVersionOfExecution(commandContext, processInstance, newProcessDefinition);
// switch the historic process instance to the new process definition version
commandContext.getHistoryManager().recordProcessDefinitionChange(processInstanceId, newProcessDefinition.getId());
// switch all sub-executions of the process instance to the new process definition version
List<ExecutionEntity> childExecutions = executionManager.findChildExecutionsByProcessInstanceId(processInstanceId);
for (ExecutionEntity executionEntity : childExecutions) {
validateAndSwitchVersionOfExecution(commandContext, executionEntity, newProcessDefinition);
}
return null;
}
Aggregations