我正在尝试复制整个 Folder。
为此,我正在创建一个新文件夹并将所有内容再次放入其中:文件夹和文档。
但是我在尝试创建文档时遇到了 Alfresco 服务异常:
新创建的对象不是文档!
我的代码如下:
List<Document> documentsChildren = documentFolderService.getDocuments(folderToCopy);
for (Document document:documentsChildren){
ContentFile contentFileToCopy = documentFolderService.getContent(document);
String nameFileToCopy = document.getName();
// problem there
documentFolderService.createDocument(folderCopied, nameFileToCopy, properties, contentFileToCopy);
}
奇怪的是,我还以相同的方式在存储库中实现了一个简单文档的副本,并且运行良好:
Document documentToCopy = (Document) documentFolderService.getNodeByIdentifier(fileToCopy.getIdentifier());
ContentFile contentFileToCopy = documentFolderService.getContent(documentToCopy);
String nameFileToCopy = fileToCopy.getName();
documentFolderService.createDocument(folderParent, nameFileToCopy, properties, contentFileToCopy);
唯一改变的是获取文档的方式:获取文件夹的子文档或获取带有其标识符的文档。
问题更新:
错误的确切消息是:
Caused by: org.alfresco.mobile.android.api.exceptions.AlfrescoServiceException: Newly created object is not a document! New id: workspace://SpacesStore/85753128-1ac9-4b5e-b909-91dcb7d5ff5d
at org.alfresco.mobile.android.api.services.impl.AbstractDocumentFolderServiceImpl.createDocument(AbstractDocumentFolderServiceImpl.java:482)
属性是空地图:
地图属性 = new HashMap();
我测试 .ppt 文件,当你问这个问题时,我也测试 .docx 和 .jpg
引发异常时节点的类型是文件夹
您建议的快速修复不起作用。也许我在某个地方犯了一个愚蠢的错误,但我没能找到它。
完整代码:
List<Folder> foldersChildren = null;
List<Document> documentsChildren = null;
try {
ServiceRegistry serviceRegistry = Login.session.getServiceRegistry();
DocumentFolderService documentFolderService = serviceRegistry.getDocumentFolderService();
Folder folderParent = (Folder) documentFolderService.getNodeByIdentifier(repositoryParent.getIdentifier());
// create the folder
Map<String,Serializable> properties = new HashMap<String,Serializable>();
Folder folderToCopy = (Folder) documentFolderService.getNodeByIdentifier(repositoryToCopy.getIdentifier());
String nameRepositoryToCopy = repositoryToCopy.getName();
Folder folderCopied = documentFolderService.createFolder(folderParent, nameRepositoryToCopy, properties);
foldersChildren = documentFolderService.getFolders(folderToCopy);
documentsChildren = documentFolderService.getDocuments(folderToCopy);
// create the files inside the folder
ContentFile contentFileToCopy = null;
String nameFileToCopy = null;
for (Document document : documentsChildren){
contentFileToCopy = documentFolderService.getContent(document);
nameFileToCopy = document.getName();
// this operation doesn't work
documentFolderService.createDocument(folderCopied, nameFileToCopy, properties, contentFileToCopy);
}
} catch (Exception e){
this.cancel(true);
UIAlertDialog.runOnUIThreadOperationFailed(activity, context);
}