I try to use the Alfresco NodeService
to make a content node (QName cm:content
) the primary parent of another content node. NodeService
provides a method
public ChildAssociationRef moveNode(
NodeRef nodeToMoveRef,
NodeRef newParentRef,
QName assocTypeQName,
QName assocQName)
throws InvalidNodeRefException;
Let's say the current primary parent of the node theNodeToMove
is a folder and the primary parent assoc reference of the node in the folder is primaryAssocRef
. Let theTargetContentNode
be the target content node.
Calling the above message like this
nodeService.moveNode(theNodeToMove,
theTargetContentNode,
primaryAssocRef.getTypeQName(),
primaryAssocRef.getQName());
fails. Alfresco reporst an integrity violation:
The association source type is incorrect:
Source Node: workspace://SpacesStore/27a97736-222c-4bac-8610-f15ce312b074
Association: Association[ class=ClassDef[name={http://www.alfresco.org/model/content/1.0}folder], name={http://www.alfresco.org/model/content/1.0}contains, 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/content/1.0}folder
Actual Source Type: {http://www.alfresco.org/model/content/1.0}content
Is it even possible to make a content node the primary parent of an existing content node?
Yes and no. Yes because content node can have children, and no because you can't use the "contains" association.
Basically, when you create a "parent-child" relation, you need to state it's association type. You can have as many of these, for instance rm:rendition
is one of these types.
The "main" association type used when you create a document under a folder is cm:contains
, and is setup in a way that does not allow content nodes to have children. This is done through model definition, and looks something like this:
<type name="cm:folder">
<title>Folder</title>
<parent>cm:cmobject</parent>
<archive>true</archive>
<associations>
<child-association name="cm:contains">
<source>
<mandatory>false</mandatory>
<many>true</many>
</source>
<target>
<class>sys:base</class>
<mandatory>false</mandatory>
<many>true</many>
</target>
<duplicate>false</duplicate>
<propagateTimestamps>true</propagateTimestamps>
</child-association>
</associations>
</type>