Enabling viewing custom object versions on the UI

To enable viewing version objects in the UI, you create a serialization JSP file that retrieves the version object data, and you also update the query template file to make the SQL queries versionable to retrieve the different version information.

Before you begin

  • Ensure that the custom tables have already been added to the version schema.
  • Review the following topic for additional information about viewing version details: Viewing version details.

Procedure

  1. Create a serialization JSP file to transform the server version objects into XML that the client understands.
  2. Update your custom query template file.
    To view the version information, you must update the query template file. The query template file defines SQL queries that retrieve data from the server.

    When versions are displayed, some of the data must be retrieved from the version schema and other data must be retrieved from the base schema. You must determine whether you need to write version-specific queries. For more information about query template SQL generation, see Viewing version details.

    Here's an example of a custom query template file that retrieves different versions for the Recipe object using the version SQL generation.
    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
  3. Configure existing services to retrieve version-related information.
    The HCL Commerce framework shares services to retrieve information for the business objects and its versions. For example, a product object uses the following GetChildrenService in ProductPrimaryObjectDefinition.def to retrieve defining attributes:
    <GetChildrenService objectTypes="CatalogEntryDefiningAttribute" url="/cmc/GetCatalogEntryChildren-DefiningAttributes">
    	<ServiceParam name="storeId"/>
    	<ServiceParam name="defaultLanguageId"/>
    </GetChildrenService> 
    If you want to version defining attributes that belong to this Product, you can configure this service to retrieve defining attributes for the versions of this product or the product itself as follows:
    1. Identify the corresponding GetChildrenService as shown in the primary object definition of this business object.
    2. Use the Struts configuration file to identify the JSP file that provides this service:
      <action name="GetCatalogEntryChildren-DefiningAttributes">
      <result name="GetCatalogEntryChildren-DefiningAttributes">
      <param name="location">/jsp/commerce/catalog/restricted/GetCatalogEntryDefiningAttributes.jsp</param>
      </result>
      </action>
    3. In the GetCatalogEntryDefiningAttributes.jsp file, add the following context data to the getData service:
      <wcf:contextData name="versionId" data="${param.objectVersionId}"/> 
      The complete getData service code:
      <wcf:getData type="com.ibm.commerce.catalog.facade.datatypes.CatalogEntryType[]"
      var="catalogEntry"
      expressionBuilder="getCatalogEntryDefiningAttributesByID">
      	<wcf:contextData name="storeId" data="${param.storeId}"/>
      	<wcf:contextData name="versionId" data="${param.objectVersionId}"/>
      	<wcf:param name="catEntryId" value="${param.parentId}"/>
      	<wcf:param name="dataLanguageIds" value="${param.dataLanguageIds}"/>
      </wcf:getData> 

      When a content version service is invoked, the versionId context data indicates to the getData service on the server side whether the request is for the business object or for the business object version. For example, when you open a product, the getData service is invoked to retrieve defining attribute information. In this case, an empty value is assigned to the versionId parameter; because this is not a product version. However, if you open a product version, a non-empty value is assigned to the versionId parameter, and the getData service uses this ID to return the defining attribute information for the particular product version.

    4. If you are versioning other child objects of this primary object, repeat the preceding steps for the corresponding GetChildrenService.
    5. If you decide to version a particular relationship that belongs to a business object, for example, the parent category of a product, you must configure the corresponding GetReferencesService in ProductPrimaryObjectDefinition.def:
      <GetReferencesService url="/cmc/GetCatalogEntryParent-MasterCatalogCatalogGroup">
      	<ServiceParam name="storeId"/>
      	<ServiceParam name="masterCatalogId"/>
      	<ServiceParam name="catentryId" propertyName="catentryId"/>
      	<ServiceParam name="childType" value="ChildProduct"/>
      </GetReferencesService> 
    6. Use the Struts configuration file to identify the JSP file that provides this service:
      <action name="GetCatalogEntryParent-MasterCatalogCatalogGroup">
      <result name="GetCatalogEntryParent-MasterCatalogCatalogGroup">
      <param name="location">/jsp/commerce/catalog/restricted/GetCatalogEntryParent-ReferenceMasterCatalogGroup.jsp</param>
      </result>
      </action>
    7. In the GetCatalogEntryParent-ReferenceMasterCatalogGroup.jsp file, add the following context data to the getData service:
      <wcf:contextData name="versionId" data="${param.objectVersionId}"/> 
      The complete getData service code:
      <wcf:getData type="com.ibm.commerce.catalog.facade.datatypes.CatalogEntryType"
      var="catalogEntry"
      expressionBuilder="getCatalogEntrySummaryByID"
      varShowVerb="showCatalogEntryVerb">
      	<wcf:contextData name="storeId" data="${param.storeId}"/>
      	<wcf:contextData name="catalogId" data="${param.masterCatalogId}"/>
      	<wcf:contextData name="versionId" data="${param.objectVersionId}"/>
      	<wcf:param name="catEntryId" value="${param.catentryId}"/>
      </wcf:getData> 
    8. Repeat the preceding steps to configure versioning of the other relationships of this business object.
    9. Include the versionId information for the RefreshService so that when users want to refresh the versioned object, the versioned information is retrieved again. For example, for the Product object, locate the RefreshService in the CatalogEntryPrimaryObjectDefinition.def file.
      <RefreshService url="/cmc/GetCatalogEntry">
      	<ServiceParam name="storeId"/>
      	<ServiceParam name="catalogId" parentProperty="true" parentType="CatalogAlias" propertyName="catalogId"/>
      	<ServiceParam name="catentryId" propertyName="catentryId"/>
      	<ServiceParam checkObjectDefinition="true" name="objectType" propertyName="objectType"/>
      </RefreshService> 
    10. Use the Struts configuration file to identify the JSP file that provides this service:
      <action name="GetCatalogEntry">
      <result name="GetCatalogEntry">
      <param name="location">/jsp/commerce/catalog/restricted/GetCatalogEntry.jsp</param>
      </result>
      </action>
    11. In the GetCatalogEntry.jsp file, add a new context data entry as follows:
      <wcf:contextData name="versionId" data="${param.objectVersionId}"/>
      So the complete getData tag is:
      	<wcf:getData type="com.ibm.commerce.catalog.facade.datatypes.CatalogEntryType[]"
      var="catalogEntries" expressionBuilder="getCatalogEntryDetailsByIDs"
      varShowVerb="showVerb" recordSetStartNumber="${param.recordSetStartNumber}"
      recordSetReferenceId="${param.recordSetReferenceId}" maxItems="${param.maxItems}">
      	<wcf:contextData name="storeId" data="${param.storeId}"/>
      	<wcf:contextData name="catalogId" data="${param.catalogId}"/>
      	<wcf:contextData name="versionId" data="${param.objectVersionId}"/>
      	<wcf:param name="dataLanguageIds" value="${param.dataLanguageIds}"/>
      	<wcf:param name="UniqueID" value="${param.catentryId}"/>
      </wcf:getData> 
    You have configured all GetChildrenService, GetReferenceService, and RefreshService to provide the versioned information for the Product object.
  4. Update the command registry for the custom access profile to register the insert more version command implementation.
    When viewing versioned objects, the Management Center needs to know information about the version such as the version ID. To retrieve and include this information in the noun, you must register an "InsertMore" command.
    Here's the example SQL statement to register MyCompany_All custom access profile for the preceding Warranty example:
    insert into cmdreg (storeent_id, interfacename, classname, target) values 
    (0, 'com.ibm.commerce.catalog.facade.server.commands.InsertMoreCatalogEntryDataCmd+MyCompany_All.10', 
    'com.ibm.commerce.foundation.server.version.command.InsertMoreNounVersionMetaDataCmdImpl', 'Local');
    

    The InsertMoreNounVersionMetaDataCmdImpl looks up the version information for the CatalogEntry noun and adds the version information to the response.