当前位置:网站首页>Use of activiti7 workflow
Use of activiti7 workflow
2022-07-06 09:25:00 【Java domain】
1 Activiti Service Architecture #
1.1 summary #
1.2 activiti-cfg.xml#
- activiti-cfg.xml yes activiti Engine configuration file , Include :ProcessEngineConfiguration The definition of 、 Definition of data source 、 Transaction manager, etc , This file is actually a Spring The configuration file , The following is a basic configuration, which only configures ProcessEngineConfiguration And data sources .
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- Configure data sources -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
<property name="username" value="root"/>
<property name="url"
value="jdbc:mysql://192.168.134.100:3306/activiti?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true"/>
<property name="password" value="123456"/>
<property name="maxActive" value="3"/>
<property name="maxIdle" value="1"/>
</bean>
<!-- Activiti Running alone ProcessEngine To configure -->
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<!-- data source -->
<property name="dataSource" ref="dataSource"/>
<!--
activiti Database table processing strategy
false( The default value is ): Check the version of the database and the version of the dependent Library , Throw an exception if it doesn't match
true: When building a process engine , Execution check , Update if necessary . If the watch doesn't exist , create .
create-drop: Create database reports when building the process engine , Delete these tables when you shut down the process engine .
drop-create: Delete the table before creating the table .
create: Create database tables when building the process engine , Do not delete these tables when closing the process engine
-->
<property name="databaseSchemaUpdate" value="true"/>
</bean>
</beans>
1.3 ProcessEngineConfiguration#
1.3.1 summary #
- Configuration class of process engine , adopt ProcessEngineConfiguration You can create a workflow engine ProcessEngine, Two common methods are as follows :
1.3.2 StandaloneProcessEngineConfiguration#
- adopt org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration,Activiti It can run alone , Use it to create ProcessEngine,Activiti I'll handle my own business .
- Configuration file mode :
- Usually in activiti-cfg.xml Define a in the configuration file id by processEngineConfiguration Of Bean, I'm going to use Spring Build the engine with dependency injection .
- <!-- Activiti Running alone ProcessEngine To configure --> <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"> <!-- data source --> <property name="dataSource" ref="dataSource"/> <!-- activiti Database table processing strategy false( The default value is ): Check the version of the database and the version of the dependent Library , Throw an exception if it doesn't match true: When building a process engine , Execution check , Update if necessary . If the watch doesn't exist , create . create-drop: Create database reports when building the process engine , Delete these tables when you shut down the process engine . drop-create: Delete the table before creating the table . create: Create database tables when building the process engine , Do not delete these tables when closing the process engine --> <property name="databaseSchemaUpdate" value="true"/> </bean>
1.3.3 SpringProcessEngineConfiguration#
- adopt org.activiti.spring.SpringProcessEngineConfiguration and Spring Integrate .
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns="http://www.springframework.org/schema/beans" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- Configure data sources -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
<property name="username" value="root"/>
<property name="url"
value="jdbc:mysql://192.168.134.100:3306/activiti?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true"/>
<property name="password" value="123456"/>
<property name="maxActive" value="3"/>
<property name="maxIdle" value="1"/>
</bean>
<!-- Workflow engine configuration bean -->
<bean id="processEngineConfiguration"
class="org.activiti.spring.SpringProcessEngineConfiguration">
<!-- data source -->
<property name="dataSource" ref="dataSource"/>
<!-- Use spring Transaction manager -->
<property name="transactionManager" ref="transactionManager"/>
<!-- Database policy -->
<property name="databaseSchemaUpdate" value="drop-create"/>
</bean>
<!-- Process engine -->
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration"
ref="processEngineConfiguration"/>
</bean>
<!-- Resource service service -->
<bean id="repositoryService" factory-bean="processEngine"
factory-method="getRepositoryService" />
<!-- Process operation service -->
<bean id="runtimeService" factory-bean="processEngine"
factory-method="getRuntimeService" />
<!-- task management service -->
<bean id="taskService" factory-bean="processEngine"
factory-method="getTaskService" />
<!-- History management service -->
<bean id="historyService" factory-bean="processEngine"
factory-method="getHistoryService" />
<!-- Engine management service -->
<bean id="managementService" factory-bean="processEngine"
factory-method="getManagementService" />
<!-- Transaction manager -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- notice -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- Communication behavior -->
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="find*" propagation="SUPPORTS" read-only="true" />
<tx:method name="get*" propagation="SUPPORTS" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- section , Modify the tangent point configuration according to the specific project -->
<aop:config proxy-target-class="true">
<aop:advisor advice-ref="txAdvice"
pointcut="execution(* com.sunxiaping.*.service.impl.*.*(..))" />
</aop:config>
</beans>
1.3.4 establish ProcessEngineConfiguration#
- The following method : requirement activiti-cfg.xml There must be one processEngineConfiguration Of Bean Of id.
public static ProcessEngineConfiguration createProcessEngineConfigurationFromResource(String resource) {
return createProcessEngineConfigurationFromResource(resource, "processEngineConfiguration");
}
- The following method , You can change Bean Of id.
public static ProcessEngineConfiguration createProcessEngineConfigurationFromResource(String resource, String beanName) {
return BeansConfigurationHelper.parseProcessEngineConfigurationFromResource(resource, beanName);
}
1.4 ProcessEngine#
- Workflow engine , It's equivalent to a facade interface , adopt ProcessEngineConfiguration establish ProcessEngine, adopt ProcessEngine Create each Service Interface .
1.4.1 General creation method #
- Example :
package com.sunxiaping;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
/**
* @author <a href="mailto:[email protected]">weiwei.xu</a>
* @version 1.0
* 2020-07-31 6:41
*/
public class ActivitiTest {
public static void main(String[] args) {
// establish ProcessEngineConfiguration object
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
// establish ProcessEngine object
ProcessEngine processEngine = configuration.buildProcessEngine();
System.out.println("processEngine = " + processEngine);
}
}
1.4.2 Simple creation #
- take activiti.cfg.xml The file name and path are fixed , And activiti.cfg.xml In file processEngineConfiguration Configuration of , Then you can use the following code to create ProcessEngine.
package com.sunxiaping;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
/**
* @author <a href="mailto:[email protected]">weiwei.xu</a>
* @version 1.0
* 2020-07-31 6:41
*/
public class ActivitiTest {
public static void main(String[] args) {
// This method has limitations
//①Activiti The configuration file name of must be activiti.cfg.xml
//②Bean Of id Must be processEngineConfiguration
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
System.out.println("processEngine = " + processEngine);
}
}
1.5 Service#
1.5.1 Service How to create #
- adopt ProcessEngine establish Service,Service It is provided by the workflow engine for workflow deployment 、 Appoint 、 Managed service interface .
- Create it as follows :
package com.sunxiaping;
import org.activiti.engine.*;
/**
* @author <a href="mailto:[email protected]">weiwei.xu</a>
* @version 1.0
* 2020-07-31 11:55
*/
public class ActivitiTest {
public static void main(String[] args) {
// establish ProcessEngineConfiguration object
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti-cfg.xml");
// establish ProcessEngine object
ProcessEngine processEngine = configuration.buildProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
RuntimeService runtimeService = processEngine.getRuntimeService();
TaskService taskService = processEngine.getTaskService();
HistoryService historyService = processEngine.getHistoryService();
ManagementService managementService = processEngine.getManagementService();
System.out.println("repositoryService = " + repositoryService);
System.out.println("runtimeService = " + runtimeService);
System.out.println("taskService = " + taskService);
System.out.println("historyService = " + historyService);
System.out.println("managementService = " + managementService);
}
}
1.5.2 Service The overview #
Service Interface | explain |
RepositoryService | Activiti Resource management interface |
RuntimeService | Activiti Process operation management interface |
TaskService | Activiti Task management interface |
HistoryService | Activiti History management interface |
ManagementService | Activiti Engine management interface |
1.5.3 RepositoryService#
- RepositoryService, yes Activiti Resource management interface , Provides operations to manage and control process release packages and process definitions . This is required for business process diagrams designed with workflow modeling tools Service Deploy the contents of the process definition file to the computer .
- In addition to the process deployment definition, you can also do the following operations :1️⃣ Publishing package and process definition in query engine .2️⃣ Pause or activate the release package and all corresponding and specific process definitions . Pausing means that they can no longer perform task operations , Activation is the corresponding reverse operation .3️⃣ Get a variety of resources , Like the flow chart automatically generated by the engine for the files included in the release package .4️⃣ Get the of the process definition POJO, You can use the parsing process , Without having to go through XML.
1.5.4 RuntimeService#
- RuntimeService yes Activiti Process operation management interface , You can get a lot of information about process execution from this interface .
1.5.5 TaskService#
- TaskService yes Activiti Task management interface , You can get the task information from this interface .
1.5.6 HistoryService#
- HistoryService yes Activiti The history management of , You can query historical information , When executing the process , The engine will contain a lot of data ( According to the configuration ), For example, start time of process instance , Participants in the task , Time to complete the task , The execution path of each process instance , wait .
1.5.7 ManagementService#
- ManagementService yes Activiti Engine management interface , Provide for the right to Activiti Management and maintenance functions of process engine , These features are not used in workflow driven applications , It is mainly used for Activiti Daily maintenance of the system .
2 Activiti Entry experience #
2.1 Process definition #
2.1.1 Drawing board #
- stay IDEA Install the corresponding Activiti-Designer(Activiti Designer ) Plug in is ready to use , The drawing board includes the following nodes :
- Connection-- Connect .
- Event-- event .
- Task-- Mission .
- Gateway-- gateway .
- Container-- Containers .
- Boundary event-- Boundary event .
- Intermediate event-- Intermediate Events .
- After the flowchart is designed, save and generate .bpmn file .
- I use IDEA The version is 2020.2, and IDEA Medium Activiti Designer plug-ins actiBPM At this time, the location has stopped updating .
- I can only use Eclipse Draw flow chart .Eclipse Need to install Activiti plug-in unit , A little .
2.1.2 Drawing process #
2.1.3 Specify the process definition key#
- Process definition key That is, the identification of the process definition .
Suggest : The same business process , Process defined key The name is the same as the definition . If you need to create a new business process , Use the new key.
2.1.4 Appoint task leader #
- Assign a person in charge for each task node , For example, the person in charge of adding the leave form is Zhang San .
2.2 Deployment process definition #
- Will just generate the holiday.bpmn and holiday.png Copy... To the project resources Under the table of contents .
- Example : Use RepositoryService Deployment process definition
package com.sunxiaping;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.junit.Test;
/**
* @author <a href="mailto:[email protected]">weiwei.xu</a>
* @version 1.0
* 2020-07-31 11:55
*/
public class ActivitiDeploymentTest {
/**
* Deployment process definition : Put the bpmn Document and png Save the file to Activiti In the database
*
* act_re_deployment Deployment information
* act_re_procdef Some information about process definition
* act_ge_bytearray Process definition bpmn Document and png file
*/
@Test
public void test() {
// establish ProcessEngineConfiguration object
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti-cfg.xml");
ProcessEngine processEngine = configuration.buildProcessEngine();
// obtain RepositoryService object
RepositoryService repositoryService = processEngine.getRepositoryService();
// Deployment
Deployment deployment = repositoryService.createDeployment()
.addClasspathResource("diagram/holiday.bpmn") // add to bpmn resources
.addClasspathResource("diagram/holiday.png")
.name(" Leave application process ")
.deploy(); // Deploy
// Output some information about the deployment
String id = deployment.getId();
System.out.println(" Process deployment id = " + id);
String name = deployment.getName();
System.out.println(" Process deployment name = " + name);
}
}
2.3 Start a process instance #
- The process definition is deployed in Activiti After that, you can manage business processes through workflow .
- For this process , Starting a process means starting a new leave application form , This is equivalent to Java Classes and Java Relationship of objects , After the class is defined, you need new Create an object to use , Of course , It's fine too new Multiple objects .
- For the leave application process , Zhang San needs to start a process instance to initiate a leave application form , When Li Si initiates a request application form, he also needs to start a process instance .
Relationship :
Process definition (BPMN file )--> Process deployment (Activiti Three tables of ).
Process instance --> Start process instance .
analogy :
The process definition is similar to Java Class in , Process instances are similar to Java An example of ( object ), So a process definition key Corresponding to multiple different process instances .
- Example :
package com.sunxiaping;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Test;
/**
* @author <a href="mailto:[email protected]">weiwei.xu</a>
* @version 1.0
* 2020-08-01 14:35
*/
public class ActivitiStartProcessInstanceTest {
/**
* act_hi_actinst Examples of activities
* act_hi_identitylink Participant information
* act_hi_procinst Process instance
* act_hi_taskinst Task instance
* act_ru_execution Executive table
* act_ru_identitylink Participant information
* act_ru_task Task list
*/
@Test
public void test() {
// establish ProcessEngineConfiguration object
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti-cfg.xml");
ProcessEngine processEngine = configuration.buildProcessEngine();
// obtain RuntimeService object
RuntimeService runtimeService = processEngine.getRuntimeService();
// According to the process definition key Start process instance
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("holiday");
// Get information about process instances
String processDefinitionId = processInstance.getProcessDefinitionId();
System.out.println(" Process defined id = " + processDefinitionId);
String deploymentId = processInstance.getDeploymentId();
System.out.println(" Process deployed id = " + deploymentId);
String id = processInstance.getId();
System.out.println(" Of process instances id = " + id);
String activityId = processInstance.getActivityId();
System.out.println(" Currently active id = " + activityId);
}
}
2.4 Task query #
- After the process starts , The person in charge of each task can query the task he or she currently needs to deal with , The tasks found are all to-do tasks of the user .
- Example :
package com.sunxiaping;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
import org.junit.Test;
import java.util.List;
/**
* @author <a href="mailto:[email protected]">weiwei.xu</a>
* @version 1.0
* 2020-08-01 15:00
*/
public class ActivitiTaskTest {
/**
* act_ru_task
*/
@Test
public void test() {
// Task leader
String assignee = " Zhang San ";
// establish ProcessEngineConfiguration object
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti-cfg.xml");
ProcessEngine processEngine = configuration.buildProcessEngine();
// obtain TaskService object
TaskService taskService = processEngine.getTaskService();
// Query the task list , According to the process definition key And the task leader
List<Task> taskList = taskService.createTaskQuery().processDefinitionKey("holiday").taskAssignee(assignee).list();
// Traverse task list
for (Task task : taskList) {
String processDefinitionId = task.getProcessDefinitionId();
System.out.println(" Process definition id = " + processDefinitionId);
String processInstanceId = task.getProcessInstanceId();
System.out.println(" Process instance id = " + processInstanceId);
String assignee1 = task.getAssignee();
System.out.println(" Task leader = " + assignee1);
String id = task.getId();
System.out.println(" Mission id = " + id);
String name = task.getName();
System.out.println(" The name of the task = " + name);
}
}
}
2.5 Task processing #
- The person in charge of the task inquires about the to-do tasks , Select tasks to process , To complete the task .
- Example :
package com.sunxiaping;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
import org.junit.Test;
import java.util.List;
/**
* @author <a href="mailto:[email protected]">weiwei.xu</a>
* @version 1.0
* 2020-08-01 15:20
*/
public class ActivitiTaskCompleteTest {
/**
* act_hi_actinst Examples of activities
* act_hi_identitylink Participant information
* act_hi_taskinst Task instance
* act_ru_execution Executive table
* act_ru_identitylink Participant information
* act_ru_task Task list
*/
@Test
public void test() {
// Task leader
String assignee = " Zhang San ";
// establish ProcessEngineConfiguration object
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti-cfg.xml");
ProcessEngine processEngine = configuration.buildProcessEngine();
// obtain TaskService object
TaskService taskService = processEngine.getTaskService();
// Query the task list , According to the process definition key And the task leader
List<Task> taskList = taskService.createTaskQuery().processDefinitionKey("holiday").taskAssignee(assignee).list();
// Traverse task list
for (Task task : taskList) {
String id = task.getId();
// To complete the task
taskService.complete(id);
}
}
}
3 Process definition #
3.1 Overview of process definition #
3.1.1 What is a process definition ?#
- The process definition is based on BPMN2.0 Standards to describe business processes , Usually use Activiti-explorer(Activiti Console ) or Activiti-eclipse-designer(Activiti Of eclipse Designer ) The plug-in models the business process , Both ways follow BPMN2.0 standard .
- If you use Activiti-eclipse-designer The plug-in completes business process modeling . Two files can be generated :.bpmn and .png file .
3.1.2 bpmn file #
- .bpmn The document is actually XML file .
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="holiday" name=" Leave application process " isExecutable="true">
<startEvent id="startevent2" name=" Start "/>
<userTask id="usertask1" name=" Fill out the leave application form " activiti:assignee=" Zhang San "/>
<sequenceFlow id="flow1" sourceRef="startevent2" targetRef="usertask1"/>
<userTask id="usertask2" name=" Approved by Department Manager " activiti:assignee=" Li Si "/>
<sequenceFlow id="flow2" sourceRef="usertask1" targetRef="usertask2"/>
<userTask id="usertask3" name=" General manager approval " activiti:assignee=" Wang Wu "/>
<sequenceFlow id="flow3" sourceRef="usertask2" targetRef="usertask3"/>
<endEvent id="endevent1" name=" end "/>
<sequenceFlow id="flow4" sourceRef="usertask3" targetRef="endevent1"/>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_holiday">
<bpmndi:BPMNPlane bpmnElement="holiday" id="BPMNPlane_holiday">
<bpmndi:BPMNShape bpmnElement="startevent2" id="BPMNShape_startevent2">
<omgdc:Bounds height="35.0" width="35.0" x="100.0" y="160.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="180.0" y="150.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
<omgdc:Bounds height="55.0" width="105.0" x="330.0" y="150.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
<omgdc:Bounds height="55.0" width="105.0" x="480.0" y="150.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="630.0" y="160.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="135.0" y="177.0"/>
<omgdi:waypoint x="180.0" y="177.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="285.0" y="177.0"/>
<omgdi:waypoint x="330.0" y="177.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="435.0" y="177.0"/>
<omgdi:waypoint x="480.0" y="177.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
<omgdi:waypoint x="585.0" y="177.0"/>
<omgdi:waypoint x="630.0" y="177.0"/>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
- .bpmn The root node of the file is definitions node . In this element , You can define multiple process definitions ( It is recommended that each file contain only one process definition , It can simplify the maintenance difficulty in the development process ). Be careful ,definitions The element should at least contain xmlns and targetNamespace Statement of .targetNamespace It can be anything , It is used to classify process instances .
- Process definition section : It defines the description of each node of the process and the process flow between nodes .
- Process layout definition : Define the location coordinates and other information of each process node on the flowchart .
3.1.3 png Picture file #
- If it's in Eclipse in , The following configuration is required :
3.2 Process definition deployment #
3.2.1 What is process definition deployment #
- Deploy the generated process definition to Activiti In the database of , This is the process definition deployment , By calling Activiti Of API Define the process bpmn and png Two files are added to the deployment one by one Activiti in , You can also type two files into zip Package to deploy .
3.2.2 Single file deployment mode #
- Separately bpmn Document and png Picture file deployment .
- Example :
package com.sunxiaping;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.junit.Test;
/**
* @author <a href="mailto:[email protected]">weiwei.xu</a>
* @version 1.0
* 2020-07-31 11:55
*/
public class ActivitiDeploymentTest {
/**
* Deployment process definition : Put the bpmn Document and png Save the file to Activiti In the database
*
* act_re_deployment Deployment information
* act_re_procdef Some information about process definition
* act_ge_bytearray Process definition bpmn Document and png file
*/
@Test
public void test() {
// establish ProcessEngineConfiguration object
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti-cfg.xml");
ProcessEngine processEngine = configuration.buildProcessEngine();
// obtain RepositoryService object
RepositoryService repositoryService = processEngine.getRepositoryService();
// Deployment
Deployment deployment = repositoryService.createDeployment()
.addClasspathResource("diagram/holiday.bpmn") // add to bpmn resources
.addClasspathResource("diagram/holiday.png")
.name(" Leave application process ")
.deploy(); // Deploy
// Output some information about the deployment
String id = deployment.getId();
System.out.println(" Process deployment id = " + id);
String name = deployment.getName();
System.out.println(" Process deployment name = " + name);
}
}
3.2.3 Deployment mode of compressed package #
- take .bpmn Document and .png The picture is compressed into a zip package .
- Example :
package com.sunxiaping;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.junit.Test;
import java.io.InputStream;
import java.util.zip.ZipInputStream;
/**
* @author <a href="mailto:[email protected]">weiwei.xu</a>
* @version 1.0
* 2020-07-31 11:55
*/
public class ActivitiZipDeploymentTest {
/**
* Deployment process definition : Put the bpmn Document and png Save the file to Activiti In the database
*
* act_re_deployment Deployment information
* act_re_procdef Some information about process definition
* act_ge_bytearray Process definition bpmn Document and png file
*/
@Test
public void test() {
// establish ProcessEngineConfiguration object
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti-cfg.xml");
ProcessEngine processEngine = configuration.buildProcessEngine();
// obtain RepositoryService object
RepositoryService repositoryService = processEngine.getRepositoryService();
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("diagram/holiday.zip");
ZipInputStream zipInputStream = new ZipInputStream(inputStream);
// Deployment
Deployment deployment = repositoryService.createDeployment()
.addZipInputStream(zipInputStream)
.name(" Leave application process ")
.deploy(); // Deploy
// Output some information about the deployment
String id = deployment.getId();
System.out.println(" Process deployment id = " + id);
String name = deployment.getName();
System.out.println(" Process deployment name = " + name);
}
}
3.2.4 Operation data sheet #
- After the process definition is deployed , Can operate three tables :act_re_deployment、act_re_procdef and act_ge_bytearray.
- act_re_deployment It is the process definition deployment table , Record process deployment information .
- act_re_procdef It is the process definition table , Record process definition information .
- act_ge_bytearray Is a resource table , take .bpmn Document and .png Save the pictures into this table .
explain :
act_re_deployment and act_re_procdef It's a one-to-many relationship , A deployment generates a record in the process deployment table , But one process deployment can deploy multiple process definitions , Each process definition generates a record in the process definition table . Each process is defined in act_ge_bytearray There will be two resource records .bpmn Document and .png picture .
Suggest :
Deploy one process at a time , In this way, the deployment table and process definition represent a one-to-one relationship , It is convenient to read process deployment and process definition information .
3.3 Process definition query #
- Example :
package com.sunxiaping;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;
import org.junit.Test;
import java.util.List;
/**
* @author <a href="mailto:[email protected]">weiwei.xu</a>
* @version 1.0
* 2020-08-01 21:24
*/
public class ActivitiProcessDefinitionQueryTest {
/**
* Query process definition information
*/
@Test
public void test() {
// establish ProcessEngineConfiguration object
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti-cfg.xml");
ProcessEngine processEngine = configuration.buildProcessEngine();
// obtain RepositoryService object
RepositoryService repositoryService = processEngine.getRepositoryService();
// obtain ProcessDefinitionQuery object
ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
// Set conditions , And query all current process definitions
List<ProcessDefinition> processDefinitionList = processDefinitionQuery.processDefinitionKey("holiday")
.orderByProcessDefinitionVersion()
.desc()
.list();
// Output process definition information
for (ProcessDefinition processDefinition : processDefinitionList) {
System.out.println(" Process defined id = " + processDefinition.getId());
System.out.println(" Process defined name = " + processDefinition.getName());
System.out.println(" Process defined key = " + processDefinition.getKey());
System.out.println(" Process defined version = " + processDefinition.getVersion());
}
}
}
3.4 Process definition delete #
- Example :
package com.sunxiaping;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.junit.Test;
/**
* @author <a href="mailto:[email protected]">weiwei.xu</a>
* @version 1.0
* 2020-08-01 21:13
*/
public class ActivitiDeleteProcessDefinitionTest {
/**
* Delete the deployed process definition
*
* matters needing attention :
* ① When the process we are implementing is not over , At this time, if you want to delete the process definition information, you will fail ( call void deleteDeployment(String deploymentId) Method ).
* ② When the process we are implementing is not over , At this time, if you want to forcibly delete the process definition information , Need to call void deleteDeployment(String deploymentId, boolean cascade) This way , take cascade Set to true.
*/
@Test
public void test() {
// establish ProcessEngineConfiguration object
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti-cfg.xml");
ProcessEngine processEngine = configuration.buildProcessEngine();
// obtain RepositoryService object
RepositoryService repositoryService = processEngine.getRepositoryService();
// Delete the deployed process definition
String deploymentId = "1";
repositoryService.deleteDeployment(deploymentId);
}
}
3.5 Process definition resource query #
- Example : Obtain process definition resources by querying process definition objects , namely bpmn and png
package com.sunxiaping;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;
import org.junit.Test;
import org.springframework.util.FileCopyUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/**
* @author <a href="mailto:[email protected]">weiwei.xu</a>
* @version 1.0
* 2020-08-02 10:22
*/
public class ActivitiResourceTest {
@Test
public void test() throws IOException {
// establish ProcessEngineConfiguration object
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti-cfg.xml");
ProcessEngine processEngine = configuration.buildProcessEngine();
// obtain RepositoryService object
RepositoryService repositoryService = processEngine.getRepositoryService();
// obtain ProcessDefinitionQuery object
ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
// Set query conditions , Perform query operation
List<ProcessDefinition> processDefinitionList = processDefinitionQuery.processDefinitionKey("holiday").orderByProcessDefinitionVersion().desc().list();
// Traverse query results
for (ProcessDefinition processDefinition : processDefinitionList) {
// Get resource name , namely png The name of the picture
String resourceName = processDefinition.getResourceName();
// Get chart resources , namely bpmn The name of the picture
String diagramResourceName = processDefinition.getDiagramResourceName();
// Get the input stream of the resource , namely png Input stream of pictures
InputStream resourceNameInputStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName);
InputStream diagramResourceNameInputStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), diagramResourceName);
String resourcePath = "d:" + File.separator + resourceName;
File file = new File(resourcePath);
if (!file.exists()) {
file.getParentFile().mkdirs();
}
String diagramResourcePath = "d:" + File.separator + diagramResourceName;
file = new File(diagramResourcePath);
if (!file.exists()) {
file.getParentFile().mkdirs();
}
// Copy file
FileCopyUtils.copy(resourceNameInputStream, new FileOutputStream(resourcePath));
FileCopyUtils.copy(diagramResourceNameInputStream, new FileOutputStream(diagramResourcePath));
}
}
}
3.6 Process history information query #
- Example :
package com.sunxiaping;
import org.activiti.engine.HistoryService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricActivityInstanceQuery;
import org.junit.Test;
import java.util.List;
/**
* @author <a href="mailto:[email protected]">weiwei.xu</a>
* @version 1.0
* 2020-08-01 21:13
*/
public class ActivitiHistoryTest {
@Test
public void test() {
// establish ProcessEngineConfiguration object
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti-cfg.xml");
// obtain ProcessEngine object
ProcessEngine processEngine = configuration.buildProcessEngine();
// obtain HistoryService object
HistoryService historyService = processEngine.getHistoryService();
// obtain HistoricActivityInstanceQuery Query object
HistoricActivityInstanceQuery historicActivityInstanceQuery = historyService.createHistoricActivityInstanceQuery();
List<HistoricActivityInstance> historicActivityInstanceList = historicActivityInstanceQuery.list();
for (HistoricActivityInstance historicActivityInstance : historicActivityInstanceList) {
String activityId = historicActivityInstance.getActivityId();
System.out.println("activityId = " + activityId);
String activityName = historicActivityInstance.getActivityName();
System.out.println("activityName = " + activityName);
String processDefinitionId = historicActivityInstance.getProcessDefinitionId();
System.out.println("processDefinitionId = " + processDefinitionId);
String processInstanceId = historicActivityInstance.getProcessInstanceId();
System.out.println("processInstanceId = " + processInstanceId);
}
}
}
If this article helps you , Don't forget to give me a 3 even , give the thumbs-up , forward , Comment on ,
I'll see you next time ! Learn more JAVA Knowledge and skills ( Get the original ), Follow up with private bloggers (666)
边栏推荐
- Advanced Computer Network Review(5)——COPE
- Intel distiller Toolkit - Quantitative implementation 3
- Advanced Computer Network Review(5)——COPE
- Simclr: comparative learning in NLP
- 【每日一题】搬运工 (DFS / DP)
- Global and Chinese market of capacitive displacement sensors 2022-2028: Research Report on technology, participants, trends, market size and share
- What is MySQL? What is the learning path of MySQL
- Pytest parameterization some tips you don't know / pytest you don't know
- Design and implementation of online shopping system based on Web (attached: source code paper SQL file)
- 基于B/S的影视创作论坛的设计与实现(附:源码 论文 sql文件 项目部署教程)
猜你喜欢
甘肃旅游产品预订增四倍:“绿马”走红,甘肃博物馆周边民宿一房难求
为拿 Offer,“闭关修炼,相信努力必成大器
Opencv+dlib realizes "matching" glasses for Mona Lisa
Redis之性能指标、监控方式
postman之参数化详解
Selenium+Pytest自动化测试框架实战
Heap (priority queue) topic
Ijcai2022 collection of papers (continuously updated)
LeetCode41——First Missing Positive——hashing in place & swap
[oc]- < getting started with UI> -- learning common controls
随机推荐
go-redis之初始化連接
IDS cache preheating, avalanche, penetration
【shell脚本】——归档文件脚本
Blue Bridge Cup_ Single chip microcomputer_ PWM output
Global and Chinese market of bank smart cards 2022-2028: Research Report on technology, participants, trends, market size and share
[oc]- < getting started with UI> -- learning common controls
在QWidget上实现窗口阻塞
CSP salary calculation
In depth analysis and encapsulation call of requests
美团二面:为什么 Redis 会有哨兵?
[three storage methods of graph] just use adjacency matrix to go out
CUDA realizes focal_ loss
Opencv+dlib realizes "matching" glasses for Mona Lisa
CSP student queue
Advanced Computer Network Review(3)——BBR
KDD 2022论文合集(持续更新中)
Le modèle sentinelle de redis
一文读懂,DDD落地数据库设计实战
Redis分布式锁实现Redisson 15问
Intel distiller Toolkit - Quantitative implementation 1