REQ-3540: rename
This commit is contained in:
parent
abe3918984
commit
5c3b7e6bb1
@ -158,6 +158,12 @@ public class IndexNode extends BaseEntity<IndexNode> implements NodeValue, Index
|
||||
return Objects.equals(n1.getId(), n2.getId());
|
||||
}
|
||||
|
||||
public static void setScope(IndexNode indexNode, IndexNodeScope scope) {
|
||||
indexNode.setContext(scope.context());
|
||||
indexNode.setScope(scope.scope());
|
||||
indexNode.setScopeCode(scope.scopeCode());
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@JSONField(serialize = false, deserialize = false)
|
||||
public boolean isFile() {
|
||||
|
||||
@ -11,6 +11,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import cn.axzo.nanopart.doc.file.index.copy.CopiedOssFiles;
|
||||
import cn.axzo.nanopart.doc.file.index.copy.ScopedCopyFileVisitor;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -41,7 +43,6 @@ import cn.axzo.nanopart.doc.entity.TemplateDatabase;
|
||||
import cn.axzo.nanopart.doc.file.index.IndexManager;
|
||||
import cn.axzo.nanopart.doc.file.index.IndexQueryService;
|
||||
import cn.axzo.nanopart.doc.file.index.copy.CopyFileVisitor;
|
||||
import cn.axzo.nanopart.doc.file.index.copy.SetScopeProcessor;
|
||||
import cn.axzo.nanopart.doc.file.index.domain.IndexNodes;
|
||||
import cn.axzo.nanopart.doc.file.templatedb.TemplateDatabaseManager;
|
||||
import cn.axzo.nanopart.doc.utils.AsyncUtils;
|
||||
@ -95,12 +96,12 @@ public class FileDatabaseService {
|
||||
IndexNode template = indexManager.getOrThrow(db.getTemplateDatabaseCode());
|
||||
Future<?> future = indexManager.async(() -> {
|
||||
// don't inline in transaction
|
||||
CopyFileVisitor copyFileVisitor = indexManager.createCopyFileVisitor(template, new SetScopeProcessor(db));
|
||||
CopiedOssFiles copiedOssFiles = indexManager.copySubtreeOssFiles(template);
|
||||
transaction.executeWithoutResult(unused -> {
|
||||
FileDatabase reload = fileDatabaseDao.getForUpdateOrThrow(request.getCode());
|
||||
if (reload.isActivated())
|
||||
return;
|
||||
indexManager.copySubTree(template, null, copyFileVisitor);
|
||||
indexManager.copySubTree(template, null, new ScopedCopyFileVisitor(copiedOssFiles, db));
|
||||
fileDatabaseDao.setActivated(reload.getCode());
|
||||
});
|
||||
});
|
||||
|
||||
@ -4,7 +4,6 @@ package cn.axzo.nanopart.doc.file.index;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@ -151,17 +150,16 @@ public class IndexManager {
|
||||
IndexNode destParentNode = findOrNull(destParentCode);
|
||||
return async(() -> {
|
||||
// don't inline in transaction
|
||||
CopyFileVisitor copyNodeVisitor = createCopyFileVisitor(srcNode, null);
|
||||
CopyFileVisitor copyNodeVisitor = new CopyFileVisitor(copySubtreeOssFiles(srcNode));
|
||||
//noinspection SpringTransactionalMethodCallsInspection
|
||||
return transaction.execute(unused -> copySubTree(srcNode, destParentNode, copyNodeVisitor));
|
||||
});
|
||||
}
|
||||
|
||||
public CopyFileVisitor createCopyFileVisitor(IndexNode srcNode, @Nullable Consumer<IndexNode> copyPostProcessor) {
|
||||
public CopiedOssFiles copySubtreeOssFiles(IndexNode srcNode) {
|
||||
BizAssertions.assertFalse(TransactionSynchronizationManager.isActualTransactionActive(), "不能在事务中使用");
|
||||
List<String> ossFileKeys = indexNodeDao.collectValidSubtreeFileOssKeys(srcNode);
|
||||
CopiedOssFiles copiedOssFiles = new CopiedOssFiles(ossClient.copy(ossFileKeys));
|
||||
return new CopyFileVisitor(copiedOssFiles, copyPostProcessor);
|
||||
return new CopiedOssFiles(ossClient.copy(ossFileKeys));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -30,7 +30,6 @@ import cn.axzo.nanopart.doc.dao.DocLockDao;
|
||||
import cn.axzo.nanopart.doc.dao.IndexNodeDao;
|
||||
import cn.axzo.nanopart.doc.entity.IndexNode;
|
||||
import cn.axzo.nanopart.doc.entity.domain.Path;
|
||||
import cn.axzo.nanopart.doc.file.index.copy.SetScopeProcessor;
|
||||
import cn.axzo.nanopart.doc.file.index.domain.NameUsedException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -56,7 +55,7 @@ class IndexSupport {
|
||||
validateBeforeCreateChild(parent, create, nodeType);
|
||||
}
|
||||
IndexNode child = new IndexNode();
|
||||
new SetScopeProcessor(create.nodeScope()).accept(child);
|
||||
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());
|
||||
|
||||
@ -1,10 +1,6 @@
|
||||
|
||||
package cn.axzo.nanopart.doc.file.index.copy;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import cn.axzo.maokai.api.vo.response.tree.ValueNode;
|
||||
import cn.axzo.maokai.api.vo.response.tree.WalkingDecision;
|
||||
import cn.axzo.nanopart.doc.api.domain.FileAttributes;
|
||||
@ -18,8 +14,6 @@ import lombok.RequiredArgsConstructor;
|
||||
public class CopyFileVisitor extends CopyNodeVisitor {
|
||||
|
||||
private final CopiedOssFiles copiedOssFiles;
|
||||
@Nullable
|
||||
private final Consumer<IndexNode> copyPostProcessor;
|
||||
|
||||
@Override
|
||||
public WalkingDecision visit(ValueNode<IndexNode> node) {
|
||||
@ -29,8 +23,6 @@ public class CopyFileVisitor extends CopyNodeVisitor {
|
||||
String newOssFileKey = copiedOssFiles.getCopyOssFileKey(fileAttributes.getOssFileKey());
|
||||
fileAttributes.setOssFileKey(newOssFileKey);
|
||||
}
|
||||
if (copyPostProcessor != null)
|
||||
copyPostProcessor.accept(copy);
|
||||
return super.visit(node);
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
|
||||
package cn.axzo.nanopart.doc.file.index.copy;
|
||||
|
||||
import cn.axzo.maokai.api.vo.response.tree.ValueNode;
|
||||
import cn.axzo.maokai.api.vo.response.tree.WalkingDecision;
|
||||
import cn.axzo.nanopart.doc.api.domain.IndexNodeScope;
|
||||
import cn.axzo.nanopart.doc.entity.IndexNode;
|
||||
|
||||
/**
|
||||
* @author yanglin
|
||||
*/
|
||||
public class ScopedCopyFileVisitor extends CopyFileVisitor {
|
||||
|
||||
private final IndexNodeScope nodeScope;
|
||||
|
||||
public ScopedCopyFileVisitor(CopiedOssFiles copiedOssFiles, IndexNodeScope nodeScope) {
|
||||
super(copiedOssFiles);
|
||||
this.nodeScope = nodeScope;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WalkingDecision visit(ValueNode<IndexNode> node) {
|
||||
IndexNode indexNode = node.<IndexNode> asValueNode().getValue();
|
||||
IndexNode.setScope(indexNode, nodeScope);
|
||||
return super.visit(node);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
|
||||
package cn.axzo.nanopart.doc.file.index.copy;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import cn.axzo.nanopart.doc.api.domain.IndexNodeScope;
|
||||
import cn.axzo.nanopart.doc.entity.IndexNode;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author yanglin
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public class SetScopeProcessor implements Consumer<IndexNode> {
|
||||
|
||||
private final IndexNodeScope nodeScope;;
|
||||
|
||||
@Override
|
||||
public void accept(IndexNode indexNode) {
|
||||
indexNode.setContext(nodeScope.context());
|
||||
indexNode.setScope(nodeScope.scope());
|
||||
indexNode.setScopeCode(nodeScope.scopeCode());
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user