0

我正在尝试复制整个 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);
    }
4

1 回答 1

2

正如错误信息所解释的:新创建的对象不是文档!此错误发生在创建文档后,该方法检查当前节点是否正确创建并具有正确的属性。

我需要更多信息(堆栈跟踪、节点类型...)来了解它是 SDK 端的错误还是方法未涵盖的特定问题。你能提供信息吗

  • 属性值:是空地图吗?和复制的地图一样吗?
  • 它发生在每个文档还是仅针对某些类型的文档?
  • 引发异常时节点的类型是什么?

但是,如果第二种方法有效,则可以快速解决:

List<Document> documentsChildren = documentFolderService.getDocuments(folderToCopy);
Document documentToCopy = null;
ContentFile contentFileToCopy = null;
String nameFileToCopy = null;
for (Document document : documentsChildren){
   documentToCopy = (Document) documentFolderService.getNodeByIdentifier(document .getIdentifier());
   contentFileToCopy = documentFolderService.getContent(documentToCopy);
   nameFileToCopy = fileToCopy.getName();
   documentFolderService.createDocument(folderParent, nameFileToCopy, properties, contentFileToCopy);
}

编辑 06.02

显然,documentFolderService.createFolder() 中的属性对象存在问题参考。此方法后映射不为空,并且包含干扰代码下一部分的信息。所以要更正它(如果你的属性在复制操作期间并不重要),请找到解决方案

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
        Folder folderToCopy = (Folder) documentFolderService.getNodeByIdentifier(repositoryToCopy.getIdentifier());
        String nameRepositoryToCopy = repositoryToCopy.getName();
        Folder folderCopied = documentFolderService.createFolder(folderParent, nameRepositoryToCopy, null);

        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, null, contentFileToCopy);
        }
    } catch (Exception e){
        this.cancel(true);
        UIAlertDialog.runOnUIThreadOperationFailed(activity, context);
    }

注意:属性是一个可选参数,因此它可以为空。

于 2013-02-01T22:50:01.813 回答