Tutorials > Management Center > Add a Recipes tool to the Management Center
Process Management Center services by transforming URL requests into BODs
Process Management Center services involves transforming URL requests into Process BODs and Change BODs.
It is sometimes difficult to determine whether a URL will be transferred to a Process service or a Change service. In general, when working with primary objects, such as a product, URLs are handled by a Process service, and when working with secondary objects, such as a product description, URLs are handled by a Change service. For example, adding a product transfers to a Process service with an actionCode of Add, but adding a product description is a Change service with an actionCode of Add and an actionExpression that points to the description.
An actionExpression is an element that represents a processing instruction that pertains to the request. The actionCode attribute indicates the operation, while the value points to the element to apply the action expression to.
An actionCode is a URL parameter that indicates the type of action to be performed on the Noun or Noun part. Valid values are Add and Delete.
Procedure
- Create new Struts actions to process Management Center services:
- In the Enterprise Explorer view, expand LOBTools > WebContent > WEB-INF
- Copy the struts-extension.xml file from TutorialSource\LOBTools\WebContent\WEB-INF to the WEB-INF directory that you navigated to, overwriting the current copy of the file. TutorialSource is the location where you unzipped the Tutorial sample source code.
- Open the struts-extension.xml file. New Struts actions are registered in the file. The following code is provided as a sample. It shows the mapping to a Change BOD and a Process BOD.
<action path="/UpdateRecipe" parameter="Project" type="com.ibm.commerce.foundation.client.facade.bod.servlet.struts.BusinessObjectDocumentAction" className="com.ibm.commerce.foundation.client.facade.bod.servlet.struts.BusinessObjectDocumentActionMapping"> <set-property property="contextParameters" value="storeId,langId" /> <set-property property="verb" value="Change" /> <set-property property="documentRootFactory" value="com.mycompany.commerce.project.facade.datatypes.ProjectFactory" /> <set-property property="clientLibrary" value="com.mycompany.commerce.project.facade.client.ProjectFacadeClient" /> <set-property property="clientLibraryMethod" value="changeProject" /> <set-property property="actionCode" value="Change"/> </action>
<action path="/CreateRecipe" parameter="Project" type="com.ibm.commerce.foundation.client.facade.bod.servlet.struts.BusinessObjectDocumentAction" className="com.ibm.commerce.foundation.client.facade.bod.servlet.struts.BusinessObjectDocumentActionMapping"> <set-property property="contextParameters" value="storeId,langId" /> <set-property property="verb" value="Process" /> <set-property property="documentRootFactory" value="com.mycompany.commerce.project.facade.datatypes.ProjectFactory" /> <set-property property="clientLibrary" value="com.mycompany.commerce.project.facade.client.ProjectFacadeClient" /> <set-property property="clientLibraryMethod" value="processProject" /> <set-property property="actionCode" value="Create"/> <set-property property="var" value="projects" /> <forward name="success" path="/jsp/mycompany/recipe/RespondCreateRecipe.jsp"/> </action>
- parameter
- A comma separated list of the URL parameters that represent information placed in the business context area of the request. Unless the colon override is specified, the name of the context parameter is the URL parameter. For example, if masterCatalogId:catalogId is specified, the URL parameter value of masterCatalogId is used, but the context parameter name is catalog. If storeId is specified, the URL parameter and context name are storeId. This property is optional.
- actionCode
- The name of the URLParameterGroup in wc-project-clientobjects.xml, which is created in the next step.
- clientLibraryMethod
- The method to invoke on the client library to initiate the service request.
- clientLibrary
- The class name of the that the client library invokes.
- verb
- The verb of the BOD documentRootFactory, which is the factory that is used to create the BOD object.
- After registering the Struts actions, configure the mapping between the URL parameters and BOD Nouns:
- In the Enterprise Explorer view, expand LOBTools > WebContent > WEB-INF > config > com.mycompany.commerce.project.
- Import TutorialSource\LOBTools\WebContent\WEB-INF\config\com.mycompany.commerce.project\wc-project-clientobjects.xml to this directory, where TutorialSource is the directory where you unzipped the sample code.
- Within the mapping file, define the noun and noun part first, then define the mapping between the URL parameters and the noun elements. The following sample code show the mappings:
<_config:NounDefinitions> <_config:Noun name="Project"> <_config:NounElement name="ProjectIdentifier" /> <_config:NounElement name="Description" part="true" /> <_config:NounElement name="Tool" part="true" /> <_config:NounElement name="Material" part="true" /> <_config:NounElement name="Instruction" part="true" /> <_config:NounElement name="Collection" part="true" /> <_config:NounElement name="Material/ProjectMaterialIdentifier" /> <_config:NounElement name="Collection/ProjectCollectionIdentifier" /> </_config:Noun> </_config:NounDefinitions> <_config:URLDefinitions> <_config:URLParameterGroup name="Project" noun="Project"> <_config:URLParameter name="recipeId" nounElement="/ProjectIdentifier/UniqueID" key="true" return="true"/> <_config:URLParameter name="name" nounElement="/ProjectIdentifier/ExternalIdentifier/Name" key="false" /> <_config:URLParameter name="time" nounElement="/TimeToComplete" key="false" /> <_config:URLParameter name="difficulty" nounElement="/Difficulty" key="false" /> <_config:IncludeURLParameterGroup urlParameterGroup="Description" /> <_config:IncludeURLParameterGroup urlParameterGroup="Material" /> <_config:IncludeURLParameterGroup urlParameterGroup="Instruction" /> <_config:IncludeURLParameterGroup urlParameterGroup="Tool" /> <_config:IncludeURLParameterGroup urlParameterGroup="Collection" /> </_config:URLParameterGroup> <_config:URLParameterGroup name="Description" noun="Project"> <_config:URLParameter name="recipeId" nounElement="/ProjectIdentifier/UniqueID" key="true" /> <_config:URLParameter name="languageId" nounElement="/Description/@language" key="true" /> <_config:URLParameter name="sDesc" nounElement="/Description/ShortDescription" key="false" /> <_config:URLParameter name="lDesc" nounElement="/Description/LongDescription" key="false" /> </_config:URLParameterGroup> ... ... </_config:URLDefinitions>
- The Noun definition and NounElement definitions should be consistent with the noun and noun part defined in the service module. <_config:Noun represents the noun while <_config:NounElement represents the noun part and should mark with part="true".
- <_config:URLParameterGroup is used to provide the mapping from the Model Object and Model Property in the user interface, to the Noun element on the service side. The name in each URLParameter represents the parameter in the service doRequest URL, and the value comes from the model property in the user interface object XML.
- After you finish the mapping file, register the mapping file in the Struts configuration file:
- In the Enterprise Explorer view, expand LOBTools > WebContent > WEB-INF
- Open the struts-extension.xml file.
- Within the Struts config file, locate the following lines before the closing </struts-config> in the file:
<plug-in className="com.ibm.commerce.foundation.client.facade.bod.servlet.struts.BusinessObjectDocumentPlugInImpl"> <set-property property="config" value="/WEB-INF/config/com.mycompany.commerce.project/wc-project-clientobjects.xml" /> </plug-in>
- If these lines are not present, copy them into the file before the closing </struts-config>.