Professional Documents
Culture Documents
Hybris?
Starting on Hybris platform as a beginner thought that defining an item type in
Hybris so simple by adding its entry in items.xml file. Yes this is true; In Hybris all
the type definitions are defined in items.xml file under the custom extension.
Hybris will create corresponding table definitions, column types and relationships in
the underlying data base leaving the developer to only concentrate on business
logic.
After having a good amount of experience on Hybris platform now considering
above statement is not 100% true. Considering the HMC (Hybris Management
Console) and Product cockpit it is not enough to add the type definition into
items.xml file. There are so many files that we need to write in order to make a
type available completely useable in the hybris system.
Lets explore what would be required to create a new item type (ProductWarranty)
definition in Hybris
-items.xml
All the new type definitions in the hybris system are defined in items.xml file.
This file is used to structure the database objects for the hybris service layer.
<itemtype code="ProductWarranty" extends="GenericItem"
autocreate="true" generate="true">
<deployment table="Warranties" typecode="12143" />
<custom-properties>
<property
name="catalogItemType"><value>java.lang.Boolean.TRUE</value></property
>
<property
name="catalogVersionAttributeQualifier"><value>"catalogVersion"</value></p
roperty>
<property
name="uniqueKeyAttributeQualifier"><value>"code"</value></property>
</custom-properties>
<attributes>
<attribute qualifier="code" type="java.lang.String">
<description>url</description>
<modifiers optional="false" read="true" write="true"
unique="true"
search="true" />
<persistence type="property" />
</attribute>
<attribute qualifier="active" type="java.lang.Boolean">
<description>GLN</description>
<modifiers optional="true" read="true" write="true"
search="true" />
<defaultvalue>java.lang.Boolean.TRUE</defaultvalue>
<persistence type="property" />
</attribute>
<attribute qualifier="catalogVersion"
type="CatalogVersion">
<modifiers initial="true" optional="false" write="false"/>
<persistence type="property"/>
</attribute>
</attributes>
</itemtype>
width="200"></attribute>
<attribute name="active" ></attribute>
<attribute name="catalogVersion"
width="200"> </attribute>
</itemlayout>
</listview>
</result>
<editor>
<tab name="tab.warranty.details">
<section name="section.warranty.details">
<listlayout>
<attribute name="code"
width="200"></attribute>
<attribute name="active" ></attribute>
<attribute name="catalogVersion"
width="200"> </attribute>
</listlayout>
</section>
</tab>
</editor>
</organizer>
<defaultreference searchattribute="code" mode="replace">
<itemlayout>
<attribute name="code"/>
</itemlayout>
</defaultreference>
</type>
Lets go over line by line from the above definition
<type name="ProductWarranty" mode="append">
Above type definition notifies hybris system that we are making a new item
type available into hybris and the type name is ProductWarranty
Mode can be one of 'append', 'replace' or 'delete'. Default is 'append'. When
you specify mode as append for a new item type definition (if you are
defining this new item type for the first time in hmc.xml) its add some extra
information to the item type layouts in HMC (We will see that in next
sections.
<organizer>
<search></search>
<result></result>
<editor> </editor>
</organizer>
Organizer contains descriptions on how the different organizer components
represent this type.
Search section will define the search attributes for this type
Result will define the how the results will be displayed
Editor will define the tabs and sections of this type
<defaultreference>
Describes how items of this type look (by default) when they are referenced
in a different location.
Now lets see all these sections in HMC
Now above screen in hmc will allow searching for a product warranty based
on warranty, active and catalog conditions.
The search results will be displayed in result section after the search. Result
section can be configured in list, edit and tree modes by default list (For
more information on these modes refer wiki.hybris.com)
From the results after selecting a warranty editor section will display with the
tabs and sections which are configured in the editor section of organizer tag
in hmc.xml
Though Administration tab was not added to the definition. Hybris will add
this tab by default for every new item type defined in hmc.xml.
Now all the sections for the product warranty have been configured in hmc.
The question is now how to come to this page?
To add an access point for this page. We need to add this product warranty to
one of the customized folder or existing folder from the left navigation.
Lets see how to add this access point for this page.
<explorertree>
<group name="sbdgroup">
<typeref type="ProductWarranty"
description="tree.ProductWarranty.name"/>
</group>
</explorertree>
Above definition need to be added to hmc.xml file (refer hmc.xsd file on
where to mention this entry)
Explorertree design the layout of the left navigation. A folder with SBD is
created and a reference link for the product warranty has been created
Now all the configuration for the Product Warranty in HMC is established.
There is one last configuration is still pending. Labels for the Product
Warranty. In the hmc.xml for tab, section and explorertree definitions we
used keys for labels. But where these keys and its values would be defined?
sbdcore-locales_en.properties
All the localization parameters are defined into this properties file and in
Hybris there is a predefined structure to add labels for item types
#
#
#
#
#
#
of
of
of
of
type>.name=XY
type>.<qualifier of attribute>.name=XY
type>.description=XY
type>.<qualifier of attribute>.description=XY
locales_en.properties
All the hmc specific labels / localizations are defined locales_en.properties file
Sbdgroup = SBD
tab.warranty.details= Warranty Details
section.warranty.details= Warranty Information
tree.ProductWarranty.name= Warranty
This completes the HMC configuration. For more information please look at
wiki.hybris.com
base_ProductWarranty.xml
<?xml version="1.0" encoding="UTF-8"?>
<base>
<search>
<search-properties>
<property qualifier="ProductWarranty.code" />
<property qualifier="ProductWarranty.catalogVersion" />
</search-properties>
<sort-properties>
<property qualifier="ProductWarranty.code" />
<property qualifier="ProductWarranty.catalogVersion" />
<property qualifier="ProductWarranty.active" />
<property qualifier="Item.pk"/>
</sort-properties>
</search>
<label spring-bean="sbdProductWarrantyLabelProvider"/>
</base>
Base configuration defines base search and sort properties and also product
warranty label used wherever product warranty is selected.
Search configuration defines on which fields are being considered for a
general search in product cockpit. Any text entered in base search field
(refer wiki) will be carried search on code and catalogVersion is considered
based on the user catalog access for the ProductWarranty.
Sort configuration defines which fields are considering for the sorting. By
default the first attribute which is defined under sort properties is considered
for sorting.
Labels are used when a product warranty is selected for a product. If not
used warranty primary key will be displayed. Since ProductWarranty is a
composed type Hybris doesnt understand how to render the attribute.
Hybris understands the automic attributes (e.g. String, Collection etc)
editorArea_ProductWarranty.xml
editor area defines the layout in product cockpit for creation and updating of
ProductWarranty type.
gridview_ProductWarranty.xml
Product cockpit provides two layouts grid and list views for search results.
For grid view below is the configuration
listViewSelector_ProductWarranty.xml
List ivew selector configuration will be used to display the search results
when a product warranty type is selected from the reference sections.
wizardConfig_ProductWarranty.xml
This is the final file for the type configuration. Wizard configuration defines
how the product warranty field would be configured in the cockpits. ( More
info refer wiki)
<?xml version="1.0" encoding="UTF-8"?>
<wizard-config selectMode="true" createMode="false" activateAfterCreate="true"
createWithinPopup="false" createWithinEditor="false">
<displayed-properties>
<group qualifier="General" visible="true" initially-opened="false">
<label key="cockpit.config.label.General" />
<property qualifier="ProductWarranty.code"/>
<property qualifier="ProductWarranty.active" />
<property qualifier="ProductWarranty.catalogVersion"/>
</group>
</displayed-properties>
</wizard-config>