Flowable simple understanding

Keywords: Java

Basic introduction

Flowable definition

Flowable is a lightweight business process engine written in Java and open source using Apache V2 license protocol. In October 2016, the main developer of Activiti workflow engine left Alfresco and started the flowable open source project on the basis of Activiti branch. The first Flowable release version released based on Activiti V6 beta 4 is 6.0. Publishing in JAR makes it easy for flowable to join any Java environment: servlet containers such as Java SE, Tomcat, Jetty or Spring; Java EE servers such as JBoss or WebSphere, and so on.

Flowable classification

Flowable BPMN business process engine

Process engine is the key module to support the configuration of business flow process. Flowable supports the BPMN 2.0 industry standard, and provides some flowable customized BPMN extensions, which allow the establishment of processes by importing XML files or through the front-end visual interface.

Flowable DMN decision engine

As a workflow engine with BPMN as the core, Flowable was not strongly associated with the rule engine, but in the actual business process, sometimes multiple decisions need to determine the process direction, and each decision should be determined according to its own rules, and there may be association between each decision. At this point, the rule engine is needed to provide decision support.

Flowable CMMN case model engine

CMMN is the abbreviation of Case Management Model, which is embodied in the "case model" menu in the Flowable Modeler application. When used, it can be used to visually configure processes similar to the process engine, or through XML format files.

Flowable Form engine

In the Flowable framework, the form is regarded as an independent sub module, and the form can be called in other modules as a service. The form service can control the readable and writable forms and form fields used by all processes. Form related use can be divided into two stages: form definition and form running instance. Form definition supports importing form definition files with. Form as suffix (written in JSON language).

Basic use

Flowchart xml file

<definitions id="definitions"
             targetNamespace="http://flowable.org/bpmn20"
             xmlns:flowable="http://flowable.org/bpmn"
             xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL">

    <process id="financialReport" name="Monthly financial report reminder process">

        <startEvent id="theStart" />

        <sequenceFlow id="flow1" sourceRef="theStart" targetRef="writeReportTask" />

        <userTask id="writeReportTask" name="Write monthly financial report" >
            <documentation>
                Write monthly financial report for publication to shareholders.
            </documentation>
            <potentialOwner>
                <resourceAssignmentExpression>
                    <formalExpression>accountancy</formalExpression>
                </resourceAssignmentExpression>
            </potentialOwner>
        </userTask>

        <sequenceFlow id="flow2" sourceRef="writeReportTask" targetRef="verifyReportTask" />

        <userTask id="verifyReportTask" name="Verify monthly financial report" >
            <documentation>
                Verify monthly financial report composed by the accountancy department.
                This financial report is going to be sent to all the company shareholders.
            </documentation>
            <potentialOwner>
                <resourceAssignmentExpression>
                    <formalExpression>management</formalExpression>
                </resourceAssignmentExpression>
            </potentialOwner>
        </userTask>

        <sequenceFlow id="flow3" sourceRef="verifyReportTask" targetRef="theEnd" />

        <endEvent id="theEnd" />

    </process>

</definitions>

Dependency settings

<dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-spring-boot-starter</artifactId>
            <version>6.4.2</version>
 </dependency>

Basic code

public static void main(String[] args) {
        // Create a Flowable process engine
        ProcessEngine processEngine = ProcessEngineConfiguration
                .createStandaloneProcessEngineConfiguration()
                .buildProcessEngine();

        // Get Flowable service
        RepositoryService repositoryService = processEngine.getRepositoryService();
        RuntimeService runtimeService = processEngine.getRuntimeService();

        // Deployment process definition
        repositoryService.createDeployment()
                .addClasspathResource("one-task-process.bpmn20.xml")
                .deploy();

        // Start process instance
        String procId =runtimeService.startProcessInstanceByKey("financialReport").getId();
        // Get the first task
        TaskService taskService = processEngine.getTaskService();
        List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup("accountancy").list();
        for (Task task : tasks) {
            System.out.println("Following task is available for accountancy group: " + task.getName());
            // Claim task
            taskService.claim(task.getId(), "fozzie");
        }
        // Verify that Fozzie got the task
        tasks = taskService.createTaskQuery().taskAssignee("fozzie").list();
        for (Task task : tasks) {
            System.out.println("Task for fozzie: " + task.getName());

            // Complete the task
            taskService.complete(task.getId());
        }System.out.println("Number of tasks for fozzie: "
                + taskService.createTaskQuery().taskAssignee("fozzie").count());

        // Get and claim the second task
        tasks = taskService.createTaskQuery().taskCandidateGroup("management").list();
        for (Task task : tasks) {
            System.out.println("Following task is available for management group: " + task.getName());
            taskService.claim(task.getId(), "kermit");
        }

        // Complete the second task and end the process
        for (Task task : tasks) {
            taskService.complete(task.getId());
        }

        // The validation process has ended
        HistoryService historyService = processEngine.getHistoryService();
        HistoricProcessInstance historicProcessInstance =
                historyService.createHistoricProcessInstanceQuery().processInstanceId(procId).singleResult();
        System.out.println("Process instance end time: " + historicProcessInstance.getEndTime());
    }

Posted by polymnia on Fri, 22 Oct 2021 03:04:17 -0700