Eleven new features of workflow engine activiti7

Posted by phpnoobguy on Wed, 16 Feb 2022 16:53:29 +0100

catalogue

1, Activiti7 basic introduction

2, Download the demo of Activit official website to learn

2.1 enter the activiti core learning wizard page

2.2 # download the demo example of activiti core

2.3 # Activiti7 challenges

2.4 components of Activiti7

2.5 introduction to Activiti's new API

        2.5.1 TaskRuntime

2.5.2 ProcessRuntime

3, Activiti7 and SpringBoot integrated development

3.1 spring boot integrates the configuration of Activiti7

3.1.1 # import dependency

3.1.2 configuration file

3.2 add spring security framework integration configuration

3.2.1. Add SecurityUtil class

3.2.2 add DemoApplicationConfig class

3.3 using SpringBoot to integrate Junit to test new features

3.4 viewing process definition information

3.5 start process example

1, Activiti7 basic introduction

Alfresco software announced the official launch of the activiti business process management (BPM) open source project on May 17, 2010. Its chief architect is Tom Baeyens, an expert in Business Process Management BPM. Tom Baeyens is the architect of the original jbpm, which is a very famous workflow engine. Of course, activiti is also a workflow engine. The business process is pre-defined in the business process management system (activiti), which can be implemented by a business process management engine in the business process management system (activiti. 0), Reduce the workload of system upgrading and transformation of business system due to process change, so as to improve the robustness of the system and reduce the cost of system development and maintenance.

Official website: https://www.activiti.org/

Version: 5 x,6.x,7.x

2, Download the demo of Activit official website to learn

Activiti7 is divided into core and cloud. We mainly study the content of core.

2.1 enter the activiti core learning wizard page

                activiti-7-developers-guide/getting-started-activiti-core.md at 51a1681c0e4bb5e2f96a6dea73516c9fd53d8521 · Activiti/activiti-7-developers-guide · GitHubhttps://activiti.gitbook.io/activiti-7-developers-guide/ - activiti-7-developers-guide/getting-started-activiti-core.md at 51a1681c0e4bb5e2f96a6dea73516c9fd53d8521 · Activiti/activiti-7-developers-guidehttps://github.com/Activiti/activiti-7-developers-guide/blob/51a1681c0e4bb5e2f96a6dea73516c9fd53d8521/getting-started/getting-started-activiti-core.md

2.2 # download the demo example of activiti core

GitHub - AlfrescoArchive/activiti-examples: This repository contains Activiti 7.x Examples

2.3 # Activiti7 challenges

Tom Baeyens resigned and developed a new version of workflow engine called flowable with the original activiti developers. This is a lot of challenges for the activiti camp. Activiti7 we are learning now is another layer of encapsulation by another architect based on the original Activiti6, so the API has changed a lot.  

2.4 components of Activiti7

From this part, we can see that activiti has been divided into two different parts. Activiti Core is the core part of activiti, which we will focus on this time. The other part of Activiti Cloud mainly uses cloud services to realize distributed business process development.  

2.5 introduction to Activiti's new API

In order to simplify the operation of workflow, Activiti7 is closed again on the basis of the original API, so that the basic API of Activiti7 we learned originally is closed. Specific to learn include: ProcessRuntime interface TaskRuntime interface

        2.5.1 TaskRuntime

The following link is the textbook address of the new API

Getting Started - Activiti Core - Activiti & Activiti Cloud Developers Guide

public interface TaskRuntime {
  TaskRuntimeConfiguration configuration();
  Task task(String taskId);
  Page tasks(Pageable pageable);
  Page tasks(Pageable pageable, GetTasksPayload payload);
  Task create(CreateTaskPayload payload);
  Task claim(ClaimTaskPayload payload);
  Task release(ReleaseTaskPayload payload);
  Task complete(CompleteTaskPayload payload);
  Task update(UpdateTaskPayload payload);
  Task delete(DeleteTaskPayload payload);
  ...
}

Create task

taskRuntime.create(
            TaskPayloadBuilder.create()
                .withName("First Team Task")
                .withDescription("This is something really important")
                .withGroup("activitiTeam")
                .withPriority(10)
           .build());

2.5.2 ProcessRuntime

public interface ProcessRuntime {
  ProcessRuntimeConfiguration configuration();
  ProcessDefinition processDefinition(String processDefinitionId);
  Page processDefinitions(Pageable pageable);
  Page processDefinitions(Pageable pageable,
              GetProcessDefinitionsPayload payload);
  ProcessInstance start(StartProcessPayload payload);
  Page processInstances(Pageable pageable);
  Page processInstances(Pageable pageable,
              GetProcessInstancesPayload payload);
  ProcessInstance processInstance(String processInstanceId);
  ProcessInstance suspend(SuspendProcessPayload payload);
  ProcessInstance resume(ResumeProcessPayload payload);
  ProcessInstance delete(DeleteProcessPayload payload);
  void signal(SignalPayload payload);
  ...
}

Get these two classes and directly @ autowritten

Query process definition

Page processDefinitionPage = processRuntime
                                .processDefinitions(Pageable.of(0, 10));
logger.info("> Available Process definitions: " +
                  processDefinitionPage.getTotalItems());
for (ProcessDefinition pd : processDefinitionPage.getContent()) {
  logger.info("\t > Process definition: " + pd);
}

 

1. Because activiti7 and spring security are strongly coupled, permission verification should be done when adding, deleting, modifying and checking activiti7

2. The process definition needs to be placed in / src/main/resources/processes/

3, Activiti7 and SpringBoot integrated development

After the official release of Activiti7, it is compatible with SpringBoot 2 X has fully supported integrated development. We can introduce the coordinates of Activiti7 and SpringBoot integrated development into the project, so that SpringBoot supports Activiti7 integration.

The specific steps of integrating Activti7 with SpringBoot are as follows:

1. Add the coordinates of SpringBoot integration Activti7

2. Add the integrated configuration information of spring security security framework

3. Use the newly supported classes of Activti7 to implement the workflow development ProcessRuntime interface and TaskRuntime interface

4. Use the new API to realize workflow development, mainly including

Process definition query

Start process instance

Task query

Completion of tasks

3.1 spring boot integrates the configuration of Activiti7

3.1.1 import dependency

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>springBoot_Activiti7New</artifactId>
    <version>1.0-SNAPSHOT</version>


    <!--activiti7 And SpringBoot Integration related dependencies-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.activiti/activiti-spring-boot-starter -->
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-spring-boot-starter</artifactId>
            <version>7.1.0.M6</version>
        </dependency>

        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.5</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.21</version>
        </dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

3.1.2 configuration file

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/activiti?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT
    username : root
    password : root
    driver-class-name: com.mysql.jdbc.Driver
activiti:
    historyLevel: audit
    db-history-used: true

When Activiti7 is integrated with SpringBoot, there are only 17 tables in the activiti database generated by default, and there are no other 8 historical tables.

Activiti turns off the use of history tables by default.

In the application. To connect to the database In the YML configuration file, open it. The content of the configuration file is as follows.

3.2 add spring security framework integration configuration

After Activiti7 and SpringBoot are integrated, the SpringSecurity security framework is integrated by default, so we need to prepare the relevant user permission configuration information integrated by SpringSecurity.

You can check the dependency package integrating SpringBoot and find that the dependency package of SpringSecurity has also been added to the project,

3.2.1. Add SecurityUtil class

Add the SecurityUtil class. In order to quickly implement the configuration of spring security security framework, a component is added.

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.context.SecurityContextImpl;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
public class SecurityUtil {

    @Autowired
    private UserDetailsService userDetailsService;

    public void logInAs(String username) {

        UserDetails user = userDetailsService.loadUserByUsername(username);
        if (user == null) {
            throw new IllegalStateException("User " + username + " doesn't exist, please provide a valid user");
        }

        SecurityContextHolder.setContext(new SecurityContextImpl(new Authentication() {
            @Override
            public Collection<? extends GrantedAuthority> getAuthorities() {
                return user.getAuthorities();
            }

            @Override
            public Object getCredentials() {
                return user.getPassword();
            }

            @Override
            public Object getDetails() {
                return user;
            }

            @Override
            public Object getPrincipal() {
                return user;
            }

            @Override
            public boolean isAuthenticated() {
                return true;
            }

            @Override
            public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {

            }

            @Override
            public String getName() {
                return user.getUsername();
            }
        }));
        org.activiti.engine.impl.identity.Authentication.setAuthenticatedUserId(username);
    }
}

3.2.2 add DemoApplicationConfig class

Find the DemoApplicationConfig class in the Example officially downloaded by Activiti7. Its function is to configure the user permission of the spring security framework, so that we can use the user permission information in the system. In this project, the user information is basically defined in the file. Of course, it can also be the user permission information queried in the database.

/*
 * Copyright 2018 Alfresco, Inc. and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Configuration
@EnableWebSecurity
public class DemoApplicationConfiguration extends WebSecurityConfigurerAdapter {

    private Logger logger = LoggerFactory.getLogger(DemoApplicationConfiguration.class);

    @Override
    @Autowired
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(myUserDetailsService());
    }

    @Bean
    public UserDetailsService myUserDetailsService() {

        InMemoryUserDetailsManager inMemoryUserDetailsManager = new InMemoryUserDetailsManager();

        String[][] usersGroupsAndRoles = {
                {"salaboy", "password", "ROLE_ACTIVITI_USER", "GROUP_activitiTeam"},
                {"ryandawsonuk", "password", "ROLE_ACTIVITI_USER", "GROUP_activitiTeam"},
                {"erdemedeiros", "password", "ROLE_ACTIVITI_USER", "GROUP_activitiTeam"},
                {"other", "password", "ROLE_ACTIVITI_USER", "GROUP_otherTeam"},
                {"admin", "password", "ROLE_ACTIVITI_ADMIN"},
        };

        for (String[] user : usersGroupsAndRoles) {
            List<String> authoritiesStrings = Arrays.asList(Arrays.copyOfRange(user, 2, user.length));
            logger.info("> Registering new user: " + user[0] + " with the following Authorities[" + authoritiesStrings + "]");
            inMemoryUserDetailsManager.createUser(new User(user[0], passwordEncoder().encode(user[1]),
                    authoritiesStrings.stream().map(s -> new SimpleGrantedAuthority(s)).collect(Collectors.toList())));
        }


        return inMemoryUserDetailsManager;
    }


    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .csrf().disable()
                .authorizeRequests()
                .anyRequest()
                .authenticated()
                .and()
                .httpBasic();


    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }
}

3.3 using SpringBoot to integrate Junit to test new features

3.4 viewing process definition information

3.5 start process example

I haven't finished it today. I'll write it tomorrow

Topics: .NET Activiti linq p2p