AnsweredAssumed Answered

Create node with custom content model

Question asked by driekhof on Aug 10, 2012
Latest reply on Aug 14, 2012 by driekhof
I've dynamically added a custom content model.  It looks like this:

<model name="agile:task" xmlns="">
   <description>Agile Task Model</description>

       <!– Import Alfresco Dictionary Definitions –>
       <import uri="" prefix="d"/>
       <!– Import Alfresco Content Domain Model Definitions –>
       <import uri="" prefix="cm"/>

      <!– Define a Namespace for my new definitions –>
      <namespace uri="agile.model" prefix="agile"/>
   <!– Type and Aspect definitions go here –>
      <type name="agile:task">
            <property name="agile:task">
            <property name="agile:responsibleParty">
            <property name="agile:toDo">
            <property name="agile:inProcess">
            <property name="agile:toVerify">
            <property name="agile:done">

    <!– TODO:  Aspects and Associations –>

Now I'd like to create a few nodes in the repository using this content model in my Java-backed WebScript.  I've looked over some example code, and can create nodes from an SDK example like this:

        // code for authenticate and locate the company home node not shown

        // create new content node within company home
        // assign name
        String name = "Foundation API sample (" + System.currentTimeMillis() + ")";
        Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
        contentProps.put(ContentModel.PROP_NAME, name);

        // create content node
        NodeService nodeService = registry.getNodeService();
        ChildAssociationRef association = nodeService.createNode(companyHome,
                        QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, name),
        NodeRef content = association.getChildRef();

        // add titled aspect (for Web Client display)
        Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>();
        titledProps.put(ContentModel.PROP_TITLE, name);
        titledProps.put(ContentModel.PROP_DESCRIPTION, name);
        nodeService.addAspect(content, ContentModel.ASPECT_TITLED, titledProps);


I assume I'm pretty close, but I need a little help.  How do I change the above Java Code so it creates nodes of my custom content type?  What names/values do I need to use out of my custom content type XML?  Are there any Java code examples of creating custom content model nodes?