Bootstraping Data with Alfresco

When you work with Alfresco, soon you realize that there lot’s of data/configuration that has to be done to run Alfresco properly. In the end developing with Alfresco means extending it;

  • Implementing a custom content model
  • Setting up a repository structure
  • Applying custom rules on spaces
  • Adding users/groups and configuring access rights

It means every time you install a new Alfresco instance, you also have to setup these prerequisites. However there is a much simpler way to do it, you don’t have to do it by hand. You can use ImporterBootstraps, in order to do so what you have to do is;

  • Define a org.alfresco.repo.module.ImporterModuleComponent for your module
  • Configure it accordingly to import all your data

A module component is a bean that is executed only when the module is being installed for the first time, so it will not run again when you restart Alfresco.

ImporterBootstrap supports two formats for data import; xml and acp. Both of them are Alfresco specific formats and you can generate these files using Alfresco web client by exporting your content. Initially you have to do it all by hand but then you can export everything as xml and amp and reuse it.

See the following sample configuration for importing an acp at the time of module installation.

<bean id="amp-main.bootstrap" class="org.alfresco.repo.module.ImporterModuleComponent"

    <!-- Module Details -->
    <property name="moduleId" value="amp-main"/>
    <property name="name" value="amp-main.bootstrap"/>
    <property name="description" value="Imports bootstrap data required by this module."/>
    <property name="sinceVersion" value="1.0"/>
    <property name="appliesFromVersion" value="1.0"/>

    <!-- Data properties -->
    <property name="importer" ref="spacesBootstrap"/>
    <property name="bootstrapViews">
                <prop key="path">/${spaces.company_home.childname}</prop>
                <prop key="location">com/sony/forest/roots/extensions/config/data/repository.acp</prop>

All you have to do is define this bean and configure it accordingly. It basically imports repository.acp on the given classpath to Company Home (/${spaces.company_home.childname}) space in Alfresco. You can find the complete list of childnames in in Alfresco source.

This example extends only spacesBootstrap bean for inserting content to space. There are also other pre-configured importers for importing different kinds of data. Please refer to spring configuration file repository/config/alfresco/import-export-context.xml in Alfresco source code for more information or see this page on Alfresco Wiki.

One final tiny detail, it cost me one hour to figure it out. You have to use your module’s id for the moduleId property of the component. Otherwise Alfresco cannot relate this ModuleComponent with your module and as a result of this it is not executed. And you should also set the versions properly. I don’t know why they need this much configuration, it is like launching a rocket, just run the damn importer.

Leave a Reply

Your email address will not be published.