org.activiti.validation.validator
创始人
2024-01-22 17:04:22
0

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 {@Overrideprotected void executeValidation(BpmnModel bpmnModel, Process process, List errors) {List 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 {@Overridepublic void validate(BpmnModel bpmnModel, List errors) {// Global associationsCollection artifacts = bpmnModel.getGlobalArtifacts();if (artifacts != null) {for (Artifact artifact : artifacts) {if (artifact instanceof Association) {validate(null, (Association) artifact, errors);}}}// Process associationsfor (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 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 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 getProcessesWithSameId(final List processes) {List 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> getDuplicatesMap(List processes) {return processes.stream().collect(Collectors.groupingBy(Process::getId));}

5.DataObjectValidator

*/
public class DataObjectValidator extends ProcessLevelValidator {@Overrideprotected void executeValidation(BpmnModel bpmnModel, Process process, List errors) {// Gather data objectsList allDataObjects = new ArrayList();allDataObjects.addAll(process.getDataObjects());List subProcesses = process.findFlowElementsOfType(SubProcess.class, true);for (SubProcess subProcess : subProcesses) {allDataObjects.addAll(subProcess.getDataObjects());}// Validatefor (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 {@Overrideprotected void executeValidation(BpmnModel bpmnModel, Process process, List errors) {List 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 errors) {MessageEventDefinition messageEventDefinition = (MessageEventDefinition) eventDefinition;if (StringUtils.isEmpty(messageEventDefinition.getMessageRef())) {if (StringUtils.isEmpty(messageEventDefinition.getMessageExpression())) {// message ref should be filled inaddError(errors, Problems.MESSAGE_EVENT_MISSING_MESSAGE_REF, process, event, "attribute 'messageRef' is required");}} else if (!bpmnModel.containsMessageId(messageEventDefinition.getMessageRef())) {// message ref should existaddError(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/

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

相关内容

热门资讯

喜欢穿一身黑的男生性格(喜欢穿... 今天百科达人给各位分享喜欢穿一身黑的男生性格的知识,其中也会对喜欢穿一身黑衣服的男人人好相处吗进行解...
发春是什么意思(思春和发春是什... 本篇文章极速百科给大家谈谈发春是什么意思,以及思春和发春是什么意思对应的知识点,希望对各位有所帮助,...
网络用语zl是什么意思(zl是... 今天给各位分享网络用语zl是什么意思的知识,其中也会对zl是啥意思是什么网络用语进行解释,如果能碰巧...
为什么酷狗音乐自己唱的歌不能下... 本篇文章极速百科小编给大家谈谈为什么酷狗音乐自己唱的歌不能下载到本地?,以及为什么酷狗下载的歌曲不是...
华为下载未安装的文件去哪找(华... 今天百科达人给各位分享华为下载未安装的文件去哪找的知识,其中也会对华为下载未安装的文件去哪找到进行解...
怎么往应用助手里添加应用(应用... 今天百科达人给各位分享怎么往应用助手里添加应用的知识,其中也会对应用助手怎么添加微信进行解释,如果能...
家里可以做假山养金鱼吗(假山能... 今天百科达人给各位分享家里可以做假山养金鱼吗的知识,其中也会对假山能放鱼缸里吗进行解释,如果能碰巧解...
四分五裂是什么生肖什么动物(四... 本篇文章极速百科小编给大家谈谈四分五裂是什么生肖什么动物,以及四分五裂打一生肖是什么对应的知识点,希...
一帆风顺二龙腾飞三阳开泰祝福语... 本篇文章极速百科给大家谈谈一帆风顺二龙腾飞三阳开泰祝福语,以及一帆风顺二龙腾飞三阳开泰祝福语结婚对应...
美团联名卡审核成功待激活(美团... 今天百科达人给各位分享美团联名卡审核成功待激活的知识,其中也会对美团联名卡审核未通过进行解释,如果能...