1

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.

Andy
  • 3,228
  • 8
  • 40
  • 65
  • 1
    Do you want a java backend webscript or javascript one ? – Akah Jul 20 '16 at 15:42
  • Personally I don't mind. I was thinking that I was just going to do javascript for the more lightweight tasks like this, and java for the more involved tasks. But it's pretty trivial which backend I go with at this point. – Andy Jul 20 '16 at 15:43

1 Answers1

1

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)
Akah
  • 1,890
  • 20
  • 28