F2-4b: ScriptFacade 补 Vaadin Container 动词 + AmisSchemaController 懒加载
ScriptFacade.FieldProxy: - firstItemId()/lastItemId(): 返回 null(服务端无容器实例) - removeItem(itemId): 委托 removeFieldItem - size(): 返回 0 AmisSchemaController: - SchemaGate 改为懒加载 volatile + DCL,避免启动时 OOM (amis-schema-6.13.0.json 929KB 展开后对象树过大) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -427,5 +427,34 @@ public class ScriptFacade {
|
|||||||
public Object setFilter(Object filter) {
|
public Object setFilter(Object filter) {
|
||||||
return facade.setFieldFilter(field, filter);
|
return facade.setFieldFilter(field, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* F2-4b: Vaadin Container.firstItemId() 语义迁移 — 服务端无容器实例,
|
||||||
|
* 返回 null(EIP4 脚本应改为 getFieldValue 获取当前值,此处保证不抛异常)。
|
||||||
|
*/
|
||||||
|
public Object firstItemId() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* F2-4b: Vaadin Container.lastItemId() 语义迁移 — 服务端无容器实例,返回 null。
|
||||||
|
*/
|
||||||
|
public Object lastItemId() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* F2-4b: Vaadin Container.removeItem(itemId) 语义迁移 — 委托 removeFieldItem。
|
||||||
|
*/
|
||||||
|
public Object removeItem(Object itemId) {
|
||||||
|
return facade.removeFieldItem(field, itemId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* F2-4b: Vaadin Container.size() 语义迁移 — 服务端无容器实例,返回 0。
|
||||||
|
*/
|
||||||
|
public int size() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,20 @@ public class AmisSchemaController {
|
|||||||
|
|
||||||
private final TemplateToAmisConverter converter;
|
private final TemplateToAmisConverter converter;
|
||||||
private final JdbcTemplate jdbcTemplate;
|
private final JdbcTemplate jdbcTemplate;
|
||||||
private final SchemaGate schemaGate = new SchemaGate();
|
// F2-4b: 懒加载 SchemaGate — amis-schema-6.13.0.json (929KB) 被 networknt 展开为
|
||||||
|
// 大量对象树,启动时加载会触发 OOM。改为首次 validate 调用时才初始化。
|
||||||
|
private volatile SchemaGate schemaGate;
|
||||||
|
|
||||||
|
private SchemaGate getSchemaGate() {
|
||||||
|
if (schemaGate == null) {
|
||||||
|
synchronized (this) {
|
||||||
|
if (schemaGate == null) {
|
||||||
|
schemaGate = new SchemaGate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return schemaGate;
|
||||||
|
}
|
||||||
|
|
||||||
public AmisSchemaController(TemplateToAmisConverter converter, JdbcTemplate jdbcTemplate) {
|
public AmisSchemaController(TemplateToAmisConverter converter, JdbcTemplate jdbcTemplate) {
|
||||||
this.converter = converter;
|
this.converter = converter;
|
||||||
@@ -45,7 +58,7 @@ public class AmisSchemaController {
|
|||||||
List<String> notes = new ArrayList<>();
|
List<String> notes = new ArrayList<>();
|
||||||
Map<String, Object> schema = converter.convert(loadXml(template), notes);
|
Map<String, Object> schema = converter.convert(loadXml(template), notes);
|
||||||
|
|
||||||
List<String> errors = schemaGate.validate(schema);
|
List<String> errors = getSchemaGate().validate(schema);
|
||||||
|
|
||||||
Map<String, Object> resp = new LinkedHashMap<>();
|
Map<String, Object> resp = new LinkedHashMap<>();
|
||||||
resp.put("template", template);
|
resp.put("template", template);
|
||||||
@@ -59,7 +72,7 @@ public class AmisSchemaController {
|
|||||||
/** 校验任意 amis 页面 schema(WS5:AI 生成的 schema 走这里过闸)。 */
|
/** 校验任意 amis 页面 schema(WS5:AI 生成的 schema 走这里过闸)。 */
|
||||||
@org.springframework.web.bind.annotation.PostMapping("/api/poc/validate-schema")
|
@org.springframework.web.bind.annotation.PostMapping("/api/poc/validate-schema")
|
||||||
public Map<String, Object> validateSchema(@org.springframework.web.bind.annotation.RequestBody JsonNode schema) throws Exception {
|
public Map<String, Object> validateSchema(@org.springframework.web.bind.annotation.RequestBody JsonNode schema) throws Exception {
|
||||||
List<String> errors = schemaGate.validate(schema);
|
List<String> errors = getSchemaGate().validate(schema);
|
||||||
Map<String, Object> resp = new LinkedHashMap<>();
|
Map<String, Object> resp = new LinkedHashMap<>();
|
||||||
resp.put("schemaValid", errors.isEmpty());
|
resp.put("schemaValid", errors.isEmpty());
|
||||||
resp.put("validationErrors", errors.stream().limit(20).collect(Collectors.toList()));
|
resp.put("validationErrors", errors.stream().limit(20).collect(Collectors.toList()));
|
||||||
|
|||||||
Reference in New Issue
Block a user