Processing Management Center services by transforming URL requests into BODs

Processing Management Center services involves transforming URL requests into Process BODs and Change BODs.

About this task

It is sometimes difficult to determine whether a URL is transferred to a Process service or a Change service. In general, when you are working with primary objects, such as a product, URLs are handled by a Process service, and when you are 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

  1. Create new Struts actions to process Management Center services:
    1. In the Enterprise Explorer view, expand LOBTools > WebContent > WEB-INF
    2. Copy the struts-extension.xml file from the TutorialSource\LOBTools\WebContent\WEB-INF directory to the WEB-INF directory that you navigated to, overwriting the current copy of the file. TutorialSource is the location where you extracted the Tutorial sample source code.
    3. 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 that is 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 that the client library invokes.
      verb
      The verb of the BOD documentRootFactory, which is the factory that is used to create the BOD object.
  2. After you register the Struts actions, you must configure the mapping between the URL parameters and BOD Nouns:
    1. In the Enterprise Explorer view, expand LOBTools > WebContent > WEB-INF > config > com.mycompany.commerce.project.
    2. 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 extracted the sample code.
    3. Within the mapping file, define the noun and noun part. Then, define the mapping between the URL parameters and the noun elements. The following sample code that shows 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>
      
      Note:
      • The Noun definition and NounElement definitions should be consistent with the noun and noun part that is 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.
  3. After you finish the mapping file, register the mapping file in the Struts configuration file:
    1. In the Enterprise Explorer view, expand LOBTools > WebContent > WEB-INF
    2. Open the struts-extension.xml file.
    3. 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>
      
    4. If these lines are not present, copy them into the file before the closing </struts-config>.