Andy
Andy

Reputation: 3522

Alfresco content modelling: referencing properties multiple times

I'm trying to build a content model in alfresco, and I have the following content model xml:

<model name="my:custommodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
    <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="http://www.mycompany.com/model/content/1.0" prefix="my" />
    </namespaces>
    <types>
        <type name="my:bound">
            <title>Bound</title>
            <parent>cm:content</parent>
            <properties>
                <property name="my:width">
                    <type>d:int</type>
                    <multiple>false</multiple>
                </property>
                <property name="my:height">
                    <type>d:int</type>
                    <multiple>false</multiple>
                </property>
            </properties>
        </type>

        <type name="my:rectangle">
            <title>Rectangle</title>
            <parent>cm:content</parent>
            <properties>
                <property name="my:x">
                    <type>d:int</type>
                    <multiple>false</multiple>
                </property>
                <property name="my:y">
                    <type>d:int</type>
                    <multiple>false</multiple>
                <property name="my:width">
                    <type>d:int</type>
                    <multiple>false</multiple>
                </property>
                <property name="my:height">
                    <type>d:int</type>
                    <multiple>false</multiple>
                </property>
            </properties>
        </type>
    </types>
</model>

When I try to build the project containing this, I get the following error:

org.alfresco.service.cmr.dictionary.DictionaryException$DuplicateDefinitionException: 06130000 Found duplicate property definition 'my:x' within class 'my:rectangle' and class 'my:bound'

I would expect that because the properties are essentially children of the type, that they are scoped to that type. But this error indicates otherwise. I'm wondering why that is, and what the correct way around this problem is?

I've tried looking for a way to define properties outside of the type, and then have each type reference them, but I can't find any examples of this. I've also considered creating an aspect which contains the x property, and an aspect that contains the y property, and attaching them to each type, but that doesn't feel right.

Upvotes: 0

Views: 495

Answers (2)

Lista
Lista

Reputation: 2246

When using aspects, you can use the "mandatory-aspects" functionality to apply "common aspects" to specific, specialized aspects.

Just take into account that you will not be able to remove them afterwards, since mandatory is another word for "required", this is not a mechanism for applying aspects in an easy way.

http://docs.alfresco.com/5.0/tasks/dev-extensions-content-models-tutorials-add-mandatory-aspect.html

Upvotes: 1

mitpatoliya
mitpatoliya

Reputation: 2037

For using properties to multiple types you have two ways.

Inheritance:

Create base type with those common properties and set it as parent type in all other types. By that way all child types will inherit properties from parent type.

Aspects:

Create aspect with those common properties and add that aspect to all types. Aspects are meant for that so there is not issue in following this approch.

Upvotes: 4

Related Questions