cancel
Showing results for 
Search instead for 
Did you mean: 

where should nodes get created?

gengstrand
Champ in-the-making
Champ in-the-making
I have put something similar to the following in the executeImpl method of an ActionExecuterAbstractBase subclass.

NodeRef parent = nodeService.getPrimaryParent(actionedUponNodeRef).getParentRef();
Map<QName, Serializable> props = new TreeMap<QName, Serializable>();
props.put(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "name"), "test dump");
props.put(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "title"), "testing node create");
props.put(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "author"), "Glenn");
props.put(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "description"), "test description");
nodeService.createNode(parent,
ContentModel.ASSOC_CHILDREN,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "test dump"),
QName.createQName("kato.model", "criteria"),
props);

Which, when run, generates this error.

Failed to run Actions due to error: 00020002 Found 1 integrity violations: The association source type is incorrect: Source Node: workspace://SpacesStore/b1761401-a167-4fdc-9241-885e9526543e Association: Association[ class=ClassDef[name={http://www.alfresco.org/model/system/1.0}container], name={http://www.alfresco.org/model/system/1.0}children, target class={http://www.alfresco.org/model/system/1.0}base, source role=null, target role=null] Required Source Type: {http://www.alfresco.org/model/system/1.0}container Actual Source Type: {http://www.alfresco.org/model/content/1.0}folder

I was trying to put this new node in the same folder as the node on which this action is being run.  What is the difference between a container and a folder?

Yes, I have registered a kato.model with a custom content type called criteria.

When I replaced that first line in the code excerpt with this.

NodeRef parent = nodeService.getRootNode(Repository.getStoreRef());

The node gets created and I can find it in search results but not by browsing around. Also, the node has a description but no content in it. How do you create a node with content?
2 REPLIES 2

mrogers
Star Contributor
Star Contributor
You probably want to use cm:contains rather than sys:children.

To write a content property there are some convienence methods on the Node Service that allow you to write Strings to a content properties.   And you should also look at the Content Service that will allow you to get a ContentWriter.

gengstrand
Champ in-the-making
Champ in-the-making
Thanks, mrogers, your advise was perfect. Here is the corrected, and working, sample code.


NodeRef parent = nodeService.getPrimaryParent(actionedUponNodeRef).getParentRef();
props = new TreeMap<QName, Serializable>();
props.put(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "name"), "test dump");
props.put(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "title"), "testing node create");
props.put(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "author"), "Glenn");
props.put(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "description"), "test description");
ChildAssociationRef td = nodeService.createNode(parent,
  ContentModel.ASSOC_CONTAINS,
  QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "test dump"),
  QName.createQName("kato.model", "criteria"),
  props);
ContentWriter writer = contentService.getWriter(td.getChildRef(), ContentModel.PROP_CONTENT, true);
writer.putContent("test content");