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="http://www.alfresco.org/model/dictionary/1.0">
   <description>Agile Task Model</description>
   <author></author>
   <version>1.0</version>

    <imports>
       <!– Import Alfresco Dictionary Definitions –>
       <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
       <!– Import Alfresco Content Domain Model Definitions –>
       <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
    </imports>

   <namespaces>
      <!– Define a Namespace for my new definitions –>
      <namespace uri="agile.model" prefix="agile"/>
   </namespaces>
  
   <!– Type and Aspect definitions go here –>
   <types>
      <type name="agile:task">
         <title>Task</title>
         <parent>cm:content</parent>
         <properties>
            <property name="agile:task">
               <type>d:text</type>
            </property>
            <property name="agile:responsibleParty">
               <type>d:text</type>
            </property>
            <property name="agile:toDo">
               <type>d:text</type>
            </property>
            <property name="agile:inProcess">
               <type>d:text</type>
            </property>
            <property name="agile:toVerify">
               <type>d:text</type>
            </property>
            <property name="agile:done">
               <type>d:text</type>
            </property>
         </properties>
      </type>
    </types>  

    <!– TODO:  Aspects and Associations –>
</model>


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,
                        ContentModel.ASSOC_CONTAINS,
                        QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, name),
                ContentModel.TYPE_CONTENT,
                contentProps);
        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);

SNIP


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?

Outcomes