DeploymentCache deploymentCache = Context
.getProcessEngineConfiguration()
.getDeploymentCache();
// Find the case definition
CaseDefinitionEntity caseDefinition = null;
ensureAtLeastOneNotNull("caseDefinition and caseDefinitionKey are null", caseDefinitionId, caseDefinitionKey);
if (caseDefinitionId!=null) {
caseDefinition = deploymentCache.findDeployedCaseDefinitionById(caseDefinitionId);
ensureNotNull(CaseDefinitionNotFoundException.class, "No case definition found for id = '" + caseDefinitionId + "'", "caseDefinition", caseDefinition);
} else {
caseDefinition = deploymentCache.findDeployedLatestCaseDefinitionByKey(caseDefinitionKey);
ensureNotNull(CaseDefinitionNotFoundException.class, "No case definition found for key '" + caseDefinitionKey + "'", "caseDefinition", caseDefinition);
}
// Start the case instance
CaseExecutionEntity caseInstance = (CaseExecutionEntity) caseDefinition.createCaseInstance(businessKey);
caseInstance.create(variables);
return caseInstance;
}