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

< Previous | Next >


Create the AddExtendedCatalogDescCmdImpl task command

This command will implement the AddExtendedCatalogDescCmd interface created in the last step. The performExecute() method will make 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 Name field, type AddExtendedCatalogDescCmdImpl.

  4. In the Package field, type com.mycompany.catalog.commands.

  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 to select com.ibm.commerce.command.TaskCommandImpl.

  8. Click OK.

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

  10. In the Implemented Interfaces Selection window, type AddExtendedCatalogDescCmd to the Choose interfaces field to select com.mycompany.catalog.commands.AddExtendedCatalogDescCmd.

  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;
    private java.lang.String catalogCode = 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. The method uses the new resource manager, ExtendedCatalogDescriptionResourceManager.

    /**
      * Executes the command.
      */
     public void performExecute() throws ECException {
      final String METHODNAME = "performExecute";
    
      if (ECTrace.isTraceEnabled()) {
       ECTrace.entry(ECTraceIdentifiers.COMPONENT_CATALOG, 
                     CLASSNAME,      
                     METHODNAME);
      }
    
      // call the parent class
      super.performExecute();
    
      // get the catalog ID based on the catalog code
      CatalogAccessBean cab = new CatalogAccessBean();
      Long catalogID = null;
      try {
       cab = cab.findByCatalogIdentifierAndStore(getCatalogCode(),      
                                                 getCommandContext().getStoreId());
    
       catalogID = cab.getCatalogReferenceNumberInEJBType();
    
       setCatalogId(catalogID);
      } catch (CreateException e1) 
      {
       if (ECTrace.isTraceEnabled()) 
       {
        ECTrace.trace(ECTraceIdentifiers.COMPONENT_CATALOG,         
                      CLASSNAME,         
                      METHODNAME,         
                      "A CreateException occured while trying to find the CatalogAccessBean. Exception: "
                      + e1.getMessage());
       }
      } catch (RemoteException e1) {
       if (ECTrace.isTraceEnabled()) {
        ECTrace.trace( ECTraceIdentifiers.COMPONENT_CATALOG,         
                       CLASSNAME,         
                       METHODNAME,         
                       "A RemoteException occured while trying to find the CatalogAccessBean. Exception: "
                      + e1.getMessage());
       }
      } catch (NamingException e1) {
       if (ECTrace.isTraceEnabled()) {
        ECTrace.trace(ECTraceIdentifiers.COMPONENT_CATALOG,         
                      CLASSNAME,         
                      METHODNAME,         
                      "A NamingException occured while trying to find the CatalogAccessBean. Exception: "
                      + e1.getMessage());
       }
      } catch (FinderException e1) {
       if (ECTrace.isTraceEnabled()) {
        ECTrace.trace(ECTraceIdentifiers.COMPONENT_CATALOG,         
                      CLASSNAME,         
                      METHODNAME,         
                      "A FinderException occured while trying to find the CatalogAccessBean. Exception: "
                      + e1.getMessage());
       }
      }
    
      if (catalogID != null) {
       try {
        // Get the resource manager from the
        // ExtendedCatalogDescriptionResourceContainer
        ResourceManager rmExtendedCatalogDescription = ExtendedCatalogDescriptionResourceContainer
          .singleton()
          .getResourceManager(
            ExtendedCatalogDescriptionResourceContainer.EXTCATALOGDSC);
    
        // Extra checking in case it could not be obtained.
        if (rmExtendedCatalogDescription == null) {
         rmExtendedCatalogDescription = new com.mycompany.catalog.content.resources.ExtendedCatalogDescriptionResourceManager();
        }
    
        // Create entity creation data for this resource
        ExtendedCatalogDescriptionEntityBeanCreationData ecdExtendededCatalogDescription = new ExtendedCatalogDescriptionEntityBeanCreationData();
        ecdExtendededCatalogDescription.setCatalog_id(getCatalogId());
        ecdExtendededCatalogDescription.setLanguage_id(getLanguageId());
        ecdExtendededCatalogDescription.setBackImg(getBackImg());
        ecdExtendededCatalogDescription.setFrontImg(getFrontImg());
        ecdExtendededCatalogDescription.setSideImg(getSideImg());
        ecdExtendededCatalogDescription.setTopImg(getTopImg());
        ecdExtendededCatalogDescription
          .setLastModified(getLastModified());
    
        // Call the createManagedResource method to create the new
        // resource
        ExtendedCatalogDescriptionAccessBean ab
        ExtendedCatalogDescription = (ExtendedCatalogDescriptionAccessBean) rm
        ExtendedCatalogDescription.createManagedResource(getCommandContext().getActivityToken(),         
        ecdExtendededCatalogDescription);
    
        // Log information to the WC_CATALOG trace
        if (ECTrace.isTraceEnabled()) {
         ECTrace.trace(ECTraceIdentifiers.COMPONENT_CATALOG,        
                       CLASSNAME, METHODNAME,        
                       "Extended Catalog Description created. "
                       + "Catalog ID = " + getCatalogId()
             + ",Description Language ID = "
             + getLanguageId() + ",backImg = "
             + getBackImg() + ",topImg = " + getTopImg()
             + ",sideImg = " + getSideImg()
             + ",frontImg = " + getFrontImg() + ".");
        }
    
       } catch (ResourceException e) {
        Throwable cause = e.getCause();
        if (e instanceof ResourceLockedException) {
         // Resource is locked, see workspace locking in the
         // WebSphere
         // Commerce      // Information Center
         ResourceLockedException ex = (ResourceLockedException) e;
         if (ECTrace.isTraceEnabled()) {
          ECTrace.trace(ECTraceIdentifiers.COMPONENT_CATALOG,           
                        CLASSNAME, METHODNAME,           
                        "Error. Resource is locked. Table EXTCATALOGDSC is locked.");
         }
         throw ResourceExceptionHelper
           .convertResourceLockedExceptionToEcSystemException(
             CLASSNAME, METHODNAME, ex);
    
        } else if (cause instanceof DuplicateKeyException) {
         if (ECTrace.isTraceEnabled()) {ECTrace.trace(ECTraceIdentifiers.COMPONENT_CATALOG,         
                                        CLASSNAME, 
                                        METHODNAME,         
                                        "Error. Duplicate Key. Catalog ID = "
                                        + getCatalogId() + ", Language ID = "
                                        + getLanguageId() + ".");
         }
         throw new ECSystemException(ECMessage._ERR_DUPLICATE_RECORD, CLASSNAME,        
                                     METHODNAME, ECMessageHelper.generateMsgParms(cause.toString()), cause);
        } else if (cause instanceof javax.ejb.CreateException) {
         throw new ECSystemException(ECMessage._ERR_CREATE_EXCEPTION, 
                                     CLASSNAME,        
                                     METHODNAME, ECMessageHelper.generateMsgParms(cause.toString()), cause);
        } else if (cause instanceof javax.ejb.FinderException) {
         throw new ECSystemException(ECMessage._ERR_FINDER_EXCEPTION, 
                                     CLASSNAME,        
                                     METHODNAME, ECMessageHelper.generateMsgParms(cause.toString()), cause);
        } else if (cause instanceof javax.naming.NamingException) {
         throw new ECSystemException(ECMessage._ERR_NAMING_EXCEPTION, 
                                     CLASSNAME,        
                                     METHODNAME, ECMessageHelper.generateMsgParms(cause.toString()), cause);
        } else if (cause instanceof java.rmi.RemoteException) {
         throw new ECSystemException(ECMessage._ERR_REMOTE_EXCEPTION, 
                                     CLASSNAME,        
                                     METHODNAME, ECMessageHelper.generateMsgParms(cause.toString()), cause);
        } else {
         throw new ECSystemException(ECMessage._ERR_GENERIC,        
                                     CLASSNAME, METHODNAME, 
                                     ECMessageHelper.generateMsgParms(cause.toString()), cause);
        }
       }
      }
    
      // Exit tracing
      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);
      }
     }
    
     /**
      * Resets values of the parameters passed into the command.
      */
     public void reset() {
      catalogId = null;
      languageId = null;
      lastModified = null;
      frontImg = null;
      backImg = null;
      sideImg = null;
      topImg = null;
      catalogCode = null;
     }
    
       
    

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

    • javax.ejb.DuplicateKeyException

    • 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

    • com.mycompany.catalog.objects.ExtendedCatalogDescriptionEntityBeanCreationData

  21. Save and close the file.

< Previous | Next >


+

Search Tips   |   Advanced Search