REQ-3540: misc
This commit is contained in:
parent
ec1790137c
commit
a13a4bb45a
@ -8,6 +8,26 @@ public interface IndexNodeParentScope {
|
||||
|
||||
IndexNodeScope nodeScope();
|
||||
|
||||
default boolean isChildrenNameDuplicatable() {
|
||||
switch (nodeScope().context()) {
|
||||
case FILE_TEMPLATE:
|
||||
case TEMPLATE_DATABASE:
|
||||
return false;
|
||||
default:
|
||||
return nodeScope().scope().getChildNameDuplicatable();
|
||||
}
|
||||
}
|
||||
|
||||
default boolean isLimitChildrenCount() {
|
||||
switch (nodeScope().context()) {
|
||||
case FILE_TEMPLATE:
|
||||
case TEMPLATE_DATABASE:
|
||||
return true;
|
||||
default:
|
||||
return nodeScope().scope().getLimitChildrenCount();
|
||||
}
|
||||
}
|
||||
|
||||
default String parentCode() {
|
||||
return IndexNodeScope.TREE_ROOT_NODE_CODE;
|
||||
}
|
||||
|
||||
@ -19,26 +19,6 @@ public interface IndexNodeScope {
|
||||
return TREE_ROOT_NODE_CODE;
|
||||
}
|
||||
|
||||
default boolean isChildrenNameDuplicatable() {
|
||||
switch (context()) {
|
||||
case FILE_TEMPLATE:
|
||||
case TEMPLATE_DATABASE:
|
||||
return false;
|
||||
default:
|
||||
return scope().getChildNameDuplicatable();
|
||||
}
|
||||
}
|
||||
|
||||
default boolean isLimitChildrenCount() {
|
||||
switch (context()) {
|
||||
case FILE_TEMPLATE:
|
||||
case TEMPLATE_DATABASE:
|
||||
return true;
|
||||
default:
|
||||
return scope().getLimitChildrenCount();
|
||||
}
|
||||
}
|
||||
|
||||
String TREE_ROOT_NODE_CODE = "";
|
||||
|
||||
Long TREE_ROOT_NODE_ID = 0L;
|
||||
|
||||
@ -125,7 +125,7 @@ public class IndexManager {
|
||||
}
|
||||
|
||||
private void ensureChildNameNotUsed(NodeCreate create, IndexNodeType nodeType, boolean withLock) {
|
||||
if (create.nodeScope().isChildrenNameDuplicatable())
|
||||
if (indexSupport.isChildrenNameDuplicatable(create))
|
||||
return;
|
||||
if (withLock)
|
||||
indexSupport.lockParentAndReleaseOnCommit(create);
|
||||
@ -138,7 +138,7 @@ public class IndexManager {
|
||||
if (indexNode.getName().equals(newName))
|
||||
return;
|
||||
docLogDao.log("indexNode:rename", code, "newName", newName);
|
||||
if (!indexNode.isChildrenNameDuplicatable()) {
|
||||
if (!indexSupport.isChildrenNameDuplicatable(indexNode)) {
|
||||
indexSupport.lockParentAndReleaseOnCommit(indexNode);
|
||||
indexSupport.ensureChildNameNotUsed(indexNode, indexNode.getNodeType(), newName);
|
||||
}
|
||||
@ -228,7 +228,7 @@ public class IndexManager {
|
||||
indexNodeDao.connectNodes(TreeUtils.collectValues(connectRoot));
|
||||
IndexNode rootNode = connectRoot.getChildren().get(0).tryGetValue();
|
||||
// resolve the name issue
|
||||
if (!rootNode.isChildrenNameDuplicatable())
|
||||
if (!indexSupport.isChildrenNameDuplicatable(rootNode))
|
||||
indexSupport.incrNameIfDuplicate(rootNode);
|
||||
// get the coped root with full props
|
||||
return indexNodeDao.findOrNull(rootNode.getCode());
|
||||
|
||||
@ -96,11 +96,23 @@ public class IndexSupport {
|
||||
BizAssertions.assertTrue(
|
||||
indexNodeDao.validChildrenCount(parent.getCode()) < docProps.getIndexNodeMaxChildrenSize(),
|
||||
"创建失败, 子节点数量不能超过 {}", docProps.getIndexNodeMaxChildrenSize());
|
||||
if (!parent.isRoot() && parent.isLimitChildrenCount())
|
||||
if (!parent.isRoot() && isLimitChildrenCount(child))
|
||||
BizAssertions.assertTrue(parent.path().depth() < docProps.getIndexNodeMaxDepth(), //
|
||||
"节点深度超过限制{}, 无法再创建新节点", docProps.getIndexNodeMaxDepth());
|
||||
}
|
||||
|
||||
boolean isChildrenNameDuplicatable(IndexNodeParentScope parentScope) {
|
||||
if (StringUtils.isNotBlank(parentScope.parentCode()))
|
||||
return indexNodeDao.getOrThrow(parentScope.parentCode()).isChildrenNameDuplicatable();
|
||||
return parentScope.isChildrenNameDuplicatable();
|
||||
}
|
||||
|
||||
boolean isLimitChildrenCount(IndexNodeParentScope parentScope) {
|
||||
if (StringUtils.isNotBlank(parentScope.parentCode()))
|
||||
return indexNodeDao.getOrThrow(parentScope.parentCode()).isLimitChildrenCount();
|
||||
return parentScope.isLimitChildrenCount();
|
||||
}
|
||||
|
||||
List<IndexNode> collectValidSubtreeAsValueRoot(IndexNode srcNode) {
|
||||
List<IndexNode> subtreeNodes = indexNodeDao.collectValidSubtreeNodes(srcNode);
|
||||
subtreeNodes.stream() //
|
||||
|
||||
Loading…
Reference in New Issue
Block a user