Deployment management of Flowable actual combat process

Posted by seby on Mon, 10 Jan 2022 15:42:14 +0100

1, Version of process definition

  when deploying a process definition, the process definition in the database will look like this:

idkeynameversion
myProcess:1:676myProcessMy important process1

   if we deploy an updated version of the same process (for example, modify some user tasks) and keep the id of the process definition unchanged, the following records will be included in the process definition table:

idkeynameversion
myProcess:1:676myProcessMy important process1
myProcess:2:870myProcessMy important process2

  when calling the execution process, the version 2 process definition will be used because this is the latest version of the process definition.

2, Process deployment method

2.1 resource file deployment within the specified project

  for example, create a new resource file single task under resources / bpmn20. xml

<?xml version="1.0" encoding="UTF-8"?>
<definitions
        xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
        xmlns:flowable="http://flowable.org/bpmn"
        targetNamespace="Examples">

    <process id="singleTask" name="The One Task Process">
        <startEvent id="theStart" />
        <sequenceFlow id="flow1" sourceRef="theStart" targetRef="theTask" />
        <userTask id="theTask" name="my task" flowable:assignee="zhangsan" />
        <sequenceFlow id="flow2" sourceRef="theTask" targetRef="theEnd" />
        <endEvent id="theEnd" />
    </process>

</definitions>

  deployment example code:

 // Resource path
String path = "single-task.bpmn20.xml";
// Create deployment builder
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
// Add resource
deploymentBuilder.addClasspathResource(path);
// Execute deployment
deploymentBuilder.deploy();
// Validate deployment
long count = repositoryService.createProcessDefinitionQuery().processDefinitionKey("singleTask").count();
// If count equals 1, the deployment is successful

  any resource in the project class directory can be deployed in this way.

  this method is generally used in the development and testing stage. The real production environment is deployed interactively with the web management page.

2.2 spring boot automatic deployment

  in the springboot environment, any BPMN 2.0 process definition in the resources/processes directory will be automatically deployed.

2.3 interface mode

   in actual production, we need to receive the process definition data from the front end, and then update the deployment.

  next, we will omit the display of front-end access interface parameters and only demonstrate the back-end processing code.

// XML string received from the front end
// The specific content of XML is omitted here. Please refer to single task.xml in 2.1 bpmn20. XML example
// Note that the id is defined as single task 2 to distinguish it from the content of 2.1
String text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><definitions...</definitions>";
// Create deployment builder
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
// Execute deployment
deploymentBuilder.addString("single-task2.bpmn20.xml", text).deploy();
// Validate deployment
long count = repositoryService.createProcessDefinitionQuery().processDefinitionKey("singleTask2").count();
// If count equals 1, the deployment is successful

2.4 zip package

    when we need to deploy multiple resources at the same time, we can use the zip package deployment method.

String fileName = "path/multi-task.zip";
ZipInputStream inputStream = new ZipInputStream(new FileInputStream(fileName));

repositoryService.createDeployment()
    .name("multi-task.zip")
    .addZipInputStream(inputStream)
    .deploy();

3, Process management

  the first step of the business system is to need a list to browse and manage process definitions.

3.1 get the list of deployed processes

@Autowired
private RepositoryService repositoryService;

public List getDeployList() {
    List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().list();
    return list;
}

3.2 reading process pictures

  obviously, the management page needs the function of displaying process pictures.

  the Flowable engine will automatically generate process pictures when the process is deployed.

  method of obtaining process picture:

ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
  .processDefinitionKey("singleTask")
  .singleResult();

String diagramResourceName = processDefinition.getDiagramResourceName();
InputStream imageStream = repositoryService.getResourceAsStream(
    processDefinition.getDeploymentId(), diagramResourceName);

Note: if you do not need or want to generate a flowchart during deployment, you can set the isCreateDiagramOnDeploy parameter in the process engine configuration:

<property name="createDiagramOnDeploy" value="false" />

3.3 reading XML of process definition

  the "display process definition code" function can be added to the management interface, that is, read and display the XML content of the process definition.

// Query by processDefinitionId
ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
// Read the resource stream. resourceName is the resource name returned by the front end
InputStream stream = repositoryService.getResourceAsStream(pd.getDeploymentId(), resourceName);
//The read resource stream is returned to the front end

3.4 delete deployment

  a process definition is not deleted through the process definition ID, but through the deployment ID of the process definition. When deleting, the resources related to this deployment will be deleted together.

repositoryService.deleteDeployment(deploymentId, true);

4, Summary

  this chapter introduces the version, deployment and management of process definition. Of course, in practical application, there are still many details to be optimized, such as de duplication during process definition and deployment, paging to obtain process list, and so on.

Topics: Java bpmn