cancel
Showing results for 
Search instead for 
Did you mean: 

How to create root node in the spacesStore?

davidsun
Champ in-the-making
Champ in-the-making
I have a data model as following and now I want to create root node in the spaces store, just like out-of-box Catetory_root in the contentModel.xml.


<?xml version="1.0" encoding="UTF-8"?>
<!– Definition of new Model –>
<model name="sc:somecompanymodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
   <!– Optional meta-data about the model –>
   <description>SomeCompany Content Model</description>
   <author>Some Guy</author>
   <version>1.0</version>

   <!– Imports are required to allow references to definitions in other models –>
   <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" />
      <import uri="http://www.alfresco.org/model/system/1.0" prefix="sys" />
   </imports>

   <!– Introduction of new namespaces defined by this model –>
   <namespaces>
      <namespace uri="http://www.somecompany.com/model/content/1.0" prefix="sc" />
   </namespaces>

      <type name="sc:searchField">
         <title>Search Fields</title>
         <description>The search field payer organization defined</description>
         <parent>cm:cmobject</parent>
         <properties>
            <property name="sc:organizationId">
               <type>d:text</type>
               <mandatory enforced="true">true</mandatory>
               <multiple>false</multiple>
            </property>
            <property name="sc:definedSearchedFields">
               <type>d:text</type>
               <mandatory enforced="true">true</mandatory>
               <multiple>false</multiple>
            </property>
         </properties>
      </type>
      
      <type name="sc:searchFields_root">
         <title>Search Field Root</title>
         <parent>cm:cmobject</parent>
         <associations>
            <child-association name="sc:searchFields">
               <source>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>sc:searchField</class>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </child-association>
         </associations>
         <mandatory-aspects>
            <aspect>sys:aspect_root</aspect>
         </mandatory-aspects>
      </type>
   </types>
</model>


I get spaces store in the following way:

       List<StoreRef> stores = nodeService.getStores();
       StoreRef store = null;
       for(StoreRef s : stores) {
          if(s.getProtocol().equalsIgnoreCase(StoreRef.PROTOCOL_WORKSPACE) && s.getIdentifier().equalsIgnoreCase("SpacesStore")) {
             store = s;
             break;
          }
       }

but nodeService only have function to create NodeRef under another NodeRef. How can I create a root node in the Spaces Store?


Thank you!
3 REPLIES 3

s_palyukh
Star Contributor
Star Contributor
You just need to get root node of the space store


   NodeRef rootNode = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);

davidsun
Champ in-the-making
Champ in-the-making
Thank you! You information is very useful. following I still have the problem to create node in SpacesStore root. The code is like this:

<java>
       NodeRef rootNode = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
       QName nodeTypeQName = QName.createQName(NAMESPACE_HIGHROADS_CONTENT_MODEL, TYPE_HR_SEARCHFIELD_ROOT);
       ChildAssociationRef childAssRef = nodeService.createNode(rootNode, ContentModel.ASSOC_CONTAINS, QName.createQName("{app}searchfields"), nodeTypeQName);
</java>

I get the following exception:

<cite>
org.alfresco.repo.node.integrity.IntegrityException: 01130007 Found 1 integrity violations:
The association source type is incorrect:
   Source Node: workspace://SpacesStore/e909ccce-092e-4bce-a77f-6848dd7b1f42
   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/system/1.0}store_root
   at org.alfresco.repo.node.integrity.IntegrityChecker.checkIntegrity(IntegrityChecker.java:664)
   at org.alfresco.repo.node.integrity.IntegrityChecker.beforeCommit(IntegrityChecker.java:766)
   at org.alfresco.util.transaction.TransactionSupportUtil$TransactionSynchronizationImpl.beforeCommit(TransactionSupportUtil.java:498)
   at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:95)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:925)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:738)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:724)
   at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:475)
</cite>

But if I use "company home" as parent node, it will success.

Any suggestion? Sorry I am new for Alfresco.

Thank you!

s_palyukh
Star Contributor
Star Contributor
I think association type should be sys:children (ContentModel.ASSOC_CHILDREN) instead of cm:contains (ContentModel.ASSOC_CONTAINS). Try this:


        NodeRef rootNode = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
       QName nodeTypeQName = QName.createQName(NAMESPACE_HIGHROADS_CONTENT_MODEL, TYPE_HR_SEARCHFIELD_ROOT);
       ChildAssociationRef childAssRef = nodeService.createNode(rootNode, ContentModel.ASSOC_CHILDREN, QName.createQName("{app}searchfields"), nodeTypeQName);