Processing Management Center services by transforming URL requests into BODs

In this lesson, you process the Management Center services for the new Recipes tool by 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. 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. However, 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 a Spring controller configuration to define how to process the Management Center services.
    1. In the Enterprise Explorer view, expand LOBTools > WebContent > WEB-INF
    2. Open the spring-extension.xml file for editing.
    3. In a file manager utility, browse to the spring-extension.xml within the TutorialSource\LOBTools\WebContent\WEB-INF directory, where TutorialSource is the directory where you extracted the sample code.
    4. Copy the contents of this spring-extension.xml file into the spring-extension.xml file within your workspace. Do not copy over any duplicate configurations or code. The spring-extension.xml file within your workspace now includes the controller configurations for the Recipes tool.
      The following code snippet shows the controller mappings for a Change BOD and a Process BOD service.
      
      <bean id="/UpdateRecipe" 
        class="com.ibm.commerce.foundation.client.facade.bod.servlet.spring.BusinessObjectDocumentController">
        <property name="urlObject" value="Project"/>
        <property name="contextParameters">
          <props>
            <prop key="storeId">storeId</prop>
            <prop key="langId">langId</prop>
          </props>
        </property>
        <property name="verb" value="Change"/>
        <property name="documentRootFactory" value="com.mycompany.commerce.project.facade.datatypes.ProjectFactory"/>
        <property name="clientLibrary" value="com.mycompany.commerce.project.facade.client.ProjectFacadeClient"/>
        <property name="clientLibraryMethod" value="changeProject"/>
        <property name="actionCode" value="Change"/>
      </bean>
      ...
      <bean id="/CreateRecipe" 
        class="com.ibm.commerce.foundation.client.facade.bod.servlet.spring.BusinessObjectDocumentController">
        <property name="urlObject" value="Project"/>
        <property name="contextParameters">
          <props>
            <prop key="storeId">storeId</prop>
            <prop key="langId">langId</prop>
          </props>
        </property>
        <property name="verb" value="Process"/>
        <property name="documentRootFactory" value="com.mycompany.commerce.project.facade.datatypes.ProjectFactory"/>
        <property name="clientLibrary" value="com.mycompany.commerce.project.facade.client.ProjectFacadeClient"/>
        <property name="clientLibraryMethod" value="processProject"/>
        <property name="actionCode" value="Create"/>
        <property name="var" value="projects"/>
        <property name="successView" value="/jsp/mycompany/recipe/RespondCreateRecipe.jsp"/>
      </bean>
      contextParameters
      The URL parameters that represent information that is placed in the business context area of the request. The name of the context parameter is the URL parameter. For example, 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 Spring controller configuration, 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 the wc-project-clientobjects.xml from the TutorialSource\LOBTools\WebContent\WEB-INF\config\com.mycompany.commerce.project directory into this directory.
    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 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/ProjectMaterialDescription" part="true" />			
          <_config:NounElement name="Instruction/ProjectInstructionDescription" part="true" />
          <_config:NounElement name="Material/ProjectMaterialIdentifier" />
          <_config:NounElement name="Collection/ProjectCollectionIdentifier" />
        </_config:Noun>
      		
        <_config:Noun name="ProjectCollection">
          <_config:NounElement name="ProjectCollectionIdentifier" />
          <_config:NounElement name="Description" part="true"/>
        </_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 Spring extensions configuration file:
    1. In the Spring-extension.xml file, locate the following lines before the closing </beans> tag in the file:
      
      <bean class="com.ibm.commerce.foundation.client.facade.bod.servlet.spring.BusinessObjectDocumentConfiguration" 
        lazy-init="false">
        <property name="config" value="/WEB-INF/config/com.mycompany.commerce.project/wc-project-clientobjects.xml" />	
      </bean>
    2. If these lines are not present, copy the code into the file before the closing </beans> tag.