1
votes

In the definition of a hybris type I've come across difficulty with understanding the meaning of this two tags: <custom-properties> and <attributes>

In detail, the first contains child tags <property> and the second contains child tags <attribute>. In the "property" tags there is a further tag <value> with content.

The example code on which I am based is taken from the hybris trail, that is:

<itemtype
    code="News"
    autocreate="false"
    generate="false">
    <custom-properties>
        <property name="catalogItemType"><value>java.lang.Boolean.TRUE</value></property>
        <property name="catalogVersionAttributeQualifier"><value>"catalogVersion"</value></property>
        <property name="uniqueKeyAttributeQualifier"><value>"id"</value></property>
    </custom-properties>
    <attributes>
        <attribute qualifier="id" type="java.lang.String">
            <modifiers initial="true" optional="false" write="true"/>
            <persistence type="property"/>
            </attribute>
        <attribute qualifier="catalogVersion" type="CatalogVersion">
            <modifiers initial="true" optional="false" write="true"/>
            <persistence type="property"/>
        </attribute>
    </attributes>
</itemtype>

Overall, what is the difference between the two tags <custom-properties> and <attributes>?

2

2 Answers

3
votes

Item attributes define the state of an item. They are actually the columns of the the db table that is created (except the dynamic attributes) as a result of platform build and update process.

Custom attributes are certain defined attributes which are used in the type system definition to defined certain properties of a type. In general, if you interpret the metadata of the type system you may read the attributes to achieve the desired behaviour. They could be defined at various levels

  1. At an item type level - Custom-properties are used to define properties for a type. This is the example that you have posted in the question body. The custom types in the question

<custom-properties>
        <property name="catalogItemType"><value>java.lang.Boolean.TRUE</value></property>
        <property name="catalogVersionAttributeQualifier"><value>"catalogVersion"</value></property>
        <property name="uniqueKeyAttributeQualifier"><value>"id"</value></property>
    </custom-properties>

these properties are defined at a type level - These attributes provide catalog awareness at a type level. These attributes could be retrieved these item type properties at runtime via the getProperty( String propertyName ) methodThere are other examples as well.

  1. Relation level, please see the snippet below

<relation code="User2Addresses" generate="true" localized="false" autocreate="true">
    <sourceElement type="User" cardinality="one" qualifier="owner">
        <modifiers read="true" write="true" search="true" optional="true" initial="false"/>
    </sourceElement>
    <targetElement type="Address" cardinality="many" qualifier="addresses">
        <modifiers read="true" write="true" search="true" optional="true" partof="true"/>
        <custom-properties>
            <property name="condition.query">
                <value>"{original} is null"</value>
            </property>
        </custom-properties>
    </targetElement>
</relation>

The property holds a string that is later added to the 'where' part of the select query generated for a one-to-many or many-to-one relation.

  1. Ordering Attribute - By defining ordering.attribute, it is possible to specify which attribute will be used to order the many-side items when retrieving from the database

<relation code="AbstractOrder2AbstractOrderEntry" localized="false" generate="true" autocreate="true">
			<sourceElement type="AbstractOrder" qualifier="order" cardinality="one">
				<modifiers read="true" write="true" search="true" optional="true" />
				<custom-properties>
					<property name="ordering.attribute">
						<value>"entryNumber"</value>
					</property>
				</custom-properties>
			</sourceElement>
			<targetElement type="AbstractOrderEntry" qualifier="entries" cardinality="many" collectiontype="list" ordered="false" >
				<modifiers read="true" write="true" search="true" optional="true" partof="true" />
			</targetElement>
		</relation>
  1. Backoffice Custom Attributes- Backoffice would allow to display all attributes of any type (out of the box), nevertheless there are some special (let's say technical) attributes that definitely should not be visible in the UI or should at least be readonly in the UI (no matter what the access rights they have). For those very rare case hybris have introduced two custom attributes that we interprete when the typesystem is scanned

<property name="readOnlyForUI">
     <value>Boolean.TRUE</value>
 </property>
 <property name="hiddenForUI">
     <value>Boolean.TRUE</value>
 </property>

Hope this helps!

2
votes
<custom-properties>
    <property name="catalogItemType">
        <value>java.lang.Boolean.TRUE</value>
    </property>
    <property name="catalogVersionAttributeQualifier">
        <value>"catalogVersion"</value>
    </property>
    <property name="uniqueKeyAttributeQualifier">
        <value>"code"</value>
    </property>
</custom-properties>

These <custom-properties> are used to define ItemType as catalog aware. Like Product Type. You can refer this post for more detail.

<attribute> is used to define and configure a column of the table/item.

In SQL word, I can say <custom-properties> is used for table level configuration(metadata) and <attribute> is used to define and configure the column of that table.