springboot集成flowable6.5.0及Flowable Modeler实现免登录

本文档详细记录了在ruoyi微服务框架中集成Flowable 6.5.0的步骤,包括添加依赖、配置流程引擎、禁用定时任务、配置Flowable相关参数,并提供了启动流程、查询模型实例、任务操作等核心API的代码示例。此外,还介绍了如何集成Flowable UI并进行定制,如去除IDM登录、添加内置用户以实现免登录,以及如何适配国产化数据库。
摘要由CSDN通过智能技术生成

本项目是在ruoyi微服务版本的代码上进行集成,其他框架的集成可以参考,单纯为了做个笔记。

这里选择的flowable版本是6.5.0,首先新建模块sky-modules-flowable,然后通过pom添加流程引擎和页面相关的依赖包。

    <properties>        
       <flowable.version>6.5.0</flowable.version>
    </properties>
<!-- flowable 流程引擎-->
        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-spring-boot-starter</artifactId>
            <version>${flowable.version}</version>
        </dependency>
        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-spring-boot-starter-rest-api</artifactId>
            <version>${flowable.version}</version>
        </dependency>
        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-json-converter</artifactId>
            <version>${flowable.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.flowable</groupId>
                    <artifactId>flowable-bpmn-model</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- flowable UI集成 -->
        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-ui-modeler-conf</artifactId>
            <version>${flowable.version}</version>
        </dependency>
        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-ui-task-conf</artifactId>
            <version>${flowable.version}</version>
        </dependency>
        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-ui-admin-conf</artifactId>
            <version>${flowable.version}</version>
        </dependency>
        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-ui-idm-conf</artifactId>
            <version>${flowable.version}</version>
        </dependency>

然后在nacos中的 配置文件或者项目中的yml添加flowable相关的配置:

flowable:
  #关闭定时任务JOB
  async-executor-activate: false
  # 检测身份信息表是否存在
  db-identity-used: false
  database-schema-update: false

在本项目里没有配置ProcessEngine,直接通过配置文件控制flowable的相关信息,如果需要初始化ProcessEngine可以参考如下代码:

@Primary
    @Bean(name = "processEngine")
    public ProcessEngine initProcessEngine() {
        logger.info("=============================ProcessEngineBegin=============================");
        // 流程引擎配置 对应配置文件中的数据库配置和flowable配置
        ProcessEngineConfiguration cfg = null;
        try {
            cfg = new StandaloneProcessEngineConfiguration()
                    .setJdbcUrl(url)
                    .setJdbcUsername(username)
                    .setJdbcPassword(password)
                    .setJdbcDriver(driverClassName)                   .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE)
                    .setDatabaseSchema("TEST");
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 初始化流程引擎对象
        ProcessEngine processEngine = cfg.buildProcessEngine();
        logger.info("=============================ProcessEngineEnd=============================");
        return processEngine;
    }

至此flowable流程引擎就集成完毕了,可以编写流程控制方法,具体可参考下面代码:

@RestController
@RequestMapping("/process")
public class ProcessBasicController {

    @Autowired
    IProcessActionService processActionService;

    @Autowired
    RemoteFlowableCallBackService callBackService;
    /**
     * 清楚所有数据
     * @return
     */
    @DeleteMapping("clear")
    public AjaxResult clearAllProcess(){
        processActionService.clear();
        return AjaxResult.success("删除成功");
    }

    /**
     * 启动流程
     * @param req
     * @throws IOException
     */
    @PostMapping("task/start")
    public R<String> startProcess(@RequestBody FlowReqPara req) throws IOException {
        if(StringUtils.isEmpty(req.getCandidates())){
            throw new RuntimeException("请指定审核人!");
        }
        if(StringUtils.isEmpty(req.getDeployId())){
            throw new RuntimeException("需要传入流程定义ID");
        }
        R<String> stringR = processActionService.startProcess(req);
        return stringR;
    }

    /**
     * 查询已经部署的模型实例
     * @return
     */
    @GetMapping("deploy/list")
    public R<List<FlowReqPara>> getDeployedModels(){
        R<List<FlowReqPara>> listR = processActionService.listDeployedModels();
        return listR;
    }

    /**
     * 查询任务列表
     * @param userId 用户ID
     * @return
     */
    @GetMapping("task/list")
    public R<List<String>> getTasks(String userId){

        R<List<Task>> listR = processActionService.listTask(userId);

        List<Task> tasks = listR.getData();
        if(StringUtils.isEmpty(tasks)){

            return null;
        }

        ArrayList<String> processDefinitionIds = new ArrayList<>();
        tasks.forEach(e -> processDefinitionIds.add(e.getProcessDefinitionId()));

        R<List<String>> listTaskId = new R<List<String>>();
        listTaskId.setData(processDefinitionIds);
        return listTaskId;
    }

    /**
     * 同意
     * @param flowReqPara
     * @return
     */
    @PostMapping("task/approve")
    public R<String> taskApprove(@RequestBody FlowReqPara flowReqPara){

        if(StringUtils.isEmpty(flowReqPara.getTaskId())){
            throw new RuntimeException("请确认已传入流程任务ID");
        }
        if(StringUtils.isEmpty(flowReqPara.getUserId())){
            throw new RuntimeException("用户身份信息获取失败");
        }
        R<String> approved = processActionService.approved(flowReqPara);
        return approved;
    }

    /**
     * 驳回
     * @param flowReqPara
     * @return
     */
    @PostMapping("task/reject")
    public R<String> taskReject(@RequestBody FlowReqPara flowReqPara){

        if(StringUtils.isEmpty(flowReqPara.getTaskId())){
            throw new RuntimeException("请确认已传入流程任务ID");
        }
        if(StringUtils.isEmpty(flowReqPara.getUserId())){
            throw new RuntimeException("用户身份信息获取失败");
        }
        R<String> reject = processActionService.reject(flowReqPara);
        return reject;
    }

    /**
     * 撤销审批
     * @param flowReqPara
     * @return
     */
    @DeleteMapping("task/revo")
    public R<String> taskRevocation(FlowReqPara flowReqPara){

        if(StringUtils.isEmpty(flowReqPara.getTaskId())){
            throw new RuntimeException("需要填入任务ID");
        }
        return processActionService.delTask(flowReqPara);

    }

如果还需要集成Flowable Modeler,那么去官网下载该版本的源码包,然后找到源码包下面modules\flowable-ui-modeler\flowable-ui-modeler-app\src\main\resources\static,在新模块的resource文件夹下建立static文件夹,将源码中static下面所有的文件拷贝到static文件夹里面。

然后为了实现在模块启动时加载Flowable Modeler以及去掉idm权限登录等功能,还需要加载以及修改源码包的部分文件。在模块中新建conf文件夹,将相关配置文件拷贝到该文件夹中,主要包括:

ApplicationConfiguration.java------modules\flowable-ui-modeler\flowable-ui-modeler-conf\src\main\java\org\flowable\ui\modeler\servlet

需要在文件中注释开头的"org.flowable.ui.modeler.conf"、"org.flowable.ui.modeler.security"、"org.flowable.ui.common.conf"、"org.flowable.ui.common.filter","org.flowable.ui.common.security"等与idm相关的配置文件,最终文件如下:

/* 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.
 */
package com.sky.flowable.conf;

import org.flowable.ui.modeler.properties.FlowableModelerAppProperties;
import org.flowable.ui.modeler.servlet.ApiDispatcherServletConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(FlowableModelerAppProperties.class)
@ComponentScan(basePackages = {
        "org.flowable.ui.modeler.repository",
        "org.flowable.ui.modeler.service",
        "org.flowable.ui.common.service",
        "org.flowable.ui.common.repository",
        "org.flowable.ui.common.tenant" })
public class ApplicationConfiguration {

    @Bean
    public ServletRegistrationBean modelerApiServlet(ApplicationContext applicationContext) {
        AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
        dispatcherServletConfiguration.setParent(applicationContext);
        dispatcherServletConfiguration.register(ApiDispatcherServletConfiguration.class);
        DispatcherServlet servlet = new DispatcherServlet(dispatcherServletConfiguration);
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(servlet, "/api/*");
        registrationBean.setName("Flowable Modeler App API Servlet");
        registrationBean.setLoadOnStartup(1);
        registrationBean.setAsyncSupported(true);
        return registrationBean;
    }

}

AppDispatcherServletConfiguration.java------modules\flowable-ui-modeler\flowable-ui-modeler-conf\src\main\java\org\flowable\ui\modeler\servlet

需要移除和idm以及用户相关的文件,最终文件如下:

/* 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.
 */
package com.sky.flowable.conf;

import org.flowable.ui.modeler.rest.app.EditorGroupsResource;
import org.flowable.ui.modeler.rest.app.EditorUsersResource;
import org.flowable.ui.modeler.rest.app.StencilSetResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

@Configuration
@ComponentScan(value = { "org.flowable.ui.modeler.rest.app"},excludeFilters = {
        // 移除 EditorUsersResource 与 EditorGroupsResource,因为不使用 IDM 部分
        @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = EditorUsersResource.class),
        @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = EditorGroupsResource.class),
        // 配置文件用自己的
        @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = StencilSetResource.class),})
@EnableAsync
public class AppDispatcherServletConfiguration implements WebMvcRegistrations {

    private static final Logger LOGGER = LoggerFactory.getLogger(AppDispatcherServletConfiguration.class);

    @Bean
    public SessionLocaleResolver localeResolver() {
        return new SessionLocaleResolver();
    }

    @Bean
    public LocaleChangeInterceptor localeChangeInterceptor() {
        LOGGER.debug("Configuring localeChangeInterceptor");
        LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
        localeChangeInterceptor.setParamName("language");
        return localeChangeInterceptor;
    }

    @Override
    public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
        LOGGER.debug("Creating requestMappingHandlerMapping");
        RequestMappingHandlerMapping requestMappingHandlerMapping = new RequestMappingHandlerMapping();
        requestMappingHandlerMapping.setUseSuffixPatternMatch(false);
        requestMappingHandlerMapping.setRemoveSemicolonContent(false);
        Object[] interceptors = { localeChangeInterceptor() };
        requestMappingHandlerMapping.setInterceptors(interceptors);
        return requestMappingHandlerMapping;
    }
}

如果还需要汉化的话那就拷贝StencilSetResource到本地并且重新命名,不然会由于bean同名冲突。

StencilSetResource.java------modules\flowable-ui-modeler\flowable-ui-modeler-rest\src\main\java\org\flowable\ui\modeler\rest\app

同时拷贝汉化文件到本地resource资源文件夹下,在StencilSetResource文件中进行路径修改修改,加载当前项目资源的汉化文件。

@GetMapping(value = "/rest/stencil-sets/editor", produces = "application/json")
    public JsonNode getStencilSetForEditor() {
        try {
            JsonNode stencilNode = objectMapper.readTree(this.getClass().getClassLoader().getResourceAsStream("stencilset/stencilset_bpmn.json"));
            return stencilNode;
        } catch (Exception e) {
            LOGGER.error("Error reading bpmn stencil set json", e);
            throw new InternalServerErrorException("Error reading bpmn stencil set json");
        }
    }

    @GetMapping(value = "/rest/stencil-sets/cmmneditor", produces = "application/json")
    public JsonNode getCmmnStencilSetForEditor() {
        try {
            JsonNode stencilNode = objectMapper.readTree(this.getClass().getClassLoader().getResourceAsStream("stencilset/stencilset_cmmn.json"));
            return stencilNode;
        } catch (Exception e) {
            LOGGER.error("Error reading bpmn stencil set json", e);
            throw new InternalServerErrorException("Error reading bpmn stencil set json");
        }
    }

为了实现免登录还需要添加内置用户以及修改调用idm获取用户的接口,首先复写文件

SecurityUtils.java------modules\flowable-ui-common\src\main\java\org\flowable\ui\common\security

需要注意的是要在本地项目中建立相同的路径org.flowable.ui.common.security才能实现复写,在文件中添加设置默认登录的用户。

public static User getCurrentUserObject() {
        if (assumeUser != null) {
            return assumeUser;
        }
        RemoteUser user = new RemoteUser();
        user.setId("admin");
        user.setDisplayName("Administrator");
        user.setPassword("123456");
        List<String> pris = new ArrayList<>();
        pris.add(DefaultPrivileges.ACCESS_MODELER);
        pris.add(DefaultPrivileges.ACCESS_IDM);
        pris.add(DefaultPrivileges.ACCESS_ADMIN);
        pris.add(DefaultPrivileges.ACCESS_TASK);
        pris.add(DefaultPrivileges.ACCESS_REST_API);
        user.setPrivileges(pris);
        return user;
    }

然后在前端url-config.js文件中修改前获取用户信息接口同时自定义实现返回默认用户接口:

getAccountUrl: function () {
        return FLOWABLE.CONFIG.contextRoot + '/rest/account';
    },
@RequestMapping(value = "/rest/account", method = RequestMethod.GET, produces = "application/json")
    public UserRepresentation getAccount() {
        UserRepresentation userRepresentation = new UserRepresentation();
        userRepresentation.setId("admin");
        userRepresentation.setEmail("admin@flowable.org");
        userRepresentation.setFullName("Administrator");
        userRepresentation.setFirstName("Administrator");
        List<String> privileges = new ArrayList<>();
        privileges.add(DefaultPrivileges.ACCESS_MODELER);
        privileges.add(DefaultPrivileges.ACCESS_IDM);
        privileges.add(DefaultPrivileges.ACCESS_ADMIN);
        privileges.add(DefaultPrivileges.ACCESS_TASK);
        privileges.add(DefaultPrivileges.ACCESS_REST_API);
        userRepresentation.setPrivileges(privileges);
        return userRepresentation;
    }

最后修改启动器,加载本地的配置文件。

//启用全局异常拦截器
@Import(value={
        // 引入修改的配置
        ApplicationConfiguration.class,
        AppDispatcherServletConfiguration.class, DatabaseAutoConfiguration.class})
@EnableCustomConfig
@EnableRyFeignClients
@SpringBootApplication(exclude = {FlowableSecurityAutoConfiguration.class,SecurityAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class,SecurityFilterAutoConfiguration.class})
@EnableTransactionManagement
@EnableCustomSwagger2
public class SkyFlowableApplication {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SkyFlowableApplication.class, args);
    }
}

如果需要适配达梦数据库或其他国产化数据库的可以参考适配达梦

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要在Spring Boot集成Flowable Modeler,可以按照以下步骤进行操作: 1. 添加依赖项 在pom.xml文件中添加以下依赖项: ``` <dependency> <groupId>org.flowable</groupId> <artifactId>flowable-spring-boot-starter-modeler</artifactId> <version>${flowable.version}</version> </dependency> ``` 其中,${flowable.version}是Flowable版本号。 2. 配置数据库 在application.properties文件中,配置FlowableSpring Boot共享的数据源,例如: ``` spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false spring.datasource.username=root spring.datasource.password=123456 spring.datasource.driver-class-name=com.mysql.jdbc.Driver #flowable配置 spring.datasource.flowable.driver-class-name=${spring.datasource.driver-class-name} spring.datasource.flowable.url=${spring.datasource.url} spring.datasource.flowable.username=${spring.datasource.username} spring.datasource.flowable.password=${spring.datasource.password} spring.datasource.flowable.maxActive=20 spring.datasource.flowable.maxIdle=10 spring.datasource.flowable.minIdle=5 spring.datasource.flowable.initialSize=5 spring.datasource.flowable.removeAbandoned=true spring.datasource.flowable.removeAbandonedTimeout=1800 spring.datasource.flowable.testOnBorrow=true spring.datasource.flowable.validationQuery=SELECT 1 ``` 3. 配置Flowable Modelerapplication.properties文件中,配置Flowable Modeler。以下是一个简单的示例: ``` #flowable modeler配置 spring.flowable.modeler.app.name=MyFlowableModeler spring.flowable.modeler.app.description=My Flowable Modeler spring.flowable.modeler.app.rest.root=http://localhost:8080/flowable-modeler spring.flowable.modeler.app.rest.account=admin spring.flowable.modeler.app.rest.password=admin ``` 4. 运行应用程序 现在,您可以运行Spring Boot应用程序,并在浏览器中访问Flowable Modeler,例如http://localhost:8080/modeler/index.html。使用上面的配置,您应该可以使用用户名“admin”和密码“admin”登录。 至此,您已经成功地将Flowable Modeler集成Spring Boot应用程序中!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

皮的开心

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值