Example: Code to add a new tab in the Product Management tools

You can add a new tab in the Product Management tools to better meet your business needs.

This code is part of the implementation of Adding a new tab to the Product Management tools in the Product Management tools. In the following code, com.myCompany.commerce.tools.catalog.commands is the package which contains your customized code.

The interface and implementation for CatalogEntryXMLInventoryExtensionControllerCmd follow.

Interface


package com.myCompany.commerce.tools.catalog.commands; 
import com.ibm.commerce.command.ControllerCommand; 
/** 
* @author A developer 
* 
*/ 
 
public interface CatalogEntryXMLInventoryExtensionControllerCmd extends 
  ControllerCommand { 
 
/** 
* Method interface name 
*/ 
 
public static final String NAME = "com.myCompany.commerce.tools.catalog.commands.CatalogEntryXMLInventoryExtensionControllerCmd"; 
 
/** 
* Method implementation classname 
*/ 
 
public static String defaultCommandClassName = "com.myCompany.commerce.tools.catalog.commands.CatalogEntryXMLInventoryExtensionControllerCmdImpl"; 
}
 

Implementation


package com.myCompany.commerce.tools.catalog.commands;
 
import java.util.Hashtable;
import java.util.Vector;
 
import com.ibm.commerce.command.CommandFactory;
import com.ibm.commerce.datatype.TypedProperty;
import com.ibm.commerce.exception.ECApplicationException;
import com.ibm.commerce.exception.ECException;
import com.ibm.commerce.exception.ECSystemException;
import com.ibm.commerce.fulfillment.objects.InventoryAccessBean;
import com.ibm.commerce.ras.ECTrace;
import com.ibm.commerce.ras.ECTraceIdentifiers;
import com.ibm.commerce.tools.catalog.commands.CatalogEntryXMLControllerCmd;
import com.ibm.commerce.tools.catalog.commands.CatalogEntryXMLControllerCmdImpl;
import com.ibm.commerce.tools.xml.XMLStringReader;
 
/**
 * @author A developer
 *
 */
public class CatalogEntryXMLInventoryExtensionControllerCmdImpl
 extends com.ibm.commerce.tools.command.ToolsControllerCommandImpl {
 
 public static final String CLASSNAME =
  "com.myCompany.commerce.tools.catalog.commands. 
       CatalogEntryXMLInventoryExtensionControllerCmdImpl";
 
 private static final String CATALOGENTRY = "CatalogEntry";
 private static final String CATALOGENTRY_ACTION = "action";
 private static final String CATALOGENTRY_ACTIONUPDATE = "update";
 private static final String CATALOGENTRY_CATALOGENTRYID = "catalogEntryId";
 private static final String CATALOGINVENTORY = "Inventory";
 private static final String CATALOGINVENTORY_FLAG = "inventoryFlag";
 private static final String CATALOGINVENTORY_QUANTITY = "inventoryQuantity";
 
 private Hashtable catalogEntryXML = null;
 
 /********************************************************************************
 * This method accepts input parameters from RequestProperties for the controller 
  * command.
 *
 * @param reqParams com.ibm.commerce.datatype.TypedProperty
 * @exception ECApplicationException.
 *
 ********************************************************************************/
 public void setRequestProperties(TypedProperty reqParams)
  throws ECApplicationException {
  super.setRequestProperties(reqParams);
  String xmlstring = requestProperties.getString("CatalogXML", null);
  if (xmlstring == null) {
   return;
  }
 
  try {
   XMLStringReader xsr = new XMLStringReader(xmlstring);
   Hashtable val = xsr.read();
   if (val != null) {
    catalogEntryXML = (Hashtable) val.get("XML");
   }
  } catch (ECSystemException e) {
   ECTrace.trace(
    ECTraceIdentifiers.COMPONENT_TOOLSFRAMEWORK,
    this.getClass().getName(),
    "setRequestProperties",
    "Error parsing XML object");
  }
 }
 
 /********************************************************************************
 * This function updates the catalog entry inventory information
 * 
 * @param  catalogEntryID String - catalog entry ID
 * @param  h Hashtable - this is the hashtable of changes to the catalog entry 
 *          inventory information
 * @throws ECException
 ********************************************************************************/
 public void updateCatalogEntryInventory(String catalogEntryID, Hashtable h)
  throws ECException {
  final String METHODNAME = "updateCatalogInventory";
 
  try {
   //Update the access bean
   InventoryAccessBean abInventory = new InventoryAccessBean();
   abInventory.setInitKey_catalogEntryId(catalogEntryID);
   abInventory.setInitKey_fulfillmentCenterId(getCommandContext().getStore().
          getFulfillmentCenterId());
   abInventory.setInitKey_storeId(getCommandContext().getStoreId().toString());
   abInventory.refreshCopyHelper(); 
   if (h.containsKey(CATALOGINVENTORY_FLAG))
   {
    abInventory.setInventoryFlags(h.get(CATALOGINVENTORY_FLAG).toString());
   }
   if (h.containsKey(CATALOGINVENTORY_QUANTITY))
   {
    abInventory.setQuantity(h.get(CATALOGINVENTORY_QUANTITY).toString());
   }
   abInventory.commitCopyHelper();
  } catch (Exception ex) {
   ECTrace.trace(
    ECTraceIdentifiers.COMPONENT_CATALOG,
    CLASSNAME,
    METHODNAME,
    "Cannot update Inventory.");
  }
 }
 
 /********************************************************************************
 * This function updates a single catalog entry
 * 
 * @param  hEntry Hashtable - a hashtable with containing the catalog entry 
 * information
 *********************************************************************************/
 public void updateCatalogEntryObject(Hashtable hEntry) {
  final String METHODNAME = "updateCatalogEntryObject";
 
  try {
   String action = (String) hEntry.get(CATALOGENTRY_ACTION);
   String catalogEntryID =
    (String) hEntry.get(CATALOGENTRY_CATALOGENTRYID);
   if (action.equals(CATALOGENTRY_ACTIONUPDATE))
      {
    updateCatalogEntryInventory(catalogEntryID,hEntry);
   }
  } catch (Exception e) {
   ECTrace.trace(
    ECTraceIdentifiers.COMPONENT_CATALOG,
    CLASSNAME,
    METHODNAME,
    "Catalog Entry Inventory Update Failed.");
  }
 }
 
 /******************************************************************************
 * This function accepts an XML string parameter containing the update 
  * information for the set of catalog entries modified by the Product Line 
  * Update tool. 
  * These updates are then processed.
 * 
 * @throws ECException
 *******************************************************************************/
 public void performExecute()
  throws com.ibm.commerce.exception.ECException {
  final String METHODNAME = "performExecute";
  // perform server side parameter checking
  super.performExecute();
  
  
  // determine if there is something to parse
  if (catalogEntryXML != null) {
   java.lang.Object objXML = catalogEntryXML.get(CATALOGENTRY);
   if (objXML instanceof Hashtable) {
    updateCatalogEntryObject((Hashtable) objXML);
   }
   if (objXML instanceof Vector) {
    for (int i = 0; i < ((Vector) objXML).size(); i++) {
     Hashtable hXML = (Hashtable) ((Vector) objXML).elementAt(i);
     updateCatalogEntryObject(hXML);
    }
   }
  }
  
  
  try {
   //
   // Call the old command. 
   // We do not need to know what it accepts but rather
   // just call it with the input from the JSP file like we did originally.
   //
   // Retrieve the response properties from the command since we don't know
   // what it sends back to the JSP file.
   //
   CatalogEntryXMLControllerCmd catalogEntryXMLControllerCmd = null;
   catalogEntryXMLControllerCmd =(CatalogEntryXMLControllerCmd) CommandFactory.createCommand(
     "com.ibm.commerce.tools.catalog.commands.CatalogEntryXMLControllerCmd",
     getStoreId());
   catalogEntryXMLControllerCmd.setCommandContext(getCommandContext());
   catalogEntryXMLControllerCmd.setRequestProperties(requestProperties);
   catalogEntryXMLControllerCmd.performExecute();
   responseProperties =catalogEntryXMLControllerCmd.getResponseProperties();
  } catch (Exception e) {
   ECTrace.trace(ECTraceIdentifiers.COMPONENT_CATALOG,
    CLASSNAME,
    METHODNAME,
    "The update failed.");
  }
  
 }
 
}