Tutorials > Management Center > Modify the storefront to display Recipe information

< Previous | Next >


Create new expression builders to process Recipe service requests

In this lesson, we will create expression builders that allow the storefront to access the Recipe and RecipeCollection objects. The get-data-config.xml file contains expression builders, each represents a different SQL query defined in the Recipe Project's query template file. By referencing the appropriate expression builder, getData tags in the storefront JavaServer Pages (JSP) files can retrieve specific data from the database.


Procedure

  1. Create a get-data-config file for the Recipe Project.

    • In the Enterprise Explorer view, expand Stores > WebContent > WEB_INF > config.

    • Right-click config and select New > Folder.

    • In the Folder name field, enter com.mycompany.commerce.project.

    • If the com.mycompany.commerce.project folder is not visible, right-click the config directory in the Enterprise Explorer view and click Refresh.

    • Right-click the com.mycompany.commerce.project folder and select New > File > Next.

    • In the File name field, enter get-data-config.xml and click Finish. The newly created get-data-config.xml file automatically opens.

  2. Insert recipe related expression builders into the get-data-config file. Copy the following code into the get-data-config.xml file:

    <?xml version="1.0" encoding="UTF-8"?>
    <wcf:get-data-config   xmlns:wcf="http://www.ibm.com/xmlns/prod/commerce/foundation"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.ibm.com/xmlns/prod/commerce/foundation ../../xsd/get-data-config.xsd ">
     
        <data-type>
            <name>Project</name>
            <type>com.mycompany.commerce.project.facade.datatypes.ProjectType</type>
        </data-type>
        <data-type>
            <name>ProjectCollection</name>
            <type>com.mycompany.commerce.project.facade.datatypes.ProjectCollectionType</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>
        <client-facade>
            <data-type-name>ProjectCollection</data-type-name>
            <class>com.mycompany.commerce.project.facade.client.ProjectFacadeClient</class>
            <method>getProjectCollection</method>
        </client-facade>
    
        <!-- Gets Projects by their UniqueID -->
        <expression-builder>
            <name>getProjectsByID</name>
            <data-type-name>Project</data-type-name>
            <expression-template>{_wcf.ap=$accessProfile$}/Project[ProjectIdentifier[(UniqueID='$projectID$')]]</expression-template>
            <param>
                <name>accessProfile</name>
                <value>MyCompany_Store_Details</value>
            </param>
        </expression-builder>
    
        <!-- Gets all ProjectCollections. -->   
        <expression-builder>       
            <name>getAllCollections</name>       
            <data-type-name>ProjectCollection</data-type-name>       
            <expression-template>{_wcf.ap=$accessProfile$}/ProjectCollection</expression-template>       
            <param>           
                <name>accessProfile</name>           
                <value>MyCompany_Store_Details</value>       
            </param>           
        </expression-builder>      
    
        <!-- Gets all Projects that are not assigned to a ProjectCollection. -->
        <expression-builder>       
            <name>getUnassignedProjects</name>       
            <data-type-name>Project</data-type-name>       
            <expression-template>{_wcf.ap=$accessProfile$}/Project[Unassigned]</expression-template>       
            <param>
                <name>accessProfile</name>
                    <value>MyCompany_Store_Details</value>       
            </param>       
        </expression-builder>      
    
        <!-- Gets all Projects assigned to a particular ProjectCollection. -->   
        <expression-builder>       
            <name>getProjectsByCollection</name>       
            <data-type-name>Project</data-type-name>       
            <expression-template>{_wcf.ap=$accessProfile$}/Project[Collection[ProjectCollectionIdentifier[(UniqueID='$collectionID$')]]]</expression-template>       
            <param>           
                <name>accessProfile</name>           
                <value>MyCompany_Store_Summary</value>       
            </param>           
        </expression-builder>
          
        <!-- Gets the Projects using a particular CatalogEntry as a material. -->   
        <expression-builder>       
            <name>getProjectsUsingAsMaterial</name>       
            <data-type-name>Project</data-type-name>       
            <expression-template>{_wcf.ap=$accessProfile$}/Project[Material[CatalogEntry[CatalogEntryIdentifier[(UniqueID='$catEntryId$')]]]]
    </expression-template>
            <param>           
                <name>accessProfile</name>           
                <value>MyCompany_Store_Summary</value>       
            </param>           
        </expression-builder>      
    
        <!-- Gets the Projects using a particular CatalogEntry as a tool. -->   
        <expression-builder>       
            <name>getProjectsUsingAsTool</name>       
            <data-type-name>Project</data-type-name>       
            <expression-template>{_wcf.ap=$accessProfile$}/Project[Tool[CatalogEntryIdentifier[(UniqueID='$catEntryId$')]]]
    </expression-template>       
            <param>           
                <name>accessProfile</name>           
                <value>MyCompany_Store_Summary</value>       
            </param>           
        </expression-builder>   
    </wcf:get-data-config>
    

    Each expression builder has the following elements:

    • The <name> node uniquely identifies the expression builder and is used by getData tags in the recipe JSP files when referring to an expression builder.

    • The <data-type-name> node contains the noun type that is returned by this expression builder.

    • The <expression-template> node refers to an XPath query defined in the Recipe project query template file, which is used to retrieve specific information from the database. Parameters such as $projectID$ can be passed to the expression builder by a getData tag.

    • Each <param> node contains a pair of <name> and <value> child nodes, which define a parameter that is passed to the query template file. This parameter associates each expression builder with a specific Access Profile. This Access Profile, together with the XPath query defined above, uniquely identifies a query in the query template file.

< Previous | Next >


+

Search Tips   |   Advanced Search