cancel
Showing results for 
Search instead for 
Did you mean: 

How to properly bootstrap folder in Company Home?

patrykl
Champ in-the-making
Champ in-the-making
Hi.
I'm using Alfresco Community Edition 4.2.c. As I'm starting my journey with Alfresco I want to achieve something simple. I want to bootstrap new folder called MyFolder in Company Home space. I'm following this tutorial: http://wiki.alfresco.com/wiki/Bootstrap_Data

I have simple module with following module-context.xml file:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>
   <bean id="customSpacesBootstrap" parent="spacesStoreImporter"
      singleton="true">
      <property name="useExistingStore">
         <value>false</value>
      </property>
      <property name="bootstrapViews">
         <list>
            <props>
               <prop key="path">/${spaces.company_home.childname}</prop>
               <prop key="location">alfresco/module/myModule/bootstrap.xml</prop>
            </props>
         </list>
      </property>
   </bean>
</beans>


And my bootstrap.xml is also very simple:

<view:view xmlns:view="http://www.alfresco.org/view/repository/1.0"
   xmlns:cm="http://www.alfresco.org/model/content/1.0" xmlns:app="http://www.alfresco.org/model/application/1.0"
   xmlns:emailserver="http://www.alfresco.org/model/emailserver/1.0"
   xmlns:sys="http://www.alfresco.org/model/system/1.0">

   <cm:folder view:childName="cm:MyFolder">
      <app:uifacets />
      <cm:name>MyFolder</cm:name>
      <app:icon>space-icon-default</app:icon>
      <cm:title>MyFolder</cm:title>
      <cm:description>MyFolder</cm:description>
   </cm:folder>
</view:view>


And the problem is that it isn't creating MyFolder. I have tried to redeploy Alfresco with this module many times, including tests with wiping up Alfresco data repository folder and its database. I'm using default Tomcat with Postgres and Jetty + H2 - both behave the same. To make it work I have to change 'useExistingStore' to true. After that change and redeploy MyFolder is being created. But it creates another problem: when I redeploy again, Alfresco throws Exception during Spring context spin up, complaining about duplicate node name (MyFolder) and deeper about unique constraint violation from DB. So I have to change useExistingStore to false again. This is very inconvenient for final production environment.

From what I have read about useExistingStore, when set to false, it should behave exactly how I would like: create folder once and then skip any changes and touching it when it exists.

I have also read Alfresco spaces.xml and import-export-context.xml file. I can easily reproduce the problem in these files as well. For example in spaces.xml top level Company Home folder is created. When I add another top level folder besides it, lets call it CompanyHome2 and redeploy Alfresco - CompanyHome2 won't be created (but it does not exist so should be). But when I wipe out Alfresco data and redeploy then it will be created.

What am I doing wrong?
2 REPLIES 2

afaust
Legendary Innovator
Legendary Innovator
Hello,

using the spacesStoreImporter directly as in your case is really only useful for a first time setup with useExistingStore set to false. The wiki already states the behavior you have observed:
<blockquote>
If the store does not yet exist (the very first time a new alfresco installation starts up), the data will aways be bootstrapped, no matter the value, but from that moment on the store exists, and setting this to false means the next alfresco reboot these files won't be overridden with those on the classpath. Set it to true again and the next reboot the classpath files are loaded! Only import when YOU want it!
</blockquote>

useExistingStore does NOT mean it will check the content structure, i.e. if you add a bootstrap for a new folder, it won't check the existence of the folder. It only checks for existance of workspace://SpacesStore and if that is not available or useExistingStore is set to true, the bootstrap will be executed. In the latter case, this means it will always be executed, leading to the conflict you have witnessed.

I almost always use the ImporterModuleComponent to bootstrap content structures for my modules. A module component is treated differently than the bootstrap by Alfresco. Its execution depends on the state of your Repository, i.e. if the component has not run once yet (and is applicable for the current version of the module), it will automatically executed. It does not matter if the store already exists.

Regards
Axel

patrykl
Champ in-the-making
Champ in-the-making
Thank you for detailed explanation Axel. Clearly I did not understand different importers and concept of stores etc.
Using ImporterModuleComponent for my module does exactly what I want and works like a charm!.

Cheers.