DeploymentCache deploymentCache = Context
.getProcessEngineConfiguration()
.getDeploymentCache();
// Find the process definition
ProcessDefinitionEntity processDefinition = null;
if (processDefinitionId!=null) {
processDefinition = deploymentCache.findDeployedProcessDefinitionById(processDefinitionId);
ensureNotNull("No process definition found for id = '" + processDefinitionId + "'", "processDefinition", processDefinition);
} else if(processDefinitionKey != null) {
processDefinition = deploymentCache.findDeployedLatestProcessDefinitionByKey(processDefinitionKey);
ensureNotNull("No process definition found for key '" + processDefinitionKey + "'", "processDefinition", processDefinition);
} else {
throw new ProcessEngineException("processDefinitionKey and processDefinitionId are null");
}
// Start the process instance
ExecutionEntity processInstance = processDefinition.createProcessInstance(businessKey, caseInstanceId);
processInstance.start(variables);
return processInstance;
}