Enabling view versions of Recipe and RecipeCollection
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
- Update the query template file to add the version parameter.
- In the Enterprise Explorer view, expand WC > xml > config > com.mycompany.commerce.project.
- Open the wc-query-Project-get.tpl file.
- 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
- Similarly, update the template file wc-query-ProjectCollection-get.tpl to make the queries versionable.
- Save the changes.
- Add the versioned context data to the services:
- In the Enterprise Explorer view, expand LOBTools > WebContent > config > mycompany > recipe > objectDefinitions.
- Open the RecipePrimaryObjectDefinition.def file.
Notice the following code for
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.<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>
- 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" />
- 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}"/>
- 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
- Save all your changes.
- 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. - Register the version mediator for the Project and ProjectCollection
nouns.
- Open WC\xml\config\com.mycompany.commerce.project\wc-business-object-mediator.xml.
- 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>
- 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>
- 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>
- Save your changes.