fix 修复工具类可能出现空指针情况
This commit is contained in:
parent
148ad7a3d1
commit
6954fdec0a
@ -9,6 +9,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.dromara.common.core.utils.SpringUtils;
|
||||||
import org.dromara.common.core.utils.StreamUtils;
|
import org.dromara.common.core.utils.StreamUtils;
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
import org.dromara.common.json.utils.JsonUtils;
|
import org.dromara.common.json.utils.JsonUtils;
|
||||||
@ -17,7 +18,7 @@ import org.flowable.bpmn.converter.BpmnXMLConverter;
|
|||||||
import org.flowable.bpmn.model.*;
|
import org.flowable.bpmn.model.*;
|
||||||
import org.flowable.bpmn.model.Process;
|
import org.flowable.bpmn.model.Process;
|
||||||
import org.flowable.editor.language.json.converter.BpmnJsonConverter;
|
import org.flowable.editor.language.json.converter.BpmnJsonConverter;
|
||||||
import org.flowable.engine.impl.util.ProcessDefinitionUtil;
|
import org.flowable.engine.ProcessEngine;
|
||||||
|
|
||||||
import javax.xml.stream.XMLInputFactory;
|
import javax.xml.stream.XMLInputFactory;
|
||||||
import javax.xml.stream.XMLStreamException;
|
import javax.xml.stream.XMLStreamException;
|
||||||
@ -37,6 +38,8 @@ import java.util.stream.Collectors;
|
|||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class ModelUtils {
|
public class ModelUtils {
|
||||||
|
|
||||||
|
private static final ProcessEngine PROCESS_ENGINE = SpringUtils.getBean(ProcessEngine.class);
|
||||||
|
|
||||||
public static BpmnModel xmlToBpmnModel(String xml) throws IOException {
|
public static BpmnModel xmlToBpmnModel(String xml) throws IOException {
|
||||||
if (xml == null) {
|
if (xml == null) {
|
||||||
throw new ServerException("xml不能为空");
|
throw new ServerException("xml不能为空");
|
||||||
@ -166,7 +169,7 @@ public class ModelUtils {
|
|||||||
* @param processDefinitionId 流程定义id
|
* @param processDefinitionId 流程定义id
|
||||||
*/
|
*/
|
||||||
public static List<FlowElement> getFlowElements(String processDefinitionId) {
|
public static List<FlowElement> getFlowElements(String processDefinitionId) {
|
||||||
BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(processDefinitionId);
|
BpmnModel bpmnModel = PROCESS_ENGINE.getRepositoryService().getBpmnModel(processDefinitionId);
|
||||||
List<FlowElement> list = new ArrayList<>();
|
List<FlowElement> list = new ArrayList<>();
|
||||||
List<Process> processes = bpmnModel.getProcesses();
|
List<Process> processes = bpmnModel.getProcesses();
|
||||||
Collection<FlowElement> flowElements = processes.get(0).getFlowElements();
|
Collection<FlowElement> flowElements = processes.get(0).getFlowElements();
|
||||||
@ -213,7 +216,7 @@ public class ModelUtils {
|
|||||||
* @param flowElementId 节点id
|
* @param flowElementId 节点id
|
||||||
*/
|
*/
|
||||||
public static Map<String, List<ExtensionElement>> getExtensionElement(String processDefinitionId, String flowElementId) {
|
public static Map<String, List<ExtensionElement>> getExtensionElement(String processDefinitionId, String flowElementId) {
|
||||||
BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(processDefinitionId);
|
BpmnModel bpmnModel = PROCESS_ENGINE.getRepositoryService().getBpmnModel(processDefinitionId);
|
||||||
Process process = bpmnModel.getMainProcess();
|
Process process = bpmnModel.getMainProcess();
|
||||||
FlowElement flowElement = process.getFlowElement(flowElementId);
|
FlowElement flowElement = process.getFlowElement(flowElementId);
|
||||||
return flowElement.getExtensionElements();
|
return flowElement.getExtensionElements();
|
||||||
@ -226,7 +229,7 @@ public class ModelUtils {
|
|||||||
* @param taskDefinitionKey 流程定义id
|
* @param taskDefinitionKey 流程定义id
|
||||||
*/
|
*/
|
||||||
public static boolean isUserTask(String processDefinitionId, String taskDefinitionKey) {
|
public static boolean isUserTask(String processDefinitionId, String taskDefinitionKey) {
|
||||||
BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(processDefinitionId);
|
BpmnModel bpmnModel = PROCESS_ENGINE.getRepositoryService().getBpmnModel(processDefinitionId);
|
||||||
FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(taskDefinitionKey);
|
FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(taskDefinitionKey);
|
||||||
return flowNode instanceof UserTask;
|
return flowNode instanceof UserTask;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user