1. Introduction
For what flowable is and specific information about this framework, please refer to the official documentation of this project: https://www.flowable.org/docs/userguide/index.html
Flowable is a light-weight business process engine written in Java. This is a perfect explanation of the framework in the official website documentation: Flowable is a lightweight workflow engine written in Java.
In actual development, the user system in flowable is rarely used directly, but after all, this thing is officially designed, and its existence must be reasonable. Write a Spring Boot demo to learn how to add, delete, and modify a user or group.
2. springboot integration flowable
1. Use version
springBoot version: 2.3.2.RELEASE
flowable version: 6.5.0
2. Create a project
Create a SpringBoot project and introduce two dependencies of Web and MySQL driver. The screenshot is as follows:
3. Project depends on pom.xml
springboot version
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.0.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent>
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.flowable</groupId> <artifactId>flowable-engine</artifactId> <scope>compile</scope> <version>6.5.0</version> <exclusions> <exclusion> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.flowable</groupId> <artifactId>flowable-spring-boot-starter-basic</artifactId> <version>6.5.0</version> </dependency> <dependency> <groupId>org.flowable</groupId> <artifactId>flowable-bpmn-layout</artifactId> <version>6.5.0</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency>
4. Project configuration application.yml
Configuration of database and flowable:
spring: datasource: url: jdbc:mysql://localhost:3306/flowable?useSSL=false &characterEncoding=UTF-8 &serverTimezone=GMT+8 driver-class-name: com.mysql.jdbc.Driver username: root password: 123456 flowable: database-schema-update: true # flase: Default value. When activiti starts, it will compare the version saved in the database table. If there is no table or the version does not match, an exception will be thrown. (commonly used in production environments) # true: activiti will update all tables in the database. If the table does not exist, it is created automatically. (commonly used during development) # create_drop: Create a table when activiti starts, and delete the table when it is closed (the engine must be manually shut down to delete the table). (commonly used in unit testing) # drop-create: Delete the original old table when activiti starts, and then create a new table (no need to manually shut down the engine). process: definition-cache-limit: -1 activity-font-name: Arial label-font-name: Arial annotation-font-name: Arial check-process-definitions: false process-definition-location-prefix: classpath*:/processes/ process-definition-location-suffixes: **.bpmn20.xml, **.bpmn
flowable.check-process-definitions: This indicates whether to check whether there is a corresponding process file in the file directory when the project starts. If this property is true, it will be automatically deployed if there is a process file. If false, it will not be checked, so it will not will be deployed automatically.
flowable.process-definition-location-prefix: This is the location of the process file. The default is classpath*:/processes/. Of course, developers can also configure it.
flowable.process-definition-location-suffixes: This is the suffix of the process file. There are two by default, namely **.bpmn20.xml and **.bpmn. Of course, developers can also configure them.
The configuration of flowable, and by default, the processes located in resources/processes will be automatically deployed.
After the configuration is complete, you can start the project. After the project is successfully started, the following tables will be automatically created in the flowable database, and the database will be automatically initialized. In the future, the data when the process engine is running will be automatically persisted in the database. . A screenshot of the database table is as follows:
3. User group operation
In Spring Boot, flowable has configured the IdentityService object for us by default, and we only need to inject it into the project to use it.
1. Add user group interface
The attributes of the user group are relatively few, and the adding method is similar to that of user. The code is as follows:
@Autowired IdentityService identityService; @Test void test09() { GroupEntityImpl g = new GroupEntityImpl(); g.setName("team leader"); g.setId("leader"); g. setRevision(0); identityService. saveGroup(g); }
After adding, the group information is saved in the ACT_ID_GROUP table, as shown in the following figure:
After the user group is created, the next step is to add users to the user group. The adding method is as follows:
identityService.createMembership("zhangsan", "leader"); identityService. createMembership("lisi", "leader");
This is to set zhangsan and lisi as group leaders (note that there are foreign keys in the user and group association table, so you need to ensure that both parameters are real).
After adding the relationship, let’s check the ACT_ID_MEMBERSHIP table, as follows:
Call the following method to delete the relationship:
identityService.deleteMembership("zhangsan","leader");
2. Modify user group interface
Update the group name whose id is leader to supervisor, the code is as follows:
Group g = identityService.createGroupQuery().groupId("leader").singleResult(); g.setName("supervisor"); identityService. saveGroup(g);
3. Delete user group interface
code show as below:
identityService.deleteGroup("leader");
When deleting a group, the relationship between the group and the user will also be deleted, but don’t worry about the user being deleted.
4. Query user group interface
User groups can be queried based on id or name or group member information. The code is as follows:
//Query group information according to id Group g1 = identityService.createGroupQuery().groupId("leader").singleResult(); System.out.println("g1.getName() = " + g1.getName()); //Query group information according to name Group g2 = identityService.createGroupQuery().groupName("Group Leader").singleResult(); System.out.println("g2.getId() = " + g2.getId()); //Query group information according to the user (the user is included in the group) List<Group> list = identityService.createGroupQuery().groupMember("zhangsan").list(); for (Group group : list) { System.out.println("group.getName() = " + group.getName()); }
5. View table details
If you need to view the details of the table, you can view it through the following code:
@Test void test15() { //Get system information, actually read the information of ACT_ID_PROPERTY table Map<String, String> properties = idmManagementService. getProperties(); System.out.println("properties = " + properties); //Get the details of the table TableMetaData tableMetaData = idmManagementService.getTableMetaData(idmManagementService.getTableName(User.class)); // get table name System.out.println("tableMetaData.getTableName() = " + tableMetaData.getTableName()); // get the column name System.out.println("tableMetaData.getColumnNames() = " + tableMetaData.getColumnNames()); // Get the column type System.out.println("tableMetaData.getColumnTypes() = " + tableMetaData.getColumnTypes()); }
Four. Conclusion
If you want to use your own user system and don’t want to abandon flowable users, you can add/update users to flowable when adding system local users in the above way.
“The Shawshank Redemption”
Life boils down to a simple choice: get busy living, or get busy dying.
Cowardice imprisons the soul, hoping to feel free. The strong save themselves, the saint saves others.
Hope is a beautiful thing, perhaps the best of things. Good things never die.
Every man is his own god. If you give up on yourself, who else will save you?
“furnace”
We fight all the way, not to change the world, but to prevent the world from changing us.
Reality is like a jellyfish, its seemingly benign and harmless reality is always deadly.
When we come to the world, we all travel alone. Even if there are people around us, we will eventually go our separate ways!
The most beautiful and precious things in the world are inaudible and invisible, and can only be felt with the heart.
“godfather”
People can make mistakes all the time, but they can never make fatal mistakes.
Don’t hate your enemies, it will cloud your judgment.
People are not born great, but the more they live, the greater they become.
“Alive”
People live to live themselves, not to live for anything other than life.
To cry with laughter, to live with death.
There is nothing more telling than time, because time can change everything without telling us.
Your life is given by your parents, if you want to die, you have to ask them first.
“I’m Not the God of Medicine”
There is only one disease in the world, the disease of poverty, and you have no cure for this disease, nor can you cure it.
The most noble thing in the world is kindness, which is a tribute to life.
The Lord of the Rings
Hold your hand tightly, and there is nothing inside; let go of your hand, and you get everything.
I would rather spend the short life of a mortal with you than see the vicissitudes of the world alone.
20. All happy families are alike, but every unhappy family is unhappy in its own way.
There may be a day when human beings become shrunken and cowardly, abandoning friends and severing friendships, but not today.
“Eating Men and Women”
22. Life can’t be like cooking, you have to prepare all the ingredients before cooking.
What is “pity”? Only when you have the word “pity” in your heart can you know pity.
In fact, a family, living under the same roof, can still live their own lives, but the scruples that arise from the heart are what makes a home a home.
“Let the bullets fly”
There is no road in the world, but there is a road when there are legs.
If you live, you will die sooner or later; if you die, you will live forever.
Make money, don’t be shabby