An overview of the

In this section, we will create an Activit workflow and start the process, which consists of the following steps:

  1. Define the process, according to BPMN specifications, using process definition tools, with process symbols to describe the entire process

  2. Deploy the process, load the drawn process definition file into the database, and generate the data of the table

Use of process designer

Create a BPMN directory under the Resources directory to hold the process definition files. Select the BPMN directory and click on the menu New -> New Activity 6.x BPMN 2.x file to create a *.bPMn20.xml. Select this file and right-click View BPMN(Activity) Diagram to see the bPMN-Activiti-Diagram process design page. Right click on the page, you can choose the graph in the menu, drag the graph, line, you can complete the process design diagram

When connecting, select the graph, and an arrow symbol appears in the upper right corner of the graph. Double-click to select the arrow symbol, right – click hold to elongate to complete the line

If you select a graph, an attribute bar will appear. Take creating a business trip application as an example, fill in only the task name and the person in charge

Process deployment

Process deployment is the deployment of a process defined in the designer to an Activiti database. Activiti provides several ways to deploy a process, including automatic deployment, CLASspath deployment, input stream deployment, ZIP /bar deployment, and upload deployment, as described below:

1. Automatic deployment

Activiti7 can automatically deploy processes if, under the Resources directory, a new directory, Processes, is created to hold BPMN files

2. The classpath deployment

The Classpath deployment mode is implemented in code, using Java code as follows:

public class ActivitDemo {

    @Test
    public void testDeployment(a) {
        // 1. Create ProcessEngine
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        // 2. Get RepositoryService
        RepositoryService repositoryService = processEngine.getRepositoryService();
        // 3. Use service to deploy the process, that is, deploy BPMN to the database and define the name of the process
        Deployment deploy = repositoryService.createDeployment()
            	// Define the process resource name
                .name("Business Trip Application Process")
            	// Load the resource to be deployed. You can reference the resource multiple times
                .addClasspathResource("bpmn/evection.bpmn20.xml")
            	// The deployment is complete.deploy(); }}Copy the code

3. Deploy input streams

Activiti provides InputStream deployment. Input streams can come from a variety of sources, such as a local machine, a CLASspath read, a network read, and so on. The following is a sample code for a local machine read deployment mode

public class ActivitDemo {

    @Test
    public void testDeployment(a) {
        // 1. Create ProcessEngine
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        // 2. Get RepositoryService
        RepositoryService repositoryService = processEngine.getRepositoryService();
        // 3. Get the input stream
        String filePath = "D:/workflow/bpmn/evection.bpmn20.xml";
        FileInputStream fileIns = new FileInputStream(filePath);
        // 4. Deploy the process using service
        Deployment deploy = repositoryService.createDeployment()
                .name("Business Trip Application Process")
                .addInputStream("bpmn/evection.bpmn20.xml", fileIns) .deploy(); }}Copy the code

4. Zip/bar deployment

Compress the process resource files into zip packages for deployment, again in a streaming manner

public void deployProcessByZip(a) {
    // 1. Obtain the flow engine
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    // 2. Get RepositoryService
    RepositoryService repositoryService = processEngine.getRepositoryService();
    // 3. Process deployment
    InputStream inputStream = this.getClass()
        .getClassLoader()
        .getResourceAsStream("bpmn/evection.zip");
    ZipInputStream zipInputStream = new ZipInputStream(inputStream);
    repositoryService.createDeployment()
        .addZipInputStream(zipInputStream)
        .deploy();
}
Copy the code

5. Deploy it as a string

The deployment in string mode actually converts a string into a byte stream and then deploys it, which also provides developers with another deployment mode

public void deployProcessByStr(a) {
    // 1. Obtain the flow engine
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    // 2. Get RepositoryService
    RepositoryService repositoryService = processEngine.getRepositoryService();
    // 3. Construct a string
    String str = "
      
      
       ... 
      "
    // 4. Process deployment
    repositoryService.createDeployment()
        .name("Business Trip Application Process")
        .addStr("bpmn/evection.bpmn20.xml", str)
        .deploy();
}
Copy the code

The advantage of string deployment is that you can define a process through the user interface and then deploy it, or when testing, write the process code directly to the program and deploy the process

6. Dynamic BPMN model deployment

To deploy the BPMN dynamically by generating a process model in the program, you need to specify each element in the program, give the relationship between the elements, and finally integrate these elements into a complete BPMN

public void testDeploymentByBPMN(a) {
    // 1. Create a BPMN model instance
    BpmnModel bpmnModel = new BpmnModel();
    // 2. Create start event
    StartEvent startEvent = new StartEvent();
    startEvent.setId("startEvent");
    startEvent.setName("Dynamically create start node");
    // 3. Create user tasks
    UserTask userTask = new UserTask();
    userTask.setId("userTask1");
    userTask.setName("User Task node 1");
    // 4. Create end event
    EndEvent endEvent = new EndEvent();
    endEvent.setId("endEvent");
    endEvent.setName("Dynamically create end node");
    // 5. Define the connection
    ArrayList<SequenceFlow> sequenceFlows = new ArrayList<>();
    ArrayList<SequenceFlow> toEnd = new ArrayList<>();

    SequenceFlow s1 = new SequenceFlow();
    s1.setId("sequenceFlow1");
    s1.setName("Start node points to user task node");
    s1.setSourceRef("startEvent");
    s1.setTargetRef("userTask1");
    sequenceFlows.add(s1);
    SequenceFlow s2 = new SequenceFlow();
    s2.setId("sequenceFlow2");
    s2.setName("User task node points to end node");
    s2.setSourceRef("userTask1");
    s2.setTargetRef("endEvent");
    toEnd.add(s2);

    startEvent.setOutgoingFlows(sequenceFlows);
    userTask.setOutgoingFlows(toEnd);
    userTask.setIncomingFlows(sequenceFlows);
    endEvent.setIncomingFlows(toEnd);

    Process process = new Process();
    process.setId("process1");
    process.setName("test");
    process.addFlowElement(startEvent);
    process.addFlowElement(s1);
    process.addFlowElement(userTask);
    process.addFlowElement(s2);
    process.addFlowElement(endEvent);
    bpmnModel.addProcess(process);
    new BpmnAutoLayout(bpmnModel).execute();
    / / 6. Deployment
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    RepositoryService repositoryService = processEngine.getRepositoryService();
    Deployment deploy = repositoryService.createDeployment()
        .name("Business Trip Application Process")
        .addBpmnModel("evection.bpmn20.xml", bpmnModel)
        .deploy();
}
Copy the code

7. Related data table analysis

After the process is deployed, all process-related resources are stored in the data table in the form of data flow. In actual operation, the process is processed by calling related resources in the data table. The following describes the data table related to the process:

  • act_re_deployment

    Process deployment table, used to hold deployment information defined by the process. A record is added when a process is deployed

  • act_re_procdef

    The act_RE_procDEF table is a one-to-many relationship with act_RE_Deployment. The ACT_RE_procdef table can have multiple records, each of which corresponds to one record in act_RE_Deployment

  • act_ge_bytearray

    Resource file table. The BPMN process definition file is saved as a record when the process is deployed, and records are added if the deployed process also includes other resources, such as PNG image files