feat(metadata): 服务流执行 REST 门面 FlowController + 本地自举 + 单测
P1-2 第二步:报表方案 D 类——79 个 selectservice 服务流的统一 REST 化入口。
FlowController(com.eip4.platform.metadata.web):
GET /api/flow/{id}?k=v query 参数 → 服务流入参 map(查询/报表类)
POST /api/flow/{id} body JSON body → 服务流入参 map(参数多/带结构)
统一封装 {status,msg,data};响应递归归一化(GeneralPOJO→平面行、
listSelect 结果 {listresult,pagecount}→amis {items,total})。OpenAPI 注解。
REST 入口读写时机:引擎不区分读写,P1 不在门面做引擎级读写闸,由调用方按
「流定义 XML 审阅」确认查询/报表类后放行;风险与 P2 三层防护待办写入注释与报告。
适配(P1 服务流脚本编译):SecureGroovyScriptEngineFactory 的 DEFAULTIMPORTSLIST
移除两条 Vaadin 客户端 UI 默认导入(client.groovy.TestService、
com.dsasp.client.viewframework.component.MainComponent)——它们逐脚本注入,
classpath 缺失会使每个服务流脚本编译失败;与服务端取数无关,原值登记于注释供 diff。
LegacyXmlWiring:补 FlowServiceImpl.setJdbcTemplate(等价原 XML <property> 注入)。
本地自举:platform-parity bootstrap-flow.sql(幂等)——在 eip4m0 上建 SYS_SERVICEFLOW
+ 自描述元数据 + 最小查询流 EIP4M0_USERGROUP_SEARCH,参照 parity bootstrap 思路,
无客户库副本时引擎可独立跑通。
单测 18 例:FlowModelParseTest(9,XML 解析/参数绑定/默认流生成/往返序列化)+
FlowControllerTest(8,mock 引擎,GET/POST 参数透传 + 响应归一化)+
FlowExecuteLocalIT(1,@SpringBootTest local profile,自举 SQL + 真实引擎执行 +
二次一致;eip4m0 不可达则 assumeTrue 跳过)。全绿。
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
package com.eip4.platform.app;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import com.dsasp.server.common.core.service.FlowExcuteService;
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
||||
import com.dsasp.server.common.util.UserSession;
|
||||
|
||||
/**
|
||||
* 服务流引擎 DB 落地集成测试(local profile,本地 eip4m0 自举库)。
|
||||
*
|
||||
* <p>用 platform-parity 的 bootstrap-sys.sql + bootstrap-flow.sql 在 eip4m0 上自举
|
||||
* 一个最小「查询类」服务流 EIP4M0_USERGROUP_SEARCH(对 SYS_USERGROUP 做 listSelect),
|
||||
* 经真实引擎 {@link FlowExcuteService#excute} 走通整条链(XML 解析 → groovy start 脚本
|
||||
* → service 节点 pojoCRUDService.listSelect → output),验证移植后的引擎在无客户库时
|
||||
* 也可独立运行。eip4m0 不可达时整类跳过(assumeTrue),保证 CI 无该库时不红。
|
||||
*/
|
||||
@SpringBootTest
|
||||
@ActiveProfiles("local")
|
||||
class FlowExecuteLocalIT {
|
||||
|
||||
@Autowired
|
||||
private FlowExcuteService flowExcuteService;
|
||||
|
||||
@Autowired
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
private static boolean dbReady;
|
||||
|
||||
@BeforeAll
|
||||
static void noop() {
|
||||
// 实际就绪判定在每个测试前置(需要注入的 jdbcTemplate),见 ensureBootstrap。
|
||||
}
|
||||
|
||||
private void ensureBootstrap() {
|
||||
try {
|
||||
jdbcTemplate.queryForObject("select 1", Integer.class);
|
||||
} catch (Exception e) {
|
||||
assumeTrue(false, "本地 eip4m0 不可达,跳过服务流引擎 DB 集成测试");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
runSql("bootstrap/bootstrap-sys.sql");
|
||||
runSql("bootstrap/bootstrap-flow.sql");
|
||||
dbReady = true;
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("自举 SQL 执行失败:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void runSql(String classpath) throws IOException {
|
||||
String sql = StreamUtils.copyToString(
|
||||
new ClassPathResource(classpath).getInputStream(), StandardCharsets.UTF_8);
|
||||
// bootstrap 内含 $XML$...$XML$ dollar-quoted 块,整体作为单条 statement 提交即可(PG 支持多语句)。
|
||||
jdbcTemplate.execute(sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("本地查询类服务流经引擎执行:返回种子用户组行,且二次执行一致")
|
||||
@SuppressWarnings("unchecked")
|
||||
void executeLocalSearchFlow() {
|
||||
ensureBootstrap();
|
||||
assumeTrue(dbReady);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
Properties ctx = UserSession.getAdmin();
|
||||
|
||||
Object out = flowExcuteService.excute(map, ctx, "EIP4M0_USERGROUP_SEARCH");
|
||||
assertNotNull(out, "引擎应返回 output map");
|
||||
|
||||
Map<String, Object> output = (Map<String, Object>) out;
|
||||
Map<String, Object> result = (Map<String, Object>) output.get("result");
|
||||
assertNotNull(result, "应有 result 输出(listSelect 结果)");
|
||||
|
||||
List<GeneralPOJO> rows = (List<GeneralPOJO>) result.get(POJOCRUDService.LIST_RESULT);
|
||||
assertNotNull(rows);
|
||||
assertTrue(rows.size() >= 1, "bootstrap 种子 SYS_USERGROUP 至少 1 行");
|
||||
|
||||
boolean found = rows.stream().anyMatch(p -> "系统管理员组".equals(p.get_Value("NAME")));
|
||||
assertTrue(found, "应能查到种子用户组「系统管理员组」");
|
||||
|
||||
// 二次执行结果一致(行数稳定)
|
||||
Map<String, Object> map2 = new HashMap<>();
|
||||
Object out2 = flowExcuteService.excute(map2, ctx, "EIP4M0_USERGROUP_SEARCH");
|
||||
Map<String, Object> result2 = (Map<String, Object>) ((Map<String, Object>) out2).get("result");
|
||||
List<GeneralPOJO> rows2 = (List<GeneralPOJO>) result2.get(POJOCRUDService.LIST_RESULT);
|
||||
assertEquals(rows.size(), rows2.size(), "同流二次执行行数应一致");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user