keyList.add(processDefinition.getKey());
}
CommandContext commandContext = Context.getCommandContext();
ProcessDefinitionManager processDefinitionManager = commandContext.getProcessDefinitionManager();
DeploymentCache deploymentCache = Context.getProcessEngineConfiguration().getDeploymentCache();
DbEntityManager dbEntityManager = commandContext.getDbEntityManager();
for (ProcessDefinitionEntity processDefinition : processDefinitions) {
if (deployment.isNew()) {
ProcessDefinitionEntity latestProcessDefinition = processDefinitionManager.findLatestProcessDefinitionByKey(processDefinition.getKey());
processDefinition.setDeploymentId(deployment.getId());
processDefinition.setVersion(getVersionForNewProcessDefinition(deployment, processDefinition, latestProcessDefinition));
processDefinition.setId(getProcessDefinitionId(deployment, processDefinition));
List<JobDeclaration<?>> declarations = jobDeclarations.get(processDefinition.getKey());
updateJobDeclarations(declarations, processDefinition, deployment.isNew());
adjustStartEventSubscriptions(processDefinition, latestProcessDefinition);
dbEntityManager.insert(processDefinition);
deploymentCache.addProcessDefinition(processDefinition);
addAuthorizations(processDefinition);
} else {
String deploymentId = deployment.getId();
processDefinition.setDeploymentId(deploymentId);
ProcessDefinitionEntity persistedProcessDefinition = processDefinitionManager.findProcessDefinitionByDeploymentAndKey(deploymentId, processDefinition.getKey());
processDefinition.setId(persistedProcessDefinition.getId());
processDefinition.setVersion(persistedProcessDefinition.getVersion());
processDefinition.setSuspensionState(persistedProcessDefinition.getSuspensionState());
List<JobDeclaration<?>> declarations = jobDeclarations.get(processDefinition.getKey());
updateJobDeclarations(declarations, processDefinition, deployment.isNew());
deploymentCache.addProcessDefinition(processDefinition);
addAuthorizations(processDefinition);
}
// Add to cache