简体   繁体   中英

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM