use of org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache in project camunda-bpm-platform by camunda.
the class SetProcessDefinitionVersionCmd method execute.
public Void execute(CommandContext commandContext) {
ProcessEngineConfigurationImpl configuration = commandContext.getProcessEngineConfiguration();
// check that the new process definition is just another version of the same
// process definition that the process instance is using
ExecutionManager executionManager = commandContext.getExecutionManager();
final ExecutionEntity processInstance = executionManager.findExecutionById(processInstanceId);
if (processInstance == null) {
throw new ProcessEngineException("No process instance found for id = '" + processInstanceId + "'.");
} else if (!processInstance.isProcessInstanceExecution()) {
throw new ProcessEngineException("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();
DeploymentCache deploymentCache = configuration.getDeploymentCache();
ProcessDefinitionEntity currentProcessDefinition;
if (currentProcessDefinitionImpl instanceof ProcessDefinitionEntity) {
currentProcessDefinition = (ProcessDefinitionEntity) currentProcessDefinitionImpl;
} else {
currentProcessDefinition = deploymentCache.findDeployedProcessDefinitionById(currentProcessDefinitionImpl.getId());
}
ProcessDefinitionEntity newProcessDefinition = deploymentCache.findDeployedProcessDefinitionByKeyVersionAndTenantId(currentProcessDefinition.getKey(), processDefinitionVersion, currentProcessDefinition.getTenantId());
validateAndSwitchVersionOfExecution(commandContext, processInstance, newProcessDefinition);
HistoryLevel historyLevel = configuration.getHistoryLevel();
if (historyLevel.isHistoryEventProduced(HistoryEventTypes.PROCESS_INSTANCE_UPDATE, processInstance)) {
HistoryEventProcessor.processHistoryEvents(new HistoryEventProcessor.HistoryEventCreator() {
@Override
public HistoryEvent createHistoryEvent(HistoryEventProducer producer) {
return producer.createProcessInstanceUpdateEvt(processInstance);
}
});
}
// switch all sub-executions of the process instance to the new process definition version
List<ExecutionEntity> childExecutions = executionManager.findExecutionsByProcessInstanceId(processInstanceId);
for (ExecutionEntity executionEntity : childExecutions) {
validateAndSwitchVersionOfExecution(commandContext, executionEntity, newProcessDefinition);
}
// switch all jobs to the new process definition version
List<JobEntity> jobs = commandContext.getJobManager().findJobsByProcessInstanceId(processInstanceId);
List<JobDefinitionEntity> currentJobDefinitions = commandContext.getJobDefinitionManager().findByProcessDefinitionId(currentProcessDefinition.getId());
List<JobDefinitionEntity> newVersionJobDefinitions = commandContext.getJobDefinitionManager().findByProcessDefinitionId(newProcessDefinition.getId());
Map<String, String> jobDefinitionMapping = getJobDefinitionMapping(currentJobDefinitions, newVersionJobDefinitions);
for (JobEntity jobEntity : jobs) {
switchVersionOfJob(jobEntity, newProcessDefinition, jobDefinitionMapping);
}
// switch all incidents to the new process definition version
List<IncidentEntity> incidents = commandContext.getIncidentManager().findIncidentsByProcessInstance(processInstanceId);
for (IncidentEntity incidentEntity : incidents) {
switchVersionOfIncident(commandContext, incidentEntity, newProcessDefinition);
}
// add an entry to the op log
PropertyChange change = new PropertyChange("processDefinitionVersion", currentProcessDefinition.getVersion(), processDefinitionVersion);
commandContext.getOperationLogManager().logProcessInstanceOperation(UserOperationLogEntry.OPERATION_TYPE_MODIFY_PROCESS_INSTANCE, processInstanceId, null, null, Collections.singletonList(change));
return null;
}
use of org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache in project camunda-bpm-platform by camunda.
the class GetFormKeyCmd method execute.
public String execute(CommandContext commandContext) {
ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
DeploymentCache deploymentCache = processEngineConfiguration.getDeploymentCache();
ProcessDefinitionEntity processDefinition = deploymentCache.findDeployedProcessDefinitionById(processDefinitionId);
for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
checker.checkReadProcessDefinition(processDefinition);
}
Expression formKeyExpression = null;
if (taskDefinitionKey == null) {
// TODO: Maybe add getFormKey() to FormHandler interface to avoid the following cast
FormHandler formHandler = processDefinition.getStartFormHandler();
if (formHandler instanceof DelegateStartFormHandler) {
DelegateStartFormHandler delegateFormHandler = (DelegateStartFormHandler) formHandler;
formHandler = delegateFormHandler.getFormHandler();
}
// form handler (for a startForm) has always to extend the DefaultStartFormHandler!
if (formHandler instanceof DefaultStartFormHandler) {
DefaultStartFormHandler startFormHandler = (DefaultStartFormHandler) formHandler;
formKeyExpression = startFormHandler.getFormKey();
}
} else {
TaskDefinition taskDefinition = processDefinition.getTaskDefinitions().get(taskDefinitionKey);
formKeyExpression = taskDefinition.getFormKey();
}
String formKey = null;
if (formKeyExpression != null) {
formKey = formKeyExpression.getExpressionText();
}
return formKey;
}
use of org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache in project camunda-bpm-platform by camunda.
the class GetStartFormCmd method execute.
public StartFormData execute(CommandContext commandContext) {
ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
DeploymentCache deploymentCache = processEngineConfiguration.getDeploymentCache();
ProcessDefinitionEntity processDefinition = deploymentCache.findDeployedProcessDefinitionById(processDefinitionId);
ensureNotNull("No process definition found for id '" + processDefinitionId + "'", "processDefinition", processDefinition);
for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
checker.checkReadProcessDefinition(processDefinition);
}
StartFormHandler startFormHandler = processDefinition.getStartFormHandler();
ensureNotNull("No startFormHandler defined in process '" + processDefinitionId + "'", "startFormHandler", startFormHandler);
return startFormHandler.createStartFormData(processDefinition);
}
use of org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache in project camunda-bpm-platform by camunda.
the class GetDeploymentDmnModelInstanceCmd method execute.
public DmnModelInstance execute(CommandContext commandContext) {
ensureNotNull("decisionDefinitionId", decisionDefinitionId);
DeploymentCache deploymentCache = Context.getProcessEngineConfiguration().getDeploymentCache();
DecisionDefinitionEntity decisionDefinition = deploymentCache.findDeployedDecisionDefinitionById(decisionDefinitionId);
for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
checker.checkReadDecisionDefinition(decisionDefinition);
}
DmnModelInstance modelInstance = deploymentCache.findDmnModelInstanceForDecisionDefinition(decisionDefinitionId);
ensureNotNull(DmnModelInstanceNotFoundException.class, "No DMN model instance found for decision definition id " + decisionDefinitionId, "modelInstance", modelInstance);
return modelInstance;
}
use of org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache in project camunda-bpm-platform by camunda.
the class DecisionRequirementsDefinitionEntity method loadDecisionRequirementsDefinition.
/**
* Returns the cached version if exists; does not update the entity from the database in that case
*/
protected DecisionRequirementsDefinitionEntity loadDecisionRequirementsDefinition(String decisionRequirementsDefinitionId) {
ProcessEngineConfigurationImpl configuration = Context.getProcessEngineConfiguration();
DeploymentCache deploymentCache = configuration.getDeploymentCache();
DecisionRequirementsDefinitionEntity decisionRequirementsDefinition = deploymentCache.findDecisionRequirementsDefinitionFromCache(decisionRequirementsDefinitionId);
if (decisionRequirementsDefinition == null) {
CommandContext commandContext = Context.getCommandContext();
DecisionRequirementsDefinitionManager manager = commandContext.getDecisionRequirementsDefinitionManager();
decisionRequirementsDefinition = manager.findDecisionRequirementsDefinitionById(decisionRequirementsDefinitionId);
if (decisionRequirementsDefinition != null) {
decisionRequirementsDefinition = deploymentCache.resolveDecisionRequirementsDefinition(decisionRequirementsDefinition);
}
}
return decisionRequirementsDefinition;
}
Aggregations