flowable 獲取自定義屬性值


背景

我們在做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;
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM