繁体   English   中英

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

[英]Create an aspect in Alfresco Content Model

我现在开始使用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内容模型中执行该操作?

让我尝试根据你的评论为@ 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>

有你的类型,与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>

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

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

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

  • 方面现在您想要一个方面 - 在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>

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

<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发送电子邮件)。 基本上,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>

现在,您可以创建常规的露天文件夹(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.

你应该先看看这里 在Alfresco中创建模型远离数据库。

它只是一个定义良好的XML。 您必须先编写XML,然后通过bootstrap初始化它。

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

希望能帮助到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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