feat(flow): 按 procDefId 取净化源 XML 端点(含 idMap,D7 载入侧)
新增 GET /api/flow/process-definitions/{procDefId}/source:
createProcessDefinitionQuery 取 key/version + readProcessModel 取 BPMN
+ BpmnIdSanitizer.sanitize 净化中文 id → {found,bpmnXml,idMap,procDefKey,version}。
定义不存在 / XML 为空或读取异常 → {found:false}(HTTP 200,WARN log,防御性同 diagram 端点)。
idMap 透出原→净化映射,供发布时逆向还原原 key(D7)。
TDD:ProcessDiagramControllerTest +3 用例(净化XML+idMap+key版本 / 定义不存在
found:false / 读取异常 found:false),既有 4 用例零修改仍绿。
类 7/7、模块全量 71/71 绿(JDK21)。
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -17,6 +17,8 @@ import org.flowable.engine.history.HistoricActivityInstance;
|
||||
import org.flowable.engine.history.HistoricActivityInstanceQuery;
|
||||
import org.flowable.engine.history.HistoricProcessInstance;
|
||||
import org.flowable.engine.history.HistoricProcessInstanceQuery;
|
||||
import org.flowable.engine.repository.ProcessDefinition;
|
||||
import org.flowable.engine.repository.ProcessDefinitionQuery;
|
||||
import org.flowable.engine.runtime.ProcessInstance;
|
||||
import org.flowable.engine.runtime.ProcessInstanceQuery;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -39,6 +41,7 @@ class ProcessDiagramControllerTest {
|
||||
@Mock ProcessInstanceQuery processInstanceQuery;
|
||||
@Mock HistoricProcessInstanceQuery historicProcessInstanceQuery;
|
||||
@Mock HistoricActivityInstanceQuery historicActivityInstanceQuery;
|
||||
@Mock ProcessDefinitionQuery processDefinitionQuery;
|
||||
|
||||
MockMvc mvc;
|
||||
|
||||
@@ -150,4 +153,58 @@ class ProcessDiagramControllerTest {
|
||||
org.junit.jupiter.api.Assertions.assertEquals(safe, finished.get(0));
|
||||
org.junit.jupiter.api.Assertions.assertEquals("sid-A", active.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void source_按procDefId返净化XML与idMap及key版本() throws Exception {
|
||||
// 存量流程 process id 为中文(如「总包合同交底」),moddle 载入前须净化;端点透出原→净化映射供发布时逆向。
|
||||
ProcessDefinition def = org.mockito.Mockito.mock(ProcessDefinition.class);
|
||||
when(def.getKey()).thenReturn("总包合同交底");
|
||||
when(def.getVersion()).thenReturn(3);
|
||||
when(repositoryService.createProcessDefinitionQuery()).thenReturn(processDefinitionQuery);
|
||||
when(processDefinitionQuery.processDefinitionId("def-1")).thenReturn(processDefinitionQuery);
|
||||
when(processDefinitionQuery.singleResult()).thenReturn(def);
|
||||
|
||||
String xml = "<definitions>"
|
||||
+ "<process id=\"总包合同交底\" name=\"总包合同交底\">"
|
||||
+ "<userTask id=\"sid-A\"/>"
|
||||
+ "<sequenceFlow id=\"f1\" sourceRef=\"总包合同交底\" targetRef=\"sid-A\"/>"
|
||||
+ "</process></definitions>";
|
||||
when(repositoryService.getProcessModel("def-1"))
|
||||
.thenReturn(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
|
||||
|
||||
mvc.perform(get("/api/flow/process-definitions/def-1/source"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.found").value(true))
|
||||
.andExpect(jsonPath("$.procDefKey").value("总包合同交底"))
|
||||
.andExpect(jsonPath("$.version").value(3))
|
||||
// idMap 非空且含中文原 key;净化后 XML 的 id 属性不再含中文(name 展示位不受影响)
|
||||
.andExpect(jsonPath("$.idMap").isNotEmpty())
|
||||
.andExpect(jsonPath("$.idMap['总包合同交底']").isNotEmpty())
|
||||
.andExpect(jsonPath("$.bpmnXml",
|
||||
org.hamcrest.Matchers.not(org.hamcrest.Matchers.containsString("id=\"总包合同交底\""))));
|
||||
}
|
||||
|
||||
@Test
|
||||
void source_定义不存在返found_false() throws Exception {
|
||||
when(repositoryService.createProcessDefinitionQuery()).thenReturn(processDefinitionQuery);
|
||||
when(processDefinitionQuery.processDefinitionId("nope")).thenReturn(processDefinitionQuery);
|
||||
when(processDefinitionQuery.singleResult()).thenReturn(null);
|
||||
|
||||
mvc.perform(get("/api/flow/process-definitions/nope/source"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.found").value(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void source_读取XML异常返found_false不抛500() throws Exception {
|
||||
ProcessDefinition def = org.mockito.Mockito.mock(ProcessDefinition.class);
|
||||
when(repositoryService.createProcessDefinitionQuery()).thenReturn(processDefinitionQuery);
|
||||
when(processDefinitionQuery.processDefinitionId("def-x")).thenReturn(processDefinitionQuery);
|
||||
when(processDefinitionQuery.singleResult()).thenReturn(def);
|
||||
when(repositoryService.getProcessModel("def-x")).thenThrow(new RuntimeException("boom"));
|
||||
|
||||
mvc.perform(get("/api/flow/process-definitions/def-x/source"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.found").value(false));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user