在Alfresco内容模型中创建一个方面

arj*_*soh 4 database-design alfresco content-management-system database-schema content-model

我现在开始使用Alfresco CMS.我需要在我的内容模型中创建一个"方面",它必须包含许多属性:

Aspect: 
    property 1 : String
    property 2 : int
    property 3 : int
    property 4 : long
Run Code Online (Sandbox Code Playgroud)

此外,它必须包含另外两个属性,这些属性由以下属性组成:

Format: 
   FormatProperty1: int
   FormatProperty2: int
   FormatProperty3: int

Metadata:
   list1: List<String>
   list2: List<String>
   MetadataProperty 3: boolean
Run Code Online (Sandbox Code Playgroud)

我还没有在Alfresco中创建简单的内容模型和方面.基于我之前在关系数据库中的知识,我将上述结构视为表之间的关联.如何在具有一个或多个方面的Alfresco内容模型中执行该操作?

Zla*_*tko 6

让我尝试根据你的评论为@ Alch3mi5t的答案添加一些额外的信息.我在这里使用一个想象中的商业案例.

基本上,Alfresco模型由3个部分组成:约束,类型和方面.另外,我会添加混合中的关联.

  • 类型

露天中的每个节点(您可能错误地将其视为"记录")具有类型.所以这种类型有属性("列").所以你有你的基本类型,让我们说它叫做供应商.它有两个道具,名称和税号(字符串和整数).您的类型定义如下所示:

<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>
Run Code Online (Sandbox Code Playgroud)

有你的类型,与db表的列和vendor类型的vendorName和vendorTaxID不同.

  • 约束

假设您现在必须在tax id上添加一些约束 - 简单的正则表达式示例.所以你有一个像这样定义的约束:

<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>
Run Code Online (Sandbox Code Playgroud)

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

<property name="myCompany:vendorTaxID">
  <title>Vendor Tax ID</title>
  <type>d:int</type>
  <constraints>
    <constraint ref="myCompany:taxIdConstraint">
  </constraints>
</property>
Run Code Online (Sandbox Code Playgroud)

所以,您现在对该属性设置了约束.

  • 方面 现在您想要一个方面 - 在Alfresco中,这就好像您想要向该表添加一些额外的列.

不 - 更好的类比,你想要原始表中的关系.因此,如果它为null,则为null.但另外,它会将您的记录创建为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>
Run Code Online (Sandbox Code Playgroud)

如果将其添加到类型定义中(在属性部分之后),则可以将此设置为必需的方面:

<mandatory-aspects>
  <aspect>myCompany:myAspect</aspect>
</mandatory-aspects>
Run Code Online (Sandbox Code Playgroud)

现在,您可以在基础"表格"中添加"记录",如果您将其添加为必填方面,则每条记录将包含3个道具:名称,税号和城市.如果不是强制性的,那么每条记录将有两个基本列,但您可以添加第三列以选择少数几列.以编程方式或手动方式,无关紧要.

  • 关联 现在我们还可以在混合中添加关联:这是仅在两个节点(或"记录")之间的链接.因此,在类型的属性部分之后,您可以添加关联部分.假设您想将(某些)供应商连接到他们的创建者(主要帐户).

您将其添加到您的类型:

<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>
Run Code Online (Sandbox Code Playgroud)

你有它!您现在可以将供应商表中的部分或全部供应商连接到各自的KAM(因此,当供应商发生某些事情时,您可以通过电子邮件向KAM发送电子邮件,比如说).基本上,Vendors表和Users表之间的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>
Run Code Online (Sandbox Code Playgroud)

现在,您可以创建常规的露天文件夹(cm:文件夹类型)并在状态后命名,并将每个城市连接到其中一个文件夹.(不是最好的方式,但显示了我的观点.)所以这种关联是强制性的,这意味着如果你添加另一个方面(不是原始方面),这不是强制性的,你必须创建一个关联.

所以玩组合来做你需要的.

  • 模型

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

    <?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.
Run Code Online (Sandbox Code Playgroud)