Skip to content

Commit

Permalink
Fix bpmn - allow updating BPM processes (#4148)
Browse files Browse the repository at this point in the history
  • Loading branch information
iliyan-velichkov authored Jul 17, 2024
1 parent c26ec57 commit 00b3f6e
Showing 1 changed file with 18 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,6 @@ public BpmnSynchronizer(BpmnService bpmnService, BpmProviderFlowable bpmProvider
this.bpmProviderFlowable = bpmProviderFlowable;
}

/**
* Gets the bpm provider flowable.
*
* @return the bpm provider flowable
*/
public BpmProviderFlowable getBpmProviderFlowable() {
return bpmProviderFlowable;
}

/**
* Checks if is accepted.
*
Expand Down Expand Up @@ -177,13 +168,13 @@ protected boolean completeImpl(TopologyWrapper<Bpmn> wrapper, ArtefactPhase flow
switch (flow) {
case CREATE:
if (ArtefactLifecycle.NEW.equals(bpmn.getLifecycle())) {
deployOnProcessEngine(bpmn);
deployProcess(bpmn);
callback.registerState(this, wrapper, ArtefactLifecycle.CREATED);
}
break;
case UPDATE:
if (ArtefactLifecycle.MODIFIED.equals(bpmn.getLifecycle())) {
updateOnProcessEngine(bpmn);
deployProcess(bpmn);
callback.registerState(this, wrapper, ArtefactLifecycle.UPDATED);
}
if (ArtefactLifecycle.FAILED.equals(bpmn.getLifecycle())) {
Expand All @@ -206,12 +197,7 @@ protected boolean completeImpl(TopologyWrapper<Bpmn> wrapper, ArtefactPhase flow
}
}

/**
* Deploy on process engine.
*
* @param bpmn the bpmn
*/
private void deployOnProcessEngine(Bpmn bpmn) {
private void deployProcess(Bpmn bpmn) {
try {
ProcessEngine processEngine = bpmProviderFlowable.getProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
Expand All @@ -220,91 +206,23 @@ private void deployOnProcessEngine(Bpmn bpmn) {
.key(bpmn.getLocation())
.addBytes(bpmn.getLocation(), bpmn.getContent())
.deploy();
List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery()
.deploymentId(deployment.getId())
.list();
if (processDefinitions.size() > 0) {
ProcessDefinition processDefinition = processDefinitions.get(0);
bpmn.setDeploymentId(processDefinition.getDeploymentId());
bpmn.setProcessDefinitionId(processDefinition.getId());
bpmn.setProcessDefinitionKey(processDefinition.getKey());
bpmn.setProcessDefinitionName(processDefinition.getName());
bpmn.setProcessDefinitionVersion(processDefinition.getVersion());
bpmn.setProcessDefinitionTenantId(processDefinition.getTenantId());
bpmn.setProcessDefinitionCategory(processDefinition.getCategory());
bpmn.setProcessDefinitionDescription(processDefinition.getDescription());
}
if (logger.isInfoEnabled()) {
logger.info(
format("Deployed: [{0}] with key: [{1}] on the Flowable BPMN Engine.", deployment.getId(), deployment.getKey()));
}
} catch (Exception e) {
if (logger.isErrorEnabled()) {
logger.error("Error on deploying a BPMN file from location: {}", bpmn.getLocation(), e);
}
}
}

/**
* Deploy on process engine.
*
* @param bpmn the bpmn
*/
private void updateOnProcessEngine(Bpmn bpmn) {
try {
ProcessEngine processEngine = bpmProviderFlowable.getProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
.deploymentId(deployment.getId())
.singleResult();

List<Deployment> deployments = repositoryService.createDeploymentQuery()
.list();
for (Deployment deployment : deployments) {
if (logger.isTraceEnabled()) {
logger.trace(format("Deployment: [{0}] with key: [{1}]", deployment.getId(), deployment.getKey()));
}
if (bpmn.getLocation()
.equals(deployment.getKey())) {
List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery()
.deploymentId(deployment.getId())
.active()
.list();
if (processDefinitions.size() > 0) {
ProcessDefinition processDefinition = processDefinitions.get(0);
// repositoryService.suspendProcessDefinitionById(processDefinition.getId());
repositoryService.deleteDeployment(processDefinition.getDeploymentId());
Deployment newDeployment = repositoryService.createDeployment()
.key(bpmn.getLocation())
.addBytes(bpmn.getLocation(), bpmn.getContent())
.deploy();
processDefinitions = repositoryService.createProcessDefinitionQuery()
.deploymentId(newDeployment.getId())
.list();
if (processDefinitions.size() > 0) {
processDefinition = processDefinitions.get(0);
bpmn.setDeploymentId(processDefinition.getDeploymentId());
bpmn.setProcessDefinitionId(processDefinition.getId());
bpmn.setProcessDefinitionKey(processDefinition.getKey());
bpmn.setProcessDefinitionName(processDefinition.getName());
bpmn.setProcessDefinitionVersion(processDefinition.getVersion());
bpmn.setProcessDefinitionTenantId(processDefinition.getTenantId());
bpmn.setProcessDefinitionCategory(processDefinition.getCategory());
bpmn.setProcessDefinitionDescription(processDefinition.getDescription());
if (logger.isInfoEnabled()) {
logger.info(format("Updated deployment: [{0}] with key: [{1}] on the Flowable BPMN Engine.",
deployment.getId(), deployment.getKey()));
}
return;
}
}
}

// backup if the definitions is modified, but the old version get broken and does not exist in the
// process engine
deployOnProcessEngine(bpmn);
}
} catch (Exception e) {
if (logger.isErrorEnabled()) {
logger.error("Error on deploying a BPMN file from location: {}", bpmn.getLocation(), e);
}
bpmn.setDeploymentId(processDefinition.getDeploymentId());
bpmn.setProcessDefinitionId(processDefinition.getId());
bpmn.setProcessDefinitionKey(processDefinition.getKey());
bpmn.setProcessDefinitionName(processDefinition.getName());
bpmn.setProcessDefinitionVersion(processDefinition.getVersion());
bpmn.setProcessDefinitionTenantId(processDefinition.getTenantId());
bpmn.setProcessDefinitionCategory(processDefinition.getCategory());
bpmn.setProcessDefinitionDescription(processDefinition.getDescription());
logger.info("BPMN [{}] has been deployed : id [{}], key: [{}]", bpmn, deployment.getId(), deployment.getKey());
} catch (RuntimeException ex) {
String errorMessage = "Failed to deploy BPMN: " + bpmn;
throw new IllegalStateException(errorMessage, ex);
}
}

Expand Down

0 comments on commit 00b3f6e

Please sign in to comment.