REQ-3540: 添加校验
This commit is contained in:
parent
3d96f2c04c
commit
b423209b17
@ -152,6 +152,16 @@ public class IndexNode extends BaseEntity<IndexNode> implements NodeValue, Index
|
||||
indexNode.setScopeCode(scope.scopeCode());
|
||||
}
|
||||
|
||||
public boolean isParentOf(IndexNode node) {
|
||||
if (isSameNode(node))
|
||||
return false;
|
||||
return node.path.startsWith(path);
|
||||
}
|
||||
|
||||
public boolean isSameNode(IndexNode node) {
|
||||
return id.equals(node.id);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@JSONField(serialize = false, deserialize = false)
|
||||
public String getFullFileName() {
|
||||
|
||||
@ -158,6 +158,8 @@ public class IndexManager {
|
||||
BizAssertions.assertTrue(indexNodeDao.validSubtreeFileCount(srcNode) <= docProps.getIndexNodeMaxCopyFileSize(),
|
||||
"拷贝文件数超过限制: {}", docProps.getIndexNodeMaxCopyFileSize());
|
||||
IndexNode destParentNode = findOrNull(destParentCode);
|
||||
if (destParentNode != null)
|
||||
checkBeforeMoveOrCopy(srcNode, destParentNode, "拷贝");
|
||||
return async(() -> {
|
||||
// don't inline in transaction
|
||||
CopyFileVisitor copyNodeVisitor = new CopyFileVisitor(copySubtreeOssFiles(srcNode));
|
||||
@ -179,7 +181,7 @@ public class IndexManager {
|
||||
IndexNode srcNode = getOrThrow(srcCode);
|
||||
IndexNode destParentNode = StringUtils.isBlank(destParentCode) ? null : getOrThrow(destParentCode);
|
||||
if (destParentNode != null)
|
||||
BizAssertions.assertFalse(srcNode.isDirectory() && destParentNode.isFile(), "不能移动文件夹到文件下");
|
||||
checkBeforeMoveOrCopy(srcNode, destParentNode, "移动");
|
||||
return async(() -> {
|
||||
RootNode<IndexNode> moveRoot = TreeBuilder.build(collectValidSubtreeAsValueRoot(srcNode));
|
||||
return transaction.execute(unused -> {
|
||||
@ -189,6 +191,12 @@ public class IndexManager {
|
||||
});
|
||||
}
|
||||
|
||||
private static void checkBeforeMoveOrCopy(IndexNode srcNode, IndexNode destParentNode, String op) {
|
||||
BizAssertions.assertFalse(srcNode.isDirectory() && destParentNode.isFile(), "不能{}文件夹到文件下", op);
|
||||
BizAssertions.assertFalse(srcNode.isSameNode(destParentNode), "不能{}到同一节点下", op);
|
||||
BizAssertions.assertFalse(srcNode.isParentOf(destParentNode), "不能{}到子节点下", op);
|
||||
}
|
||||
|
||||
@BizTransactional
|
||||
public IndexNode copySubTree(IndexNode src, @Nullable IndexNode destParent, CopyNodeVisitor copyNodeVisitor) {
|
||||
RootNode<IndexNode> srcRoot = TreeUtils.transform(collectValidSubtreeAsValueRoot(src), IndexNode.class);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user