在工作中,有些工作需求flow able自带的节点属性并不能满足,就需要添加一些自定义的节点属性
对于上面就是实际项目中的效果,那么如何做呢?
{
"name": "nodetypepackage",
"properties": [
{
"id": "nodetype",
"type": "dragon-nodetype-combobox",
"title": "节点类型",
"value": "",
"description": "节点类型",
"popular": true,
"items": [
{
"key": "协同",
"value": "coordination"
},
{
"key": "评审",
"value": "review"
},
{
"key": "普通",
"value": ""
}
]
}
]
}
{
"type" : "node",
"id" : "UserTask",
"title" : "\u7528\u6237\u4efb\u52a1",
"description" : "\u4efb\u52a1\u624b\u52a8\u5206\u914d\u7ed9\u4e00\u4e2a\u7279\u5b9a\u7684\u4eba",
"view" : "\n",
"icon" : "activity/list/type.user.png",
"groups" : [ "\u4efb\u52a1" ],
"propertyPackages" : [ "overrideidpackage", "namepackage", "documentationpackage", "asynchronousdefinitionpackage", "exclusivedefinitionpackage", "executionlistenerspackage", "multiinstance_typepackage", "multiinstance_cardinalitypackage", "multiinstance_collectionpackage", "multiinstance_variablepackage", "multiinstance_conditionpackage", "isforcompensationpackage", "usertaskassignmentpackage", "formkeydefinitionpackage", "formreferencepackage", "duedatedefinitionpackage", "prioritydefinitionpackage", "formpropertiespackage", "tasklistenerspackage", "skipexpressionpackage","nodetypepackage","editdatapackage" ],
"hiddenPropertyPackages" : [ ],
"roles" : [ "Activity", "sequence_start", "sequence_end", "ActivitiesMorph", "all" ]
}
public class BruceUserTaskJsonConverter extends UserTaskJsonConverter {
public static final String IS_EDITDATA = "iseditdata";
public static final String NODE_TYPE = "nodetype";
public static void fillTypes(Map> convertersToBpmnMap,
Map, Class extends BaseBpmnJsonConverter>> convertersToJsonMap) {
fillJsonTypes(convertersToBpmnMap);
fillBpmnTypes(convertersToJsonMap);
}
public static void setCustomTypes(Map> convertersToBpmnMap,
Map, Class extends BaseBpmnJsonConverter>> convertersToJsonMap) {
removeTypes(convertersToBpmnMap,convertersToJsonMap);
fillTypes(convertersToBpmnMap,convertersToJsonMap);
}
public static void removeTypes(Map> convertersToBpmnMap,
Map, Class extends BaseBpmnJsonConverter>> convertersToJsonMap) {
convertersToJsonMap.remove(UserTask.class);
convertersToBpmnMap.remove(StencilConstants.STENCIL_TASK_USER);
}
public static void fillJsonTypes(Map> convertersToBpmnMap) {
convertersToBpmnMap.put(STENCIL_TASK_USER, BruceUserTaskJsonConverter.class);
}
public static void fillBpmnTypes(
Map, Class extends BaseBpmnJsonConverter>> convertersToJsonMap) {
convertersToJsonMap.put(UserTask.class, BruceUserTaskJsonConverter.class);
}
@Override
public void convertToJson(BaseElement baseElement, ActivityProcessor processor, BpmnModel model, FlowElementsContainer container, ArrayNode shapesArrayNode, double subProcessX, double subProcessY){
super.convertToJson(baseElement, processor, model, container, shapesArrayNode, subProcessX, subProcessY);
}
@Override
protected FlowElement convertJsonToElement(JsonNode elementNode, JsonNode modelNode,
Map shapeMap) {
UserTask flowElement = (UserTask) super.convertJsonToElement(elementNode, modelNode, shapeMap);
List customProperties = new ArrayList<>();
// 自定义属性扩展 节点可编辑
String isEditdata = getPropertyValueAsString(IS_EDITDATA, elementNode);
if (StringUtils.isNotBlank(isEditdata)) {
CustomProperty editData = this.createProperty(IS_EDITDATA, isEditdata);
customProperties.add(editData);
}
// 扩展 节点类型
String nodetype = getPropertyValueAsString(NODE_TYPE, elementNode);
if (StringUtils.isNotBlank(nodetype)) {
CustomProperty nodeType = this.createProperty(NODE_TYPE, nodetype);
customProperties.add(nodeType);
}
if (CollectionUtils.isNotEmpty(customProperties)) {
flowElement.setCustomProperties(customProperties);
}
return flowElement;
}
/**
* 创建自定义属性
*
* @param propertyName 属性名称
* @param propertyValue 属性值
*/
private CustomProperty createProperty(String propertyName, String propertyValue) {
CustomProperty customProperty = new CustomProperty();
customProperty.setId(propertyName);
customProperty.setName(propertyName);
customProperty.setSimpleValue(propertyValue);
return customProperty;
}
}
public class CustomPropertyInit {
public void init() {
Map, Class extends BaseBpmnJsonConverter>> convertersToJsonMap = BpmnJsonConverter.convertersToJsonMap;
Map> convertersToBpmnMap = BpmnJsonConverter.convertersToBpmnMap;
//添加自定义的任务json转化器
BruceUserTaskJsonConverter.setCustomTypes(convertersToBpmnMap, convertersToJsonMap);
}
}
public void configure(SpringProcessEngineConfiguration configure) {
//配置中文
configure.setActivityFontName(activityFontName);
configure.setLabelFontName(labelFontName);
configure.setAnnotationFontName(annotationFontName);
//设置自定义的uuid生成策略
configure.setIdGenerator(new UuidGenerator());
configure.setXmlEncoding(xmlEncoding);
//全局监听
Map> typedListeners = this.createGlobEventListeners();
configure.setTypedEventListeners(typedListeners);
//启用任务关系计数
configure.setEnableTaskRelationshipCounts(true);
/**
* 兼容V5
*/
configure.setDatabaseSchemaUpdate("true");
configure.setFlowable5CompatibilityEnabled(true);
configure.setFlowable5CompatibilityHandlerFactory(createSpringFlowable5CompatibilityHandlerFactory());
/**
* 自定义节点属性初始化
*/
createCustomPropertyInit().init();
}
@Bean
public CustomPropertyInit createCustomPropertyInit() {
CustomPropertyInit customPropertyInit = new CustomPropertyInit();
return customPropertyInit;
}