-->

创建Alfresco的内容模型方面(Create an aspect in Alfresco Con

2019-07-22 14:10发布

我开始目前使用露天CMS。 我需要它必须包含一些特性,如我的内容模式,创造“方面”:

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

此外,它必须包含两个其由任一性质的数目的多个性质:

Format: 
   FormatProperty1: int
   FormatProperty2: int
   FormatProperty3: int

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

我尚未创建既不是简单的内容模型,也不在露天的一个方面。 根据我以前的关系数据库中的知识,我认为上述结构表之间的关联。 我怎样才能进行,在露天内容模型一个方面或更多?

Answer 1:

你应该看看这里第一。 创建于露天的模型是远离的DB。

这只是良好定义的XML。 你必须先写XML,然后通过引导初始化。

例如XML模型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>

模型上下文命名CMOD-模型的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>

希望能帮助到你。



Answer 2:

让我尝试了一些额外的信息添加到@根据您的评论Alch3mi5t的答案。 我在这里使用一个虚构的商业案例。

基本上,露天模型包括3个部分:约束,类型和方面。 另外,我会在组合加入协会。

  • 类型

在露天(你可能会错误地认为它是一个“记录”),每个节点都有一个类型。 因此,这类型有属性(“列”)。 所以,你有你的基地型,让我们说这就是所谓的供应商 。 它有两个道具,名称及税号(字符串和INT)。 你的类型定义将如下所示:

<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>

有去你的类型,而不是不像列VENDORNAME和字符串和整型的vendorTaxID一个数据库表。

  • 约束

比方说,你现在必须添加的税号一些约束 - 简单的regex例子。 所以,你必须这样定义的约束:

<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>

现在,我们只需要修改我们的taxId属性:

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

所以,你现在摆在该属性的约束。

  • 看点现在,你想一个方面-在露天,这将是,如果你想要一些额外的列添加到该表。

否 - 更好的类比,你想从你的原始表的关系。 所以,如果它为空,它为空。 但另外,它创建了一个1-1(通常)关系到你的记录,其他表。

这里的底线是,你永远不会孤单添加任何东西到表方面 - 它只是谈到作为除基本类型。 示例方面:

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

你可以让这个强制性的方面,如果你(后只是属性部分)添加到您的类型定义:

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

现在,你可以添加一个“记录”到你的基地“表”,如果你加入这个作为强制性的方面,则每条记录将有3个支柱:名称,税号和城市。 如果不是强制性的,则每条记录将有两个基本列,但你可以添加第三选择等等。 编程方式或手动,无所谓。

  • 协会现在,我们还可以在混合添加associatons:这是只有两个节点(或“记录”)之间的联系。 所以,在你的类型的属性部分后,您可以添加协会部分。 比方说,你想连接(部分)供应商它们的创造者(主要客户)。

您添加到您的类型:

<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>

你有它! 现在,您可以连接一些或所有卖方在您的供应商表各自KAMS(这样你就可以通过电子邮件,当有些事情正在发生与卖方KAMS,让我们说)。 基本上,你的供应商表和用户表之间的1-N连接。 1-N这意味着你可以将一个供应商连接到许多人。 您也可以在不同的供应商连接到一个人。 (许多参数)。

您还可以添加协会一方面,以相同的方式:

<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>

现在,您可以创建普通露天文件夹(厘米:折叠式)和状态之后,他们的名字,并有每个城市的连接到他们的一个文件夹。 (不是最好的方式,但显示我的观点。)所以这个协会是强制性的,如果添加这种其它方面(不是原单),这不是强制性的意思是,你必须创建一个关联。

因此,与组合发挥到你所需要的。

  • 模型

所以,现在你有你的示例模型:

    <?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.


文章来源: Create an aspect in Alfresco Content Model