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:
2026-07-02 10:59:04 +08:00
parent 88ab0b8f0e
commit 9cfef7e931
6 changed files with 153 additions and 4 deletions

View File

@@ -244,6 +244,22 @@ public class FlowableClient {
.body(Map.class));
}
/**
* 按流程 key 取最新版净化源 XML(供 Modeler 打开器按真流程 key 载入)。对应 flowable-service
* {@code GET /api/flow/process-definitions/by-key/{key}/source},返回体与 {@link #procDefSource} 同形状。
*
* <p>process-select 的 {@code source='model'} 选项 id 是 act_re_model id 而非 procDefId,
* by-id 端点永远 {@code found:false} → 打开器改用真流程 key 走本路。key 同样作为 uri 变量严格编码
* (纯中文 key percent 编码),<b>绝不字符串拼 URL</b>。
*/
@SuppressWarnings("unchecked")
public Map<String, Object> procDefSourceByKey(String key) {
return execute("流程源(按key)", () -> restClient.get()
.uri("/api/flow/process-definitions/by-key/{key}/source", key)
.retrieve()
.body(Map.class));
}
/** 按发起人查询历史流程实例。对应 flowable-service {@code GET /api/flow/process/started}。 */
public List<ProcessInstanceDto> started(String startedBy, int firstResult, int maxResults) {
return execute("发起流程列表", () -> restClient.get()

View File

@@ -51,6 +51,20 @@ public class ProcessModelerController {
return ResponseEntity.ok(flowableClient.procDefSource(procDefId));
}
@Operation(summary = "按流程 key 取最新版净化源 XML(超管)",
description = "超管门后转发 flowable-service /api/flow/process-definitions/by-key/{key}/source,"
+ "返回与 by-id 端点同形状。打开器对 process-select 的 source='model' 选项改用真流程 key 走本路"
+ "(该选项 id 是 act_re_model id 非 procDefId,by-id 永远 found:false)。非超管 403。"
+ "中文 key 由 FlowableClient 以 uri 变量严格编码转发。")
@GetMapping("/process-definitions/by-key/{key}/source")
public ResponseEntity<Map<String, Object>> sourceByKey(@AuthenticationPrincipal AuthPrincipal principal,
@PathVariable String key) {
if (!EngineContextBinder.isSystemAdmin(principal)) {
return forbidden();
}
return ResponseEntity.ok(flowableClient.procDefSourceByKey(key));
}
/** 超管门未过:403 + {status:1,msg} 风格对齐既有网关端点。 */
private static ResponseEntity<Map<String, Object>> forbidden() {
Map<String, Object> body = new LinkedHashMap<>();

View File

@@ -235,6 +235,33 @@ class FlowableClientTest {
server.verify();
}
/**
* by-key 端点:process-select options 的 source='model' 项 id 非 procDefId,打开器改用真流程 key 走此路。
* 纯中文 key「总包合同交底」作为 uri 变量严格编码转发——percent 编码,绝无裸中文。
*/
@Test
void 取流程源按key_纯中文key作为uri变量严格编码不裸传() {
FlowGatewayProperties p = props();
RestClient.Builder builder = RestClient.builder().baseUrl(p.getBaseUrl());
MockRestServiceServer server = MockRestServiceServer.bindTo(builder).build();
String key = "总包合同交底";
server.expect(ExpectedCount.once(), requestTo(allOf(
startsWith("http://localhost:8089/api/flow/process-definitions/by-key/"),
endsWith("/source"),
containsString("%E6%80%BB"), // 「总」的 UTF-8 percent 编码,证明已编码
not(containsString("总包合同交底"))))) // 中文未裸传
.andExpect(method(HttpMethod.GET))
.andRespond(withSuccess("{\"found\":true,\"procDefKey\":\"总包合同交底\",\"version\":2}",
MediaType.APPLICATION_JSON));
FlowableClient client = new FlowableClient(builder.build(), p);
Map<String, Object> resp = client.procDefSourceByKey(key);
assertThat(resp).containsEntry("procDefKey", "总包合同交底");
assertThat(resp).containsEntry("found", true);
server.verify();
}
@Test
void 取流程源_下游4xx透传FlowRemote且不重试() {
FlowGatewayProperties p = props();

View File

@@ -82,4 +82,30 @@ class ProcessModelerControllerTest {
.isInstanceOf(FlowServiceUnavailableException.class);
verify(flowableClient).procDefSource(CN_PROCDEF);
}
// ---- by-key:process-select options=model 的语义缺口修复,打开器用真流程 key ----
private static final String CN_KEY = "总包合同交底";
@Test
void byKey_超管_透传下游源XML返回200() {
Map<String, Object> downstream = Map.of("found", true, "procDefId", "总包合同交底:2:aa22",
"procDefKey", "总包合同交底", "bpmnXml", "<definitions/>", "idMap", Map.of(), "version", 2);
when(flowableClient.procDefSourceByKey(CN_KEY)).thenReturn(downstream);
ResponseEntity<Map<String, Object>> resp = controller.sourceByKey(admin(), CN_KEY);
assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(resp.getBody()).isEqualTo(downstream);
verify(flowableClient).procDefSourceByKey(CN_KEY);
}
@Test
void byKey_非超管_403且不触发下游调用() {
ResponseEntity<Map<String, Object>> resp = controller.sourceByKey(normalUser(), CN_KEY);
assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
assertThat(resp.getBody()).containsEntry("status", 1).containsEntry("msg", "仅系统管理员可用");
verify(flowableClient, never()).procDefSourceByKey(anyString());
}
}