Official documentation: https://tkjohn.github.io/flowable-userguide/#bpmnFirstExampleDiagram
Turn around and play again. Seems to understand nothing. The second time, look for something that I can understand.
The text begins:
The main chapters are shown in the figure:
It ’s my own understanding
The document flow is as follows
1. Need to solve
The use case is simple: there is a company called BPMCorp. In BPMCorp, the accounting department is responsible for writing a report for investors every month. After the report is completed, one of the senior managers needs to be reviewed before it can be sent to all investors
2. An XML file defines the process. As for how to define it, there are tools.
<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>
3. Deploy and start the process instance (deploy XML to workflow engine)
We just got an XML, which was not related to the workflow. The obtained XML can be understood as a process definition (definition, I feel a little spring feeling). Then to get the process instance, we need to deploy this XML (definition). There are two main steps:
-
The process definition will be stored in the persistent database configured by the Flowable engine. Therefore, the deployment of business processes ensures that the process definition can be found even after the engine is restarted.
-
The BPMN 2.0 process XML is parsed into an object model in memory for use by the Flowable API.
More information about deployment can be found in the deployment chapter.
Deployment code:
Deployment deployment = repositoryService.createDeployment() .addClasspathResource("FinancialReportProcess.bpmn20.xml") .deploy();
Then we can get an example: financialReport is the value of id in xml, called key in the workflow
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("financialReport");
An official demo:
public static void main(String[] args) { // Create 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("FinancialReportProcess.bpmn20.xml") .deploy(); // Start process instance runtimeService.startProcessInstanceByKey ( " financialReport " ); }
4. Perform the task.
After the instance starts, the accountancy members of the first task group can see this task. If one of them requests the task, the other members of the task group will not see it.
Then complete the task
taskService.complete(task.getId());
Then the process will go to the second task, which is the same as the first task.
Complete code:
This code considers that you may have started some process instances using the Flowable UI application. The code always gets a task list instead of a task
public class TenMinuteTutorial { public static void main(String[] args) { // Create 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("FinancialReportProcess.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()); // apply for a job taskService.claim (task.getId (), " fozzie " ); } // Verify that Fozzie obtained the tasks tasks = taskService.createTaskQuery (). TaskAssignee ( " fozzie " ) .list (); for (Task task: tasks) { System.out.println("Task for fozzie: " + task.getName()); // Complete 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()); } // Verify the process has ended HistoryService historyService = processEngine.getHistoryService (); HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(procId).singleResult(); System.out.println("Process instance end time: " + historicProcessInstance.getEndTime()); } }
to sum up:
Define Workflow (xml) ----- "Run Workflow Instance (by deployment) ------" Perform Tasks (Multiple) ----- "Finish
Follow-up:
It can be seen that this business process is too simple to be practically used. But as long as you continue to learn the BPMN 2.0 structure available in Flowable, you can enhance the business process with the following elements:
-
Defining a gateway allows the manager to choose: dismiss the financial report and recreate the task for the accountant; or accept the report.
-
Define and use variables to store or reference the report, and display it in the form.
-
Define a service task at the end of the process and send the report to each investor.
-
and many more.