Question

I am starting currently using Alfresco CMS. I need to create an "aspect" in my content model which must contains a number of properties as:

Aspect: 
    property 1 : String
    property 2 : int
    property 3 : int
    property 4 : long

Moreover it must contains two more properties which are composed either of number of properties as:

Format: 
   FormatProperty1: int
   FormatProperty2: int
   FormatProperty3: int

Metadata:
   list1: List<String>
   list2: List<String>
   MetadataProperty 3: boolean

I have not yet created neither a simple content model nor an aspect in Alfresco. Based on my previous knowledge in Relational Databases I perceive the above structure as association between tables. How can I carry out that in Alfresco content model with an aspect or more?

Was it helpful?

Solution 2

You should take a look here first. Creating a model in Alfresco is far away from a DB.

it's just an XML well defined. You have to write the XML first, then initialize it through bootstrap.

Example XML Model cmodModel.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Definition of new Model -->
<model name="custom:custommodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
    <!-- Optional meta-data about the model -->
    <description>Custom Model</description>
    <author>Whatever</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="custom.model" prefix="cmod" />
    </namespaces>
    <!-- Lists <String> -->
    <constraints>
        <constraint name="cmod:liststring1" type="LIST">
            <parameter name="allowedValues">
                <list>
                    <value>value 1</value>
                    <value>value 2</value>
                </list>
            </parameter>
        </constraint>
        <constraint name="cmod:liststring2" type="LIST">
            <parameter name="allowedValues">
                <list>
                    <value>value 1</value>
                    <value>value 2</value>
                </list>
            </parameter>
        </constraint>
    </constraints> 
    <types>
        <!-- Document Type -->
        <type name="cmod:customDoc">
            <title>Document</title>
            <description>Document</description>
            <parent>cm:content</parent>
            <mandatory-aspects>
                <aspect>cmod:aspectBase</aspect>
                <aspect>cmod:aspectFormat</aspect>
                <aspect>cmod:aspectMetadata</aspect>
            </mandatory-aspects>
        </type>
</types> 
    <!-- Definition of custom aspects  -->
    <aspects>
        <aspect name="cmod:aspectBase">
            <title>Aspect base properties</title>
            <properties>
                <property name="cmod:property1">
                    <title>p1</title>
                    <description>p1</description>
                    <type>d:text</type>
                </property>
                <property name="cmod:property2">
                    <title>p2</title>
                    <description>p2</description>
                    <type>d:int</type>
                </property>
                <property name="cmod:property3">
                    <title>p3</title>
                    <description>p3</description>
                    <type>d:int</type>
                </property>
                <property name="cmod:property4">
                    <title>p4</title>
                    <description>p4</description>
                    <type>d:text</type>
                </property>
            </properties>
        </aspect>
        <aspect name="cmod:aspectFormat">
            <title>Aspect Format</title>
            <properties>
                <property name="cmod:formatProperty1">
                    <title>fp1</title>
                    <description>fp1</description>
                    <type>d:int</type>
                </property>
                <property name="cmod:formatProperty2">
                    <title>fp2</title>
                    <description>fp2</description>
                    <type>d:int</type>
                </property>
                <property name="cmod:formatProperty3">
                    <title>fp3</title>
                    <description>fp3</description>
                    <type>d:int</type>
                </property>
            </properties>
        </aspect>
        <aspect name="cmod:aspectMetadata">
            <title>Aspetto Metadata</title>
            <properties>
                <property name="cmod:metadataProperty1">
                    <title>mp1</title>
                    <description>mp1</description>
                    <type>d:text</type>
                    <constraints>
                        <constraint ref="cmod:liststring1" />
                    </constraints>
                </property>
                <property name="cmod:metadataProperty2">
                    <title>mp2</title>
                    <description>mp2</description>
                    <type>d:text</type>
                    <constraints>
                        <constraint ref="cmod:liststring2" />
                    </constraints>
                </property>
                <property name="cmod:metadataProperty3">
                    <title>mp3</title>
                    <description>mp3</description>
                    <type>d:boolean</type>
                </property>
            </properties>
        </aspect>
</aspects>
</model>

model context named cmod-model-context.xml

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

<beans>
    <!-- Registration of new models -->
    <bean id="extension.dictionaryBootstrap" 
        parent="dictionaryModelBootstrap" 
        depends-on="dictionaryBootstrap">
        <property name="models">
            <list>
                <value>alfresco/extension/model/cmodModel.xml</value>
          </list>
        </property>
    </bean>

</beans>

Hope it helps.

OTHER TIPS

Let me try to add some extra info to @Alch3mi5t's answer based on your comment. I'm using an imaginary business case here.

Basically, Alfresco model consists of 3 sections: constraints, types and aspects. Plus, I'll add associations in the mix.

  • Type

Each node in alfresco (you might incorrectly think of it as of a "record") has a type. So this type has properties ("columns"). So you have your base type, let's say it's called Vendor. It has two props, Name and tax ID (string and int). Your type definition would look like:

<type name="myCompany:vendor">
  <title>Vendor</type>
  <parent>cm:folder</parent>
  <properties>
    <property name="myCompany:vendorName">
      <title>Vendor name</title>
      <type>d:text</type>
    </property>
    <property name="myCompany:vendorTaxID">
      <title>Vendor Tax ID</title>
      <type>d:int</type>
    </property>
  </properties>
</type>

There goes your type, not unlike a db table with columns vendorName and vendorTaxID of the string and int type.

  • Constraint

Let's say you now have to add some constraint on the tax id - simple regex example. So you have a constraint defined like this:

<constraint name="myCompany:taxIdConstraint" type="REGEX">
  <parameter name="expression">
    <value>^ID[1-9](\-[1-9])*</value>
  </parameter>
  <parameter name="requiresMatch">
    <value>true</value>
  </parameter>
</constraint>

Now we only need to modify our taxId property:

<property name="myCompany:vendorTaxID">
  <title>Vendor Tax ID</title>
  <type>d:int</type>
  <constraints>
    <constraint ref="myCompany:taxIdConstraint">
  </constraints>
</property>

So, you now placed a constraint on that property.

  • Aspect Now you want an aspect - in Alfresco, this would be as if you want to add few extra columns to that table.

No - better analogy, you want a relation from your original table. So if it's null, it's null. But alternatively, it creates a 1-1 (usually) relation to your records to that other table.

The baseline here is that you would never add anything into the aspect table alone - it only comes as an addition to the base type. An example aspect:

<aspect name="myCompany:myAspect">
  <title>Address aspect</title>
  <properties>
    <property name="myCompany:city">
      <title>City</title>
      <type>d:text</type>
    </property>
  </properties>
</aspect>

You can make this a mandatory aspect if you add this to your type definition (just after the properties section):

<mandatory-aspects>
  <aspect>myCompany:myAspect</aspect>
</mandatory-aspects>

Now, you can add a "record" to your base "table", and if you added this as a mandatory aspect, then each record will have 3 props: name, tax id and city. If not mandatory, then each record will have two base columns, but you will be able to add the third to select few. Programatically or manually, doesn't matter.

  • Associations Now we can also add associatons in the mix: this is a link only between two nodes (or "records"). So, after the properties section in your type, you can add associations section. Let's say you want to connect (some) Vendors to their creators (Key accounts).

You add this to your type:

<associations>
  <association name="myCompany:keyAccountManager">
    <source>
      <mandatory>false</mandatory>
      <many>true</many>
    </source>
    <target>
      <class>cm:person</class>
      <mandatory>false</mandatory>
      <many>true</many>
    </target>
  </association>
</associations>

There you have it! You can now connect some or all of the Vendors in your Vendor table to their respective KAMs (so you can email KAMs when something is going on with the Vendor, let's say). Basically, a 1-n connection between your Vendors table and your Users table. 1-n meaning you can connect one Vendor to many Persons. You can also connect different Vendors to one person. (the many parameters).

You can also add association to an aspect, in the same manner:

<aspect name="myCompany:stateAspect">
 <properties>
 ...
 </properties>
 <associations>
  <association name="myCompany:myState">
    <source>
      <mandatory>true</mandatory>
      <many>true</many>
    </source>
    <target>
      <class>cm:folder</class>
      <mandatory>false</mandatory>
      <many>true</many>
    </target>
  </association>
 </associations>
</aspect>

Now you can create regular alfresco folders (cm:folder type) and name them after the state, and have each of the cities be connected to one of them folders. (Not the best way, but shows my point.) so this association is mandatory, meaning if you add this other aspect (not the original one), which is not mandatory, you HAVE to create an association.

So play with the combinations to do what you need.

  • Model

So now you have your example model:

    <?xml version="1.0" encoding="UTF-8"?>
    <model name="myCompany:myContentModel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
      <description>Custom Content Model</description>
      <author>Zlatko Đurić</author>
      <published>2013-03-22</published>
      <version>1.0</version>
      <imports>
        <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
        <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
      </imports>

      <namespaces>
        <namespace uri="myCompany.model" prefix="bv"/>
      </namespaces>

      <constraints>
        <constraint name="myCompany:taxIdConstraint" type="REGEX">
          <parameter name="expression">
            <value>^ID[1-9](\-[1-9])*</value>
          </parameter>
          <parameter name="requiresMatch">
            <value>true</value>
          </parameter>
        </constraint>
      </constraints>

      <types>
        <type name="myCompany:vendor">
          <title>Vendor</type>
          <parent>cm:folder</parent>
          <properties>
            <property name="myCompany:vendorName">
              <title>Vendor name</title>
              <type>d:text</type>
            </property>
            <property name="myCompany:vendorTaxID">
              <title>Vendor Tax ID</title>
              <type>d:int</type>
              <constraints>
                <constraint ref="myCompany:taxIdConstraint">
              </constraints>
              </property>
          </properties>
          <mandatory-aspects>
            <aspect>myCompany:myAspect</aspect>
          </mandatory-aspects>
          <associations>
            <association name="myCompany:keyAccountManager">
              <source>
                <mandatory>false</mandatory>
                <many>true</many>
              </source>
              <target>
                <class>cm:person</class>
                <mandatory>false</mandatory>
                <many>true</many>
              </target>
            </association>
          </associations>
        </type>
      </types>

      <aspects>
        <aspect name="myCompany:myAspect">
          <title>Address aspect</title>
          <properties>
            <property name="myCompany:city">
              <title>City</title>
              <type>d:text</type>
            </property>
          </properties>

          <associations>
            <association name="myCompany:myState">
              <source>
                <mandatory>true</mandatory>
                <many>true</many>
              </source>
              <target>
                <class>cm:folder</class>
                <mandatory>false</mandatory>
                <many>true</many>
              </target>
            </association>
           </associations>
         </aspect>
      </aspects>
    </model>

There, I hope this helps you.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top