activiti-api-impl

news2025/2/28 13:08:51

activiti-api-impl

  • 目录
    • 概述
      • 需求:
    • 设计思路
    • 实现思路分析
      • 1.CommonModelAutoConfiguration
      • 2.RuntimeEventImpl
      • 3.ProcessModelAutoConfiguration
      • 4.DefaultServiceTaskBehavior
      • 5.APIVariableInstanceConverter
    • TaskModelAutoConfiguration
  • 参考资料和推荐阅读

Survive by day and develop by night.
talk for import biz , show your perfect code,full busy,skip hardness,make a better result,wait for change,challenge Survive.
happy for hardess to solve denpendies.

目录

在这里插入图片描述

概述

activiti-api-impl的是一个非常常见的需求。

需求:

设计思路

在这里插入图片描述

实现思路分析

1.CommonModelAutoConfiguration

@Configuration
@PropertySource("classpath:conf/rest-jackson-configuration.properties") //load default jackson configuration
public class CommonModelAutoConfiguration {

    //this bean will be automatically injected inside boot's ObjectMapper
    @Bean
    public Module customizeCommonModelObjectMapper() {
        SimpleModule module = new SimpleModule("mapCommonModelInterfaces",
                                               Version.unknownVersion());
        SimpleAbstractTypeResolver resolver = new SimpleAbstractTypeResolver() {
            //this is a workaround for https://github.com/FasterXML/jackson-databind/issues/2019
            //once version 2.9.6 is related we can remove this @override method
            @Override
            public JavaType resolveAbstractType(DeserializationConfig config,
                                                BeanDescription typeDesc) {
                return findTypeMapping(config,
                                       typeDesc.getType());
            }
        };

        resolver.addMapping(VariableInstance.class,
                            VariableInstanceImpl.class);

        module.setAbstractTypes(resolver);

        module.setMixInAnnotation(Payload.class,
                                  PayloadMixIn.class);
        module.setMixInAnnotation(Result.class,
                                  ResultMixIn.class);

        module.registerSubtypes(new NamedType(EmptyResult.class,
                                              EmptyResult.class.getSimpleName()));

        return module;
    }
}

2.RuntimeEventImpl

public abstract class RuntimeEventImpl<ENTITY_TYPE, EVENT_TYPE extends Enum<?>> implements RuntimeEvent<ENTITY_TYPE, EVENT_TYPE> {

    private String id;
    private Long timestamp;
    private String processInstanceId;
    private String processDefinitionId;
    private String processDefinitionKey;
    private Integer processDefinitionVersion;
    private String businessKey;
    private String parentProcessInstanceId;

    private ENTITY_TYPE entity;

    public RuntimeEventImpl() {
        id = UUID.randomUUID().toString();
        timestamp = System.currentTimeMillis();
    }

    public RuntimeEventImpl(ENTITY_TYPE entity) {
        this();
        this.entity = entity;
    }

    public RuntimeEventImpl(String id,
                            Long timestamp,
                            ENTITY_TYPE entity) {
        this.id = id;
        this.timestamp = timestamp;
        this.entity = entity;
    }

3.ProcessModelAutoConfiguration

public class ProcessModelAutoConfiguration {

    @Autowired(required = false)
    @ProcessVariableTypeConverter
    @Lazy
    private Set<Converter<?, ?>> converters = Collections.emptySet();


    //this bean will be automatically injected inside boot's ObjectMapper
    @Bean
    @Order(Ordered.HIGHEST_PRECEDENCE)
    public Module customizeProcessModelObjectMapper(ObjectProvider<ConversionService> conversionServiceProvider) {
        SimpleModule module = new SimpleModule("mapProcessModelInterfaces",
                                               Version.unknownVersion());
        SimpleAbstractTypeResolver resolver = new SimpleAbstractTypeResolver() {
            //this is a workaround for https://github.com/FasterXML/jackson-databind/issues/2019
            //once version 2.9.6 is related we can remove this @override method
            @Override
            public JavaType resolveAbstractType(DeserializationConfig config,
                                                BeanDescription typeDesc) {
                return findTypeMapping(config,
                                       typeDesc.getType());
            }
        };

        resolver.addMapping(BPMNActivity.class,
                            BPMNActivityImpl.class);
        resolver.addMapping(ProcessInstance.class,
                            ProcessInstanceImpl.class);
        resolver.addMapping(ProcessDefinition.class,
                            ProcessDefinitionImpl.class);
        resolver.addMapping(BPMNSequenceFlow.class,
                            BPMNSequenceFlowImpl.class);
        resolver.addMapping(IntegrationContext.class,
                            IntegrationContextImpl.class);
        resolver.addMapping(BPMNSignal.class,
        					BPMNSignalImpl.class);
        resolver.addMapping(BPMNTimer.class,
                            BPMNTimerImpl.class);
        resolver.addMapping(BPMNMessage.class,
                            BPMNMessageImpl.class);
        resolver.addMapping(BPMNError.class,
                            BPMNErrorImpl.class);
        resolver.addMapping(MessageSubscription.class,
                            MessageSubscriptionImpl.class);
        resolver.addMapping(StartMessageSubscription.class,
                            StartMessageSubscriptionImpl.class);
        resolver.addMapping(StartMessageDeployedEvent.class,
                            StartMessageDeployedEventImpl.class);
        resolver.addMapping(StartMessageDeploymentDefinition.class,
                            StartMessageDeploymentDefinitionImpl.class);
        resolver.addMapping(ProcessCandidateStarterUser.class,
                            ProcessCandidateStarterUserImpl.class);
        resolver.addMapping(ProcessCandidateStarterGroup.class,
                            ProcessCandidateStarterGroupImpl.class);

        module.registerSubtypes(new NamedType(ProcessInstanceResult.class,
                                              ProcessInstanceResult.class.getSimpleName()));

        module.registerSubtypes(new NamedType(DeleteProcessPayload.class,
                                              DeleteProcessPayload.class.getSimpleName()));
        module.registerSubtypes(new NamedType(GetProcessDefinitionsPayload.class,
                                              GetProcessDefinitionsPayload.class.getSimpleName()));
        module.registerSubtypes(new NamedType(GetProcessInstancesPayload.class,
                                              GetProcessInstancesPayload.class.getSimpleName()));
        module.registerSubtypes(new NamedType(GetVariablesPayload.class,
                                              GetVariablesPayload.class.getSimpleName()));
        module.registerSubtypes(new NamedType(RemoveProcessVariablesPayload.class,
                                              RemoveProcessVariablesPayload.class.getSimpleName()));
        module.registerSubtypes(new NamedType(SetProcessVariablesPayload.class,
                                              SetProcessVariablesPayload.class.getSimpleName()));
        module.registerSubtypes(new NamedType(SignalPayload.class,
                                              SignalPayload.class.getSimpleName()));
        module.registerSubtypes(new NamedType(TimerPayload.class,
                                              TimerPayload.class.getSimpleName()));
        module.registerSubtypes(new NamedType(StartProcessPayload.class,
                                              StartProcessPayload.class.getSimpleName()));
        module.registerSubtypes(new NamedType(CreateProcessInstancePayload.class,
                                              CreateProcessInstancePayload.class.getSimpleName()));
        module.registerSubtypes(new NamedType(SuspendProcessPayload.class,
                                              SuspendProcessPayload.class.getSimpleName()));
        module.registerSubtypes(new NamedType(ResumeProcessPayload.class,
                                              ResumeProcessPayload.class.getSimpleName()));
        module.registerSubtypes(new NamedType(UpdateProcessPayload.class,
                                              UpdateProcessPayload.class.getSimpleName()));
        module.registerSubtypes(new NamedType(StartMessagePayload.class,
                                              StartMessagePayload.class.getSimpleName()));
        module.registerSubtypes(new NamedType(ReceiveMessagePayload.class,
                                              ReceiveMessagePayload.class.getSimpleName()));
        module.registerSubtypes(new NamedType(MessageEventPayload.class,
                                              MessageEventPayload.class.getSimpleName()));
        module.setAbstractTypes(resolver);

        ConversionService conversionService = conversionServiceProvider.getIfUnique(this::conversionService);

        module.addSerializer(new ProcessVariablesMapSerializer(conversionService));

        module.addDeserializer(ProcessVariablesMap.class,
                               new ProcessVariablesMapDeserializer(conversionService));

        return module;
    }

4.DefaultServiceTaskBehavior

在这里插入图片描述
在这里插入图片描述

public class DefaultServiceTaskBehavior extends AbstractBpmnActivityBehavior {

    private final ApplicationContext applicationContext;
    private final IntegrationContextBuilder integrationContextBuilder;
    private final VariablesPropagator variablesPropagator;

    public DefaultServiceTaskBehavior(ApplicationContext applicationContext,
        IntegrationContextBuilder integrationContextBuilder, VariablesPropagator variablesPropagator) {
        this.applicationContext = applicationContext;
        this.integrationContextBuilder = integrationContextBuilder;
        this.variablesPropagator = variablesPropagator;
    }

    /**
     * We have two different implementation strategy that can be executed
     * in according if we have a connector action definition match or not.
     **/
    @Override
    public void execute(DelegateExecution execution) {
        Connector connector = getConnector(getImplementation(execution));
        IntegrationContext integrationContext = connector.apply(integrationContextBuilder.from(execution));

        variablesPropagator.propagate(execution, integrationContext.getOutBoundVariables());
        leave(execution);
    }

    private String getImplementation(DelegateExecution execution) {
        return ((ServiceTask) execution.getCurrentFlowElement()).getImplementation();
    }

    private Connector getConnector(String implementation) {
        return applicationContext.getBean(implementation,
                                          Connector.class);
    }

    private String getServiceTaskImplementation(DelegateExecution execution) {
        return ((ServiceTask) execution.getCurrentFlowElement()).getImplementation();
    }

    public boolean hasConnectorBean(DelegateExecution execution) {
        String implementation = getServiceTaskImplementation(execution);
        return applicationContext.containsBean(implementation) && applicationContext.getBean(implementation) instanceof Connector;
    }
}

5.APIVariableInstanceConverter

在这里插入图片描述


public class APIVariableInstanceConverter
        extends ListConverter<org.activiti.engine.impl.persistence.entity.VariableInstance, VariableInstance>
        implements ModelConverter<org.activiti.engine.impl.persistence.entity.VariableInstance, VariableInstance> {

    @Override
    public VariableInstance from(org.activiti.engine.impl.persistence.entity.VariableInstance internalVariableInstance) {
        return new VariableInstanceImpl<>(internalVariableInstance.getName(),
                internalVariableInstance.getTypeName(),
                internalVariableInstance.getValue(),
                internalVariableInstance.getProcessInstanceId(),
                internalVariableInstance.getTaskId());
    }
}

TaskModelAutoConfiguration

public class TaskModelAutoConfiguration {

    //this bean will be automatically injected inside boot's ObjectMapper
    @Bean
    public Module customizeTaskModelObjectMapper() {
        SimpleModule module = new SimpleModule("mapTaskRuntimeInterfaces",
                                               Version.unknownVersion());
        SimpleAbstractTypeResolver resolver = new SimpleAbstractTypeResolver() {
            //this is a workaround for https://github.com/FasterXML/jackson-databind/issues/2019
            //once version 2.9.6 is related we can remove this @override method
            @Override
            public JavaType resolveAbstractType(DeserializationConfig config,
                                                BeanDescription typeDesc) {
                return findTypeMapping(config,
                                       typeDesc.getType());
            }
        };
        resolver.addMapping(Task.class,
                            TaskImpl.class);
        resolver.addMapping(TaskCandidateUser.class,
                            TaskCandidateUserImpl.class);
        resolver.addMapping(TaskCandidateGroup.class,
                            TaskCandidateGroupImpl.class);

        module.registerSubtypes(new NamedType(TaskResult.class,
                                              TaskResult.class.getSimpleName()));

        module.registerSubtypes(new NamedType(ClaimTaskPayload.class,
                                              ClaimTaskPayload.class.getSimpleName()));

        module.registerSubtypes(new NamedType(CompleteTaskPayload.class,
                                              CompleteTaskPayload.class.getSimpleName()));

        module.registerSubtypes(new NamedType(SaveTaskPayload.class,
                                              SaveTaskPayload.class.getSimpleName()));

        module.registerSubtypes(new NamedType(CreateTaskPayload.class,
                                              CreateTaskPayload.class.getSimpleName()));

        module.registerSubtypes(new NamedType(DeleteTaskPayload.class,
                                              DeleteTaskPayload.class.getSimpleName()));

        module.registerSubtypes(new NamedType(GetTasksPayload.class,
                                              GetTasksPayload.class.getSimpleName()));

        module.registerSubtypes(new NamedType(GetTaskVariablesPayload.class,
                                              GetTaskVariablesPayload.class.getSimpleName()));

        module.registerSubtypes(new NamedType(ReleaseTaskPayload.class,
                                              ReleaseTaskPayload.class.getSimpleName()));

        module.registerSubtypes(new NamedType(UpdateTaskPayload.class,
                                              UpdateTaskPayload.class.getSimpleName()));

        module.setAbstractTypes(resolver);

        return module;
    }
}

至此core 包分析完毕。

参考资料和推荐阅读

[1]. https://www.activiti.org/

欢迎阅读,各位老铁,如果对你有帮助,点个赞加个关注呗!~

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/39039.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Flutter高仿微信-第53篇-群聊-删除并退出

Flutter高仿微信系列共59篇&#xff0c;从Flutter客户端、Kotlin客户端、Web服务器、数据库表结构、Xmpp即时通讯服务器、视频通话服务器、腾讯云服务器全面讲解。 详情请查看 效果图&#xff1a; 实现代码&#xff1a; //删除并退出对话框 void _deleteAndExistDialog(){Load…

图解LeetCode——1752. 检查数组是否经排序和轮转得到(难度:简单)

一、题目 给你一个数组 nums 。nums 的源数组中&#xff0c;所有元素与 nums 相同&#xff0c;但按非递减顺序排列。 如果 nums 能够由源数组轮转若干位置&#xff08;包括 0 个位置&#xff09;得到&#xff0c;则返回 true &#xff1b;否则&#xff0c;返回 false 。 源数…

一文了解Linux上TCP的几个内核参数调优

Linux作为一个强大的操作系统&#xff0c;提供了一系列内核参数供我们进行调优。光TCP的调优参数就有50多个。在和线上问题斗智斗勇的过程中&#xff0c;笔者积累了一些在内网环境应该进行调优的参数。在此分享出来&#xff0c;希望对大家有所帮助。 调优清单 好了&#xff0…

Java#27(Arrays)

目录 一.Arrays 操作数组的工具类 二.Lambda表达式 1.注意: 2.省略规则 一.Arrays 操作数组的工具类 方法名 作用 public static String toString(数组) 把数组拼接…

大数据毕设选题 - 深度学习动物识别与检测系统( python opencv)

文章目录0 前言1 深度学习实现动物识别与检测2 卷积神经网络2.1卷积层2.2 池化层2.3 激活函数2.4 全连接层2.5 使用tensorflow中keras模块实现卷积神经网络3 YOLOV53.1 网络架构图3.2 输入端3.3 基准网络3.4 Neck网络3.5 Head输出层4 数据集准备4.1 数据标注简介4.2 数据保存5 …

kafka集群搭建与prometheus监控配置

文章目录1、基于zookeeper的集群2、kafka集群安装2.1 基于Zookeeper集群的配置2.2 基于KRaft模式集群的配置2.3、启动Kafka集群3、kafka_exporter监控组件安装3.1、安装3.2、系统服务3.3、集成到prometheus4、与Grafana集成1、基于zookeeper的集群 下载地址&#xff1a;https:…

ABAP学习笔记之——第三章:OPEN SQL和NATIVE SQL

一、SAP R/3体系结构 SAP R/3一个分为三层&#xff1a;数据库层、应用层、表示层。其中应用层和数据库层由一个系统构成。 表示层&#xff1a;表示层(Presentation Layer)简单来讲其实就是指个人PC&#xff0c;是保存构成SAPGUI(GraphicalUserInterface)的软件组件(Software Co…

数字验证学习笔记——SystemVerilog芯片验证10 ——类的成员

一、类和成员 类是成员变量和成员方法的载体&#xff0c;之所以称为自洽体&#xff0c;是因为其变量和方法应符合‘聚拢’原则&#xff0c;即一个类的功能应该尽可能简单&#xff0c;不应承担过多的职责&#xff0c;更不应该承担不符合它的职责&#xff0c;这在设计模式被称为…

变分自编码器(VAES)

Dimensionality reduction ,PCA and autoencoders Dimensionality reduction 我们清楚&#xff0c;数据降维其实都是减少数据的特征数量&#xff0c;如果把encoderencoderencoder看作是由高维原有特征生成低维新特征的过程。把decoderdecoderdecoder看作是将低维特征还原为高…

vulnhub靶机ha:wordy

靶机下载链接&#xff1a;HA: Wordy ~ VulnHub 靶机ip&#xff1a;192.168.174.136&#xff08;后面重启后变成192.168.174.137&#xff09; kali ip&#xff1a;192.168.174.128 目录 靶机ip发现: 靶机端口扫描: 子目录扫描&#xff1a; wpscan扫描 漏洞利用1 漏洞利…

ASEMI肖特基二极管MBR40200PT参数,MBR40200PT规格

编辑-Z ASEMI肖特基二极管MBR40200PT参数&#xff1a; 型号&#xff1a;MBR40200PT 最大重复峰值反向电压&#xff08;VRRM&#xff09;&#xff1a;200V 最大平均正向整流输出电流&#xff08;IF&#xff09;&#xff1a;40A 峰值正向浪涌电流&#xff08;IFSM&#xff0…

5、Mybatis的查询功能(必定有返回值)

Mybatis的查询功能&#xff08;必定有返回值&#xff09; 注意&#xff1a; 查询功能与前面的增删改不同&#xff0c;增删改的返回值是固定的&#xff08;所以增删改我们就有两种返回值要么设置为int获取受影响的行数&#xff0c;要么设置为void我们不获取返回值&#xff09;…

基于JAVA的农产品生鲜销售管理系统【数据库设计、源码、开题报告】

数据库脚本下载地址&#xff1a; https://download.csdn.net/download/itrjxxs_com/86468222 主要使用技术 Struts2HibernateJSPJSCSSMysql 功能介绍 1&#xff0c;游客访问 |–系统首页&#xff0c;查看商品列表 |–特价商品 |–最新上架 2&#xff0c;会员访问 |–用户登…

Qt 界面设置无边框之后如何实现缩放界面

在qt中&#xff0c;如果设置的了窗口无边框的话&#xff08;即setWindowFlag(Qt::FramelessWindowHint);&#xff09;那么窗口就没法直接被鼠标拖动了&#xff0c;也没法按住窗口的边界进行缩放。 如果要实现缩放和拖动&#xff0c;一般来说就需要的重写窗口类的mousePressEve…

目标检测论文解读复现之十九:基于YOLOv5网络模型的人员口罩佩戴实时检测

前言 此前出了目标改进算法专栏&#xff0c;但是对于应用于什么场景&#xff0c;需要什么改进方法对应与自己的应用场景有效果&#xff0c;并且多少改进点能发什么水平的文章&#xff0c;为解决大家的困惑&#xff0c;此系列文章旨在给大家解读最新目标检测算法论文&#xff0…

8.3 数据结构——交换排序

基本思想&#xff1a;两两比较&#xff0c;如果发生逆序则交换&#xff0c;直到所有记录都排好序为止。 常见的交换排序&#xff1a;&#xff08;1&#xff09;冒泡排序 &#xff08;2&#xff09;快速排序 8.3.1 冒泡排序 基本思想&#xff1a;每趟不断将记录两两比较&…

VLAN(Virtual LAN)虚拟局域网

1、广播与广播域 广播&#xff1a;将广播地址做为目标地址的数据帧 广播域&#xff1a;网络中能接收到同一个广播所有节点的集合&#xff08;广播域越小越好&#xff0c;收到的垃圾广播越少&#xff0c;这样通信效率更高&#xff09; MAC地址广播 广播地址为&#xff1a;FF-FF-…

rabbitmq配置windows authentication(windows account)登录

rabbitmq配置windows authentication(windows account开启插件配置文件创建一个不需要密码的账号&#xff0c;赋予administrator权限。用windows账号和密码登录rabbitmq加密明文密码创建密钥的文件,添加密钥字符串加密解密用户名密码配置加密后的字符串重启rabbitmq&#xff0c…

HyperLynx(三十一)高速串行总线仿真(三)

高速串行总线仿真&#xff08;三&#xff09; 1.从一个多层板工程中验证串行通道 2.在多层板中设置连接器模型 1.从一个多层板工程中验证串行通道 在本例练习中&#xff0c;将集中研究从芯片到插件形成的串行发射通道&#xff0c;并分析它的性能。 (1)打开 HyperLynx 软件&a…

Centos下安装postgreSQL

最近北京yq严重&#xff0c;在家学习下postgreSQL &#xff0c;本次使用的是 Centos 环境安装是有&#xff0c;记录下来&#xff0c;方便备查。 第一步、下载与安装 下载地址&#xff1a;postgreSQL官网 在官网上选择 Linux系统&#xff0c;使用 yum来下载软件&#xff0c;只…