当前位置:网站首页>Notes on implementation and acquisition of flowable custom attributes
Notes on implementation and acquisition of flowable custom attributes
2022-07-27 16:25:00 【Tony-devj】
flowable User defined attribute implementation and attribute acquisition notes
flowable Custom properties
Recently in the project , Need to use workflow , The use of flowable Open source framework for development . There is a requirement in the project to add a custom attribute on the process node . Spent some time on it , In case you forget , Take notes .
edit stencilset_bpmn.json file
find stencilset_bpmn.json file , Open it and you will find propertyPackages Properties of , Pictured :
We just need to follow the form created before the process , I define it here as follows :
{
"name": "isbatchapproval_package",
"properties": [
{
"id": "isbatchapproval",
"type": "Boolean", // Set to boolean type
"title": " Allow batch approval ",
"value": "",
"description": " Set whether batch approval is allowed for related nodes ",
"popular": true
}
]
}
After writing , To display related attributes on related nodes , You need to reference the above attributes on the node id The value is isbatchapproval Of , Because batch approval is only for user task nodes , So in UserTask Introduction in , as follows :
{
"type": "node",
"id": "UserTask",
"title": "\u7528\u6237\u4efb\u52a1",
...
"propertyPackages": [
...
"isbatchapproval_package", // Here corresponds to the above defined isbatchapproval_package, If you want to add it after the specified attribute , Only need to isbatchapproval_package Put it after the specified attribute introduction
...
],
...
},
Click the user node in the process design diagram to add the following attributes :
In download BPMN.xml Add attributes in
By the above operation , It can only be displayed on the process design , But when you save it , Downloaded after release bpmn.xml There will be no such attribute in the file , We need to do the following now
1. Create a IsBatchApprovalJsonConver.java Integrate UserTaskJsonConverter, The main codes are as follows :
@Override
protected FlowElement convertJsonToElement(JsonNode elementNode, JsonNode modelNode,
Map<String, JsonNode> shapeMap) {
UserTask flowElement = (UserTask) super.convertJsonToElement(elementNode, modelNode, shapeMap);
List<CustomProperty> customProperties = new ArrayList<>();
// Extend batch approval attribute , Into the process designer property value , This place can add more
Boolean isBatchApproval = getPropertyValueAsBoolean("isbatchapproval", elementNode);
if (Objects.nonNull(isBatchApproval)) {
CustomProperty nodeType = this.createProperty("isbatchapproval", isBatchApproval.toString());
customProperties.add(nodeType);
}
if (CollUtil.isNotEmpty(customProperties)) {
// Add properties to the process designer
flowElement.setCustomProperties(customProperties);
}
return flowElement;
}
@Override
protected void convertElementToJson(ObjectNode propertiesNode, BaseElement baseElement) {
super.convertElementToJson(propertiesNode, baseElement);
}
/** * Create custom properties * * @param propertyName The attribute name * @param propertyValue Property value */
private CustomProperty createProperty(String propertyName, String propertyValue) {
CustomProperty customProperty = new CustomProperty();
customProperty.setId(propertyName);
customProperty.setName(propertyName);
customProperty.setSimpleValue(propertyValue);
return customProperty;
}
2. establish CustomPropertyInit.java, And add it to the process design configuration , The code is as follows :
public CustomPropertyInit() {
Map<Class<? extends BaseElement>, Class<? extends BaseBpmnJsonConverter>> convertersToJsonMap = BpmnJsonConverter.convertersToJsonMap;
Map<String, Class<? extends BaseBpmnJsonConverter>> convertersToBpmnMap = BpmnJsonConverter.convertersToBpmnMap;
// Add custom tasks json converter
IsBatchApprovalJsonConver.setCustomTypes(convertersToBpmnMap, convertersToJsonMap);
}
/*** * Added in the process design configuration class */
@Bean
public CustomPropertyInit createCustomPropertyInit() {
return new CustomPropertyInit();
}
This redeploys the process , download bpmn You can see the correlation as follows , Mine is like this :
<flowable:isbatchapproval>true</flowable:isbatchapproval>
It shows that the custom attribute is successful .
flowable Get the value of the custom property
We set the relevant custom attributes in the front-end process , How do we get isbatchapproval What about this property ? Just use the following code :
public FlowElement getFlowElementByActivityIdAndProcessDefinitionId(String taskDefinedKey, String processDefinitionId) {
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
List<Process> processes = bpmnModel.getProcesses();
if (CollectionUtils.isNotEmpty(processes)) {
for (Process process : processes) {
FlowElement flowElement = process.getFlowElement(activityId, true);
if (Objects.nonNull(flowElement)) {
return flowElement;
}
}
}
return null;
}
public List<ExtensionElement> getCustomProperty(String taskDefinedKey, String processDefinitionId, String customPropertyName) {
FlowElement flowElement = this.getFlowElementByActivityIdAndProcessDefinitionId(activityId, processDefinitionId);
if (flowElement != null && flowElement instanceof UserTask) {
UserTask userTask = (UserTask) flowElement;
Map<String, List<ExtensionElement>> extensionElements = userTask.getExtensionElements();
if (MapUtils.isNotEmpty(extensionElements)) {
List<ExtensionElement> values = extensionElements.get(customPropertyName);
if (CollectionUtils.isNotEmpty(values)) {
return values;
}
}
}
return null;
}
This requires process definition ID And the definition of the task key,getCustomProperty Method needs to pass in the attribute name to query .
My call is as follows :
Task task = taskQueryUtils.queryTaskToById(taskId);
// Get the custom batch attribute value
List<ExtensionElement> = taskQueryUtils.getCustomProperty(task.getTaskDefinitionKey(), task.getProcessDefinitionId(), "isbatchapproval");
ExtensionElement One of the objects is ElementText attribute , This attribute is the value of this attribute .
边栏推荐
- Your password does not satisfy the current policy requirements (modify MySQL password policy setting simple password)
- COMS Technology
- Coding skills - Global exception capture & unified return body & Business exception
- MapReduce instance (III): data De duplication
- 减小PDF文档大小(转载)
- Leetcode 226 翻转二叉树(递归)
- my_ls小结
- Leetcode 226 flip binary tree (recursive)
- 2.2 JMeter基本元件
- web测试学习笔记01
猜你喜欢

2.2 JMeter基本元件

时间序列——使用tsfresh进行分类任务

The new JMeter function assistant is not under the options menu - in the toolbar

Coding skills - Global exception capture & unified return body & Business exception

DRF learning notes (IV): DRF view

Pychart import existing project

时间序列-ARIMA模型

减小PDF文档大小(转载)

For enterprise operation and maintenance security, use the cloud housekeeper fortress machine!

Yys mouse connector
随机推荐
The solution to the memory exhaustion problem when PHP circulates a large amount of data
ARIMA模型选择与残差
MySQL index
爬取常见英文名
profileapi. h header
: 0xc0000005: an access conflict occurs when writing position 0x01458000 - to be solved
Some queries of TP5
Flask connects to existing tables in MySQL database
Nacos
Leetcode25 question: turn the linked list in a group of K -- detailed explanation of the difficult questions of the linked list
时间序列——使用tsfresh进行分类任务
Install MySQL using CentOS yum
2.2 JMeter基本元件
Solve the problem that ${pagecontext.request.contextpath} is invalid
大数相加
Taking advantage of 5g Dongfeng, does MediaTek want to fight the high-end market again?
Coding skills - Global exception capture & unified return body & Business exception
Penetration test - dry goods | 80 + network security interview experience post (interview)
IO流简介
Chapter I Marxist philosophy is a scientific world outlook and methodology