4

我目前开始使用 Alfresco 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

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

4

2 回答 2

6

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

基本上,Alfresco 模型由 3 个部分组成:约束、类型和方面。另外,我将在组合中添加关联。

  • 类型

alfresco 中的每个节点(您可能会错误地将其视为“记录”)都有一个类型。所以这种类型有属性(“列”)。所以你有你的基本类型,假设它叫做Vendor。它有两个道具,名称和税号(字符串和整数)。您的类型定义如下所示:

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

这是你的类型,与包含字符串和 int 类型的 vendorName 和 vendorTaxID 列的 db 表不同。

  • 约束

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

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

因此,您现在对该属性设置了约束。

  • Aspect 现在您需要一个方面 - 在 Alfresco 中,这就像您想在该表中添加一些额外的列一样。

不-更好的类比,您想要原始表中的关系。因此,如果它为空,则为空。但或者,它会创建一个 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 个道具:姓名、税号和城市。如果不是强制性的,那么每条记录将有两个基本列,但您可以添加第三个以选择少数几个。以编程方式或手动方式都没关系。

  • 关联 现在我们还可以在混合中添加关联:这只是两个节点(或“记录”)之间的链接。因此,在您的类型中的属性部分之后,您可以添加关联部分。假设您想将(某些)供应商与其创建者(关键帐户)联系起来。

您将其添加到您的类型中:

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

你有它!您现在可以将供应商表中的部分或全部供应商连接到他们各自的 KAM(例如,当供应商发生某些事情时,您可以通过电子邮件发送 KAM)。基本上,您的供应商表和用户表之间的 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>

现在您可以创建常规的露天文件夹(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.
于 2013-03-22T14:05:45.313 回答
3

你应该先看看这里。在 Alfresco 中创建模型与数据库相去甚远。

它只是一个定义良好的 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-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>

希望能帮助到你。

于 2013-03-22T12:29:28.227 回答