Create a new search expression
Search expressions performed by WebSphere Commerce services use an expression language known as XML Path Language, or, more commonly, XPath. If we are new to XPath, we must familiarize yourself with the notation before proceeding with this customization task. WebSphere Commerce has also extended the notation for XPath to allow control over the display and ordering of the results, as well as selection of business logic command implementations.
Task info
To create a new search expression:
Procedure
- Create a new XPath search expression that describes the search we want to perform. For example, if to create a service where the customer can search the catalog based on a price range, use the following XPath to perform the query:
{_wcf.ap=$accessProfile$}/CatalogEntry[Price[StandardPrice[Price[(Price[@currency='$currency$'] and Price >= '$minPrice$') and (Price[@currency='$currency$'] and Price <= '$maxPrice$') ]]]]
Note: The XPath expression matches the structure of the logical schema. When searching on custom components, a well-defined logical model makes it simpler to write your XPath expressions.
- In our customization project, create a new service command that implements the FetchNounCmd interface. This command performs the search expression. An example of a new service command can be downloaded; see FetchCatalogEntryByPriceRangeTaskCmdImpl.java. See the Design pattern for Get service implementation for more information.
Note: For member subsystem customization, one default fetch command does all the interpretation of the XPath for each noun. We must extend this command to create new search expressions. We need to call super.performExecute() in your performExecute(), and then select your data based on your new XPath query. For example:
public void performExecute() throws Exception { // Member subsystem code example follows (additional code may precede this ...) SelectionCriteriaMapper selectionCriteria = new SelectionCriteriaMapper(getGet().getExpression()); Map mapQueryParameters = selectionCriteria.getQueryParameters(); boolean bPersonFound = false; // Check if search expression is our customized expression based on LogonID: /Person[Credential[(LogonID='$logonID$')]] if (mapQueryParameters.get("LogonID") != null) { // Add customized code to find Person by logon ID ... bPersonFound = true; } // if Person was not found, call parent class for default expressions if ( !bPersonFound) { super.performExecute(): } //Code example ends -- additional code may follow this }
- Register your new command. When you do so, you need to associate the XPath search expression key with your new custom fetch command implementation with an SQL statement. For example:
insert into cmdreg (STOREENT_ID, INTERFACENAME, CLASSNAME,TARGET) VALUES (0,'com.ibm.commerce.catalog.facade.server.commands.FetchCatalogEntryCmd+/CatalogEntry[Price[StandardPrice[Price[(Price<= and Price[@currency=]) and (Price>= and Price[@currency=])]]]]', 'com.mycompany.commerce.customization.catalog.FetchCatalogEntryByPriceRangeTaskCmdImpl', 'Local');Notes:
- The interface name contains the name of the command concatenated with the XPath.
- For member subsystem customization, you need to update the CMDREG entry for the existing default fetch command. Also, no XPath details are included in the SQL update.
- Restart test servers.
Related concepts
Design patterns
Design pattern for Get service implementation (SOI)
Related tasks
Creating the component facade
Extending a noun
Creating the service command
Related reference
WebSphere Commerce extended XPath notation