Merge feat/process-modeler 阶段2: EIP4 控件+草稿闭环
Some checks failed
ci / build-test-parity (push) Has been cancelled
Some checks failed
ci / build-test-parity (push) Has been cancelled
- 流程草稿 ProcessModelController(act_re_model,Model API 首启;metaInfo 存 eip4IdMap 供发布还原; category=eip4 隔离 143 存量;草稿保存 validateSchema=false+字节级DOCTYPE守卫;DELETE 端点) - 网关 models 五端点+DELETE 转发(requireSuperAdmin 统一门)+wftemplates picker(entityid→sys_entity.name) - EIP4 侧板五控件(办理人 codec meta 透传/会签保真读回 isSequential/elementVariable/自定义完成条件/ formKey 过滤/扩展属性/监听器);表达式 codec 与 BasePropertiesConverter 逐字对齐+引号映射防截断JUEL - 存草稿闭环(三路径保 eip4IdMap+首存回填 modelId 防刷新重复+草稿列表/删除) - live 验收:总包合同交底 中文key 打开→会签保真→saveXML(bpmn-js默认命名空间,后端XSD修复接受)→ act_re_model 含完整 eip4IdMap→重开侧板忠实回显;全 reactor mvn clean install 绿 - live 揪修3真bug:options source=model语义/属性面板ref未绑/bpmn-js输出被严格XSD拒 - 评审含金量:codec全库4794表达式往返/反编译Flowable抓XXE参数/28会签流对账保真 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -255,7 +255,9 @@ commit:`feat(modeler): 办理人/会签表达式编解码器(与 BasePropertie
|
|||||||
|
|
||||||
### Task 2.4 前端:EIP4 侧板(办理人/会签/formKey/扩展属性/监听器)
|
### Task 2.4 前端:EIP4 侧板(办理人/会签/formKey/扩展属性/监听器)
|
||||||
|
|
||||||
> 📌 **随本 task 顺带收 T1.5 评审两小项**:①红线回归测试——ProcessModelerPage 测试断言 `ModelerCtor.mock.calls[0][0].moddleExtensions` 键恰为 `['activiti']` 且 `additionalModules` 长度为 2(防有人「顺手」加 provider 静默回归);②canvas ref 为 null 分支也 set error(现停留 loading 无提示)。
|
> 🔴 **T2.3 实证——meta 透传是正确性硬要求**:真实表达式外层对象除 items 外还有 5 个业务 meta 字段(messageTemplate/taskSuccessService/isSkipInitiator/isNoUserSkip/isSkipBeforeTask;taskSuccessService 是真实任务后置服务钩子如 PM_CONTRACTUALREGISTER_UPDATEPROJECTSTATUS)。codec 的 parse 已返 `{items,variant,meta}`、build 收 meta 可选参——**侧板写回办理人/会签时必须把 parse 出的 meta 原样传回 build**,否则发布会打掉已部署流程的业务字段。测试必须含「改 items 后 meta 逐字保留」用例。
|
||||||
|
>
|
||||||
|
> 📌 **随本 task 顺带收 T1.5 评审遗留**:红线回归测试——ProcessModelerPage 测试断言 `ModelerCtor.mock.calls[0][0].moddleExtensions` 键恰为 `['activiti']` 且 `additionalModules` 长度为 2(防「顺手」加 provider 静默回归)。(canvas ref null 分支已随 dffd1f3 修复,勿重复。)
|
||||||
|
|
||||||
**Files:**
|
**Files:**
|
||||||
- Create: `src/modeler/Eip4Panel.tsx`(+`Eip4Panel.test.tsx`)、`src/modeler/useSelectedElement.ts`(订阅 `selection.changed`)
|
- Create: `src/modeler/Eip4Panel.tsx`(+`Eip4Panel.test.tsx`)、`src/modeler/useSelectedElement.ts`(订阅 `selection.changed`)
|
||||||
@@ -273,6 +275,10 @@ commit:`feat(modeler): EIP4 侧板三控件+扩展属性/监听器编辑`
|
|||||||
|
|
||||||
### Task 2.5 前端:存草稿 + 草稿列表打开
|
### Task 2.5 前端:存草稿 + 草稿列表打开
|
||||||
|
|
||||||
|
> 📌 **T2.2 评审遗留——草稿删除端点**:五端点无 DELETE,POST 重试窗口产生的重复草稿无 API 可清、草稿列表 UX 也需要删除。**本 task 或 T4.1 补**:flowable-service `DELETE /api/flow/models/{id}`(deleteModel)+ 网关同门转发 + 前端草稿列表删除按钮(confirm)。
|
||||||
|
>
|
||||||
|
> 📌 **T2.2 实证——wftemplates 名称现实**:view_wftemplate **无名称列**(计划原假设错),网关已按 entityid→sys_entity.name 解析——1016 活动模板仅 339 有中文名,其余下拉显 uuid。**formKey 下拉须加过滤输入框**(1016 项不可裸滚动),无名项显示「<uuid 前 8 位>…(未命名)」。此项归本 task 或 T2.4 收口轮顺带。
|
||||||
|
|
||||||
**Files:** Modify `processModeler.ts`(saveDraft/createDraft/listModels/getModel/fromProcDef)、`ProcessModelerPage.tsx`(顶栏「保存草稿」`saveXML({format:true})`→PUT;打开器加「草稿」tab);tests。
|
**Files:** Modify `processModeler.ts`(saveDraft/createDraft/listModels/getModel/fromProcDef)、`ProcessModelerPage.tsx`(顶栏「保存草稿」`saveXML({format:true})`→PUT;打开器加「草稿」tab);tests。
|
||||||
|
|
||||||
**阶段 2 live 验收**:打开「总包合同交底」→ from-procdef 建草稿 → 改办理人(加一个 user)→ 保存 → psql 查 `act_re_model` 新行 + `act_ge_bytearray` 编辑源含改动 + metaInfo 含 eip4IdMap → 重开草稿回显正确。
|
**阶段 2 live 验收**:打开「总包合同交底」→ from-procdef 建草稿 → 改办理人(加一个 user)→ 保存 → psql 查 `act_re_model` 新行 + `act_ge_bytearray` 编辑源含改动 + metaInfo 含 eip4IdMap → 重开草稿回显正确。
|
||||||
@@ -284,6 +290,8 @@ commit + 合 main:`feat(modeler): 阶段2 EIP4 控件+草稿闭环`
|
|||||||
|
|
||||||
### Task 3.1 后端:deploy-from-model(id 还原 + 引擎校验门)
|
### Task 3.1 后端:deploy-from-model(id 还原 + 引擎校验门)
|
||||||
|
|
||||||
|
> 🔴 **阶段2 live 实证——bpmn-js 输出被严格 XSD 校验拒(已修,且警示 T3.1)**:flowable `convertToBpmnModel(src, validateSchema=true, ...)` 的严格 Xerces XSD 校验**拒绝 bpmn-js saveXML 的默认命名空间输出**(`cvc-complex-type.2.4.a: Invalid content ... {MODEL}Process`),原始带前缀 source 能过。草稿保存已改 validateSchema=false(草稿是半成品,XSD 不适用)+ 字节级 DOCTYPE 守卫保 XXE。**本 task deploy 必须验证同问题**:`createDeployment().addString().deploy()` 也解析 bpmn-js 输出,若 Flowable 部署校验拒默认命名空间/activiti 扩展,需在部署前把 bpmn-js XML 规范化(或确认 deploy 路径不走严格 XSD)——阶段 3 live 必须用「编辑器改过并 saveXML 的真实流程」部署,不能只用原始 source。
|
||||||
|
|
||||||
> ⚠️ **T1.3 评审 I-2 预警——文本引用**:bpmn-js `saveXML` 会给流节点补 `<bpmn:incoming>/<bpmn:outgoing>` **元素文本**引用(存量 1512 文档 0 命中,但编辑器导出会有),`BpmnIdSanitizer.restore` 只还原**属性位** → 直接部署会落库「属性=中文原 id、文本引用=净化 id」的脏 XML(Flowable 不解析 incoming/outgoing 故功能无害,但再次 from-procdef 重编辑时碰撞序号换位可能指错节点)。**本 task 必须**:restore 前剥除 incoming/outgoing 元素(Flowable 自行从 sequenceFlow 推导)或把文本引用位纳入 restore,二选一并加测试(含「编辑器导出态 XML → 部署 XML 无净化 id 残留」断言)。
|
> ⚠️ **T1.3 评审 I-2 预警——文本引用**:bpmn-js `saveXML` 会给流节点补 `<bpmn:incoming>/<bpmn:outgoing>` **元素文本**引用(存量 1512 文档 0 命中,但编辑器导出会有),`BpmnIdSanitizer.restore` 只还原**属性位** → 直接部署会落库「属性=中文原 id、文本引用=净化 id」的脏 XML(Flowable 不解析 incoming/outgoing 故功能无害,但再次 from-procdef 重编辑时碰撞序号换位可能指错节点)。**本 task 必须**:restore 前剥除 incoming/outgoing 元素(Flowable 自行从 sequenceFlow 推导)或把文本引用位纳入 restore,二选一并加测试(含「编辑器导出态 XML → 部署 XML 无净化 id 残留」断言)。
|
||||||
|
|
||||||
**Files:** Modify `ProcessModelController.java` + test。
|
**Files:** Modify `ProcessModelController.java` + test。
|
||||||
@@ -299,6 +307,8 @@ commit:`feat(flow): 草稿发布(id还原+ProcessValidator校验门)+影响摘
|
|||||||
|
|
||||||
### Task 3.2 网关:EIP4 语义校验 + 部署审计(Flyway V4)
|
### Task 3.2 网关:EIP4 语义校验 + 部署审计(Flyway V4)
|
||||||
|
|
||||||
|
> 📌 **T2.4 评审补充**:语义校验白名单须加两条——①办理人/会签表达式的 `items` **非空**(`items:[]` 的 MI collection 运行期会炸,仅 JSON 可解析+type 白名单不够);②completionCondition 允许「三预设 或 保留的自定义 body」(T2.4 已实现自定义保留态,校验别把存量自定义条件拒了,白名单改为预设正则 ∪ 非空任意表达式加告警)。
|
||||||
|
|
||||||
**Files:**
|
**Files:**
|
||||||
- Create: `platform-flow-gateway/.../aggregate/ModelSemanticValidator.java` + test:解析 XML(**照 WfTemplateService.newJdkDbf :116-135 钉 JDK 解析器**,防 xerces 击穿)→ ①每个 `activiti:candidateUsers`/multiInstance collection 的内嵌 JSON 可解析且 items[].type ∈ 白名单 ②`activiti:formKey` 存在于 view_wftemplate(JdbcTemplate exists)③completionCondition 匹配预设白名单正则。返回 `List<String> errors`。
|
- Create: `platform-flow-gateway/.../aggregate/ModelSemanticValidator.java` + test:解析 XML(**照 WfTemplateService.newJdkDbf :116-135 钉 JDK 解析器**,防 xerces 击穿)→ ①每个 `activiti:candidateUsers`/multiInstance collection 的内嵌 JSON 可解析且 items[].type ∈ 白名单 ②`activiti:formKey` 存在于 view_wftemplate(JdbcTemplate exists)③completionCondition 匹配预设白名单正则。返回 `List<String> errors`。
|
||||||
- Create: `platform-app/src/main/resources/db/migration/V4__flow_deploy_audit.sql`(照 V3 风格):`sys_flow_deploy_audit(id bigserial pk, model_id, deployment_id, process_key, new_version int, operator varchar(64), deployed_at timestamp default now())`
|
- Create: `platform-app/src/main/resources/db/migration/V4__flow_deploy_audit.sql`(照 V3 风格):`sys_flow_deploy_audit(id bigserial pk, model_id, deployment_id, process_key, new_version int, operator varchar(64), deployed_at timestamp default now())`
|
||||||
|
|||||||
@@ -0,0 +1,398 @@
|
|||||||
|
package com.eip4.flowservice.api;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.flowable.bpmn.converter.BpmnXMLConverter;
|
||||||
|
import org.flowable.common.engine.impl.util.io.StringStreamSource;
|
||||||
|
import org.flowable.engine.RepositoryService;
|
||||||
|
import org.flowable.engine.repository.Model;
|
||||||
|
import org.flowable.engine.repository.ProcessDefinition;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.util.StreamUtils;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程草稿 CRUD(flowable 原生 Model API 存 act_re_model,本控制器为全仓首次启用 Model API)。
|
||||||
|
*
|
||||||
|
* <p>在线 Modeler 的草稿仓:编辑中的 BPMN 存为 flowable Model(editorSource=BPMN XML,metaInfo=EIP4 元数据 JSON),
|
||||||
|
* 不进部署库;发布(T3.1)时才 restore 中文原 key + 校验门 + deploy。act_re_model 表已有 143 行存量、schema 已在,
|
||||||
|
* {@code databaseSchemaUpdate=false} 不涉 DDL。</p>
|
||||||
|
*
|
||||||
|
* <p><b>存量隔离</b>:本控制器建的草稿一律 {@code setCategory("eip4")},{@link #list()} 只查该分类,
|
||||||
|
* 库里 143 条老 shape act_re_model(旧 metaInfo + 可能悬空 editorSource)不进 Modeler 列表、避免打不开。</p>
|
||||||
|
*
|
||||||
|
* <p>写入前 XML 一律过解析守卫({@link #parseGuard}):①字节级拒 DOCTYPE(XXE 门);②{@link BpmnXMLConverter}
|
||||||
|
* 以 {@code validateSchema=false}(草稿是半成品,不做严格 XSD——bpmn-js 默认命名空间输出与严格 XSD 已知固有不兼容,
|
||||||
|
* 完整校验属部署门)+ {@code enableSafeBpmnXml=true}(加固解析器,双保险防外部实体)解析。坏 XML 返 422 且绝不落库;
|
||||||
|
* 422 只回通用文案,原始解析原因仅进日志。守卫异常就地 catch 转 422,不逸出到 {@code FlowExceptionHandler}
|
||||||
|
* (那里 FlowableException→400,语义不符)。
|
||||||
|
* {@code from-procdef} 复用「按 procDefId 读部署 BPMN」逻辑(本控制器自带 {@link #readProcessModel} 小方法,
|
||||||
|
* 零改动 ProcessDiagramController)→ {@link BpmnIdSanitizer#sanitize} 净化中文 id → 建草稿,
|
||||||
|
* 原→净化映射连同源 procDefId/原 key 写进 metaInfo,供发布逆向还原。</p>
|
||||||
|
*
|
||||||
|
* <p><b>鉴权</b>:本控制器随 flowable-service 跑在裸 8089,进程本身无鉴权栈;所有写端点
|
||||||
|
* (POST/PUT/from-procdef)必须经 platform-flow-gateway 的超管门访问(T2.2),生产环境 8089 不对外暴露。</p>
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/flow")
|
||||||
|
@Tag(name = "流程草稿", description = "flowable Model API 草稿 CRUD(act_re_model)+ 从流程定义建草稿")
|
||||||
|
public class ProcessModelController {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(ProcessModelController.class);
|
||||||
|
|
||||||
|
/** EIP4 草稿分类:建草稿时打此标,list() 只查此分类,隔离库里 143 条老 shape 存量 act_re_model。 */
|
||||||
|
static final String EIP4_CATEGORY = "eip4";
|
||||||
|
|
||||||
|
/** DOCTYPE 门 prolog 扫描字节上限(BOM/XML 声明/注释/DOCTYPE 都在最前)。 */
|
||||||
|
private static final int PROLOG_SCAN_BYTES = 8192;
|
||||||
|
|
||||||
|
private final RepositoryService repositoryService;
|
||||||
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
public ProcessModelController(RepositoryService repositoryService) {
|
||||||
|
this.repositoryService = repositoryService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/models")
|
||||||
|
@Operation(summary = "草稿列表",
|
||||||
|
description = "createModelQuery().modelCategory(\"eip4\").orderByLastUpdateTime().desc() → "
|
||||||
|
+ "{models:[{id,name,key,lastUpdateTime(ISO)}]}。只列 EIP4 建的草稿,隔离存量 act_re_model。")
|
||||||
|
public ResponseEntity<Map<String, Object>> list() {
|
||||||
|
List<Map<String, Object>> models = repositoryService.createModelQuery()
|
||||||
|
.modelCategory(EIP4_CATEGORY)
|
||||||
|
.orderByLastUpdateTime().desc().list().stream()
|
||||||
|
.map(m -> {
|
||||||
|
Map<String, Object> row = new LinkedHashMap<>();
|
||||||
|
row.put("id", m.getId());
|
||||||
|
row.put("name", m.getName());
|
||||||
|
row.put("key", m.getKey());
|
||||||
|
row.put("lastUpdateTime", toIso(m.getLastUpdateTime()));
|
||||||
|
return row;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
Map<String, Object> resp = new LinkedHashMap<>();
|
||||||
|
resp.put("models", models);
|
||||||
|
return ResponseEntity.ok(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/models/{id}")
|
||||||
|
@Operation(summary = "取草稿",
|
||||||
|
description = "getModel + getModelEditorSource → {found,id,name,key,bpmnXml,metaInfo}。"
|
||||||
|
+ "草稿不存在或编辑源为空 → {found:false}(HTTP 200,前端降级)。")
|
||||||
|
public ResponseEntity<Map<String, Object>> get(@PathVariable String id) {
|
||||||
|
Map<String, Object> resp = new LinkedHashMap<>();
|
||||||
|
Model model = repositoryService.getModel(id);
|
||||||
|
if (model == null) {
|
||||||
|
resp.put("found", false);
|
||||||
|
return ResponseEntity.ok(resp);
|
||||||
|
}
|
||||||
|
byte[] source = repositoryService.getModelEditorSource(id);
|
||||||
|
if (source == null) {
|
||||||
|
resp.put("found", false);
|
||||||
|
return ResponseEntity.ok(resp);
|
||||||
|
}
|
||||||
|
resp.put("found", true);
|
||||||
|
resp.put("id", model.getId());
|
||||||
|
resp.put("name", model.getName());
|
||||||
|
resp.put("key", model.getKey());
|
||||||
|
resp.put("bpmnXml", new String(source, StandardCharsets.UTF_8));
|
||||||
|
resp.put("metaInfo", model.getMetaInfo());
|
||||||
|
return ResponseEntity.ok(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/models")
|
||||||
|
@Operation(summary = "建草稿",
|
||||||
|
description = "body {name,key,bpmnXml,metaInfo?}。name/key 空白→422;XML 过 BpmnXMLConverter 解析守卫"
|
||||||
|
+ "(坏 XML→422 不落库);过门后 newModel+setCategory(eip4)+saveModel+addModelEditorSource → {modelId}。")
|
||||||
|
public ResponseEntity<Map<String, Object>> create(@RequestBody CreateModelRequest req) {
|
||||||
|
// key 是 T3.1 部署资源名/中文原 key 还原的依赖,name 用于列表展示:空白一律拒。
|
||||||
|
if (isBlank(req.name) || isBlank(req.key)) {
|
||||||
|
return status(HttpStatus.UNPROCESSABLE_ENTITY, "name 与 key 不能为空");
|
||||||
|
}
|
||||||
|
ResponseEntity<Map<String, Object>> rejected = parseGuard(req.bpmnXml);
|
||||||
|
if (rejected != null) {
|
||||||
|
return rejected;
|
||||||
|
}
|
||||||
|
Model model = repositoryService.newModel();
|
||||||
|
model.setName(req.name);
|
||||||
|
model.setKey(req.key);
|
||||||
|
model.setCategory(EIP4_CATEGORY);
|
||||||
|
if (req.metaInfo != null) {
|
||||||
|
model.setMetaInfo(req.metaInfo);
|
||||||
|
}
|
||||||
|
repositoryService.saveModel(model);
|
||||||
|
repositoryService.addModelEditorSource(model.getId(), req.bpmnXml.getBytes(StandardCharsets.UTF_8));
|
||||||
|
Map<String, Object> resp = new LinkedHashMap<>();
|
||||||
|
resp.put("modelId", model.getId());
|
||||||
|
return ResponseEntity.ok(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/models/{id}")
|
||||||
|
@Operation(summary = "更新草稿",
|
||||||
|
description = "草稿不存在→404;更新 name/metaInfo(仅当请求提供,避免覆盖 eip4IdMap)与 editorSource(XML 同守卫 422) → {status:0}。")
|
||||||
|
public ResponseEntity<Map<String, Object>> update(@PathVariable String id, @RequestBody UpdateModelRequest req) {
|
||||||
|
Model model = repositoryService.getModel(id);
|
||||||
|
if (model == null) {
|
||||||
|
return status(HttpStatus.NOT_FOUND, "草稿不存在: " + id);
|
||||||
|
}
|
||||||
|
ResponseEntity<Map<String, Object>> rejected = parseGuard(req.bpmnXml);
|
||||||
|
if (rejected != null) {
|
||||||
|
return rejected;
|
||||||
|
}
|
||||||
|
if (req.name != null) {
|
||||||
|
model.setName(req.name);
|
||||||
|
}
|
||||||
|
// metaInfo 仅当请求显式提供时更新:草稿存 eip4IdMap 于 metaInfo,普通保存不重发 metaInfo 时不能抹掉它。
|
||||||
|
if (req.metaInfo != null) {
|
||||||
|
model.setMetaInfo(req.metaInfo);
|
||||||
|
}
|
||||||
|
repositoryService.saveModel(model);
|
||||||
|
repositoryService.addModelEditorSource(id, req.bpmnXml.getBytes(StandardCharsets.UTF_8));
|
||||||
|
Map<String, Object> resp = new LinkedHashMap<>();
|
||||||
|
resp.put("status", 0);
|
||||||
|
return ResponseEntity.ok(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/models/{id}")
|
||||||
|
@Operation(summary = "删草稿",
|
||||||
|
description = "草稿不存在→404;存在则 deleteModel(id)(连带 editorSource/metaInfo 一并删) → {status:0}。")
|
||||||
|
public ResponseEntity<Map<String, Object>> delete(@PathVariable String id) {
|
||||||
|
Model model = repositoryService.getModel(id);
|
||||||
|
if (model == null) {
|
||||||
|
return status(HttpStatus.NOT_FOUND, "草稿不存在: " + id);
|
||||||
|
}
|
||||||
|
repositoryService.deleteModel(id);
|
||||||
|
Map<String, Object> resp = new LinkedHashMap<>();
|
||||||
|
resp.put("status", 0);
|
||||||
|
return ResponseEntity.ok(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/models/from-procdef")
|
||||||
|
@Operation(summary = "从流程定义建草稿",
|
||||||
|
description = "body {procDefId}。读部署 BPMN → BpmnIdSanitizer.sanitize 净化中文 id → 建草稿"
|
||||||
|
+ "(name/key=procDef,editorSource=净化 XML,metaInfo={eip4IdMap,sourceProcDefId,originalKey}) → {modelId}。"
|
||||||
|
+ "procDef 不存在或 BPMN 空 → {found:false}(HTTP 200,前端降级)。")
|
||||||
|
public ResponseEntity<Map<String, Object>> fromProcDef(@RequestBody FromProcDefRequest req) {
|
||||||
|
ProcessDefinition def = repositoryService.createProcessDefinitionQuery()
|
||||||
|
.processDefinitionId(req.procDefId).singleResult();
|
||||||
|
if (def == null) {
|
||||||
|
return found(false);
|
||||||
|
}
|
||||||
|
String bpmnXml = readProcessModel(req.procDefId);
|
||||||
|
if (bpmnXml == null || bpmnXml.isBlank()) {
|
||||||
|
return found(false);
|
||||||
|
}
|
||||||
|
BpmnIdSanitizer.Result r = BpmnIdSanitizer.sanitize(bpmnXml);
|
||||||
|
|
||||||
|
Map<String, Object> meta = new LinkedHashMap<>();
|
||||||
|
meta.put("eip4IdMap", r.idMap());
|
||||||
|
meta.put("sourceProcDefId", req.procDefId);
|
||||||
|
meta.put("originalKey", def.getKey());
|
||||||
|
String metaInfoJson;
|
||||||
|
try {
|
||||||
|
metaInfoJson = objectMapper.writeValueAsString(meta);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 纯 Map<String,String/Object> 序列化理论上不会失败;防御性 500
|
||||||
|
log.error("[流程草稿] metaInfo 序列化失败 procDefId={}", req.procDefId, e);
|
||||||
|
return status(HttpStatus.INTERNAL_SERVER_ERROR, "metaInfo 序列化失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
Model model = repositoryService.newModel();
|
||||||
|
model.setName(def.getName());
|
||||||
|
model.setKey(def.getKey());
|
||||||
|
model.setCategory(EIP4_CATEGORY);
|
||||||
|
model.setMetaInfo(metaInfoJson);
|
||||||
|
repositoryService.saveModel(model);
|
||||||
|
repositoryService.addModelEditorSource(model.getId(), r.xml().getBytes(StandardCharsets.UTF_8));
|
||||||
|
Map<String, Object> resp = new LinkedHashMap<>();
|
||||||
|
resp.put("modelId", model.getId());
|
||||||
|
return ResponseEntity.ok(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BPMN 解析守卫:过则返回 {@code null}(放行),坏 XML 返回 422 ResponseEntity({status:1,msg})。
|
||||||
|
* 就地 catch 一切异常,不让引擎 XMLException/FlowableException 逸出到全局 advice(那里映射成 400,语义不符)。
|
||||||
|
*
|
||||||
|
* <p><b>两道关</b>:①解析前字节级 {@link #hasDoctypeInBytes} 拒 DOCTYPE 声明(XXE 兜底,不依赖 flowable
|
||||||
|
* 内部 {@code supportDTD=false} 实现);②{@code convertToBpmnModel(source, validateSchema, enableSafeBpmnXml)}
|
||||||
|
* 解析——{@code validateSchema=false}:草稿是可视化工具编辑的半成品,<b>不做</b>严格 BPMN 2.0 XSD 校验。
|
||||||
|
* bpmn-js {@code saveXML} 用默认命名空间(无前缀 definitions/process)重序列化,Flowable 严格 Xerces XSD 校验
|
||||||
|
* 会拒({@code cvc-complex-type.2.4.a})——这是 bpmn-js(面向 BPMN 模型,非字节级 XSD 合规)与严格 XSD 的
|
||||||
|
* <b>已知固有不兼容</b>;完整校验属部署门(T3.1 {@code ProcessValidator} 在解析后的模型上跑,非 XSD)。
|
||||||
|
* {@code validateSchema=false} 仍解析(非良构 XML 抛→422);{@code enableSafeBpmnXml=true} 保加固解析器
|
||||||
|
* (禁外部 DTD/参数实体/DOCTYPE),双保险关 XXE/SSRF。</p>
|
||||||
|
*
|
||||||
|
* <p>422 只回通用文案;原始解析原因(可能含内部路径/实体细节)仅进 {@code log.warn},不回显给调用方。</p>
|
||||||
|
*/
|
||||||
|
private ResponseEntity<Map<String, Object>> parseGuard(String xml) {
|
||||||
|
// ① XXE 兜底:解析前字节级拒 DOCTYPE。按 StringStreamSource 喂解析器的 UTF-8 字节视角扫描(含 BOM/UTF-16
|
||||||
|
// 识别),消除「扫描端 vs 解析端编码错位」绕过。null XML 同走 422(与解析必抛等价)。
|
||||||
|
if (xml == null || hasDoctypeInBytes(xml.getBytes(StandardCharsets.UTF_8))) {
|
||||||
|
log.warn("[流程草稿] BPMN 拒绝: {}", xml == null ? "空 XML" : "含 DOCTYPE 声明(XXE 防御)");
|
||||||
|
return status(HttpStatus.UNPROCESSABLE_ENTITY, "BPMN 解析失败");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// ② validateSchema=false(不做严格 XSD)+ enableSafeBpmnXml=true(加固解析器);详见方法 javadoc。
|
||||||
|
new BpmnXMLConverter().convertToBpmnModel(new StringStreamSource(xml), false, true);
|
||||||
|
return null;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("[流程草稿] BPMN 解析守卫拒绝: {}", e.toString());
|
||||||
|
return status(HttpStatus.UNPROCESSABLE_ENTITY, "BPMN 解析失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字节级 DOCTYPE 检测(XXE 门):按 BOM / 无 BOM 的 UTF-16 空字节特征识别编码后解码 prolog,再走
|
||||||
|
* {@link #hasDoctype}。消除「扫描端与解析端编码视角不一致」的绕过(UTF-8 BOM / UTF-16 会让纯字节扫描漏判
|
||||||
|
* {@code <!DOCTYPE},而 xerces 仍按 BOM 正确解析触发 XXE)。移植 platform-report {@code ReportXmlGuard}
|
||||||
|
* (flowable-service 不依赖 platform-* 模块,故就地复刻,不引依赖)。
|
||||||
|
*/
|
||||||
|
static boolean hasDoctypeInBytes(byte[] raw) {
|
||||||
|
if (raw == null || raw.length == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
java.nio.charset.Charset cs;
|
||||||
|
int off = 0;
|
||||||
|
int u0 = raw[0] & 0xFF;
|
||||||
|
int u1 = raw.length > 1 ? raw[1] & 0xFF : -1;
|
||||||
|
int u2 = raw.length > 2 ? raw[2] & 0xFF : -1;
|
||||||
|
if (u0 == 0xEF && u1 == 0xBB && u2 == 0xBF) {
|
||||||
|
cs = StandardCharsets.UTF_8;
|
||||||
|
off = 3; // UTF-8 BOM
|
||||||
|
} else if (u0 == 0xFF && u1 == 0xFE) {
|
||||||
|
cs = StandardCharsets.UTF_16LE;
|
||||||
|
off = 2; // UTF-16LE BOM
|
||||||
|
} else if (u0 == 0xFE && u1 == 0xFF) {
|
||||||
|
cs = StandardCharsets.UTF_16BE;
|
||||||
|
off = 2; // UTF-16BE BOM
|
||||||
|
} else if (u0 == '<' && u1 == 0x00) {
|
||||||
|
cs = StandardCharsets.UTF_16LE; // 无 BOM UTF-16LE(ASCII 起始字符夹空字节)
|
||||||
|
} else if (u0 == 0x00 && u1 == '<') {
|
||||||
|
cs = StandardCharsets.UTF_16BE; // 无 BOM UTF-16BE
|
||||||
|
} else {
|
||||||
|
cs = StandardCharsets.ISO_8859_1; // UTF-8 / Latin1:prolog 为 ASCII,字节级保真扫描
|
||||||
|
}
|
||||||
|
int scanLen = Math.min(raw.length - off, PROLOG_SCAN_BYTES);
|
||||||
|
return hasDoctype(new String(raw, off, scanLen, cs));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文档 prolog(根元素之前)是否含 DOCTYPE 声明(大小写不敏感)。正确跳过 XML 声明 {@code <?xml?>} 与注释
|
||||||
|
* {@code <!-- -->},命中根元素起始标签即停(元素内容里的字面 {@code <!DOCTYPE} 文本不算)。
|
||||||
|
*/
|
||||||
|
static boolean hasDoctype(String xml) {
|
||||||
|
if (xml == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int i = 0;
|
||||||
|
int n = xml.length();
|
||||||
|
while (i < n) {
|
||||||
|
char c = xml.charAt(i);
|
||||||
|
if (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '') {
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (c != '<') {
|
||||||
|
return false; // prolog 里非标记的文本 → 视为无 DOCTYPE
|
||||||
|
}
|
||||||
|
if (xml.regionMatches(true, i, "<!DOCTYPE", 0, 9)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (xml.startsWith("<!--", i)) { // 注释:整段跳过
|
||||||
|
int end = xml.indexOf("-->", i + 4);
|
||||||
|
if (end < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
i = end + 3;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (xml.startsWith("<?", i)) { // XML 声明 / 处理指令:整段跳过
|
||||||
|
int end = xml.indexOf("?>", i + 2);
|
||||||
|
if (end < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
i = end + 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return false; // 到达根元素起始标签,prolog 结束,无 DOCTYPE
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 读流程定义部署 BPMN XML(getProcessModel 返回资源流)。读失败/为空返回 null(前端降级)。 */
|
||||||
|
private String readProcessModel(String procDefId) {
|
||||||
|
try (InputStream is = repositoryService.getProcessModel(procDefId)) {
|
||||||
|
if (is == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return StreamUtils.copyToString(is, StandardCharsets.UTF_8);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("[流程草稿] 读取 BPMN 失败 procDefId={}: {}", procDefId, e.toString());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ResponseEntity<Map<String, Object>> found(boolean value) {
|
||||||
|
Map<String, Object> resp = new LinkedHashMap<>();
|
||||||
|
resp.put("found", value);
|
||||||
|
return ResponseEntity.ok(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ResponseEntity<Map<String, Object>> status(HttpStatus httpStatus, String msg) {
|
||||||
|
Map<String, Object> body = new LinkedHashMap<>();
|
||||||
|
body.put("status", 1);
|
||||||
|
body.put("msg", msg);
|
||||||
|
return ResponseEntity.status(httpStatus).body(body);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** {@link Date} → ISO-8601 UTC 字符串(如 {@code 1970-01-01T00:00:00Z});null 原样透传。 */
|
||||||
|
private static String toIso(Date d) {
|
||||||
|
return d == null ? null : d.toInstant().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** null 或纯空白(含全角/半角空格)视为空白。 */
|
||||||
|
private static boolean isBlank(String s) {
|
||||||
|
return s == null || s.isBlank();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 建草稿入参。 */
|
||||||
|
public static class CreateModelRequest {
|
||||||
|
public String name;
|
||||||
|
public String key;
|
||||||
|
public String bpmnXml;
|
||||||
|
public String metaInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 更新草稿入参(editorSource 走 bpmnXml;name/metaInfo 为 null 表示不改)。 */
|
||||||
|
public static class UpdateModelRequest {
|
||||||
|
public String name;
|
||||||
|
public String bpmnXml;
|
||||||
|
public String metaInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 从流程定义建草稿入参。 */
|
||||||
|
public static class FromProcDefRequest {
|
||||||
|
public String procDefId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,425 @@
|
|||||||
|
package com.eip4.flowservice.api;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.flowable.engine.RepositoryService;
|
||||||
|
import org.flowable.engine.repository.Model;
|
||||||
|
import org.flowable.engine.repository.ModelQuery;
|
||||||
|
import org.flowable.engine.repository.ProcessDefinition;
|
||||||
|
import org.flowable.engine.repository.ProcessDefinitionQuery;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程草稿 CRUD 端点薄层单测:mock RepositoryService + Model API(newModel/saveModel/addModelEditorSource/
|
||||||
|
* getModelEditorSource/createModelQuery),验证列表/取草稿/建草稿(坏 XML 不落库)/PUT 404/from-procdef
|
||||||
|
* 净化 XML 与 idMap 落 metaInfo。standaloneSetup 不挂 FlowExceptionHandler——422/404 由控制器本地 ResponseEntity
|
||||||
|
* 显式产出(不经引擎异常映射)。
|
||||||
|
*/
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
class ProcessModelControllerTest {
|
||||||
|
|
||||||
|
@Mock RepositoryService repositoryService;
|
||||||
|
@Mock ModelQuery modelQuery;
|
||||||
|
@Mock ProcessDefinitionQuery processDefinitionQuery;
|
||||||
|
|
||||||
|
MockMvc mvc;
|
||||||
|
|
||||||
|
// 最小 schema 合法 BPMN(default ns=BPMN20 MODEL)。
|
||||||
|
private static final String VALID_BPMN = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||||
|
+ "<definitions xmlns=\"http://www.omg.org/spec/BPMN/20100524/MODEL\" targetNamespace=\"http://eip4\">"
|
||||||
|
+ "<process id=\"p1\" name=\"p1\">"
|
||||||
|
+ "<startEvent id=\"start\"/>"
|
||||||
|
+ "<sequenceFlow id=\"f1\" sourceRef=\"start\" targetRef=\"end\"/>"
|
||||||
|
+ "<endEvent id=\"end\"/>"
|
||||||
|
+ "</process></definitions>";
|
||||||
|
|
||||||
|
// bpmn-js saveXML 风格:默认命名空间(无前缀 definitions/process)+ 带前缀 BPMNDI 布局段。
|
||||||
|
// 此处 BPMNDiagram 排在 process 之前(触发严格 XSD 的 cvc-complex-type.2.4.a 序列违例——definitions 内容
|
||||||
|
// 模型要求 rootElement* 在 BPMNDiagram* 之前)——模拟 bpmn-js 输出被严格 XSD 拒的真实故障族。
|
||||||
|
// 草稿保存关 validateSchema 后应良构解析通过 → 200。
|
||||||
|
private static final String BPMN_JS_STYLE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||||
|
+ "<definitions xmlns=\"http://www.omg.org/spec/BPMN/20100524/MODEL\""
|
||||||
|
+ " xmlns:bpmndi=\"http://www.omg.org/spec/BPMN/20100524/DI\""
|
||||||
|
+ " xmlns:dc=\"http://www.omg.org/spec/DD/20100524/DC\""
|
||||||
|
+ " xmlns:di=\"http://www.omg.org/spec/DD/20100524/DI\""
|
||||||
|
+ " id=\"Definitions_1\" targetNamespace=\"http://bpmn.io/schema/bpmn\">"
|
||||||
|
+ "<bpmndi:BPMNDiagram id=\"BPMNDiagram_1\">"
|
||||||
|
+ "<bpmndi:BPMNPlane id=\"BPMNPlane_1\" bpmnElement=\"Process_1\">"
|
||||||
|
+ "<bpmndi:BPMNShape id=\"StartEvent_1_di\" bpmnElement=\"StartEvent_1\">"
|
||||||
|
+ "<dc:Bounds x=\"152\" y=\"82\" width=\"36\" height=\"36\"/>"
|
||||||
|
+ "</bpmndi:BPMNShape></bpmndi:BPMNPlane></bpmndi:BPMNDiagram>"
|
||||||
|
+ "<process id=\"Process_1\" isExecutable=\"true\">"
|
||||||
|
+ "<startEvent id=\"StartEvent_1\" name=\"开始\"/>"
|
||||||
|
+ "</process></definitions>";
|
||||||
|
|
||||||
|
// 含 DOCTYPE 声明(XXE 面):正文良构、关严格 XSD 后本可解析,但字节级 DOCTYPE 守卫必须拒。
|
||||||
|
private static final String DOCTYPE_XML = "<?xml version=\"1.0\"?>"
|
||||||
|
+ "<!DOCTYPE definitions [<!ENTITY xxe \"payload\">]>"
|
||||||
|
+ "<definitions xmlns=\"http://www.omg.org/spec/BPMN/20100524/MODEL\">"
|
||||||
|
+ "<process id=\"p1\"><startEvent id=\"s\"/></process></definitions>";
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
ProcessModelController controller = new ProcessModelController(repositoryService);
|
||||||
|
mvc = MockMvcBuilders.standaloneSetup(controller).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 列表只查eip4分类并按最近更新降序返回id名key时间() throws Exception {
|
||||||
|
Model m = Mockito.mock(Model.class);
|
||||||
|
when(m.getId()).thenReturn("m1");
|
||||||
|
when(m.getName()).thenReturn("总包合同交底");
|
||||||
|
when(m.getKey()).thenReturn("总包合同交底");
|
||||||
|
when(m.getLastUpdateTime()).thenReturn(new Date(0L)); // 1970-01-01T00:00:00Z
|
||||||
|
when(repositoryService.createModelQuery()).thenReturn(modelQuery);
|
||||||
|
when(modelQuery.modelCategory("eip4")).thenReturn(modelQuery);
|
||||||
|
when(modelQuery.orderByLastUpdateTime()).thenReturn(modelQuery);
|
||||||
|
when(modelQuery.desc()).thenReturn(modelQuery);
|
||||||
|
when(modelQuery.list()).thenReturn(List.of(m));
|
||||||
|
|
||||||
|
mvc.perform(get("/api/flow/models"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.models[0].id").value("m1"))
|
||||||
|
.andExpect(jsonPath("$.models[0].name").value("总包合同交底"))
|
||||||
|
.andExpect(jsonPath("$.models[0].key").value("总包合同交底"))
|
||||||
|
.andExpect(jsonPath("$.models[0].lastUpdateTime").value("1970-01-01T00:00:00Z"));
|
||||||
|
|
||||||
|
// 列表只列 EIP4 建的草稿:隔离库里 143 条老 shape 存量 act_re_model(打不开)
|
||||||
|
verify(modelQuery).modelCategory("eip4");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 取草稿返回XML与metaInfo() throws Exception {
|
||||||
|
Model m = Mockito.mock(Model.class);
|
||||||
|
when(m.getId()).thenReturn("m1");
|
||||||
|
when(m.getName()).thenReturn("总包合同交底");
|
||||||
|
when(m.getKey()).thenReturn("总包合同交底");
|
||||||
|
when(m.getMetaInfo()).thenReturn("{\"eip4IdMap\":{\"总包合同交底\":\"n1\"}}");
|
||||||
|
when(repositoryService.getModel("m1")).thenReturn(m);
|
||||||
|
when(repositoryService.getModelEditorSource("m1"))
|
||||||
|
.thenReturn("<definitions/>".getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
mvc.perform(get("/api/flow/models/m1"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.found").value(true))
|
||||||
|
.andExpect(jsonPath("$.id").value("m1"))
|
||||||
|
.andExpect(jsonPath("$.key").value("总包合同交底"))
|
||||||
|
.andExpect(jsonPath("$.bpmnXml").value("<definitions/>"))
|
||||||
|
.andExpect(jsonPath("$.metaInfo").value("{\"eip4IdMap\":{\"总包合同交底\":\"n1\"}}"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 取草稿_model不存在返found_false() throws Exception {
|
||||||
|
when(repositoryService.getModel("nope")).thenReturn(null);
|
||||||
|
|
||||||
|
mvc.perform(get("/api/flow/models/nope"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.found").value(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 取草稿_editorSource为空返found_false() throws Exception {
|
||||||
|
Model m = Mockito.mock(Model.class);
|
||||||
|
when(repositoryService.getModel("m2")).thenReturn(m);
|
||||||
|
when(repositoryService.getModelEditorSource("m2")).thenReturn(null);
|
||||||
|
|
||||||
|
mvc.perform(get("/api/flow/models/m2"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.found").value(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 建草稿_合法XML落库返modelId() throws Exception {
|
||||||
|
Model m = Mockito.mock(Model.class);
|
||||||
|
when(m.getId()).thenReturn("newid");
|
||||||
|
when(repositoryService.newModel()).thenReturn(m);
|
||||||
|
|
||||||
|
String body = "{\"name\":\"新流程\",\"key\":\"newproc\",\"bpmnXml\":"
|
||||||
|
+ jsonString(VALID_BPMN) + ",\"metaInfo\":\"{}\"}";
|
||||||
|
mvc.perform(post("/api/flow/models").contentType(MediaType.APPLICATION_JSON).content(body))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.modelId").value("newid"));
|
||||||
|
|
||||||
|
verify(m).setName("新流程");
|
||||||
|
verify(m).setKey("newproc");
|
||||||
|
verify(m).setCategory("eip4"); // 建草稿打 EIP4 分类,供 list() 过滤隔离存量
|
||||||
|
verify(repositoryService).saveModel(m);
|
||||||
|
ArgumentCaptor<byte[]> src = ArgumentCaptor.forClass(byte[].class);
|
||||||
|
verify(repositoryService).addModelEditorSource(eq("newid"), src.capture());
|
||||||
|
org.junit.jupiter.api.Assertions.assertTrue(
|
||||||
|
new String(src.getValue(), StandardCharsets.UTF_8).contains("<process id=\"p1\""));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 建草稿_空白name或key返422且不落库() throws Exception {
|
||||||
|
// key 是 T3.1 部署资源名/中文原 key 还原的依赖:空白一律拒,在解析守卫之前拦。
|
||||||
|
String body = "{\"name\":\" \",\"key\":\"\",\"bpmnXml\":" + jsonString(VALID_BPMN) + "}";
|
||||||
|
mvc.perform(post("/api/flow/models").contentType(MediaType.APPLICATION_JSON).content(body))
|
||||||
|
.andExpect(status().isUnprocessableEntity())
|
||||||
|
.andExpect(jsonPath("$.status").value(1))
|
||||||
|
.andExpect(jsonPath("$.msg").isNotEmpty());
|
||||||
|
|
||||||
|
verify(repositoryService, never()).newModel();
|
||||||
|
verify(repositoryService, never()).saveModel(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 建草稿_坏XML返422且不落库() throws Exception {
|
||||||
|
String body = "{\"name\":\"坏流程\",\"key\":\"bad\",\"bpmnXml\":"
|
||||||
|
+ jsonString("<definitions><broken") + "}";
|
||||||
|
mvc.perform(post("/api/flow/models").contentType(MediaType.APPLICATION_JSON).content(body))
|
||||||
|
.andExpect(status().isUnprocessableEntity())
|
||||||
|
.andExpect(jsonPath("$.status").value(1))
|
||||||
|
.andExpect(jsonPath("$.msg").isNotEmpty());
|
||||||
|
|
||||||
|
// 解析守卫先于任何写:坏 XML 一律不落库
|
||||||
|
verify(repositoryService, never()).newModel();
|
||||||
|
verify(repositoryService, never()).saveModel(any());
|
||||||
|
verify(repositoryService, never()).addModelEditorSource(anyString(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 建草稿_bpmnJs默认命名空间输出_关严格XSD后200落库() throws Exception {
|
||||||
|
// 回归锚点:bpmn-js saveXML 默认命名空间输出被严格 XSD 拒(改前必红=422)。草稿保存不该做完整 XSD 校验
|
||||||
|
// (完整校验属部署时 ProcessValidator,非 XSD)→ 关 validateSchema 后良构解析通过 → 200 建草稿成功。
|
||||||
|
Model m = Mockito.mock(Model.class);
|
||||||
|
when(m.getId()).thenReturn("draft-js");
|
||||||
|
when(repositoryService.newModel()).thenReturn(m);
|
||||||
|
|
||||||
|
String body = "{\"name\":\"新流程\",\"key\":\"newproc\",\"bpmnXml\":" + jsonString(BPMN_JS_STYLE) + "}";
|
||||||
|
mvc.perform(post("/api/flow/models").contentType(MediaType.APPLICATION_JSON).content(body))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.modelId").value("draft-js"));
|
||||||
|
|
||||||
|
verify(repositoryService).saveModel(m);
|
||||||
|
verify(repositoryService).addModelEditorSource(eq("draft-js"), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 建草稿_含DOCTYPE声明_字节级XXE守卫返422不落库() throws Exception {
|
||||||
|
// 正文良构(关 XSD 后本可解析),但 DOCTYPE 声明是 XXE 面 → 解析前字节级守卫拒,不依赖 flowable 内部实现。
|
||||||
|
String body = "{\"name\":\"x\",\"key\":\"k\",\"bpmnXml\":" + jsonString(DOCTYPE_XML) + "}";
|
||||||
|
mvc.perform(post("/api/flow/models").contentType(MediaType.APPLICATION_JSON).content(body))
|
||||||
|
.andExpect(status().isUnprocessableEntity())
|
||||||
|
.andExpect(jsonPath("$.status").value(1));
|
||||||
|
|
||||||
|
verify(repositoryService, never()).saveModel(any());
|
||||||
|
verify(repositoryService, never()).addModelEditorSource(anyString(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 建草稿_非良构XML_关严格XSD后仍返422不落库() throws Exception {
|
||||||
|
// 关 validateSchema=false 仅关严格 XSD,仍解析:标签不匹配是非良构 XML,解析必抛 → 422。
|
||||||
|
String body = "{\"name\":\"x\",\"key\":\"k\",\"bpmnXml\":"
|
||||||
|
+ jsonString("<definitions><process></definitions>") + "}";
|
||||||
|
mvc.perform(post("/api/flow/models").contentType(MediaType.APPLICATION_JSON).content(body))
|
||||||
|
.andExpect(status().isUnprocessableEntity())
|
||||||
|
.andExpect(jsonPath("$.status").value(1));
|
||||||
|
|
||||||
|
verify(repositoryService, never()).saveModel(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 更新_草稿不存在返404() throws Exception {
|
||||||
|
when(repositoryService.getModel("nope")).thenReturn(null);
|
||||||
|
|
||||||
|
String body = "{\"name\":\"x\",\"bpmnXml\":" + jsonString(VALID_BPMN) + "}";
|
||||||
|
mvc.perform(put("/api/flow/models/nope").contentType(MediaType.APPLICATION_JSON).content(body))
|
||||||
|
.andExpect(status().isNotFound())
|
||||||
|
.andExpect(jsonPath("$.status").value(1));
|
||||||
|
|
||||||
|
verify(repositoryService, never()).saveModel(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 更新_合法XML更新name与editorSource返status0() throws Exception {
|
||||||
|
Model m = Mockito.mock(Model.class);
|
||||||
|
when(repositoryService.getModel("m1")).thenReturn(m);
|
||||||
|
|
||||||
|
String body = "{\"name\":\"改名\",\"bpmnXml\":" + jsonString(VALID_BPMN) + ",\"metaInfo\":\"{}\"}";
|
||||||
|
mvc.perform(put("/api/flow/models/m1").contentType(MediaType.APPLICATION_JSON).content(body))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.status").value(0));
|
||||||
|
|
||||||
|
verify(m).setName("改名");
|
||||||
|
verify(m).setMetaInfo("{}");
|
||||||
|
verify(repositoryService).saveModel(m);
|
||||||
|
verify(repositoryService).addModelEditorSource(eq("m1"), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 更新_只带name不带metaInfo时不改metaInfo() throws Exception {
|
||||||
|
// 草稿的 eip4IdMap 存于 metaInfo,普通保存草稿只发 name+XML 不重发 metaInfo:此时绝不能 setMetaInfo(null)
|
||||||
|
// 抹掉它——这是 T3.1 发布逆向还原原 key 的命根契约。
|
||||||
|
Model m = Mockito.mock(Model.class);
|
||||||
|
when(repositoryService.getModel("m1")).thenReturn(m);
|
||||||
|
|
||||||
|
String body = "{\"name\":\"只改名\",\"bpmnXml\":" + jsonString(VALID_BPMN) + "}";
|
||||||
|
mvc.perform(put("/api/flow/models/m1").contentType(MediaType.APPLICATION_JSON).content(body))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.status").value(0));
|
||||||
|
|
||||||
|
verify(m).setName("只改名");
|
||||||
|
verify(m, never()).setMetaInfo(any());
|
||||||
|
verify(repositoryService).saveModel(m);
|
||||||
|
verify(repositoryService).addModelEditorSource(eq("m1"), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 更新_坏XML返422且不落库() throws Exception {
|
||||||
|
Model m = Mockito.mock(Model.class);
|
||||||
|
when(repositoryService.getModel("m1")).thenReturn(m);
|
||||||
|
|
||||||
|
String body = "{\"name\":\"x\",\"bpmnXml\":" + jsonString("<nope") + "}";
|
||||||
|
mvc.perform(put("/api/flow/models/m1").contentType(MediaType.APPLICATION_JSON).content(body))
|
||||||
|
.andExpect(status().isUnprocessableEntity())
|
||||||
|
.andExpect(jsonPath("$.status").value(1));
|
||||||
|
|
||||||
|
verify(repositoryService, never()).saveModel(any());
|
||||||
|
verify(repositoryService, never()).addModelEditorSource(anyString(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 删草稿_存在则删除返status0() throws Exception {
|
||||||
|
Model m = Mockito.mock(Model.class);
|
||||||
|
when(repositoryService.getModel("m1")).thenReturn(m);
|
||||||
|
|
||||||
|
mvc.perform(delete("/api/flow/models/m1"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.status").value(0));
|
||||||
|
|
||||||
|
verify(repositoryService).deleteModel("m1");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 删草稿_不存在返404不删除() throws Exception {
|
||||||
|
when(repositoryService.getModel("nope")).thenReturn(null);
|
||||||
|
|
||||||
|
mvc.perform(delete("/api/flow/models/nope"))
|
||||||
|
.andExpect(status().isNotFound())
|
||||||
|
.andExpect(jsonPath("$.status").value(1));
|
||||||
|
|
||||||
|
verify(repositoryService, never()).deleteModel(anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void fromProcDef_净化XML与idMap落metaInfo() throws Exception {
|
||||||
|
// 存量流程 process id 为中文,from-procdef 净化后建草稿:editorSource 无中文 id,metaInfo JSON 含
|
||||||
|
// eip4IdMap + sourceProcDefId + 中文 originalKey(发布时逆向还原原 key)。
|
||||||
|
ProcessDefinition def = Mockito.mock(ProcessDefinition.class);
|
||||||
|
when(def.getName()).thenReturn("总包合同交底");
|
||||||
|
when(def.getKey()).thenReturn("总包合同交底");
|
||||||
|
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)));
|
||||||
|
|
||||||
|
Model m = Mockito.mock(Model.class);
|
||||||
|
when(m.getId()).thenReturn("draft-1");
|
||||||
|
when(repositoryService.newModel()).thenReturn(m);
|
||||||
|
|
||||||
|
String body = "{\"procDefId\":\"def-1\"}";
|
||||||
|
mvc.perform(post("/api/flow/models/from-procdef").contentType(MediaType.APPLICATION_JSON).content(body))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.modelId").value("draft-1"));
|
||||||
|
|
||||||
|
verify(m).setName("总包合同交底");
|
||||||
|
verify(m).setKey("总包合同交底");
|
||||||
|
verify(m).setCategory("eip4"); // from-procdef 建的草稿同样打 EIP4 分类
|
||||||
|
// metaInfo:JSON 含 eip4IdMap + sourceProcDefId + 中文 originalKey
|
||||||
|
ArgumentCaptor<String> meta = ArgumentCaptor.forClass(String.class);
|
||||||
|
verify(m).setMetaInfo(meta.capture());
|
||||||
|
String metaJson = meta.getValue();
|
||||||
|
org.junit.jupiter.api.Assertions.assertTrue(metaJson.contains("eip4IdMap"), metaJson);
|
||||||
|
org.junit.jupiter.api.Assertions.assertTrue(metaJson.contains("\"sourceProcDefId\":\"def-1\""), metaJson);
|
||||||
|
org.junit.jupiter.api.Assertions.assertTrue(metaJson.contains("\"originalKey\":\"总包合同交底\""), metaJson);
|
||||||
|
org.junit.jupiter.api.Assertions.assertTrue(metaJson.contains("总包合同交底"), metaJson); // idMap 键含中文原 id
|
||||||
|
// editorSource:净化后 XML 不再含中文 id(id/ref 属性),name 保留中文
|
||||||
|
ArgumentCaptor<byte[]> src = ArgumentCaptor.forClass(byte[].class);
|
||||||
|
verify(repositoryService).addModelEditorSource(eq("draft-1"), src.capture());
|
||||||
|
String savedXml = new String(src.getValue(), StandardCharsets.UTF_8);
|
||||||
|
org.junit.jupiter.api.Assertions.assertFalse(savedXml.contains("id=\"总包合同交底\""), savedXml);
|
||||||
|
org.junit.jupiter.api.Assertions.assertFalse(savedXml.contains("sourceRef=\"总包合同交底\""), savedXml);
|
||||||
|
org.junit.jupiter.api.Assertions.assertTrue(savedXml.contains("name=\"总包合同交底\""), savedXml);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void fromProcDef_procDef不存在返found_false不落库() throws Exception {
|
||||||
|
when(repositoryService.createProcessDefinitionQuery()).thenReturn(processDefinitionQuery);
|
||||||
|
when(processDefinitionQuery.processDefinitionId("nope")).thenReturn(processDefinitionQuery);
|
||||||
|
when(processDefinitionQuery.singleResult()).thenReturn(null);
|
||||||
|
|
||||||
|
mvc.perform(post("/api/flow/models/from-procdef")
|
||||||
|
.contentType(MediaType.APPLICATION_JSON).content("{\"procDefId\":\"nope\"}"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.found").value(false));
|
||||||
|
|
||||||
|
verify(repositoryService, never()).newModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void fromProcDef_BPMN读取为空返found_false不落库() throws Exception {
|
||||||
|
// procDef 存在但部署 BPMN 资源读不出(getProcessModel 返 null)→ 降级 found:false,不建空草稿。
|
||||||
|
ProcessDefinition def = Mockito.mock(ProcessDefinition.class);
|
||||||
|
when(repositoryService.createProcessDefinitionQuery()).thenReturn(processDefinitionQuery);
|
||||||
|
when(processDefinitionQuery.processDefinitionId("def-empty")).thenReturn(processDefinitionQuery);
|
||||||
|
when(processDefinitionQuery.singleResult()).thenReturn(def);
|
||||||
|
when(repositoryService.getProcessModel("def-empty")).thenReturn(null);
|
||||||
|
|
||||||
|
mvc.perform(post("/api/flow/models/from-procdef")
|
||||||
|
.contentType(MediaType.APPLICATION_JSON).content("{\"procDefId\":\"def-empty\"}"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.found").value(false));
|
||||||
|
|
||||||
|
verify(repositoryService, never()).newModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 把任意字符串编成 JSON 字符串字面量(转义引号/反斜杠/换行),用于拼请求体。 */
|
||||||
|
private static String jsonString(String s) {
|
||||||
|
StringBuilder sb = new StringBuilder("\"");
|
||||||
|
for (int i = 0; i < s.length(); i++) {
|
||||||
|
char c = s.charAt(i);
|
||||||
|
switch (c) {
|
||||||
|
case '"' -> sb.append("\\\"");
|
||||||
|
case '\\' -> sb.append("\\\\");
|
||||||
|
case '\n' -> sb.append("\\n");
|
||||||
|
case '\r' -> sb.append("\\r");
|
||||||
|
case '\t' -> sb.append("\\t");
|
||||||
|
default -> sb.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.append("\"").toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -260,6 +260,75 @@ public class FlowableClient {
|
|||||||
.body(Map.class));
|
.body(Map.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------- 草稿 Model API 转发(T2.2)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 草稿列表。对应 flowable-service {@code GET /api/flow/models},返回体
|
||||||
|
* {@code {models:[{id,name,key,lastUpdateTime}]}} 原样透传(flowable-service 已按 EIP4 分类过滤)。
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public Map<String, Object> listModels() {
|
||||||
|
return execute("草稿列表", () -> restClient.get()
|
||||||
|
.uri("/api/flow/models")
|
||||||
|
.retrieve()
|
||||||
|
.body(Map.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取草稿(editorSource + metaInfo)。对应 flowable-service {@code GET /api/flow/models/{id}},返回体
|
||||||
|
* {@code {found,id,name,key,bpmnXml,metaInfo}} 原样透传;草稿不存在下游返 {@code found:false}。
|
||||||
|
*
|
||||||
|
* <p>{@code id} 走 uri 模板变量严格编码(禁字符串拼接)。</p>
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public Map<String, Object> getModel(String id) {
|
||||||
|
return execute("取草稿", () -> restClient.get()
|
||||||
|
.uri("/api/flow/models/{id}", id)
|
||||||
|
.retrieve()
|
||||||
|
.body(Map.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 建草稿。对应 flowable-service {@code POST /api/flow/models},请求体 {@code {name,key,bpmnXml,metaInfo?}}
|
||||||
|
* 经 Jackson 序列化转发,返回 {@code {modelId}};坏 XML 下游 422 → {@link FlowRemoteException} 透传。
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public Map<String, Object> createModel(Object body) {
|
||||||
|
return post("建草稿", "/api/flow/models", body, Map.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新草稿。对应 flowable-service {@code PUT /api/flow/models/{id}},请求体 {@code {name?,bpmnXml,metaInfo?}}
|
||||||
|
* 经 Jackson 序列化转发,返回 {@code {status:0}};草稿不存在下游 404 / 坏 XML 422 → {@link FlowRemoteException} 透传。
|
||||||
|
*
|
||||||
|
* <p>{@code id} 走 uri 模板变量严格编码(禁字符串拼接)。</p>
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public Map<String, Object> updateModel(String id, Object body) {
|
||||||
|
return put("更新草稿", "/api/flow/models/{id}", body, Map.class, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从流程定义建草稿。对应 flowable-service {@code POST /api/flow/models/from-procdef},请求体
|
||||||
|
* {@code {procDefId}} 经 Jackson 序列化转发,返回 {@code {modelId}};procDef 不存在下游返 {@code found:false}。
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public Map<String, Object> modelFromProcDef(Object body) {
|
||||||
|
return post("从流程定义建草稿", "/api/flow/models/from-procdef", body, Map.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删草稿。对应 flowable-service {@code DELETE /api/flow/models/{id}},返回 {@code {status:0}};
|
||||||
|
* 草稿不存在下游 404 → {@link FlowRemoteException} 透传。
|
||||||
|
*
|
||||||
|
* <p>{@code id} 走 uri 模板变量严格编码(禁字符串拼接)。DELETE 幂等——{@link #execute} 连接级重试安全
|
||||||
|
* (重放同一 DELETE 落到同一 id,删已删=下游 404,不产生额外副作用)。</p>
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public Map<String, Object> deleteModel(String id) {
|
||||||
|
return delete("删草稿", "/api/flow/models/{id}", Map.class, id);
|
||||||
|
}
|
||||||
|
|
||||||
/** 按发起人查询历史流程实例。对应 flowable-service {@code GET /api/flow/process/started}。 */
|
/** 按发起人查询历史流程实例。对应 flowable-service {@code GET /api/flow/process/started}。 */
|
||||||
public List<ProcessInstanceDto> started(String startedBy, int firstResult, int maxResults) {
|
public List<ProcessInstanceDto> started(String startedBy, int firstResult, int maxResults) {
|
||||||
return execute("发起流程列表", () -> restClient.get()
|
return execute("发起流程列表", () -> restClient.get()
|
||||||
@@ -311,6 +380,12 @@ public class FlowableClient {
|
|||||||
.body(TASK_LIST));
|
.body(TASK_LIST));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST 转发。<b>幂等性</b>:POST 非幂等——{@link #execute} 的<b>连接级</b>重试(连不上/读超时后重放)
|
||||||
|
* 存在重复创建窗口。接受该风险的理由:①草稿创建廉价且可覆盖(重复草稿人工删即可,非扣款类不可逆副作用);
|
||||||
|
* ②本地网关↔flowable-service 同机链路,连接级瞬时故障概率极低。语义级 4xx/5xx 由 {@link #execute} 保证
|
||||||
|
* <b>绝不</b>重试,故业务错无重复窗口。对比 {@link #put}(覆盖写幂等,重试安全)。
|
||||||
|
*/
|
||||||
private <T> T post(String op, String path, Object body, Class<T> respType) {
|
private <T> T post(String op, String path, Object body, Class<T> respType) {
|
||||||
return execute(op, () -> restClient.post()
|
return execute(op, () -> restClient.post()
|
||||||
.uri(path)
|
.uri(path)
|
||||||
@@ -327,6 +402,32 @@ public class FlowableClient {
|
|||||||
.body(respType));
|
.body(respType));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PUT 转发(RestClient 无既有封装 → 照 {@link #post} 补)。{@code uriTemplate}+{@code uriVars} 走 RestClient
|
||||||
|
* 严格编码({@code id} 作 uri 变量,禁字符串拼接);连接级重试 + 4xx/5xx 透传语义与 post 一致。
|
||||||
|
*
|
||||||
|
* <p><b>幂等性</b>:PUT 是覆盖写、天然幂等 → {@link #execute} 的连接级重试<b>安全</b>(重放同一 PUT 落到同一
|
||||||
|
* 草稿 id,不产生额外副作用),无 {@link #post} 那种重复创建窗口。</p>
|
||||||
|
*/
|
||||||
|
private <T> T put(String op, String uriTemplate, Object body, Class<T> respType, Object... uriVars) {
|
||||||
|
return execute(op, () -> restClient.put()
|
||||||
|
.uri(uriTemplate, uriVars)
|
||||||
|
.body(body == null ? Map.of() : body)
|
||||||
|
.retrieve()
|
||||||
|
.body(respType));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DELETE 转发(RestClient 无既有封装 → 照 {@link #put} 补)。{@code uriTemplate}+{@code uriVars} 走 RestClient
|
||||||
|
* 严格编码({@code id} 作 uri 变量,禁字符串拼接);无请求体;连接级重试 + 4xx/5xx 透传语义与 put 一致(幂等)。
|
||||||
|
*/
|
||||||
|
private <T> T delete(String op, String uriTemplate, Class<T> respType, Object... uriVars) {
|
||||||
|
return execute(op, () -> restClient.delete()
|
||||||
|
.uri(uriTemplate, uriVars)
|
||||||
|
.retrieve()
|
||||||
|
.body(respType));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统一执行:连接级故障带退避重试 maxRetries 次,耗尽 → 503 语义;业务错(4xx/5xx)立即透传不重试。
|
* 统一执行:连接级故障带退避重试 maxRetries 次,耗尽 → 503 语义;业务错(4xx/5xx)立即透传不重试。
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,13 +1,22 @@
|
|||||||
package com.eip4.platform.flowgateway.web;
|
package com.eip4.platform.flowgateway.web;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@@ -22,22 +31,58 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
|||||||
* 在线流程 Modeler 网关门面:把 flowable-service 的流程定义/草稿能力经<b>超管门</b>暴露给设计器前端。
|
* 在线流程 Modeler 网关门面:把 flowable-service 的流程定义/草稿能力经<b>超管门</b>暴露给设计器前端。
|
||||||
*
|
*
|
||||||
* <p>flowable-service 裸 8089 无 Spring Security → 流程编辑/部署面的鉴权唯一落点在本网关层。
|
* <p>flowable-service 裸 8089 无 Spring Security → 流程编辑/部署面的鉴权唯一落点在本网关层。
|
||||||
* 本控制器所有端点先过超管门({@link EngineContextBinder#isSystemAdmin},与全站 {@code requireAdmin}
|
* 本控制器所有端点先过超管门({@link #requireSuperAdmin},委托 {@link EngineContextBinder#isSystemAdmin},
|
||||||
* 逐口径对齐),非超管返回 403,过门后转发 {@link FlowableClient},返回体原样透传。
|
* 与全站 {@code requireAdmin} 逐口径对齐),非超管返回 403,过门后转发 {@link FlowableClient},返回体原样透传。
|
||||||
*
|
*
|
||||||
* <p>阶段 1(T1.6):只读载入存量流程源 XML。草稿 CRUD / 发布门在后续阶段接入本控制器。
|
* <p>阶段 1(T1.6):只读载入存量流程源 XML。阶段 2(T2.2):草稿 CRUD 五端点转发(list/get/create/update/
|
||||||
|
* from-procdef,对齐 flowable-service {@code ProcessModelController} 契约)+ 办理人/会签 formKey 选择器数据源
|
||||||
|
* {@code /wftemplates}(读业务库 {@code view_wftemplate})。发布门在阶段 3 接入。</p>
|
||||||
*/
|
*/
|
||||||
@Tag(name = "流程 Modeler 网关", description = "流程设计器:超管门 + flowable-service 转发(存量源载入/草稿/发布)")
|
@Tag(name = "流程 Modeler 网关", description = "流程设计器:超管门 + flowable-service 转发(存量源载入/草稿/发布)")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/workflow")
|
@RequestMapping("/api/workflow")
|
||||||
public class ProcessModelerController {
|
public class ProcessModelerController {
|
||||||
|
|
||||||
private final FlowableClient flowableClient;
|
private static final Logger log = LoggerFactory.getLogger(ProcessModelerController.class);
|
||||||
|
|
||||||
public ProcessModelerController(FlowableClient flowableClient) {
|
/**
|
||||||
|
* formKey 选择器数据源:{@code view_wftemplate}(1016 行已迁移)。<b>实证(information_schema)</b>:
|
||||||
|
* 表无独立名称列(仅 {@code view_wftemplate_id CHAR + xml + isactive + 审计列}),{@code <form>} 根标签
|
||||||
|
* 也无 title/name 属性(0/1016);唯一人类可读名来自 XML 的 {@code entityid} → {@code sys_entity.name}
|
||||||
|
* (378 模板带 entityid,339 解析出中文名,如「通知管理」)。故 name = 解析出的实体名,无则回退 id。
|
||||||
|
* {@code view_wftemplate_id} 是 CHAR 补白列 → RowMapper 内 trim。
|
||||||
|
*/
|
||||||
|
static final String WFTEMPLATES_SQL =
|
||||||
|
"SELECT t.view_wftemplate_id AS id, se.name AS name "
|
||||||
|
+ "FROM view_wftemplate t "
|
||||||
|
+ "LEFT JOIN sys_entity se "
|
||||||
|
+ " ON se.sys_entity_id = substring(CAST(t.xml AS text) FROM 'entityid=\"([0-9a-fA-F-]+)\"') "
|
||||||
|
+ "WHERE t.isactive = 1 "
|
||||||
|
+ "ORDER BY se.name NULLS LAST, t.view_wftemplate_id";
|
||||||
|
|
||||||
|
/** 单行 → {@code {id(trim 补白),name(实体名,空则回退 id)}}。 */
|
||||||
|
static final RowMapper<Map<String, Object>> WFTEMPLATE_ROW = (rs, rowNum) -> {
|
||||||
|
String id = rs.getString("id");
|
||||||
|
if (id != null) {
|
||||||
|
id = id.trim();
|
||||||
|
}
|
||||||
|
String name = rs.getString("name");
|
||||||
|
Map<String, Object> row = new LinkedHashMap<>();
|
||||||
|
row.put("id", id);
|
||||||
|
row.put("name", (name != null && !name.isBlank()) ? name : id);
|
||||||
|
return row;
|
||||||
|
};
|
||||||
|
|
||||||
|
private final FlowableClient flowableClient;
|
||||||
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
public ProcessModelerController(FlowableClient flowableClient, JdbcTemplate jdbcTemplate) {
|
||||||
this.flowableClient = flowableClient;
|
this.flowableClient = flowableClient;
|
||||||
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------- 存量流程源载入(T1.6)
|
||||||
|
|
||||||
@Operation(summary = "按流程定义 id 取净化源 XML(超管)",
|
@Operation(summary = "按流程定义 id 取净化源 XML(超管)",
|
||||||
description = "超管门后转发 flowable-service /api/flow/process-definitions/{procDefId}/source,"
|
description = "超管门后转发 flowable-service /api/flow/process-definitions/{procDefId}/source,"
|
||||||
+ "返回 {procDefId, found, bpmnXml(净化后), idMap, procDefKey, version} 供 bpmn-js Modeler 载入。"
|
+ "返回 {procDefId, found, bpmnXml(净化后), idMap, procDefKey, version} 供 bpmn-js Modeler 载入。"
|
||||||
@@ -45,8 +90,9 @@ public class ProcessModelerController {
|
|||||||
@GetMapping("/process-definitions/{procDefId}/source")
|
@GetMapping("/process-definitions/{procDefId}/source")
|
||||||
public ResponseEntity<Map<String, Object>> source(@AuthenticationPrincipal AuthPrincipal principal,
|
public ResponseEntity<Map<String, Object>> source(@AuthenticationPrincipal AuthPrincipal principal,
|
||||||
@PathVariable String procDefId) {
|
@PathVariable String procDefId) {
|
||||||
if (!EngineContextBinder.isSystemAdmin(principal)) {
|
ResponseEntity<Map<String, Object>> denied = requireSuperAdmin(principal);
|
||||||
return forbidden();
|
if (denied != null) {
|
||||||
|
return denied;
|
||||||
}
|
}
|
||||||
return ResponseEntity.ok(flowableClient.procDefSource(procDefId));
|
return ResponseEntity.ok(flowableClient.procDefSource(procDefId));
|
||||||
}
|
}
|
||||||
@@ -59,14 +105,132 @@ public class ProcessModelerController {
|
|||||||
@GetMapping("/process-definitions/by-key/{key}/source")
|
@GetMapping("/process-definitions/by-key/{key}/source")
|
||||||
public ResponseEntity<Map<String, Object>> sourceByKey(@AuthenticationPrincipal AuthPrincipal principal,
|
public ResponseEntity<Map<String, Object>> sourceByKey(@AuthenticationPrincipal AuthPrincipal principal,
|
||||||
@PathVariable String key) {
|
@PathVariable String key) {
|
||||||
if (!EngineContextBinder.isSystemAdmin(principal)) {
|
ResponseEntity<Map<String, Object>> denied = requireSuperAdmin(principal);
|
||||||
return forbidden();
|
if (denied != null) {
|
||||||
|
return denied;
|
||||||
}
|
}
|
||||||
return ResponseEntity.ok(flowableClient.procDefSourceByKey(key));
|
return ResponseEntity.ok(flowableClient.procDefSourceByKey(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 超管门未过:403 + {status:1,msg} 风格对齐既有网关端点。 */
|
// ---------------------------------------------------------------- 草稿 CRUD 转发(T2.2)
|
||||||
private static ResponseEntity<Map<String, Object>> forbidden() {
|
|
||||||
|
@Operation(summary = "草稿列表(超管)",
|
||||||
|
description = "超管门后转发 flowable-service GET /api/flow/models,返回 {models:[{id,name,key,lastUpdateTime}]}。")
|
||||||
|
@GetMapping("/models")
|
||||||
|
public ResponseEntity<Map<String, Object>> listModels(@AuthenticationPrincipal AuthPrincipal principal) {
|
||||||
|
ResponseEntity<Map<String, Object>> denied = requireSuperAdmin(principal);
|
||||||
|
if (denied != null) {
|
||||||
|
return denied;
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(flowableClient.listModels());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "取草稿(超管)",
|
||||||
|
description = "超管门后转发 flowable-service GET /api/flow/models/{id},返回 {found,id,name,key,bpmnXml,metaInfo}。"
|
||||||
|
+ "id 由 FlowableClient 以 uri 变量严格编码转发。")
|
||||||
|
@GetMapping("/models/{id}")
|
||||||
|
public ResponseEntity<Map<String, Object>> getModel(@AuthenticationPrincipal AuthPrincipal principal,
|
||||||
|
@PathVariable String id) {
|
||||||
|
ResponseEntity<Map<String, Object>> denied = requireSuperAdmin(principal);
|
||||||
|
if (denied != null) {
|
||||||
|
return denied;
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(flowableClient.getModel(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "建草稿(超管)",
|
||||||
|
description = "超管门后转发 flowable-service POST /api/flow/models,body {name,key,bpmnXml,metaInfo?},"
|
||||||
|
+ "返回 {modelId}。坏 XML 下游 422 经既有 handler 透传。")
|
||||||
|
@PostMapping("/models")
|
||||||
|
public ResponseEntity<Map<String, Object>> createModel(@AuthenticationPrincipal AuthPrincipal principal,
|
||||||
|
@RequestBody Map<String, Object> body) {
|
||||||
|
ResponseEntity<Map<String, Object>> denied = requireSuperAdmin(principal);
|
||||||
|
if (denied != null) {
|
||||||
|
return denied;
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(flowableClient.createModel(body));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "更新草稿(超管)",
|
||||||
|
description = "超管门后转发 flowable-service PUT /api/flow/models/{id},body {name?,bpmnXml,metaInfo?},"
|
||||||
|
+ "返回 {status:0}。草稿不存在 404 / 坏 XML 422 经既有 handler 透传。id 以 uri 变量严格编码转发。")
|
||||||
|
@PutMapping("/models/{id}")
|
||||||
|
public ResponseEntity<Map<String, Object>> updateModel(@AuthenticationPrincipal AuthPrincipal principal,
|
||||||
|
@PathVariable String id,
|
||||||
|
@RequestBody Map<String, Object> body) {
|
||||||
|
ResponseEntity<Map<String, Object>> denied = requireSuperAdmin(principal);
|
||||||
|
if (denied != null) {
|
||||||
|
return denied;
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(flowableClient.updateModel(id, body));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "从流程定义建草稿(超管)",
|
||||||
|
description = "超管门后转发 flowable-service POST /api/flow/models/from-procdef,body {procDefId},"
|
||||||
|
+ "返回 {modelId}(净化 id 映射落 metaInfo)。procDef 不存在下游返 {found:false}。")
|
||||||
|
@PostMapping("/models/from-procdef")
|
||||||
|
public ResponseEntity<Map<String, Object>> modelFromProcDef(@AuthenticationPrincipal AuthPrincipal principal,
|
||||||
|
@RequestBody Map<String, Object> body) {
|
||||||
|
ResponseEntity<Map<String, Object>> denied = requireSuperAdmin(principal);
|
||||||
|
if (denied != null) {
|
||||||
|
return denied;
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(flowableClient.modelFromProcDef(body));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "删草稿(超管)",
|
||||||
|
description = "超管门后转发 flowable-service DELETE /api/flow/models/{id},返回 {status:0}。"
|
||||||
|
+ "草稿不存在 404 经既有 handler 透传。id 以 uri 变量严格编码转发。")
|
||||||
|
@DeleteMapping("/models/{id}")
|
||||||
|
public ResponseEntity<Map<String, Object>> deleteModel(@AuthenticationPrincipal AuthPrincipal principal,
|
||||||
|
@PathVariable String id) {
|
||||||
|
ResponseEntity<Map<String, Object>> denied = requireSuperAdmin(principal);
|
||||||
|
if (denied != null) {
|
||||||
|
return denied;
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(flowableClient.deleteModel(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------- formKey 选择器数据源(T2.2)
|
||||||
|
|
||||||
|
@Operation(summary = "wftemplate 选择器数据源(超管)",
|
||||||
|
description = "超管门后读业务库 view_wftemplate(isactive=1) → {templates:[{id,name}]},供办理人/会签 formKey"
|
||||||
|
+ " 下拉选择。name 取 XML entityid→sys_entity.name(无则回退 id),view_wftemplate_id 去 CHAR 补白。"
|
||||||
|
+ "读库异常降级为空列表(不 500 阻断设计器)。")
|
||||||
|
@GetMapping("/wftemplates")
|
||||||
|
public ResponseEntity<Map<String, Object>> wftemplates(@AuthenticationPrincipal AuthPrincipal principal) {
|
||||||
|
ResponseEntity<Map<String, Object>> denied = requireSuperAdmin(principal);
|
||||||
|
if (denied != null) {
|
||||||
|
return denied;
|
||||||
|
}
|
||||||
|
List<Map<String, Object>> templates;
|
||||||
|
boolean degraded = false;
|
||||||
|
try {
|
||||||
|
templates = jdbcTemplate.query(WFTEMPLATES_SQL, WFTEMPLATE_ROW);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
log.warn("view_wftemplate 选择器读取降级为空列表: {}", e.toString());
|
||||||
|
templates = List.of();
|
||||||
|
degraded = true;
|
||||||
|
}
|
||||||
|
Map<String, Object> resp = new LinkedHashMap<>();
|
||||||
|
resp.put("templates", templates);
|
||||||
|
if (degraded) {
|
||||||
|
// 降级标记:正常路径不带此键,前端可据此区分「真无模板」与「读库失败」并提示重试。
|
||||||
|
resp.put("degraded", true);
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------- 超管门
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一超管门:超管返回 {@code null}(放行),非超管/无身份返回 403 ResponseEntity({status:1,msg})。
|
||||||
|
* 所有端点入口调用,防漏门(T1.6 评审 M-3)。403 信封与既有网关端点逐字对齐。
|
||||||
|
*/
|
||||||
|
private static ResponseEntity<Map<String, Object>> requireSuperAdmin(AuthPrincipal principal) {
|
||||||
|
if (EngineContextBinder.isSystemAdmin(principal)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
Map<String, Object> body = new LinkedHashMap<>();
|
Map<String, Object> body = new LinkedHashMap<>();
|
||||||
body.put("status", 1);
|
body.put("status", 1);
|
||||||
body.put("msg", "仅系统管理员可用");
|
body.put("msg", "仅系统管理员可用");
|
||||||
|
|||||||
@@ -278,4 +278,156 @@ class FlowableClientTest {
|
|||||||
.satisfies(e -> assertThat(((FlowRemoteException) e).getStatus().value()).isEqualTo(400));
|
.satisfies(e -> assertThat(((FlowRemoteException) e).getStatus().value()).isEqualTo(400));
|
||||||
server.verify();
|
server.verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---- 草稿 Model API 转发(T2.2):list/get/create/update/from-procdef ----
|
||||||
|
// flowable-service ProcessModelController(T2.1) 契约:GET/POST/PUT /api/flow/models[/{id}]
|
||||||
|
// + POST /api/flow/models/from-procdef。全部返 Map 原样透传;POST/PUT body 经 Jackson 序列化转发;
|
||||||
|
// {id} 走 uri 模板变量严格编码(禁拼接);下游 4xx 透传 FlowRemoteException。
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 草稿列表_GET_models解析models数组() {
|
||||||
|
FlowGatewayProperties p = props();
|
||||||
|
RestClient.Builder builder = RestClient.builder().baseUrl(p.getBaseUrl());
|
||||||
|
MockRestServiceServer server = MockRestServiceServer.bindTo(builder).build();
|
||||||
|
server.expect(ExpectedCount.once(), requestTo("http://localhost:8089/api/flow/models"))
|
||||||
|
.andExpect(method(HttpMethod.GET))
|
||||||
|
.andRespond(withSuccess(
|
||||||
|
"{\"models\":[{\"id\":\"m1\",\"name\":\"总包合同交底\",\"key\":\"总包合同交底\"}]}",
|
||||||
|
MediaType.APPLICATION_JSON));
|
||||||
|
FlowableClient client = new FlowableClient(builder.build(), p);
|
||||||
|
|
||||||
|
Map<String, Object> resp = client.listModels();
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<Map<String, Object>> models = (List<Map<String, Object>>) resp.get("models");
|
||||||
|
assertThat(models).hasSize(1);
|
||||||
|
assertThat(models.get(0)).containsEntry("id", "m1").containsEntry("name", "总包合同交底");
|
||||||
|
server.verify();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 取草稿_GET_models按id透传() {
|
||||||
|
FlowGatewayProperties p = props();
|
||||||
|
RestClient.Builder builder = RestClient.builder().baseUrl(p.getBaseUrl());
|
||||||
|
MockRestServiceServer server = MockRestServiceServer.bindTo(builder).build();
|
||||||
|
server.expect(ExpectedCount.once(), requestTo("http://localhost:8089/api/flow/models/m1"))
|
||||||
|
.andExpect(method(HttpMethod.GET))
|
||||||
|
.andRespond(withSuccess("{\"found\":true,\"id\":\"m1\",\"bpmnXml\":\"<definitions/>\"}",
|
||||||
|
MediaType.APPLICATION_JSON));
|
||||||
|
FlowableClient client = new FlowableClient(builder.build(), p);
|
||||||
|
|
||||||
|
Map<String, Object> resp = client.getModel("m1");
|
||||||
|
|
||||||
|
assertThat(resp).containsEntry("found", true).containsEntry("bpmnXml", "<definitions/>");
|
||||||
|
server.verify();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 建草稿_POST_models_body原样透传() {
|
||||||
|
FlowGatewayProperties p = props();
|
||||||
|
RestClient.Builder builder = RestClient.builder().baseUrl(p.getBaseUrl());
|
||||||
|
MockRestServiceServer server = MockRestServiceServer.bindTo(builder).build();
|
||||||
|
server.expect(ExpectedCount.once(), requestTo("http://localhost:8089/api/flow/models"))
|
||||||
|
.andExpect(method(HttpMethod.POST))
|
||||||
|
.andExpect(jsonPath("$.name").value("总包合同交底"))
|
||||||
|
.andExpect(jsonPath("$.key").value("总包合同交底"))
|
||||||
|
.andExpect(jsonPath("$.bpmnXml").value("<definitions/>"))
|
||||||
|
.andRespond(withSuccess("{\"modelId\":\"m9\"}", MediaType.APPLICATION_JSON));
|
||||||
|
FlowableClient client = new FlowableClient(builder.build(), p);
|
||||||
|
|
||||||
|
Map<String, Object> body = new java.util.LinkedHashMap<>();
|
||||||
|
body.put("name", "总包合同交底");
|
||||||
|
body.put("key", "总包合同交底");
|
||||||
|
body.put("bpmnXml", "<definitions/>");
|
||||||
|
Map<String, Object> resp = client.createModel(body);
|
||||||
|
|
||||||
|
assertThat(resp).containsEntry("modelId", "m9");
|
||||||
|
server.verify();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 更新草稿_PUT_models按id_body原样透传() {
|
||||||
|
FlowGatewayProperties p = props();
|
||||||
|
RestClient.Builder builder = RestClient.builder().baseUrl(p.getBaseUrl());
|
||||||
|
MockRestServiceServer server = MockRestServiceServer.bindTo(builder).build();
|
||||||
|
server.expect(ExpectedCount.once(), requestTo("http://localhost:8089/api/flow/models/m1"))
|
||||||
|
.andExpect(method(HttpMethod.PUT))
|
||||||
|
.andExpect(jsonPath("$.bpmnXml").value("<definitions id=\"a\"/>"))
|
||||||
|
.andRespond(withSuccess("{\"status\":0}", MediaType.APPLICATION_JSON));
|
||||||
|
FlowableClient client = new FlowableClient(builder.build(), p);
|
||||||
|
|
||||||
|
Map<String, Object> body = new java.util.LinkedHashMap<>();
|
||||||
|
body.put("bpmnXml", "<definitions id=\"a\"/>");
|
||||||
|
Map<String, Object> resp = client.updateModel("m1", body);
|
||||||
|
|
||||||
|
assertThat(resp).containsEntry("status", 0);
|
||||||
|
server.verify();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 从流程定义建草稿_POST_from_procdef_body原样透传() {
|
||||||
|
FlowGatewayProperties p = props();
|
||||||
|
RestClient.Builder builder = RestClient.builder().baseUrl(p.getBaseUrl());
|
||||||
|
MockRestServiceServer server = MockRestServiceServer.bindTo(builder).build();
|
||||||
|
server.expect(ExpectedCount.once(), requestTo("http://localhost:8089/api/flow/models/from-procdef"))
|
||||||
|
.andExpect(method(HttpMethod.POST))
|
||||||
|
.andExpect(jsonPath("$.procDefId").value("总包合同交底:3:abc123"))
|
||||||
|
.andRespond(withSuccess("{\"modelId\":\"m7\"}", MediaType.APPLICATION_JSON));
|
||||||
|
FlowableClient client = new FlowableClient(builder.build(), p);
|
||||||
|
|
||||||
|
Map<String, Object> resp = client.modelFromProcDef(Map.of("procDefId", "总包合同交底:3:abc123"));
|
||||||
|
|
||||||
|
assertThat(resp).containsEntry("modelId", "m7");
|
||||||
|
server.verify();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 草稿转发_下游4xx透传FlowRemote且不重试() {
|
||||||
|
FlowGatewayProperties p = props();
|
||||||
|
RestClient.Builder builder = RestClient.builder().baseUrl(p.getBaseUrl());
|
||||||
|
MockRestServiceServer server = MockRestServiceServer.bindTo(builder).build();
|
||||||
|
server.expect(ExpectedCount.once(), // 业务错不重试
|
||||||
|
requestTo("http://localhost:8089/api/flow/models"))
|
||||||
|
.andExpect(method(HttpMethod.POST))
|
||||||
|
.andRespond(withStatus(HttpStatus.UNPROCESSABLE_ENTITY).body("BPMN 解析失败"));
|
||||||
|
FlowableClient client = new FlowableClient(builder.build(), p);
|
||||||
|
|
||||||
|
assertThatThrownBy(() -> client.createModel(Map.of("bpmnXml", "<bad>")))
|
||||||
|
.isInstanceOf(FlowRemoteException.class)
|
||||||
|
.satisfies(e -> assertThat(((FlowRemoteException) e).getStatus().value()).isEqualTo(422));
|
||||||
|
server.verify();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 删草稿_DELETE_models按id透传() {
|
||||||
|
FlowGatewayProperties p = props();
|
||||||
|
RestClient.Builder builder = RestClient.builder().baseUrl(p.getBaseUrl());
|
||||||
|
MockRestServiceServer server = MockRestServiceServer.bindTo(builder).build();
|
||||||
|
server.expect(ExpectedCount.once(), requestTo("http://localhost:8089/api/flow/models/m1"))
|
||||||
|
.andExpect(method(HttpMethod.DELETE))
|
||||||
|
.andRespond(withSuccess("{\"status\":0}", MediaType.APPLICATION_JSON));
|
||||||
|
FlowableClient client = new FlowableClient(builder.build(), p);
|
||||||
|
|
||||||
|
Map<String, Object> resp = client.deleteModel("m1");
|
||||||
|
|
||||||
|
assertThat(resp).containsEntry("status", 0);
|
||||||
|
server.verify();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 删草稿_下游404透传FlowRemote且不重试() {
|
||||||
|
FlowGatewayProperties p = props();
|
||||||
|
RestClient.Builder builder = RestClient.builder().baseUrl(p.getBaseUrl());
|
||||||
|
MockRestServiceServer server = MockRestServiceServer.bindTo(builder).build();
|
||||||
|
server.expect(ExpectedCount.once(), // 业务错不重试
|
||||||
|
requestTo("http://localhost:8089/api/flow/models/nope"))
|
||||||
|
.andExpect(method(HttpMethod.DELETE))
|
||||||
|
.andRespond(withStatus(HttpStatus.NOT_FOUND).body("草稿不存在"));
|
||||||
|
FlowableClient client = new FlowableClient(builder.build(), p);
|
||||||
|
|
||||||
|
assertThatThrownBy(() -> client.deleteModel("nope"))
|
||||||
|
.isInstanceOf(FlowRemoteException.class)
|
||||||
|
.satisfies(e -> assertThat(((FlowRemoteException) e).getStatus().value()).isEqualTo(404));
|
||||||
|
server.verify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,22 +2,31 @@ package com.eip4.platform.flowgateway;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
import org.springframework.web.bind.support.WebDataBinderFactory;
|
import org.springframework.web.bind.support.WebDataBinderFactory;
|
||||||
@@ -26,6 +35,7 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
|||||||
import org.springframework.web.method.support.ModelAndViewContainer;
|
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||||
|
|
||||||
import com.eip4.platform.auth.security.AuthPrincipal;
|
import com.eip4.platform.auth.security.AuthPrincipal;
|
||||||
|
import com.eip4.platform.flowgateway.client.FlowRemoteException;
|
||||||
import com.eip4.platform.flowgateway.client.FlowServiceUnavailableException;
|
import com.eip4.platform.flowgateway.client.FlowServiceUnavailableException;
|
||||||
import com.eip4.platform.flowgateway.client.FlowableClient;
|
import com.eip4.platform.flowgateway.client.FlowableClient;
|
||||||
import com.eip4.platform.flowgateway.web.FlowGatewayExceptionHandler;
|
import com.eip4.platform.flowgateway.web.FlowGatewayExceptionHandler;
|
||||||
@@ -38,7 +48,9 @@ import com.eip4.platform.flowgateway.web.ProcessModelerController;
|
|||||||
class ProcessModelerControllerTest {
|
class ProcessModelerControllerTest {
|
||||||
|
|
||||||
private final FlowableClient flowableClient = mock(FlowableClient.class);
|
private final FlowableClient flowableClient = mock(FlowableClient.class);
|
||||||
private final ProcessModelerController controller = new ProcessModelerController(flowableClient);
|
private final JdbcTemplate jdbcTemplate = mock(JdbcTemplate.class);
|
||||||
|
private final ProcessModelerController controller =
|
||||||
|
new ProcessModelerController(flowableClient, jdbcTemplate);
|
||||||
|
|
||||||
/** 真实形态:中文 key + 冒号分隔的 procDefId。 */
|
/** 真实形态:中文 key + 冒号分隔的 procDefId。 */
|
||||||
private static final String CN_PROCDEF = "总包合同交底:3:abc123";
|
private static final String CN_PROCDEF = "总包合同交底:3:abc123";
|
||||||
@@ -191,4 +203,199 @@ class ProcessModelerControllerTest {
|
|||||||
.andExpect(status().isServiceUnavailable())
|
.andExpect(status().isServiceUnavailable())
|
||||||
.andExpect(jsonPath("$.error").value("FLOW_SERVICE_UNAVAILABLE"));
|
.andExpect(jsonPath("$.error").value("FLOW_SERVICE_UNAVAILABLE"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---- 草稿 CRUD 五端点转发(T2.2):每端点 admin 200 透传 + 非超管 403。
|
||||||
|
// 两次调用(admin+非超管同参)后 verify 下游恰调 1 次 → 证明门确实拦下了非超管调用(若漏门会是 2 次)。----
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 草稿列表_超管透传200_非超管403门拦下游() {
|
||||||
|
Map<String, Object> downstream = Map.of("models", List.of(Map.of("id", "m1", "name", "总包合同交底")));
|
||||||
|
when(flowableClient.listModels()).thenReturn(downstream);
|
||||||
|
|
||||||
|
ResponseEntity<Map<String, Object>> ok = controller.listModels(admin());
|
||||||
|
assertThat(ok.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
|
assertThat(ok.getBody()).isEqualTo(downstream);
|
||||||
|
|
||||||
|
ResponseEntity<Map<String, Object>> denied = controller.listModels(normalUser());
|
||||||
|
assertThat(denied.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
|
||||||
|
assertThat(denied.getBody()).containsEntry("status", 1).containsEntry("msg", "仅系统管理员可用");
|
||||||
|
verify(flowableClient).listModels(); // 恰 1 次(仅超管):非超管被门拦,未落下游
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 取草稿_超管透传200_非超管403门拦下游() {
|
||||||
|
Map<String, Object> downstream = Map.of("found", true, "id", "m1", "bpmnXml", "<definitions/>");
|
||||||
|
when(flowableClient.getModel("m1")).thenReturn(downstream);
|
||||||
|
|
||||||
|
ResponseEntity<Map<String, Object>> ok = controller.getModel(admin(), "m1");
|
||||||
|
assertThat(ok.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
|
assertThat(ok.getBody()).isEqualTo(downstream);
|
||||||
|
|
||||||
|
ResponseEntity<Map<String, Object>> denied = controller.getModel(normalUser(), "m1");
|
||||||
|
assertThat(denied.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
|
||||||
|
verify(flowableClient).getModel("m1"); // 恰 1 次(仅超管)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 建草稿_超管透传200_非超管403门拦下游() {
|
||||||
|
Map<String, Object> req = Map.of("name", "总包合同交底", "key", "总包合同交底", "bpmnXml", "<definitions/>");
|
||||||
|
Map<String, Object> downstream = Map.of("modelId", "m9");
|
||||||
|
when(flowableClient.createModel(req)).thenReturn(downstream);
|
||||||
|
|
||||||
|
ResponseEntity<Map<String, Object>> ok = controller.createModel(admin(), req);
|
||||||
|
assertThat(ok.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
|
assertThat(ok.getBody()).isEqualTo(downstream);
|
||||||
|
|
||||||
|
ResponseEntity<Map<String, Object>> denied = controller.createModel(normalUser(), req);
|
||||||
|
assertThat(denied.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
|
||||||
|
verify(flowableClient).createModel(req); // 恰 1 次(仅超管):漏门会是 2 次
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 更新草稿_超管透传200_非超管403门拦下游() {
|
||||||
|
Map<String, Object> req = Map.of("bpmnXml", "<definitions id=\"a\"/>");
|
||||||
|
Map<String, Object> downstream = Map.of("status", 0);
|
||||||
|
when(flowableClient.updateModel("m1", req)).thenReturn(downstream);
|
||||||
|
|
||||||
|
ResponseEntity<Map<String, Object>> ok = controller.updateModel(admin(), "m1", req);
|
||||||
|
assertThat(ok.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
|
assertThat(ok.getBody()).isEqualTo(downstream);
|
||||||
|
|
||||||
|
ResponseEntity<Map<String, Object>> denied = controller.updateModel(normalUser(), "m1", req);
|
||||||
|
assertThat(denied.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
|
||||||
|
verify(flowableClient).updateModel("m1", req); // 恰 1 次(仅超管)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 从流程定义建草稿_超管透传200_非超管403门拦下游() {
|
||||||
|
Map<String, Object> req = Map.of("procDefId", CN_PROCDEF);
|
||||||
|
Map<String, Object> downstream = Map.of("modelId", "m7");
|
||||||
|
when(flowableClient.modelFromProcDef(req)).thenReturn(downstream);
|
||||||
|
|
||||||
|
ResponseEntity<Map<String, Object>> ok = controller.modelFromProcDef(admin(), req);
|
||||||
|
assertThat(ok.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
|
assertThat(ok.getBody()).isEqualTo(downstream);
|
||||||
|
|
||||||
|
ResponseEntity<Map<String, Object>> denied = controller.modelFromProcDef(normalUser(), req);
|
||||||
|
assertThat(denied.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
|
||||||
|
verify(flowableClient).modelFromProcDef(req); // 恰 1 次(仅超管)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 无身份_建草稿403且不触发下游() {
|
||||||
|
ResponseEntity<Map<String, Object>> resp = controller.createModel(null, Map.of("name", "x"));
|
||||||
|
assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
|
||||||
|
assertThat(resp.getBody()).containsEntry("status", 1);
|
||||||
|
verify(flowableClient, never()).createModel(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 删草稿_超管透传200_非超管403门拦下游() {
|
||||||
|
Map<String, Object> downstream = Map.of("status", 0);
|
||||||
|
when(flowableClient.deleteModel("m1")).thenReturn(downstream);
|
||||||
|
|
||||||
|
ResponseEntity<Map<String, Object>> ok = controller.deleteModel(admin(), "m1");
|
||||||
|
assertThat(ok.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
|
assertThat(ok.getBody()).isEqualTo(downstream);
|
||||||
|
|
||||||
|
ResponseEntity<Map<String, Object>> denied = controller.deleteModel(normalUser(), "m1");
|
||||||
|
assertThat(denied.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
|
||||||
|
assertThat(denied.getBody()).containsEntry("status", 1).containsEntry("msg", "仅系统管理员可用");
|
||||||
|
verify(flowableClient).deleteModel("m1"); // 恰 1 次(仅超管):非超管被门拦,未落下游
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 胶水_删草稿_下游404经handler透传() throws Exception {
|
||||||
|
when(flowableClient.deleteModel("nope"))
|
||||||
|
.thenThrow(new FlowRemoteException(HttpStatus.NOT_FOUND, "flowable-service 删草稿返回 404"));
|
||||||
|
|
||||||
|
glueMvc().perform(delete("/api/workflow/models/{id}", "nope"))
|
||||||
|
.andExpect(status().isNotFound())
|
||||||
|
.andExpect(jsonPath("$.status").value(404))
|
||||||
|
.andExpect(jsonPath("$.error").value("FLOW_REMOTE_ERROR"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- 422 胶水透传:下游坏 XML 422 经既有 FlowGatewayExceptionHandler 出 FLOW_REMOTE_ERROR 信封 ----
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 胶水_建草稿_下游422经handler透传() throws Exception {
|
||||||
|
when(flowableClient.createModel(any()))
|
||||||
|
.thenThrow(new FlowRemoteException(HttpStatus.UNPROCESSABLE_ENTITY, "flowable-service 建草稿返回 422"));
|
||||||
|
|
||||||
|
glueMvc().perform(post("/api/workflow/models")
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.content("{\"name\":\"x\",\"key\":\"k\",\"bpmnXml\":\"<bad>\"}"))
|
||||||
|
.andExpect(status().isUnprocessableEntity())
|
||||||
|
.andExpect(jsonPath("$.status").value(422))
|
||||||
|
.andExpect(jsonPath("$.error").value("FLOW_REMOTE_ERROR"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- wftemplates 选择器数据源:超管读库 trim CHAR 补白 + 无实体名回退 id;非超管 403 零读库 ----
|
||||||
|
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
|
@Test
|
||||||
|
void wftemplates_超管_读库trim补白并回退id() {
|
||||||
|
// mock JdbcTemplate 反射调真实 RowMapper:第一行有实体名(取名+trim补白),第二行无名(回退 trim 后的 id)
|
||||||
|
when(jdbcTemplate.query(anyString(), any(RowMapper.class))).thenAnswer(inv -> {
|
||||||
|
RowMapper<Map<String, Object>> rm = inv.getArgument(1);
|
||||||
|
ResultSet named = mock(ResultSet.class);
|
||||||
|
when(named.getString("id")).thenReturn("wft-0001 "); // CHAR(36) 补白
|
||||||
|
when(named.getString("name")).thenReturn("通知管理");
|
||||||
|
ResultSet unnamed = mock(ResultSet.class);
|
||||||
|
when(unnamed.getString("id")).thenReturn("wft-0002 ");
|
||||||
|
when(unnamed.getString("name")).thenReturn(null); // 无 entityid/实体名 → 回退 id
|
||||||
|
return List.of(rm.mapRow(named, 0), rm.mapRow(unnamed, 1));
|
||||||
|
});
|
||||||
|
|
||||||
|
ResponseEntity<Map<String, Object>> resp = controller.wftemplates(admin());
|
||||||
|
|
||||||
|
assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
|
List<Map<String, Object>> templates = (List<Map<String, Object>>) resp.getBody().get("templates");
|
||||||
|
assertThat(templates).hasSize(2);
|
||||||
|
assertThat(templates.get(0)).containsEntry("id", "wft-0001").containsEntry("name", "通知管理");
|
||||||
|
assertThat(templates.get(1)).containsEntry("id", "wft-0002").containsEntry("name", "wft-0002");
|
||||||
|
// 正常路径不带 degraded 键(与降级分支区分)
|
||||||
|
assertThat(resp.getBody()).doesNotContainKey("degraded");
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
@Test
|
||||||
|
void wftemplates_非超管_403且不读库() {
|
||||||
|
ResponseEntity<Map<String, Object>> resp = controller.wftemplates(normalUser());
|
||||||
|
|
||||||
|
assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
|
||||||
|
assertThat(resp.getBody()).containsEntry("status", 1).containsEntry("msg", "仅系统管理员可用");
|
||||||
|
verify(jdbcTemplate, never()).query(anyString(), any(RowMapper.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
|
@Test
|
||||||
|
void wftemplates_读库异常_降级空列表带degraded标记不500() {
|
||||||
|
when(jdbcTemplate.query(anyString(), any(RowMapper.class)))
|
||||||
|
.thenThrow(new org.springframework.dao.DataAccessResourceFailureException("db down"));
|
||||||
|
|
||||||
|
ResponseEntity<Map<String, Object>> resp = controller.wftemplates(admin());
|
||||||
|
|
||||||
|
assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
|
List<Map<String, Object>> templates = (List<Map<String, Object>>) resp.getBody().get("templates");
|
||||||
|
assertThat(templates).isEmpty();
|
||||||
|
assertThat(resp.getBody()).containsEntry("degraded", true); // 降级分支带标记(正常路径无此键)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- PUT 路由胶水(M-3):MockMvc 真走 PUT /api/workflow/models/{id},验路径匹配 + @PathVariable 绑定 + 200 透传 ----
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 胶水_更新草稿_PUT路由绑定pathVar并200透传() throws Exception {
|
||||||
|
Map<String, Object> downstream = Map.of("status", 0);
|
||||||
|
when(flowableClient.updateModel(eq("m1"), any())).thenReturn(downstream);
|
||||||
|
|
||||||
|
glueMvc().perform(put("/api/workflow/models/{id}", "m1")
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.content("{\"bpmnXml\":\"<definitions/>\"}"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.status").value(0));
|
||||||
|
|
||||||
|
// 路由匹配 PUT 谓词 + {id} 绑定到 "m1" 交给控制器
|
||||||
|
verify(flowableClient).updateModel(eq("m1"), any());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user