Tutorials > Content management > Create a content-managed resource > Integrate the new resource

< Previous | Next >


Create NavCatExtendedCatalogUpdateControllerCmdImpl controller command


Procedure

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

  2. Right-click src and select New > Class.

  3. In the Package field, type com.ibm.commerce.tools.catalog.commands.

  4. In the Name field, type NavCatExtendedCatalogUpdateControllerCmdImpl.

  5. Click the Browse button next to the Superclass field.

  6. In the Superclass Selection window, type NavCatCatalogUpdateControllerCmdImpl in the Choose a type field.

  7. In the Matching types box, select NavCatCatalogUpdateControllerCmdImpl.

  8. Click OK.

  9. Click the Add button next to the Interface box.

  10. In the Implemented Interfaces Selection window, type NavCatCatalogUpdateControllerCmd in the Choose interfaces field.

  11. Click OK.

  12. Clear the check box for Inherited abstract methods.

  13. Click Finish.

  14. Add the following imports into the class:

             import java.sql.Timestamp;
             import java.util.Calendar;
             import java.util.Hashtable;
             import java.util.Vector;         
             import com.ibm.commerce.command.CommandFactory;
             import com.ibm.commerce.tools.common.ECToolsConstants;
             import com.mycompany.catalog.commands.UpdateExtendedCatalogDescCmd;
       
    

  15. Add the following code into the class:

          /*
         *  The catalog ID of the catalog being managed in the accelerator. 
         */
     private String m_strCatalogId = null;
    
     /*
         *  A collection of languages being managed in the accelerator. 
         */
     private Vector m_vLanguages = new Vector();
    
        /**
      * Executes the command.
      */
     public void performExecute() throws com.ibm.commerce.exception.ECException {
      final String METHODNAME = "performExecute";
      if(ECTrace.isTraceEnabled()) {
       ECTrace.entry(ECTraceIdentifiers.COMPONENT_CATALOGTOOL, CLASSNAME,      METHODNAME);
      }  
    
      // Execute the original command logic.
      super.performExecute();
    
      // Get the request properties from the parent controller command
      Hashtable xmlObject = (Hashtable) ((Hashtable) ((Vector) requestProperties
        .get(ECToolsConstants.EC_XMLOBJECT)).firstElement()).get("XML");
      m_strCatalogId = (String) xmlObject.get("catalogId");
      java.lang.Object obj = xmlObject.get("languages");
      if (obj instanceof Hashtable) {
       m_vLanguages.addElement(obj);
      } else if (obj instanceof Vector) {
       m_vLanguages = (Vector) obj;
      }
    
      for (int i = 0; i
    < m_vLanguages.size(); i++) {
       Hashtable hLanguage = (Hashtable) m_vLanguages.elementAt(i);
       
       String frontImage = (String) hLanguage.get("frontimage");
       String backImage = (String) hLanguage.get("backimage");
       String topImage = (String) hLanguage.get("topimage");
       String sideImage = (String) hLanguage.get("sideimage");
       
       if((frontImage!=null && frontImage.trim().length()>0) ||
         (backImage!=null && backImage.trim().length()>0)  ||
         (topImage!=null && topImage.trim().length()>0) ||
         (sideImage!=null && sideImage.trim().length()>0)) {   
    
        UpdateExtendedCatalogDescCmd updateExtendedCatalogDescCmd = null;
        updateExtendedCatalogDescCmd = (UpdateExtendedCatalogDescCmd) CommandFactory
          .createCommand(UpdateExtendedCatalogDescCmd.CLASSNAME,         getStoreId());
     
        Timestamp ts = new Timestamp(Calendar.getInstance().getTime()
          .getTime());
     
        updateExtendedCatalogDescCmd.setCatalogId(new Long(m_strCatalogId));
        updateExtendedCatalogDescCmd.setLanguageId(new Integer(hLanguage
          .get("languageId").toString()));
        updateExtendedCatalogDescCmd.setLastModified(ts);
        if (hLanguage.containsKey("frontimage")) {
         updateExtendedCatalogDescCmd.setFrontImg(frontImage);
        }
        if (hLanguage.containsKey("backimage")) {
         updateExtendedCatalogDescCmd.setBackImg(backImage);
        }
        if (hLanguage.containsKey("sideimage")) {
         updateExtendedCatalogDescCmd.setSideImg(topImage);
        }
        if (hLanguage.containsKey("topimage")) {
         updateExtendedCatalogDescCmd.setTopImg(sideImage);
        }
        updateExtendedCatalogDescCmd.setCommandContext(getCommandContext());
        updateExtendedCatalogDescCmd.execute();
       }
      }
      
      if(ECTrace.isTraceEnabled()) {
       ECTrace.exit(ECTraceIdentifiers.COMPONENT_CATALOGTOOL, CLASSNAME,      METHODNAME);
      }
     }
       
      
    

  16. Save and close the file.

< Previous | Next >


+

Search Tips   |   Advanced Search