Creating an expression builder
An expression builder is used by the wcf:getData
tag on a JSP file to
construct an XPath expression that is used by an HCL Commerce service to retrieve
data.
About this task
All expression builders are defined in the get-data-config.xml file. The base get-data-config.xml file for each HCL Commerce service module is located in \LOBTools\WebContent\WEB-INF\config\com.ibm.commerce.component\get-data-config.xml. You cannot modify this file directly. Instead, create the \LOBTools\WebContent\WEB-INF\config\com.ibm.commerce.component-ext extension folder to store the extended get-data-config.xml file.
Procedure
- Open HCL Commerce Developer.
-
All new expression builders must be added to a custom get-data-config.xml
file. Do not modify default HCL Commerce files. If you have not already created a
get-data-config file:
-
If your expression builders use any custom data types, you must include a
<data-type>
and<client-facade>
element to instruct the expression builder how to work with your data. The<data-type>
element defines the Java class of your custom data type, and the<client-facade>
element defines the class, and method to call on that class, to retrieve the objects.<data-type> <name>Project</name> <type>com.mycompany.commerce.project.facade.datatypes.ProjectType</type> </data-type> <client-facade> <data-type-name>Project</data-type-name> <class>com.mycompany.commerce.project.facade.client.ProjectFacadeClient</class> <method>getProject</method> </client-facade>
-
In the file editor, add one or more expression builders. An example expression builder that
performs Catalog search is provided below as an example:
<expression-builder> <name>findAllCatentriesByWarrantySearchNumeric</name> <data-type-name>CatalogEntry</data-type-name> <class> com.ibm.commerce.catalog.internal.client.taglib.util.CatalogSearchExpressionBuilder </class> <method>formatExpression</method> <param> <name>template</name> <value> /CatalogEntry[(@catalogEntryTypeCode='$catEntryTypes$') and search(UserData/UserDataField/Warterm='$warterm$' or contains(UserData/UserDataField/Wartype,'$wartype$') or contains(Description/Attributes/careinstruction,'$careinstruction$'))] </value> </param> <param> <name>accessProfile</name> <value>MyCompany_All</value> </param> </expression-builder>
The meanings of the XML elements are described in the following list:- name
- The name of the expression builder. The
wcf:getData
tag in the controller JSP file refers to this name. - data-type-name
- The name of the data type with which this expression builder definition will be associated. In the example the expression builder is defined for a search that is associated with CatalogEntry
- class
- The fully qualified Java class name of the expression builder. The default is used in the example for Catalog search.
- method
- The method name of the expression builder. This method must accept a
java.util.Map
and return an instance ofcom.ibm.commerce.oagis9.datatypes.ExpressionType
. The default is used in the example. - param
- The
param
element is used to declare parameters that are expected by the expression builder. It is assigned byname
andvalue
These child nodes define a parameter to be passed to the query template file.- template
- The search template used to generate the XPath key and locate the SQL statement in the query template file.
- accessProfile
- Each expression builder is associated with a specific Access Profile. This Access Profile, together with the XPath query defined above, uniquely identifies a query in the query template file.
Note: The data service layer has a specialized convention for UserData in the search mapping, as/UserData/UserDataField/Warterm
is not valid XPath. This notation is used to represent the value of theWarterm
andWartype
attributes in the UserData field in the example. - Save and close the file.