Develop > Persistence layer > Work with WebSphere Commerce services > Create the component facade


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 you are new to XPath, 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.

To create a new search expression:


Procedure

  1. Create a new XPath search expression that describes the search to perform. For example, 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$')
    ]]]]
    

    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 the XPath expressions.

  2. In the 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.

    For member subsystem customization, one default fetch command does all the interpretation of the XPath for each noun. You must extend this command to create new search expressions. You need to call super.performExecute() in the performExecute(), and then select the 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 
            }
    

  3. Register your new command. When you do so, associate the XPath search expression key with the 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:

    1. The interface name contains the name of the command concatenated with the XPath.

    2. For member subsystem customization, update the CMDREG entry for the existing default fetch command. Also, no XPath details are included in the SQL update.

  4. Restart WebSphere Commerce


Related concepts

WebSphere Commerce Web services

WebSphere Commerce service module

Component facade interfaces

Design patterns

Design pattern for Get service implementation


Related tasks

Create the component facade

Extend a noun

Create the service command

Related reference

WebSphere Commerce extended XPath notation


+

Search Tips   |   Advanced Search