Retrieving objects by transforming Nouns
In this lesson, you define how Recipe objects are retreived and transformed for display in Management Center.
About this task
Management Center sends Uniform Resource Locator (URL) requests and receives XML-formatted Management Center objects, whereas WebSphere Commerce services send and receive BOD messages. The Management Center web application mediates messages between the Management Center and WebSphere Commerce. Requests that are sent from the Management Center are transformed into the appropriate BOD requests of the WebSphere Commerce service and the responses of those BOD requests are transformed into the XML representation that the Management Center understands. The steps that are required to transform messages differs based on the type of message.
Procedure
- In the Enterprise Explorer view, expand
- Create a directory that is named com.mycompany.commerce.project.
-
Within this directory, create an XML file that is named
get-data-config.xml.
This file is to include all primary data types, client facade classes, and expression builders that are used in JSP tags.
- Copy the contents of the get-data-config.xml within the TutorialSource\LOBTools\WebContent\WEB-INF\config\com.mycompany.commerce.project directory, where TutorialSource is the directory where you extracted the sample code.
-
Add the copied file contents into your new get-data-config.xml file. Your
file can resemble the following code sample:
<?xml version="1.0" encoding="UTF-8"?> <_config:get-data-config xmlns:_config="http://www.ibm.com/xmlns/prod/commerce/foundation/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ibm.com/xmlns/prod/commerce/foundation/config ../../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> <!-- Project Collection services --> <expression-builder> <name>getAllProjectCollections</name> <data-type-name>ProjectCollection</data-type-name> <expression-template>{_wcf.ap=$accessProfile$}/ProjectCollection</expression-template> <param> <name>accessProfile</name> <value>MyCompany_Admin_Details</value> </param> </expression-builder> <expression-builder> <name>getProjectCollectionById</name> <data-type-name>ProjectCollection</data-type-name> <expression-template>{_wcf.ap=$accessProfile$}/ProjectCollection[ProjectCollectionIdentifier[(UniqueID='$collectionId$')]]</expression-template> <param> <name>accessProfile</name> <value>MyCompany_Admin_Details</value> </param> </expression-builder> <expression-builder> <name>findProjectCollectionsBasicSearch</name> <data-type-name>ProjectCollection</data-type-name> <class>com.ibm.commerce.foundation.internal.client.taglib.util.SearchExpressionBuilder</class> <method>formatExpression</method> <param> <name>template</name> <value>/ProjectCollection[search(ProjectCollectionIdentifier/ExternalIdentifier/Name='$name$')]</value> </param> <param> <name>accessProfile</name> <value>MyCompany_Admin_Details</value> </param> </expression-builder> <!-- Project services --> <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_Admin_Summary</value> </param> </expression-builder> <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_Admin_Summary</value> </param> </expression-builder> <expression-builder> <name>getProjectCollectionReference</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_Admin_ProjectColRel</value> </param> </expression-builder> <expression-builder> <name>getProjectMaterial</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_Admin_ProjectMaterial</value> </param> </expression-builder> <expression-builder> <name>getProjectInstruction</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_Admin_ProjectInstruction</value> </param> </expression-builder> <expression-builder> <name>getProjectTool</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_Admin_ProjectTool</value> </param> </expression-builder> <expression-builder> <name>findProjectsBasicSearch</name> <data-type-name>Project</data-type-name> <class>com.ibm.commerce.foundation.internal.client.taglib.util.SearchExpressionBuilder</class> <method>formatExpression</method> <param> <name>template</name> <value>/Project[search(ProjectIdentifier/ExternalIdentifier/Name='$name$')]</value> </param> <param> <name>accessProfile</name> <value>MyCompany_Admin_Summary</value> </param> </expression-builder> <expression-builder> <name>getProjectsByprojectId</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_Admin_Summary</value> </param> </expression-builder> </_config:get-data-config>
There are three main parts in get-data-config.xml:- The data type element declares a supported data type for the getData action.
- The client-facade element declares the component client facade that invokes the service to fetch the data.
- The expression-builder handles building the XPath expression with the published input parameters.
- The <name> node uniquely identifies the expression builder, and is used by getData tags in the project JSPs when you refer 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 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 that define a parameter to be passed to the query template file. Each expression builder is associated with a specific Access Profile. This Access Profile, together with the XPath query previously defined , uniquely identifies a query in the query template file.
-
There are two types of JSP files that perform transformations, controller JSP files and
serialization JSP fragments. Controller JSP files create, send, and receive BOD messages from the
WebSphere Commerce server. Serialization JSP fragments transform Nouns to XML.
Each object has several
wcfGetChildrenService
andwcfGetReferenceService
to retrieve child objects and reference objects. For example, you define three instances ofwcfGetChildrenService
to retrieve ingredients, instructions, and associations of a recipe when you define one of the following file:- Recipe primary object definition
wcf:getData
tag to create, send, and receive BOD objects from the WebSphere Commerce Server. The objects are parsed by serialization JSP fragments to be transformed from Nouns to XML. The XML works as a data set for property view classes.In this step of the lesson, you create new JSP files to transform the Noun to the XML object:
Note: The XML format and JSP files have the following characteristics:- The XML format must begin with <?xml version="1.0" encoding="UTF-8"?> to ensure multilingual support.
- The XML format must contain dynamic values only. Define all constant values in the Management Center.
- All Management Center objects must have only one property that uniquely identifies the object. Although the object can be uniquely identified with two properties, the Management Center can use only one property. For information about defining Management Center objects, see Object definitions.
- The names of the JSP files must follow the existing naming conventions to indicate the purpose of the JSP file. For example, GetRecipeByCollection.jsp.
- The result set that is returned when multiple objects are returned for Find services must be
wrapped in the objects document.
For more information about Get result paging, see Get Request and the Show Response.<objects recordSetReferenceId="${show.recordSetReferenceId}" recordSetCompleteIndicator="${show.recordSetCompleteIndicator}" recordSetTotal="${show.recordSetTotal}" recordSetCount="${show.recordSetCount}" recordSetStartNumber="${show.recordSetStartNumber}">