How to add child associations in alfresco webscripts

1k Views Asked by At

I'm finding it really difficult to find useful documentation on this. Basically I have two custom types 'Concept' and 'ConceptScheme' defined in my alfresco content model. Concept scheme has an association to many child concepts. Like this:

        <type name="ancoat:conceptScheme">
            <title>Concept Scheme</title>
            <parent>ancoat:ddiObject</parent>
            <associations>
                <child-association name="ancoat:categories">
                   <source>
                       <mandatory>true</mandatory>
                       <many>false</many>
                   </source>
                   <target>
                       <class>ancoat:concept</class>
                       <mandatory>false</mandatory>
                       <many>true</many>
                   </target>
                   <duplicate>false</duplicate>
                   <propagateTimestamps>true</propagateTimestamps>
                </child-association>
            </associations>
            <mandatory-aspects>
                <aspect>ancoat:describedObject</aspect>
            </mandatory-aspects>
        </type>

I have two webscripts, one for creating the concept node, and one the concept scheme. I now want to create a webscript which takes some reference to each of those objects, and creates an association between them.

How do I do that? I've found the function Node.createAssociation, but I can't find any examples using it.

1

There are 1 best solutions below

0
On

I would answer you the java way then.

Let's say that the namespace is http://ancoat.com/model/content/1.0 for the ancoat prefix have this association :

public static final QName ANCOAT_CATEGORIES_ASSOC = QName.createQName("http://ancoat.com/model/content/1.0",
            categories);

Then you can associate one node to others with the node service :

getNodeService().setAssociations(pNode, ANCOAT_CATEGORIES_ASSOC, targets);

Where pNode is one node, and targets a list on nodes you want to do the association with.

Now, with a child association, it might be a better way to use the addChild method :

getNodeService().addChild(parentRefs, childRef, assocTypeQName, qname)