org.activiti.validation.validator

news2025/7/8 9:07:29

org.activiti.validation.validator

  • 目录
    • 概述
      • 需求:
    • 设计思路
    • 实现思路分析
      • 1.ActivitiEventListenerValidator
      • 3.AssociationValidator
      • 4.validateAtLeastOneExecutable
      • 5.DataObjectValidator
    • 拓展实现
  • 参考资料和推荐阅读

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.

目录

在这里插入图片描述

概述

验证的是一个非常常见的需求。

需求:

设计思路

实现思路分析

1.ActivitiEventListenerValidator

在这里插入图片描述

ublic class ActivitiEventListenerValidator extends ProcessLevelValidator {

  @Override
  protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
    List<EventListener> eventListeners = process.getEventListeners();
    if (eventListeners != null) {
      for (EventListener eventListener : eventListeners) {

        if (eventListener.getImplementationType() != null && eventListener.getImplementationType().equals(ImplementationType.IMPLEMENTATION_TYPE_INVALID_THROW_EVENT)) {

          addError(errors, Problems.EVENT_LISTENER_INVALID_THROW_EVENT_TYPE, process, eventListener, "Invalid or unsupported throw event type on event listener");

        } else if (eventListener.getImplementationType() == null || eventListener.getImplementationType().length() == 0) {

          addError(errors, Problems.EVENT_LISTENER_IMPLEMENTATION_MISSING, process, eventListener, "Element 'class', 'delegateExpression' or 'throwEvent' is mandatory on eventListener");

        } else if (eventListener.getImplementationType() != null) {

          if (!ImplementationType.IMPLEMENTATION_TYPE_CLASS.equals(eventListener.getImplementationType())
              && !ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION.equals(eventListener.getImplementationType())
              && !ImplementationType.IMPLEMENTATION_TYPE_THROW_SIGNAL_EVENT.equals(eventListener.getImplementationType())
              && !ImplementationType.IMPLEMENTATION_TYPE_THROW_GLOBAL_SIGNAL_EVENT.equals(eventListener.getImplementationType())
              && !ImplementationType.IMPLEMENTATION_TYPE_THROW_MESSAGE_EVENT.equals(eventListener.getImplementationType())
              && !ImplementationType.IMPLEMENTATION_TYPE_THROW_ERROR_EVENT.equals(eventListener.getImplementationType())) {
            addError(errors, Problems.EVENT_LISTENER_INVALID_IMPLEMENTATION, process, eventListener, "Unsupported implementation type for event listener");
          }

        }

      }

    }
  }

3.AssociationValidator

public class AssociationValidator extends ValidatorImpl {

  @Override
  public void validate(BpmnModel bpmnModel, List<ValidationError> errors) {

    // Global associations
    Collection<Artifact> artifacts = bpmnModel.getGlobalArtifacts();
    if (artifacts != null) {
      for (Artifact artifact : artifacts) {
        if (artifact instanceof Association) {
          validate(null, (Association) artifact, errors);
        }
      }
    }

    // Process associations
    for (Process process : bpmnModel.getProcesses()) {
      artifacts = process.getArtifacts();
      for (Artifact artifact : artifacts) {
        if (artifact instanceof Association) {
          validate(process, (Association) artifact, errors);
        }
      }
    }

  }

  protected void validate(Process process, Association association, List<ValidationError> errors) {
    if (StringUtils.isEmpty(association.getSourceRef())) {
      addError(errors, Problems.ASSOCIATION_INVALID_SOURCE_REFERENCE, process, association, "association element missing attribute 'sourceRef'");
    }
    if (StringUtils.isEmpty(association.getTargetRef())) {
      addError(errors, Problems.ASSOCIATION_INVALID_TARGET_REFERENCE, process, association, "association element missing attribute 'targetRef'");
    }
  }

4.validateAtLeastOneExecutable

	 * Returns 'true' if at least one process definition in the {@link BpmnModel} is executable.
	 */
  protected boolean validateAtLeastOneExecutable(BpmnModel bpmnModel, List<ValidationError> errors) {
	  int nrOfExecutableDefinitions = 0;
		for (Process process : bpmnModel.getProcesses()) {
			if (process.isExecutable()) {
				nrOfExecutableDefinitions++;
			}
		}

		if (nrOfExecutableDefinitions == 0) {
			addError(errors, Problems.ALL_PROCESS_DEFINITIONS_NOT_EXECUTABLE,
					"All process definition are set to be non-executable (property 'isExecutable' on process). This is not allowed.");
		}

		return nrOfExecutableDefinitions > 0;
  }

  protected List<Process> getProcessesWithSameId(final List<Process> processes) {
            List<Process> filteredProcesses = processes.stream()
                .filter(process -> process.getName() != null).collect(Collectors.toList());
          return getDuplicatesMap(filteredProcesses).values().stream()
              .filter(duplicates -> duplicates.size() > 1)
              .flatMap(Collection::stream)
              .collect(Collectors.toList());
  }

  private static Map<String, List<Process>> getDuplicatesMap(List<Process> processes) {
        return processes.stream().collect(Collectors.groupingBy(Process::getId));
    }

5.DataObjectValidator


 */
public class DataObjectValidator extends ProcessLevelValidator {

  @Override
  protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {

    // Gather data objects
    List<ValuedDataObject> allDataObjects = new ArrayList<ValuedDataObject>();
    allDataObjects.addAll(process.getDataObjects());
    List<SubProcess> subProcesses = process.findFlowElementsOfType(SubProcess.class, true);
    for (SubProcess subProcess : subProcesses) {
      allDataObjects.addAll(subProcess.getDataObjects());
    }

    // Validate
    for (ValuedDataObject dataObject : allDataObjects) {
      if (StringUtils.isEmpty(dataObject.getName())) {
        addError(errors, Problems.DATA_OBJECT_MISSING_NAME, process, dataObject, "Name is mandatory for a data object");
      }
    }

  }

}

拓展实现

public class EventValidator extends ProcessLevelValidator {

  @Override
  protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
    List<Event> events = process.findFlowElementsOfType(Event.class);
    for (Event event : events) {
      if (event.getEventDefinitions() != null) {
        for (EventDefinition eventDefinition : event.getEventDefinitions()) {

          if (eventDefinition instanceof MessageEventDefinition) {
            handleMessageEventDefinition(bpmnModel, process, event, eventDefinition, errors);
          } else if (eventDefinition instanceof SignalEventDefinition) {
            handleSignalEventDefinition(bpmnModel, process, event, eventDefinition, errors);
          } else if (eventDefinition instanceof TimerEventDefinition) {
            handleTimerEventDefinition(process, event, eventDefinition, errors);
          } else if (eventDefinition instanceof CompensateEventDefinition) {
            handleCompensationEventDefinition(bpmnModel, process, event, eventDefinition, errors);
          }

        }
      }
    }
  }

  protected void handleMessageEventDefinition(BpmnModel bpmnModel, Process process, Event event, EventDefinition eventDefinition, List<ValidationError> errors) {
    MessageEventDefinition messageEventDefinition = (MessageEventDefinition) eventDefinition;

    if (StringUtils.isEmpty(messageEventDefinition.getMessageRef())) {

      if (StringUtils.isEmpty(messageEventDefinition.getMessageExpression())) {
        // message ref should be filled in
        addError(errors, Problems.MESSAGE_EVENT_MISSING_MESSAGE_REF, process, event, "attribute 'messageRef' is required");
      }

    } else if (!bpmnModel.containsMessageId(messageEventDefinition.getMessageRef())) {
      // message ref should exist
      addError(errors, Problems.MESSAGE_EVENT_INVALID_MESSAGE_REF, process, event, "Invalid 'messageRef': no message with that id can be found in the model");
    }
  }

参考资料和推荐阅读

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

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

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

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

相关文章

【信号和槽】

前言 信号和槽是QT界面框架的一个核心特性&#xff0c;其重要性和MFC的消息映射机制一样。只要用QT开发项目&#xff0c;就一定会用到&#xff0c;所以必须100%熟练掌握&#xff0c;烂熟于心。 0x0 需要理解的概念 信号&#xff1a;特定情况下被发射的事件。鼠标单击按钮&…

基于复合粒子群优化的模糊神经预测控制的研究(Matlab代码实现)

&#x1f352;&#x1f352;&#x1f352;欢迎关注&#x1f308;&#x1f308;&#x1f308; &#x1f4dd;个人主页&#xff1a;我爱Matlab &#x1f44d;点赞➕评论➕收藏 养成习惯&#xff08;一键三连&#xff09;&#x1f33b;&#x1f33b;&#x1f33b; &#x1f34c;希…

boot+mp搭建版本踩坑记录

最近项目搭建中遇到的一些问题,涉及到 mp 版本 swagger集成等 文章目录前言一、引入mp启动报错1 相关配置2 报错 如下3 解决方案二、引入swagger1 引入的pom2 报错如下:3 解决方案三. 项目启动自动打开swagger页面总结前言 由于使用高版本springboot 导致集成遇到的一些问题 一…

Spring Boot+Netty+Websocket实现后台向前端推送信息

Netty 是一个利用 Java 的高级网络的能力&#xff0c;隐藏其背后的复杂性而提供一个易于使用的API的客户端/服务器框架。 可能在此之前你没有接触过&#xff0c;不过不要担心&#xff0c;下面我们通过一个消息推送的例子来看一下netty是怎么使用的。 1.添加Maven依赖 <!--…

动态代理静态代理

一、使用背景 将目标类包裹起来&#xff0c;对目标类增加一个前置操作和一个后置操作&#xff0c;比如添加日志&#xff0c;在调用目标类前、调用目标后添加日志。 感觉静态代理与动态代理的核心思想&#xff0c;都是根据目标类&#xff0c;拿到目标实现的接口&#xff0c;和…

【软考】-- 操作系统(上)

目录&#xff1a;操作系统&#xff08;上&#xff09;第一节 操作系统概述&#x1f384;一、操作系统基本概念1️⃣操作系统的五大部分&#xff1a;&#x1f38b;二、操作系统的分类1️⃣批处理操作系统&#xff1a;2️⃣分时操作系统&#xff1a;3️⃣实时操作系统&#xff1a…

STC51单片机28——跑马灯

//使用P1口流水点亮8位LED #include<reg51.h> //包含单片机寄存器的头文件 /**************************************** 函数功能&#xff1a;延时一段时间 *****************************************/ void delay(void) { unsigned char i,j; for(i…

Jetpack Compose 重写TopAppBar 实现标题多行折叠

没有效果图一律当水贴处理 效果动图 前言 想用composes实现类似CSDN的文章详细页面的标题栏 上滑隐藏标题后标题栏显示标题 compose.material3下的TopAppBar不能嵌套滚动 MediumTopAppBar 便使用了MediumTopAppBar一开始用着没什么问题&#xff0c;但是标题字数多了&…

一天完成react面试准备

什么是 React的refs&#xff1f;为什么它们很重要 refs允许你直接访问DOM元素或组件实例。为了使用它们&#xff0c;可以向组件添加个ref属性。 如果该属性的值是一个回调函数&#xff0c;它将接受底层的DOM元素或组件的已挂载实例作为其第一个参数。可以在组件中存储它。 ex…

字体图标以及svg图片的使用vite和webpack

先说下字体图标的使用 首先去阿里巴巴矢量图标库&#xff0c;选择你需要的图标&#xff08;可将svg图片自己上传&#xff09;添加到项目里&#xff0c;可以生成在线链接&#xff0c;或者下载资源包到本地。 资源包形式&#xff1a;在项目里创建一个fonts文件夹&#xff0c;将下…

linux 安装rar工具

1.到官网下载对应的编译包 点击跳转 也可以直接到我上传的资源去下载 https://download.csdn.net/download/liudongyang123/87032929https://download.csdn.net/download/liudongyang123/870329292.解压 tar -xf rarlinux-x64-620b2.tar.gz 3.进入到解压后的文件夹&#xf…

Spring Cloud Alibaba 版本对照表,集成nacos,sentinel,seata

一、Spring Cloud Alibaba 版本对照网址 https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E 二、集成nacos nacos源码编译打包_qq_41369135的博客-CSDN博客 连接mysql nacos\conf下的application.properties spring.datasource.…

JDBC:PreparedStatement 插入BLOB类型的数据,PreparedStatement 批量处理,Connection 事务处理

JDBC&#xff1a;PreparedStatement 插入BLOB类型的数据&#xff0c;PreparedStatement 批量处理&#xff0c;Connection 事务处理 每博一文案 村上春树说: 你要做一个不动声色的大人了&#xff0c;不准情绪化&#xff0c;不准偷偷想念&#xff0c;不准回头看自己&#xff0c;…

VGG网络详解(实现猫猫和狗狗识别)

VGG VGG在2014年由牛津大学著名研究组vGG (Visual Geometry Group)提出&#xff0c;斩获该年lmageNet竞赛中Localization Task (定位任务)第一名和 Classification Task (分类任务)第二名。 感受野 首先介绍一下感受野的概念。在卷积神经网络中&#xff0c;决定某一层输出结…

Cloud Flare 添加谷歌镜像站(反向代理)

1.首先创建一个属于自己的镜像站 参考链接&#xff1a;利用cloudflare搭建属于自己的免费Github加速站 首先&#xff0c;点击 Cloud Flare 链接 &#xff0c;创建一个属于自己的账户 登录后&#xff0c;点击 Workers 这个子域&#xff0c;可以自定义 输入好后点set up 然后…

[附源码]java毕业设计基于实时定位的超市配送业务管理

项目运行 环境配置&#xff1a; Jdk1.8 Tomcat7.0 Mysql HBuilderX&#xff08;Webstorm也行&#xff09; Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09;。 项目技术&#xff1a; SSM mybatis Maven Vue 等等组成&#xff0c;B/S模式 M…

本地外卖市场趋势怎么样?成为行业黑马的机会有多大呢?

随着互联网经济的发展&#xff0c;很多人倾向于足不出户就能吃到各种美味食物&#xff0c;因此外卖行业应运而生。这个新行业不仅解决懒人的饮食问题&#xff0c;也为社会提供了更多的就业机会——外卖配送员。据CNNIC的《2022年第49次中国互联网络发展状况统计报告》显示&…

学会这几款表白特效让你明年双十一不再是一个人

随着各种节日的到来&#xff0c;也伴随着许许多多的表白时机&#xff0c;为何不制作几款表白特效让你的行动更加充实呢&#xff0c;此文主要基于HTMLCSSJS制作网页特效&#xff0c;代码简洁&#xff0c;上手简单。 网页特效爱心画心3D爱心爱在心中3D旋转相册开发流程工具安装创…

C语言,从联合看字节序

C语言中的联合&#xff08;union&#xff09;类型为我们提供了操纵和解读“数据”的独特方式&#xff0c;它允许对同一块内存以不同的方式进行解读和操纵。 union UINT {unsigned int intValue; //占4个字节unsigned char bytes[4]; //占4个字节 }; //注意末尾分号不能少本…

aj-report页面嵌入其他项目

我们前面已经制作了自己的报表,我们可以通过共享报表将结果呈现给其他人,但是对一些小白来说,报表与其他项目合成是一个新的问题。怎么合成呢? 我们继续未完的探索。 1、首先,我们可以创建一个已做好的报表的链接: 如上图,我们可以在报表管理里面分享建成的报表,选…