Skip to content

Commit

Permalink
实现业务规则的ruleInputs属性的更新操作
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Aug 29, 2023
1 parent d38d1b7 commit b046d55
Show file tree
Hide file tree
Showing 19 changed files with 198 additions and 95 deletions.
49 changes: 49 additions & 0 deletions nop-orm/src/main/java/io/nop/orm/component/XmlOrmComponent.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package io.nop.orm.component;

import io.nop.commons.util.StringHelper;
import io.nop.core.lang.json.JsonTool;
import io.nop.core.lang.xml.XNode;
import io.nop.core.lang.xml.parse.XNodeParser;
import io.nop.orm.IOrmEntity;
import io.nop.xlang.xdef.IXDefNode;
import io.nop.xlang.xdef.IXDefinition;
import io.nop.xlang.xdsl.DslModelHelper;
import io.nop.xlang.xdsl.json.DslModelToXNodeTransformer;
import io.nop.xlang.xmeta.IObjMeta;
import io.nop.xlang.xmeta.IObjPropMeta;
import io.nop.xlang.xmeta.SchemaLoader;

import static io.nop.core.CoreConstants.DUMMY_TAG_NAME;

Expand All @@ -29,6 +38,7 @@ public void setNormalizedXml(String xml) {
if (StringHelper.isEmpty(xml)) {
this.setXmlText(null);
} else {
markDirty();
this.node = XNodeParser.instance().parseFromText(null, xml);
}
}
Expand All @@ -54,10 +64,17 @@ public void setNode(XNode node) {
if (node == null) {
setXmlText(null);
} else {
markDirty();
this.node = node;
}
}

private void markDirty() {
IOrmEntity owner = orm_owner();
if (owner != null)
owner.orm_extDirty(true);
}

public Object getJsonObject() {
XNode node = getNode();
if (node == null)
Expand All @@ -69,6 +86,8 @@ public void setJsonObject(Object value) {
this.node = XNode.fromValue(value);
if (this.node == null) {
setXmlText(null);
} else {
markDirty();
}
}

Expand Down Expand Up @@ -102,6 +121,7 @@ public String getChildBodyXml(String childName) {

public void setChildBodyXml(String rootTagName,
String childName, String xml) {
markDirty();
XNode node = makeNode(rootTagName);
XNode child = node.makeChild(childName);
if (StringHelper.isBlank(xml)) {
Expand All @@ -119,6 +139,35 @@ public void setChildBodyXml(String rootTagName,
}
}

public Object getChildValue(String xdefPath, String childName) {
XNode node = getNode();
if (node == null)
return null;

XNode inputsNode = node.childByTag(childName);
if (inputsNode == null)
return null;

IXDefinition objDef = SchemaLoader.loadXDefinition(xdefPath);
IXDefNode defNode = objDef.getChild(childName);

return JsonTool.serializeToJson(DslModelHelper.dslNodeToJson(defNode, inputsNode));
}

public void setChildValue(String xdefPath, String childName, Object value) {
markDirty();

IObjMeta objMeta = SchemaLoader.loadXMeta(xdefPath);
IObjPropMeta propMeta = objMeta.getProp(childName);
XNode list = new DslModelToXNodeTransformer(objMeta).transformValue(propMeta, value);
if (list != null) {
XNode inputsNode = makeNode(objMeta.getXmlName()).childByTag(childName);
inputsNode.replaceBy(list);
} else {
makeNode(objMeta.getXmlName()).removeChildByTag(childName);
}
}

@Override
public void flushToEntity() {
if (node != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.nop.orm.component;

import io.nop.core.initialize.CoreInitialization;
import io.nop.core.lang.json.JsonTool;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class TestXmlOrmComponent {
@BeforeAll
public static void init() {
CoreInitialization.initialize();
}

@AfterAll
public static void destroy() {
CoreInitialization.destroy();
;
}

@Test
public void testProp() {
XmlOrmComponent comp = new XmlOrmComponent();
comp.setNormalizedXml("<rule><inputs><input name='a' mandatory='true' /></inputs></rule>");

List<Map<String, Object>> value = (List<Map<String, Object>>) comp.getChildValue("/nop/schema/rule.xdef", "inputs");
System.out.println(JsonTool.serialize(value, true));

value.get(0).put("name", "b");
value.get(0).put("displayName", "xx");
comp.setChildValue("/nop/schema/rule.xdef", "inputs", value);

String xml = comp.getNormalizedXml();
assertEquals("<rule>\n" +
" <inputs>\n" +
" <input name=\"b\" mandatory=\"true\" displayName=\"xx\"/>\n" +
" </inputs>\n" +
"</rule>", xml);
}
}
Binary file modified nop-rule/model/nop-rule.orm.xlsx
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
package io.nop.rule.dao.entity;

import io.nop.api.core.annotations.biz.BizObjName;
import io.nop.core.lang.xml.XNode;
import io.nop.orm.component.XmlOrmComponent;
import io.nop.rule.dao.NopRuleDaoConstants;
import io.nop.rule.dao.entity._gen._NopRuleDefinition;
import io.nop.xlang.xdsl.DslModelHelper;
import io.nop.xlang.xmeta.IObjMeta;
import io.nop.xlang.xmeta.IObjPropMeta;
import io.nop.xlang.xmeta.SchemaLoader;

import java.util.HashSet;
import java.util.List;
Expand All @@ -19,6 +12,7 @@
import static io.nop.rule.dao.NopRuleDaoConstants.INPUTS_NAME;
import static io.nop.rule.dao.NopRuleDaoConstants.OUTPUTS_NAME;
import static io.nop.rule.dao.NopRuleDaoConstants.RULE_TAG_NAME;
import static io.nop.rule.dao.NopRuleDaoConstants.XDEF_PATH_RULE;


@BizObjName("NopRuleDefinition")
Expand All @@ -34,60 +28,21 @@ public Set<String> getRoleIds() {
return roleIds;
}

private XNode makeModelNode() {
XmlOrmComponent component = getModelTextXmlComponent();
return component.makeNode(NopRuleDaoConstants.RULE_TAG_NAME);
}

public List<Map<String, Object>> getRuleInputs() {
XNode node = getModelTextXmlComponent().getNode();
if (node == null)
return null;

XNode inputsNode = node.childByTag(INPUTS_NAME);
if (inputsNode == null)
return null;

IObjMeta objMeta = SchemaLoader.loadXMeta(NopRuleDaoConstants.XDEF_PATH_RULE);
IObjPropMeta propMeta = objMeta.getProp(INPUTS_NAME);

return (List<Map<String, Object>>) DslModelHelper.dslJsonToNode(propMeta.getSchema(), inputsNode);
return (List<Map<String, Object>>) getModelTextXmlComponent().getChildValue(XDEF_PATH_RULE, INPUTS_NAME);
}

public void setRuleInputs(List<Map<String, Object>> ruleInputs) {
IObjMeta objMeta = SchemaLoader.loadXMeta(NopRuleDaoConstants.XDEF_PATH_RULE);
IObjPropMeta propMeta = objMeta.getProp(INPUTS_NAME);
List<XNode> list = DslModelHelper.dslJsonListToNodeList(propMeta.getSchema(), ruleInputs);
if (list != null) {
XNode inputsNode = makeModelNode().makeChild(INPUTS_NAME);
inputsNode.appendChildren(list);
}
getModelTextXmlComponent().setChildValue(XDEF_PATH_RULE, INPUTS_NAME, ruleInputs);
}

public List<Map<String, Object>> getRuleOutputs() {
XNode node = getModelTextXmlComponent().getNode();
if (node == null)
return null;

XNode outputsNode = node.childByTag(OUTPUTS_NAME);
if (outputsNode == null)
return null;

IObjMeta objMeta = SchemaLoader.loadXMeta(NopRuleDaoConstants.XDEF_PATH_RULE);
IObjPropMeta propMeta = objMeta.getProp(OUTPUTS_NAME);

return (List<Map<String, Object>>) DslModelHelper.dslJsonToNode(propMeta.getSchema(), outputsNode);
return (List<Map<String, Object>>) getModelTextXmlComponent().getChildValue(XDEF_PATH_RULE, OUTPUTS_NAME);

}

public void setRuleOutputs(List<Map<String, Object>> ruleOutputs) {
IObjMeta objMeta = SchemaLoader.loadXMeta(NopRuleDaoConstants.XDEF_PATH_RULE);
IObjPropMeta propMeta = objMeta.getProp(OUTPUTS_NAME);
List<XNode> list = DslModelHelper.dslJsonListToNodeList(propMeta.getSchema(), ruleOutputs);
if (list != null) {
XNode outputsNode = makeModelNode().makeChild(OUTPUTS_NAME);
outputsNode.appendChildren(list);
}
getModelTextXmlComponent().setChildValue(XDEF_PATH_RULE, OUTPUTS_NAME, ruleOutputs);
}

public String getBeforeExecute() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
stdDataType="string" stdSqlType="VARCHAR" i18n-en:displayName="Description"/>
<column code="MODEL_TEXT" displayName="模型文本" domain="xml-16m" name="modelText" precision="16777216"
propId="8" stdDataType="string" stdDomain="xml" stdSqlType="VARCHAR"
i18n-en:displayName="Model Text"/>
i18n-en:displayName="Model Text" ui:show="X"/>
<column code="STATUS" displayName="状态" mandatory="true" name="status" propId="9" stdDataType="int"
stdSqlType="INTEGER" i18n-en:displayName="Status" ext:dict="core/active-status"/>
<column code="VERSION" displayName="数据版本" domain="version" mandatory="true" name="version" propId="10"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ prop:
parentId: 父ID
predicate: 判断条件
predicateComponent: null
predicateLabel: null
predicateLabel: 判断条件
remark: 备注
ruleDefinition: 规则定义
ruleDefinition.displayName: 规则定义
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>
<meta x:schema="/nop/schema/xmeta.xdef" xmlns:x="/nop/schema/xdsl.xdef" x:extends="_NopRuleDefinition.xmeta" xmlns:ui="ui">
<meta x:schema="/nop/schema/xmeta.xdef" xmlns:x="/nop/schema/xdsl.xdef" x:extends="_NopRuleDefinition.xmeta"
xmlns:ui="ui">

<props>
<prop name="ruleInputs" displayName="输入变量" ui:show="L">
<schema bizObjName="NopRuleInput"/>
<schema>
<item bizObjName="NopRuleInput"/>
</schema>
</prop>

<prop name="ruleOutputs" displayName="输出变量" ui:show="L">
<schema bizObjName="NopRuleOutput"/>
<schema>
<item bizObjName="NopRuleOutput"/>
</schema>
</prop>

<prop name="beforeExecute" displayName="初始化代码" ui:show="L">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<schema type="java.lang.String" precision="1000"/>
</prop>
<prop name="modelText" displayName="模型文本" i18n-en:displayName="Model Text" queryable="true" sortable="true"
insertable="true" updatable="true">
insertable="true" updatable="true" internal="true" ui:show="X">
<schema stdDomain="xml" domain="xml-16m" type="java.lang.String" precision="16777216"/>
</prop>
<prop name="status" displayName="状态" i18n-en:displayName="Status" mandatory="true" queryable="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,38 @@
<meta x:schema="/nop/schema/xmeta.xdef" xmlns:x="/nop/schema/xdsl.xdef">

<props>
<prop name="name" displayName="变量名" mandatory="true" published="true" insertable="true" updatable="true">
<prop name="name" displayName="变量名" mandatory="true">
<schema type="String" maxLength="100"/>
</prop>

<prop name="displayName" displayName="显示名" mandatory="true" published="true" insertable="true"
updatable="true">
<prop name="displayName" displayName="显示名" mandatory="true">
<schema type="String" maxLength="100"/>
</prop>

<prop name="type" displayName="类型" mandatory="true" published="true" insertable="true" updatable="true">
<prop name="type" displayName="类型" mandatory="true">
<schema type="String" stdDomain="generic-type" maxLength="100" dict="core/java-type"/>
</prop>

<prop name="mandatory" displayName="是否非空" published="true" insertable="true" updatable="true">
<prop name="mandatory" displayName="是否非空">
<schema stdDomain="boolean"/>
</prop>

<prop name="computed" displayName="是否计算值" published="true" insertable="true" updatable="true">
<prop name="computed" displayName="是否计算值">
<schema stdDomain="boolean"/>
</prop>

<prop name="defaultExpr" displayName="缺省值" published="true" insertable="true" updatable="true">
<prop name="defaultExpr" displayName="缺省值">
<schema stdDomain="xpl"/>
</prop>

<prop name="description" displayName="描述" published="true" insertable="true" updatable="true">
<prop name="description" displayName="描述">
<schema type="String"/>
</prop>

<prop name="props" displayName="对象属性" published="true" insertable="true" updatable="true">
<schema bizObjName="NopRuleInput"/>
<prop name="props" displayName="对象属性">
<schema>
<item bizObjName="NopRuleInput"/>
</schema>
</prop>
</props>
</meta>
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<meta x:schema="/nop/schema/xmeta.xdef" xmlns:x="/nop/schema/xdsl.xdef" x:extends="_NopRuleNode.xmeta">
<meta x:schema="/nop/schema/xmeta.xdef" xmlns:x="/nop/schema/xdsl.xdef"
x:extends="_NopRuleNode.xmeta" xmlns:ui="ui">

<props>
<prop name="predicateLabel" published="true">
<prop name="predicateLabel" displayName="判断条件" published="true" ui:show="L">
<schema type="String"/>
</prop>
</props>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,30 @@
<meta x:schema="/nop/schema/xmeta.xdef" xmlns:x="/nop/schema/xdsl.xdef">

<props>
<prop name="name" displayName="变量名" mandatory="true" >
<prop name="name" displayName="变量名" mandatory="true">
<schema type="String" maxLength="100"/>
</prop>

<prop name="displayName" displayName="显示名" mandatory="true">
<schema type="String" maxLength="100"/>
</prop>

<prop name="type" displayName="类型" mandatory="true" >
<prop name="type" displayName="类型" mandatory="true">
<schema type="String" stdDomain="generic-type" maxLength="100" dict="core/java-type"/>
</prop>

<prop name="aggregate" displayName="聚合方式" mandatory="true">
<schema dict="io.nop.rule.core.model.RuleAggregateMethod" />
<schema dict="io.nop.rule.core.model.RuleAggregateMethod"/>
</prop>

<prop name="description" displayName="描述" >
<prop name="description" displayName="描述">
<schema type="String"/>
</prop>

<prop name="props" displayName="对象属性" >
<schema bizObjName="NopRuleOutput"/>
<prop name="props" displayName="对象属性">
<schema>
<item bizObjName="NopRuleOutput"/>
</schema>
</prop>
</props>
</meta>
Loading

0 comments on commit b046d55

Please sign in to comment.