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

< Previous | Next >


Create the UpdateExtendedCatalogDescCmdImpl task command

This command implements the UpdateExtendedCatalogDescCmd interface created in the last step. The performExecute() method makes use of the entity bean creation data and resource managers created to make this resource content managed.


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.mycompany.catalog.commands.

  4. In the Name field, type UpdateExtendedCatalogDescCmdImpl.

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

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

  7. In the Matching types box, select TaskCommandImpl.

  8. Click OK.

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

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

  11. Click OK.

  12. Clear the check box for Inherited abstract methods.

  13. Click Finish.

  14. Add the following attributes, representing each column in the EXTCATALOGDSC table, to the class:

        private java.lang.Long catalogId = null;
            private java.lang.Integer languageId = null;
            private java.sql.Timestamp lastModified = null;
            private java.lang.String frontImg = null;
            private java.lang.String backImg = null;
            private java.lang.String sideImg = null;
            private java.lang.String topImg = null;
      
    

  15. Right-click anywhere in the editor and select Source > Generate Setters and Getters.

  16. In the Generate Getters and Setters window, click Select all to create getter and setter methods for all of the attributes.

  17. Click OK.

  18. Implement the performExecute() method.

       /**
      * Executes the command. If an extended catalog description is not found for
      * update, a new one will be added.
      */
     public void performExecute() throws ECException {
      final String METHODNAME = "performExecute";
      if(ECTrace.isTraceEnabled()) {
       ECTrace.entry(ECTraceIdentifiers.COMPONENT_CATALOG, CLASSNAME,      METHODNAME);
      }
    
      super.performExecute();
    
      try {
       ExtendedCatalogDescriptionAccessBean abExtendedCatalogDescription = new ExtendedCatalogDescriptionAccessBean();
       abExtendedCatalogDescription.setInitKey_catalog_id(getCatalogId());
       abExtendedCatalogDescription
         .setInitKey_language_id(getLanguageId());
       abExtendedCatalogDescription.refreshCopyHelper();
    
       if(ECTrace.isTraceEnabled()) {
        ECTrace.trace(ECTraceIdentifiers.COMPONENT_CATALOG, CLASSNAME,       
        METHODNAME, "Extended Catalog Description obtained. "
            + "Catalog ID = " + getCatalogId()
            + ", Language ID = " + getLanguageId() + ".");    
       }
    
       if (getFrontImg() != null) {
        abExtendedCatalogDescription.setFrontImg(getFrontImg());
       }
       if (getBackImg() != null) {
        abExtendedCatalogDescription.setBackImg(getBackImg());
       }
       if (getTopImg() != null) {
        abExtendedCatalogDescription.setTopImg(getTopImg());
       }
       if (getSideImg() != null) {
        abExtendedCatalogDescription.setSideImg(getSideImg());
       }
       if (getLastModified() != null) {
        abExtendedCatalogDescription.setLastModified(getLastModified());
       }
    
       // Get the resource manager for table EXTCATALOGDSC
       ResourceManager rmExtendedCatalogDescription = ExtendedCatalogDescriptionResourceContainer
         .singleton()
         .getResourceManager(
           ExtendedCatalogDescriptionResourceContainer.EXTCATALOGDSC);
       if (rmExtendedCatalogDescription == null) {
        rmExtendedCatalogDescription = new com.mycompany.catalog.content.resources.ExtendedCatalogDescriptionResourceManager();
       }
       rmExtendedCatalogDescription.updateManagedResource(
         getCommandContext().getActivityToken(),      abExtendedCatalogDescription);
    
      } catch (javax.ejb.CreateException e) {
       throw new ECSystemException(ECMessage._ERR_CREATE_EXCEPTION,      
             CLASSNAME, METHODNAME, ECMessageHelper.generateMsgParms(e.toString()), e);
      } catch (javax.ejb.FinderException e) {
       //Add an Extended Catalog Description
       if(ECTrace.isTraceEnabled()) {
        ECTrace.trace(
          ECTraceIdentifiers.COMPONENT_CATALOG,       
          CLASSNAME,       
          METHODNAME,       
          "Extended Catalog Description doesn't exist. Create new Extended Catalog Description.");
       }
    
       //Calling the taks command AddExtendedCatalogDescCmd
    
       AddExtendedCatalogDescCmd addExtendedCatalogDesc = (AddExtendedCatalogDescCmd) CommandFactory.createCommand(AddExtendedCatalogDescCmd.CLASSNAME, getStoreId());
       addExtendedCatalogDesc.setCatalogId(getCatalogId());
       addExtendedCatalogDesc.setLanguageId(getLanguageId());
       addExtendedCatalogDesc.setFrontImg(getFrontImg());
       addExtendedCatalogDesc.setBackImg(getBackImg());
       addExtendedCatalogDesc.setSideImg(getSideImg());
       addExtendedCatalogDesc.setTopImg(getTopImg());
       addExtendedCatalogDesc.setCommandContext(getCommandContext());
       addExtendedCatalogDesc.execute();
    
      } catch (ResourceException e) {
       throw new ECSystemException(ECMessage._ERR_GENERIC, CLASSNAME,      
        METHODNAME, 
        ECMessageHelper.generateMsgParms(e.getCause()),      
        e.getCause());
      } catch (RemoteException e) {
       throw new ECSystemException(ECMessage._ERR_REMOTE_EXCEPTION,      
        CLASSNAME, METHODNAME, 
        ECMessageHelper.generateMsgParms(e),      e);
      } catch (NamingException e) {
       throw new ECSystemException(ECMessage._ERR_NAMING_EXCEPTION,      
        CLASSNAME, METHODNAME, 
        ECMessageHelper.generateMsgParms(e),      e);
      }
      if(ECTrace.isTraceEnabled()) {
       ECTrace.exit(ECTraceIdentifiers.COMPONENT_CATALOG, CLASSNAME,      METHODNAME);
      }
     }
      
    

  19. Implement two methods for validating and resetting parameters for the command.

     /**
      * Validates the parameters passed into the command.
      */
     public void validateParameters() throws ECException {
      final String METHODNAME = "validateParameters";
      if(ECTrace.isTraceEnabled()) {
       ECTrace.entry(ECTraceIdentifiers.COMPONENT_CATALOG, CLASSNAME,      METHODNAME);
      }
    
      super.validateParameters();
      
      if(ECTrace.isTraceEnabled()) {
       ECTrace.exit(ECTraceIdentifiers.COMPONENT_CATALOG, CLASSNAME,      METHODNAME);
      }
     }
    
     /**
      * This method should be called after a command has been executed to reset
      * its states variables. After the call to reset, we should be able to
      * execute the command again.
      */
     public void reset() {
      catalogId = null;
      languageId = null;
      lastModified = null;
      frontImg = null;
      backImg = null;
      sideImg = null;
      topImg = null;
     }
       
    

  20. Press CTRL+SHIFT+O to organize imports and resolve any errors.Ensure the following classes are selected if prompted for a selection:

    • java.rmi.RemoteException

    • javax.naming.NamingException

    • com.ibm.commerce.command.CommandFactory

    • com.ibm.commerce.command.TaskCommandImpl

    • com.ibm.commerce.exception.ECException

    • com.ibm.commerce.exception.ECSystemException

    • com.ibm.commerce.ras.ECMessage

    • com.ibm.commerce.ras.ECMessageHelper

    • com.ibm.commerce.ras.ECTrace

    • com.ibm.commerce.ras.ECTraceIdentifiers

    • com.ibm.commerce.context.content.resources.ResourceManager

    • com.ibm.commerce.context.content.resources.exception.ResourceException

    • com.ibm.commerce.context.content.resources.exception.ResourceExceptionHelper

    • com.ibm.commerce.context.content.resources.exception.ResourceLockedException

    • com.mycompany.catalog.content.resources.ExtendedCatalogDescriptionResourceContainer

    • com.mycompany.catalog.objects.ExtendedCatalogDescriptionAccessBean

  21. Save and close the file.

< Previous | Next >


+

Search Tips   |   Advanced Search