背景
我们在做flowable开发的时候难免会做一些自定义属性,如何去获取他们的值呢?
我是一个有代码洁癖的人,如果哪里有写的不好的地方,请多多指教。
代码
1: 获取节点对象
public FlowElement getFlowElementByActivityIdAndProcessDefinitionId(String activityId, 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);
if (flowElement != null){
return flowElement;
}
}
}
return null;
}
2:获取节点的自定义属性
/**
* 获取自定义属性值
*
* @param activityId 节点id
* @param processDefinitionId 流程定义id
* @param customPropertyName 属性名
* @return
*/
public List<ExtensionElement> getCustomProperty(String activityId, 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;
}