Tutorials > Sales Center > Add a column to the order items table

< Previous | Next >


Extend the reply BOD from the WebSphere Commerce Server

In this step we will extend the reply Business Object Document (BOD) to include the availability date when information about an order is sent from the WebSphere Commerce Server to the IBM Sales Center client. You will perform this step using the WebSphere Commerce development environment.

The ShowElectronicCatalog class contains the code that handles displaying products. The ShowElectronicCatalog class' populateSearchResult method populates the ShowElectronicCatalog reply BOD with the product data. In this step we will extend the ShowElectronicCatalog class to add product availability date information into the ShowElectronicCatalog reply BOD for display in the Availability Date column of the custom order items table.

To extend the ShowElectronicCatalog class:


Procedure

  1. Open the WebSphere Commerce development environment.

  2. In the Enterprise Explorer view, navigate to Other Projects > WebSphereCommerceServerExtensionsLogic > src.

  3. Right-click the src project and select New > Package.

  4. In the Name field, enter com.mynewextensions.availabilitydate and click Finish.

  5. Right-click the com.mynewextensions.availabilitydate package and select New > Class.

  6. In the Name field, enter ExtendedShowElectronicCatalog.

  7. Next to the Superclass field, click Browse.

  8. In the Choose a type field, enter ShowElectronicCatalog and click OK.

  9. Click Finish.

  10. To add the availability date, we will override the populateSearchResult methods in ShowElectronicCatalog to first call the super class' method then add the availability date to the BOD. If the availability date does not exist in the database, the current time will be substituted. Add the following code to the ExtendedShowElectronicCatalog class:

               /**
                    * This method populates the search result bean with
    an additional data field called 
                    * "
    availabilityDate". First it will invoke the super class
    method to populate the 
                    * required data fields and then check the
    availability date for null, if the availability 
                    * date is not null then use it otherwise get the
    current system time.
                    */
                    public ElectronicCatalogSearchResultBean
    populateSearchResult(
                            CatalogEntryDataBean abnCatalogEntry, boolean isHeaderOnlyRequired,                         boolean isMerchandisingAssociationRequired, boolean isGetDetails,                         ElectronicCatalogSearchResultBean
    abnSearchResult)
                            throws ECException {
                    final String METHODNAME = "populateSearchResult";
                   
    ECTrace.entry(ECTraceIdentifiers.COMPONENT_MESSAGING, CLASSNAME,                                 METHODNAME);
                    super.populateSearchResult(abnCatalogEntry, isHeaderOnlyRequired,                                 isMerchandisingAssociationRequired, isGetDetails,                                 abnSearchResult);
                    try {
                            if (abnCatalogEntry.getAvailabilityDate()
    != null) {
                                   
    abnSearchResult.addUserDataField("availabilityDate",                                        
    DateFormat.getDateInstance().format(abnCatalogEntry.getAvailabilityDate()));
                            } else {
                                   
    abnSearchResult.addUserDataField("availabilityDate",                                        
    DateFormat.getDateInstance().format(new
    java.sql.Timestamp(System.currentTimeMillis())));
                            }
                    } catch (javax.naming.NamingException e) {
                            throw new
    ECSystemException(ECMessage._ERR_GENERIC, CLASSNAME,                                         METHODNAME, ECMessageHelper.generateMsgParms(e.toString()),                                         e);
                    } catch (FinderException e) {
                            throw new
    ECSystemException(ECMessage._ERR_FINDER_EXCEPTION,                                         CLASSNAME, METHODNAME, ECMessageHelper.generateMsgParms(e
                                                           
    .toString()), e);
                    } catch (CreateException e) {
    
                            throw new
    ECSystemException(ECMessage._ERR_CREATE_EXCEPTION,                                         CLASSNAME, METHODNAME, ECMessageHelper.generateMsgParms(e
                                                           
    .toString()), e);
                    } catch (RemoteException e) {
                            throw new
    ECSystemException(ECMessage._ERR_REMOTE_EXCEPTION,                                         CLASSNAME, METHODNAME, ECMessageHelper.generateMsgParms(e
                                                           
    .toString()), e);
                    }
                    return abnSearchResult;
            }
    
               /**
                    * This method populates the search result bean with
    an additional data field called 
                    * "
    availabilityDate". First it will invoke the super class
    method to populate the 
                    * required data fields and then check the
    availability date for null, if the availability 
                    * date is not null then use it otherwise get the
    current system time.
                    */
                    public ElectronicCatalogSearchResultBean
    populateSearchResult(
                            com.ibm.commerce.catalog.beans.ItemDataBean
    abnItem,                         String strElectronicCatalogType, boolean
    isMAssociationRequired,                         ElectronicCatalogSearchResultBean
    abnSearchResult)
                            throws ECException {
                    final String METHODNAME = "populateSearchResult";
                   
    ECTrace.entry(ECTraceIdentifiers.COMPONENT_MESSAGING, CLASSNAME,                                 METHODNAME);
                    super.populateSearchResult(abnItem, strElectronicCatalogType,                                 isMAssociationRequired, abnSearchResult);
                    try {
                            if (abnItem.getAvailabilityDate() != null)
    {
                                   
    abnSearchResult.addUserDataField("availabilityDate", 
                                           
    DateFormat.getDateInstance().format(abnItem.getAvailabilityDate()));
                            } else {
                                   
    abnSearchResult.addUserDataField("availabilityDate",                                        
    DateFormat.getDateInstance().format(new
    java.sql.Timestamp(System.currentTimeMillis())));       
                            }
                    } catch (javax.naming.NamingException e) {
                            throw new
    ECSystemException(ECMessage._ERR_GENERIC, CLASSNAME,                                         METHODNAME, ECMessageHelper.generateMsgParms(e.toString()),                                         e);
                    } catch (FinderException e) {
                            throw new
    ECSystemException(ECMessage._ERR_FINDER_EXCEPTION,                                         CLASSNAME, METHODNAME, ECMessageHelper.generateMsgParms(e
                                                           
    .toString()), e);
                    } catch (CreateException e) {
                            throw new
    ECSystemException(ECMessage._ERR_CREATE_EXCEPTION,                                         CLASSNAME, METHODNAME, ECMessageHelper.generateMsgParms(e
                                                           
    .toString()), e);
                    } catch (RemoteException e) {
                            throw new
    ECSystemException(ECMessage._ERR_REMOTE_EXCEPTION,                                         CLASSNAME, METHODNAME, ECMessageHelper.generateMsgParms(e
                                                           
    .toString()), e);
                    }
                    return abnSearchResult;
            }
    
               /**
                    * This method populates the search result bean with
    an additional data field called 
                    * "
    availabilityDate". First it will invoke the super class
    method to populate the 
                    * required data fields and then check the
    availability date for null, if the availability 
                    * date is not null then use it otherwise get the
    current system time.
                    */
                    public ElectronicCatalogSearchResultBean
    populateSearchResult(
                           
    com.ibm.commerce.catalog.beans.ProductDataBean abnProduct,                         String strElectronicCatalogType, boolean
    isMAssociationRequired,                         ElectronicCatalogSearchResultBean
    abnSearchResult)
                            throws ECException {
                    final String METHODNAME = "populateSearchResult";
                   
    ECTrace.entry(ECTraceIdentifiers.COMPONENT_MESSAGING, CLASSNAME,                                 METHODNAME);
                    super.populateSearchResult(abnProduct, strElectronicCatalogType,                                 isMAssociationRequired, abnSearchResult);
                    try {
                            if (abnProduct.getAvailabilityDate() !=
    null) {
                                   
    abnSearchResult.addUserDataField("availabilityDate", 
                                           
    DateFormat.getDateInstance().format(abnProduct.getAvailabilityDate()));
                            } else {
                                   
    abnSearchResult.addUserDataField("availabilityDate",                                        
    DateFormat.getDateInstance().format(new
    java.sql.Timestamp(System.currentTimeMillis())));
                            }
                    } catch (javax.naming.NamingException e) {
                            throw new
    ECSystemException(ECMessage._ERR_GENERIC, CLASSNAME,                                         METHODNAME, ECMessageHelper.generateMsgParms(e.toString()),                                         e);
                    } catch (FinderException e) {
                            throw new
    ECSystemException(ECMessage._ERR_FINDER_EXCEPTION,                                         CLASSNAME, METHODNAME, ECMessageHelper.generateMsgParms(e
                                                           
    .toString()), e);
                    } catch (CreateException e) {
                            throw new
    ECSystemException(ECMessage._ERR_CREATE_EXCEPTION,                                         CLASSNAME, METHODNAME, ECMessageHelper.generateMsgParms(e
                                                           
    .toString()), e);
                    } catch (RemoteException e) {
                            throw new
    ECSystemException(ECMessage._ERR_REMOTE_EXCEPTION,                                         CLASSNAME, METHODNAME, ECMessageHelper.generateMsgParms(e
                                                           
    .toString()), e);
                    }
                    return abnSearchResult;
            }
    

  11. From the main menu select Source > Organize Imports to resolve the compilation errors and save the file.

< Previous | Next >


+

Search Tips   |   Advanced Search