public ProcessInstance execute(CommandContext commandContext) { DeploymentManager deploymentCache = Context.getProcessEngineConfiguration().getDeploymentManager(); // Find the process definition ProcessDefinitionEntity processDefinition = null; if (processDefinitionId != null) { processDefinition = deploymentCache.findDeployedProcessDefinitionById(processDefinitionId); if (processDefinition == null) { throw new ActivitiException( "No process definition found for id = '" + processDefinitionId + "'"); } } else if (processDefinitionKey != null) { /* Original state processDefinition = deploymentCache.findDeployedLatestProcessDefinitionByKey(processDefinitionKey); if (processDefinition == null) { throw new ActivitiException("No process definition found for key '" + processDefinitionKey +"'"); } */ throw new ActivitiException( "Operation usupported due to unavailability to get latest definition by key for a Liferay Company"); } else { throw new ActivitiException("processDefinitionKey and processDefinitionId are null"); } // Do not start process a process instance if the process definition is suspended if (processDefinition.isSuspended()) { 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); if (variables != null) { processInstance.setVariables(variables); } processInstance.start(); return processInstance; }