I am trying to copy a whole Folder.
To do so I am creating a new folder and putting all again inside it : folders and documents.
But I am getting an Alfresco Service Exception when trying to create a Document:
Newly created object is not a document !
My code is as below :
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);
}
What is strange is that I yet implement the copy of a simple document inside a repository by the same way and it is working good:
Document documentToCopy = (Document) documentFolderService.getNodeByIdentifier(fileToCopy.getIdentifier());
ContentFile contentFileToCopy = documentFolderService.getContent(documentToCopy);
String nameFileToCopy = fileToCopy.getName();
documentFolderService.createDocument(folderParent, nameFileToCopy, properties, contentFileToCopy);
The only thing that changes is the way to obtain the document : by taking the children documents of a folder or by getting the document with his identifier.
Update of the question :
The exact message of error is:
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)
-
properties is en empty map :
Map properties = new HashMap();
-
I test for .ppt documents, and as you ask the question, I also test for .docx and .jpg
-
the type of the node when the exception is raised is a folder
The quick fix that you proposed is not working.
Maybe I am doing a stupid error somewhere but I don’t manage to find it.
Complete code :
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);
}
As the error message explained : Newly created object is not a document !
this error happens after the creation of the document when the method check if the current node is correctly created and have the right attributes.
I need more informations (stacktrace, type of the node…) to know if it’s a bug on SDK side or a specific the method doesn’t cover.
Could you provide informations
But if the second method work, a quick fix could be :
EDIT 06.02
Apparently there’s an issue reference with the properties object inside documentFolderService.createFolder(). The map is not empty after this method and contains informations that disturb the next part of your code.
So to correct it (and if for you properties are not important during copy operation), please find the solution
NB : Properties is an optional parameter so it can be null.