Introduced in Feature Pack 2

Enabling view versions of Recipe and RecipeCollection

Introduced in Feature Pack 2 In this lesson, you update query template file to add the version parameter. By doing this, you are able to retrieve the data for the different versions. You also enable version control for the custom objects and add versionId context data to retrieve version information for the corresponding services such as GetChildrenService, GetReferenceService, and RefreshService.

About this task

Procedure

  1. Update the query template file to add the version parameter.
    1. In the Enterprise Explorer view, expand WC > xml > config > com.mycompany.commerce.project.
    2. Open the wc-query-Project-get.tpl file.
    3. Add param=versionable to all of the versionable queries as shown in bold:
      BEGIN_XPATH_TO_SQL_STATEMENT
      name=/Project[ProjectIdentifier[(UniqueID=)]]
      base_table=XPROJECT
      param=versionable
      sql=	
      SELECT
      XPROJECT.$COLS:XPROJECT_ID$
      FROM
      XPROJECT
      WHERE
      XPROJECT.XPROJECT_ID IN (?UniqueID?)
      END_XPATH_TO_SQL_STATEMENT
    4. Similarly, update the template file wc-query-ProjectCollection-get.tpl to make the queries versionable.
    5. Save the changes.
  2. Add the versioned context data to the services:
    1. In the Enterprise Explorer view, expand LOBTools > WebContent > config > mycompany > recipe > objectDefinitions.
    2. Open the RecipePrimaryObjectDefinition.def file.
      Notice the following code for GetChildrenService:
      <GetChildrenService objectTypes="RecipeIngredients" url="/cmc/GetRecipeChildren-Ingredients">
      		<ServiceParam name="storeId"/>
      		<ServiceParam name="recipeId" propertyName="recipeId"/>
      	</GetChildrenService>
      	<GetChildrenService objectTypes="RecipeInstruction" url="/cmc/GetRecipeChildren-Instruction">
      		<ServiceParam name="storeId"/>
      		<ServiceParam name="recipeId" propertyName="recipeId"/>
      	 </GetChildrenService>
      	<GetChildrenService objectTypes="RecipeAssociation" url="/cmc/GetRecipeChildren-Association">
      		<ServiceParam name="storeId"/>
      		<ServiceParam name="recipeId" propertyName="recipeId"/>
      	</GetChildrenService>
      You can find out the corresponding JSP files for supporting the service by looking into the structs-extension.xml according to the URL information.
      • Expand LOBTools > WebContent > WEB-INF, and open the struts-extension.xml file.
      • Search for GetRecipeChildren-Ingredients in the file, you get the following:
        <action path="/GetRecipeChildren-Ingredients" forward="/jsp/mycompany/recipe/GetRecipeChildren-Ingredients.jsp" />
    3. Expand LOBTools > WebContent > jsp > mycompany > recipe, open the GetRecipeChildren-Ingredients.jsp file; add the versionId parameter as shown in bold:
      <wcf:contextData name="storeId" data="${param.storeId}"/>
      	<!-- add the parameter for the versionId -->
      	<wcf:contextData name="versionId" data="${param.objectVersionId}"/>
      	<!-- End -->
      	
      <wcf:param name="projectId" value="${param.recipeId}"/>
    4. Similarly, add the same code into the following JSP files located in LOBTools > WebContent > jsp > mycompany > recipe:
      • GetRecipeChildren-Instruction.jsp
      • GetRecipeChildren-Association.jsp
      • GetRecipeByRecipeId.jsp
      • GetRecipesByCollection.jsp
      • GetRecipeCollectionById.jsp
    5. Save all your changes.
  3. Register the version insert more command for the custom access profile into cmdreg.
    The InsertMoreNounVersionMetaDataCmdImpl looks up the version information for both the ProjectCollection noun and the Project noun and adds the version information to the response.
    
    insert into cmdreg (storeent_id, interfacename, classname, target)
    values (0, 'com.mycompany.commerce.project.facade.server.commands.InsertMoreProjectDataCmd+MyCompany_Admin_Summary.0',
    'com.ibm.commerce.foundation.server.version.command.InsertMoreNounVersionMetaDataCmdImpl', 'Local');
    
    insert into cmdreg (storeent_id, interfacename, classname, target)
    values (0, 'com.mycompany.commerce.project.facade.server.commands.InsertMoreProjectCollectionDataCmd+MyCompany_Admin_Details.0',
    'com.ibm.commerce.foundation.server.version.command.InsertMoreNounVersionMetaDataCmdImpl', 'Local');

    The InsertMoreNounVersionMetaDataCmdImpl looks up the version information for the Recipe and RecipeCollection nouns and adds the version information to the response.

  4. Register the version mediator for the Project and ProjectCollection nouns.
    1. Open WC\xml\config\com.mycompany.commerce.project\wc-business-object-mediator.xml.
    2. Locate the line <!--Here is the example to enable property mapping in the file, and add the following code before the line.
      <!-- Add the version mediator for the Project -->
      <_config:mediator className="com.ibm.commerce.content.server.version.mediator.VersionBusinessObjectMediatorImpl" 
      					interfaceName="com.ibm.commerce.foundation.server.version.mediator.VersionBusinessObjectMediator">
      		<_config:mediator-properties>
      			<_config:mediator-property name="uniqueIDProperty" value="ProjectIdentifier/UniqueID" />
      		</_config:mediator-properties>
      </_config:mediator>
    3. Locate the following code snippet:
      <_config:mediator
      			interfaceName="com.ibm.commerce.foundation.server.services.dataaccess.bom.mediator.ChangeBusinessObjectMediator"
      			className="com.mycompany.commerce.project.facade.server.services.dataaccess.bom.mediator.ChangeProjectCollectionMediator">
      		<_config:part-mediator
       	interfaceName="com.ibm.commerce.foundation.server.services.dataaccess.bom.mediator.ChangeBusinessObjectPartMediator">
      			<_config:part-mediator-implementation className="com.mycompany.commerce.project.facade.server.services.dataaccess.bom.mediator.ChangeProjectCollectionBasePartMediator" />
      			<_config:part-mediator-implementation className="com.mycompany.commerce.project.facade.server.services.dataaccess.bom.mediator.ChangeProjectCollectionDescriptionPartMediator" />
        	</_config:part-mediator>
      </_config:mediator>
    4. Add the following code for the version mediator for the ProjectCollection noun:
      <!-- Add the version mediator for the ProjectCollection -->
      <_config:mediator className="com.ibm.commerce.content.server.version.mediator.VersionBusinessObjectMediatorImpl" 
      					interfaceName="com.ibm.commerce.foundation.server.version.mediator.VersionBusinessObjectMediator">
      		<_config:mediator-properties>
      			<_config:mediator-property name="uniqueIDProperty" value="ProjectCollectionIdentifier/UniqueID" />
      		</_config:mediator-properties>
      	</_config:mediator>
    5. Save your changes.

Results