CommandContext commandContext = Context.getCommandContext();
ProcessDefinitionManager processDefinitionManager = commandContext.getProcessDefinitionManager();
DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
int processDefinitionVersion;
ProcessDefinitionBehavior latestProcessDefinition = processDefinitionManager.findLatestProcessDefinitionByKey(process.getProcessDefinitionKey());
if (latestProcessDefinition != null) {
processDefinitionVersion = latestProcessDefinition.getVersion() + 1;
} else {
processDefinitionVersion = 1;
}
if(deployment.getUpdateDeploymentId()!=null&&!deployment.getUpdateDeploymentId().equals("")){
String deploymentId = deployment.getId();
process.setDeploymentId(deploymentId);
ProcessDefinitionBehavior persistedProcessDefinition = processDefinitionManager.findProcessDefinitionByDeploymentAndKey(
deploymentId, process.getProcessDefinitionKey());
//process.setId(persistedProcessDefinition.getId());
process.setVersion(persistedProcessDefinition.getVersion());
process.setProcessDefinitionId(persistedProcessDefinition.getProcessDefinitionId());
Context.getProcessEngineConfiguration().getDeploymentCache().removeProcessDefinition(process.getProcessDefinitionId());
}else{
process.setVersion(processDefinitionVersion);
process.setDeploymentId(deployment.getId());
String processDefinitionId = process.getProcessDefinitionKey() + ":" + process.getVersion() + ":" + GuidUtil.CreateGuid(); // GUID
process.setProcessDefinitionId(processDefinitionId);
dbSqlSession.insert("insertProcessDefinition", process);
}
//Context.getProcessEngineConfiguration().getDeploymentCache().removeProcessDefinition(processDefinitionId);
//Context.getProcessEngineConfiguration().getDeploymentCache().addProcessDefinition(process);