cancel
Showing results for 
Search instead for 
Did you mean: 

how to create nodes using a CMLCreate[]?

fluca1978
Champ in-the-making
Champ in-the-making
Hi,
suppose I want to take advantage of executing an array of CMLCreate as a single transaction to create a folder and content tree. I've got the first CMLCreate that can work fine, but how can I get the parent reference to create the following CMLCreate so that they refer to the first created content node? I mean, the only way I know to get the reference of a created node is extracting the information from the UpdateResult, but I'd like to have such information before the update is executed, so that I can execute the whole array as a single batch. Any help would be appreciated.

Thanks
3 REPLIES 3

fluca1978
Champ in-the-making
Champ in-the-making
Uhm…I've find a rude way to create the PathRefernce, but I suspect there must be a smarter one:

ParentReference mainParentReference = …CMLCreate create1 = new CMLCreate();…// now create a reference to the to-be-created nodeParentReference previousNodeParentReference = new ParentReference();previousNodeParentReference.setPath( mainParentReference.getPath() + "/" + ISO9075.encode( mainParentreference.getChildName() ) );‍‍‍‍‍‍‍‍‍

So the idea is to compute the name of each node using the root + "/" + name of inner node.
Is there a simpler and smarter way to obtain the path of to-be-created node?

Thanks

fluca1978
Champ in-the-making
Champ in-the-making
Maybe I found a smarter way, but I've got still the doubt if this is correct or no: since each CMLCreate contains a ParentReference I can get the parent reference of each CMLCreate and compose the parent reference path and the parent reference child name to get the final path of the node the CML create refers to. Is a stable way of achieving this?

jcustovic
Champ in-the-making
Champ in-the-making
There is a way. Here's an example:
…// Create folder (parentFolder where you want to create your folder)CMLCreate createFolder = new CMLCreate("1", parentFolder, null, Constants.ASSOC_CONTAINS, null, Constants.TYPE_FOLDER, folderProperties);// Create document in newly future created folder (notice id "1" - 3rd parameter)CMLCreate create1 = new CMLCreate("2", null, "1", Constants.ASSOC_CONTAINS, null, documentTypeQName, properties);// Create another documentCMLCreate create2 = new CMLCreate("2", null, "1", Constants.ASSOC_CONTAINS, null, documentTypeQName1, properties2);cml.setCreate(new CMLCreate[] { createFolder, create1, create2 });UpdateResult[] results = getRepositoryService().update(cml);…‍‍‍‍‍‍‍‍‍‍