REQ-3540: 添加校验

This commit is contained in:
yanglin 2025-03-19 20:34:55 +08:00
parent 1c963a022b
commit e553fe7c69
4 changed files with 15 additions and 10 deletions

View File

@ -2,7 +2,6 @@
package cn.axzo.nanopart.doc.api.domain;
import cn.axzo.nanopart.doc.api.enums.DatabaseScope;
import cn.axzo.nanopart.doc.api.enums.DatabaseType;
import cn.axzo.nanopart.doc.api.enums.IndexNodeContext;
/**
@ -17,7 +16,7 @@ public interface IndexNodeScope {
}
default String scopeCode() {
return "";
return TREE_ROOT_NODE_CODE;
}
default boolean isChildrenNameDuplicatable() {
@ -40,6 +39,10 @@ public interface IndexNodeScope {
}
}
String TREE_ROOT_NODE_CODE = "";
Long TREE_ROOT_NODE_ID = 0L;
IndexNodeScope FILE_TEMPLATE = () -> IndexNodeContext.FILE_TEMPLATE;
IndexNodeScope TEMPLATE_DATABASE = () -> IndexNodeContext.TEMPLATE_DATABASE;

View File

@ -34,9 +34,6 @@ public class IndexNode extends BaseEntity<IndexNode> implements NodeValue, Index
// !! essentially, these are all tree attributes of the data model
public static final String TREE_ROOT_NOE_CODE = "";
public static final Long TREE_ROOT_NODE_ID = 0L;
/**
* 爷节点id
*/
@ -158,6 +155,10 @@ public class IndexNode extends BaseEntity<IndexNode> implements NodeValue, Index
return id.equals(node.id);
}
public boolean isRoot() {
return TREE_ROOT_NODE_CODE.equals(parentCode);
}
@JsonIgnore
@JSONField(serialize = false, deserialize = false)
public String getFullFileName() {

View File

@ -57,8 +57,8 @@ class IndexSupport {
IndexNode child = new IndexNode();
IndexNode.setScope(child, create.nodeScope());
child.setCode(UUIDUtil.uuidString());
child.setParentId(parent == null ? IndexNode.TREE_ROOT_NODE_ID : parent.getId());
child.setParentCode(parent == null ? IndexNode.TREE_ROOT_NOE_CODE : parent.getCode());
child.setParentId(parent == null ? IndexNodeScope.TREE_ROOT_NODE_ID : parent.getId());
child.setParentCode(parent == null ? IndexNodeScope.TREE_ROOT_NODE_CODE : parent.getCode());
child.setRootCode(parent == null ? child.getCode() : parent.getRootCode());
child.setName(create.name());
child.setBizCode(create.bizCode());
@ -92,7 +92,7 @@ class IndexSupport {
BizAssertions.assertTrue(
indexNodeDao.validChildrenCount(parent.getCode()) < docProps.getIndexNodeMaxChildrenSize(),
"创建失败, 子节点数量不能超过 {}", docProps.getIndexNodeMaxChildrenSize());
if (parent.isLimitChildrenCount())
if (!parent.isRoot() && parent.isLimitChildrenCount())
BizAssertions.assertTrue(parent.path().depth() < docProps.getIndexNodeMaxDepth(), //
"节点深度超过限制{}, 无法再创建新节点", docProps.getIndexNodeMaxDepth());
}

View File

@ -7,6 +7,7 @@ import cn.axzo.maokai.api.vo.response.tree.Node;
import cn.axzo.maokai.api.vo.response.tree.ValueNode;
import cn.axzo.maokai.api.vo.response.tree.ValueNodeRecursiveVisitor;
import cn.axzo.maokai.api.vo.response.tree.WalkingDecision;
import cn.axzo.nanopart.doc.api.domain.IndexNodeScope;
import cn.axzo.nanopart.doc.entity.IndexNode;
import cn.axzo.nanopart.doc.entity.domain.Path;
import lombok.RequiredArgsConstructor;
@ -28,10 +29,10 @@ public class ConnectNodeVisitor extends ValueNodeRecursiveVisitor<IndexNode> {
copiedRoot = copy;
copy.setRootCode(destParentNode == null ? copiedRoot.getCode() : destParentNode.getRootCode());
copy.setParentId(node.getParent().isTreeRoot()
? destParentNode == null ? IndexNode.TREE_ROOT_NODE_ID : destParentNode.getId()
? destParentNode == null ? IndexNodeScope.TREE_ROOT_NODE_ID : destParentNode.getId()
: node.getParent().<IndexNode> tryGetValue().getId());
copy.setParentCode(node.getParent().isTreeRoot() //
? destParentNode == null ? IndexNode.TREE_ROOT_NOE_CODE : destParentNode.getCode()
? destParentNode == null ? IndexNodeScope.TREE_ROOT_NODE_CODE : destParentNode.getCode()
: node.getParent().<IndexNode> tryGetValue().getCode());
copy.setPath(buildPathFor(node).toString());
return WalkingDecision.CONTINUE;