feat(flow+gateway): by-key 取最新版源 XML(修 process-select options=model 语义缺口)
live 验收发现:/api/process-select/options 在本库 143 项全部 source='model',
option.id=act_re_model id(非 procDefId)→ by-id source 端点永远 found:false;
option.key 才是真流程 key。补 by-key 姊妹端点,打开器改用 key 载入。
- flowable-service ProcessDiagramController:
+ GET /api/flow/process-definitions/by-key/{key}/source
(processDefinitionKey(key).latestVersion().singleResult(),null→found:false)。
by-id 与 by-key 逻辑抽共享私有 sourceResponse(procDefId, def),不复制粘贴;
by-id 行为不变(仍以入参 procDefId 读部署 BPMN,既有 7 测试零修改)。
- 网关:FlowableClient.procDefSourceByKey(key)(uri 变量严格编码,禁拼接)
+ ProcessModelerController GET /api/workflow/process-definitions/by-key/{key}/source
(同超管门,非超管 403)。by-id/by-key 段数不同无路由歧义。
测试(mvn -pl flowable-service,platform-flow-gateway,platform-auth -am test 全绿,既有零修改):
- ProcessDiagramControllerTest 7→9(+2:by-key 命中取最新版 v2 净化XML+idMap / key 不存在 found:false)
- FlowableClientTest 11→12(+1:纯中文 key「总包合同交底」uri 变量严格编码,断言 %E6%80%BB 且无裸中文)
- ProcessModelerControllerTest 4→6(+2:by-key 超管 200 透传 / 非超管 403 不触发下游)
- 三模块 Reactor 均 SUCCESS。
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -112,15 +112,37 @@ public class ProcessDiagramController {
|
||||
|
||||
@GetMapping("/process-definitions/{procDefId}/source")
|
||||
@Operation(summary = "按流程定义 id 取净化源 XML",
|
||||
description = "返回 {found, bpmnXml(净化后), idMap(原id→净化id), procDefKey, version},供 bpmn-js Modeler 在线编辑载入。"
|
||||
description = "返回 {procDefId, found, bpmnXml(净化后), idMap(原id→净化id), procDefKey, version},供 bpmn-js Modeler 在线编辑载入。"
|
||||
+ "流程定义不存在 / BPMN 读取失败或为空 → found=false(HTTP 200,前端降级)。"
|
||||
+ "中文 process id 经 BpmnIdSanitizer 可逆净化,idMap 供发布时逆向还原原 key(D7)。")
|
||||
public ResponseEntity<Map<String, Object>> source(@PathVariable String procDefId) {
|
||||
Map<String, Object> resp = new LinkedHashMap<>();
|
||||
resp.put("procDefId", procDefId);
|
||||
|
||||
ProcessDefinition def = repositoryService.createProcessDefinitionQuery()
|
||||
.processDefinitionId(procDefId).singleResult();
|
||||
return sourceResponse(procDefId, def);
|
||||
}
|
||||
|
||||
@GetMapping("/process-definitions/by-key/{key}/source")
|
||||
@Operation(summary = "按流程 key 取最新版净化源 XML",
|
||||
description = "返回与 by-id 端点完全相同的形状 {procDefId, found, bpmnXml, idMap, procDefKey, version},"
|
||||
+ "供 Modeler 打开器按真流程 key 载入(process-select 的 source='model' 项 id 是 act_re_model id 而非 procDefId,"
|
||||
+ "by-id 永远 found:false → 改用本端点)。processDefinitionKey(key).latestVersion() 取最新版,key 不存在 found:false。")
|
||||
public ResponseEntity<Map<String, Object>> sourceByKey(@PathVariable String key) {
|
||||
ProcessDefinition def = repositoryService.createProcessDefinitionQuery()
|
||||
.processDefinitionKey(key).latestVersion().singleResult();
|
||||
String procDefId = def == null ? null : def.getId();
|
||||
return sourceResponse(procDefId, def);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按已解析的流程定义构建源响应(by-id / by-key 共用,逻辑单一不复制):净化 XML + 原→净化 idMap + key/version。
|
||||
* {@code def==null}(不存在)或 BPMN 空/读失败 → {@code found:false}(HTTP 200,前端降级)。
|
||||
* {@code procDefId} 是读取部署 BPMN 资源用的定义 id(by-id=入参、by-key=解析出的最新版 id),命中时随响应回显。
|
||||
*/
|
||||
private ResponseEntity<Map<String, Object>> sourceResponse(String procDefId, ProcessDefinition def) {
|
||||
Map<String, Object> resp = new LinkedHashMap<>();
|
||||
if (procDefId != null) {
|
||||
resp.put("procDefId", procDefId);
|
||||
}
|
||||
if (def == null) {
|
||||
resp.put("found", false);
|
||||
return ResponseEntity.ok(resp);
|
||||
|
||||
@@ -198,6 +198,50 @@ class ProcessDiagramControllerTest {
|
||||
.andExpect(jsonPath("$.found").value(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sourceByKey_按key命中返最新版净化XML与idMap及版本() throws Exception {
|
||||
// process-select options 的 source='model' 项 id 是 act_re_model id(非 procDefId),by-id 永远 found:false;
|
||||
// 打开器改用 option.key(真流程 key)走本端点。latestVersion() 在两版本(v1/v2)里取 v2。
|
||||
ProcessDefinition v2 = org.mockito.Mockito.mock(ProcessDefinition.class);
|
||||
when(v2.getId()).thenReturn("总包合同交底:2:aa22");
|
||||
when(v2.getKey()).thenReturn("总包合同交底");
|
||||
when(v2.getVersion()).thenReturn(2);
|
||||
when(repositoryService.createProcessDefinitionQuery()).thenReturn(processDefinitionQuery);
|
||||
when(processDefinitionQuery.processDefinitionKey("总包合同交底")).thenReturn(processDefinitionQuery);
|
||||
when(processDefinitionQuery.latestVersion()).thenReturn(processDefinitionQuery);
|
||||
when(processDefinitionQuery.singleResult()).thenReturn(v2);
|
||||
|
||||
String xml = "<definitions>"
|
||||
+ "<process id=\"总包合同交底\" name=\"总包合同交底\">"
|
||||
+ "<userTask id=\"sid-A\"/>"
|
||||
+ "<sequenceFlow id=\"f1\" sourceRef=\"总包合同交底\" targetRef=\"sid-A\"/>"
|
||||
+ "</process></definitions>";
|
||||
when(repositoryService.getProcessModel("总包合同交底:2:aa22"))
|
||||
.thenReturn(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
|
||||
|
||||
mvc.perform(get("/api/flow/process-definitions/by-key/{key}/source", "总包合同交底"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.found").value(true))
|
||||
.andExpect(jsonPath("$.procDefId").value("总包合同交底:2:aa22"))
|
||||
.andExpect(jsonPath("$.procDefKey").value("总包合同交底"))
|
||||
.andExpect(jsonPath("$.version").value(2))
|
||||
.andExpect(jsonPath("$.idMap['总包合同交底']").isNotEmpty())
|
||||
.andExpect(jsonPath("$.bpmnXml",
|
||||
org.hamcrest.Matchers.not(org.hamcrest.Matchers.containsString("id=\"总包合同交底\""))));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sourceByKey_key不存在返found_false() throws Exception {
|
||||
when(repositoryService.createProcessDefinitionQuery()).thenReturn(processDefinitionQuery);
|
||||
when(processDefinitionQuery.processDefinitionKey("无此流程")).thenReturn(processDefinitionQuery);
|
||||
when(processDefinitionQuery.latestVersion()).thenReturn(processDefinitionQuery);
|
||||
when(processDefinitionQuery.singleResult()).thenReturn(null);
|
||||
|
||||
mvc.perform(get("/api/flow/process-definitions/by-key/{key}/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);
|
||||
|
||||
Reference in New Issue
Block a user