Implementing the component facade

In this step, you implement the code logic in the component facade for handling the GetTutorialStore requests, in addition to implementing the code for generating ShowTutorialStore responses.

Procedure

  1. Update the GetTutorialStoreCmdImpl.java class to handle Get requests:
    1. In the Enterprise Explorer view, expand SOITutorialStore-Server/ejbModule/com.mycompany.commerce.soitutorialstore.facade.server.commands/GetTutorialStoreCmdImpl.java
    2. Open the GetTutorialStoreCmdImpl class for editing. This is the BOD command for the Get service.
      1. Add the following code to the beginning of GetTutorialStoreCmdImpl.java to import com.ibm.commerce.common.beans.StoreDataBean.
        // Import StoreDataBean
        import com.ibm.commerce.common.beans.StoreDataBean;
        
    3. The method, performExpression(), is the callback method from the service controller upon receiving a Get service request.
      1. Search for the following snippet:
        
        // Run the compose command for each EJB retrieved by the Fetch command.
        //java.util.Iterator itr = fetchCmd.getTutorialStores().iterator();
        
      2. Replace the code snippet and the following while loop with the following snippet:
        // Run the compose command for each EJB retrieved by the Fetch command.
        java.util.Iterator itr = fetchCmd.getNouns().iterator();
        
        while (itr.hasNext()) {
        // Set the bean on the compose command and run the command.
        StoreDataBean aStoreDataBean = (StoreDataBean) itr.next();
        composeCmd.setTutorialStoreDataBean(aStoreDataBean);
        composeCmd.setSearchExpression(new SearchExpression(getTutorialStoreType.getDataArea().getGet(), SOITutorialStoreFacadeConstants.COMPONENT_NAME));
        composeCmd.execute();
        showTutorialStore.getDataArea().getTutorialStore().addAll(composeCmd.getTutorialStores());
        composeCmd.reset();
        }
        
      3. Save your changes and close the file.
  2. Import the remaining SOITutorialStore-Server code:
    1. Right-click the com.mycompany.commerce.soitutorialstore.facade.server.commands package.
    2. Select Import > General > File System and click Next.
    3. Browse to the temporary location where you unzipped TutorialStore.zip.
    4. Select the following files:
      ComposeTutorialStoreAllCmdImpl.java
      Task command to retrieve all information about a TutorialStore.
      ComposeTutorialStoreBaseCmdImpl.java
      Base compose class containing common methods.
      ComposeTutorialStoreCmd.java
      Interface for the compose task command.
      ComposeTutorialStoreDetailsCmdImpl.java
      Task command to retrieve detail information about a TutorialStore.
      ComposeTutorialStoreSummaryCmdImpl.java
      Task command to retrieve summary information about a TutorialStore.
      FetchAllTutorialStoreCmdImpl.java
      Task command to retrieve a store data bean for each store on the server.
      FetchTutorialStoreByIdCmdImpl.java
      Task command to retrieve a store data bean for the specified store ID.
    5. Click Finish. Click Yes to All to overwrite any existing files.
  3. Organize the imports for the SOITutorialStore-Server project:
    1. Open the Java perspective in WebSphere Commerce Developer.
    2. Expand SOITutorialStore-Server; right-click the EJBModule folder.
    3. Select Source > Organize Imports.
  4. Register the Get, Fetch, and Compose commands by running the following SQL statements:
    delete from cmdreg where STOREENT_ID = 0 and INTERFACENAME = 'com.mycompany.commerce.soitutorialstore.facade.server.commands.GetTutorialStoreCmd';
    
    delete from cmdreg where STOREENT_ID = 0 and INTERFACENAME = 'com.mycompany.commerce.soitutorialstore.facade.server.commands.ComposeTutorialStoreCmd+MyCompany_All';
    
    delete from cmdreg where STOREENT_ID = 0 and INTERFACENAME = 'com.mycompany.commerce.soitutorialstore.facade.server.commands.ComposeTutorialStoreCmd+MyCompany_Details';
    
    delete from cmdreg where STOREENT_ID = 0 and INTERFACENAME = 'com.mycompany.commerce.soitutorialstore.facade.server.commands.ComposeTutorialStoreCmd+MyCompany_Summary';
    
    delete from cmdreg where STOREENT_ID = 0 and INTERFACENAME = 'com.mycompany.commerce.soitutorialstore.facade.server.commands.FetchTutorialStoreCmd+/TutorialStore';
    
    delete from cmdreg where STOREENT_ID = 0 and INTERFACENAME = 'com.mycompany.commerce.soitutorialstore.facade.server.commands.FetchTutorialStoreCmd+/TutorialStore/TutorialStoreIdentifier[(UniqueID=)]';
    
    insert into cmdreg (STOREENT_ID, INTERFACENAME, CLASSNAME, TARGET) VALUES (0, 'com.mycompany.commerce.soitutorialstore.facade.server.commands.GetTutorialStoreCmd', 'com.mycompany.commerce.soitutorialstore.facade.server.commands.GetTutorialStoreCmdImpl', 'Local');
    
    insert into cmdreg (STOREENT_ID, INTERFACENAME, CLASSNAME, TARGET) VALUES (0, 'com.mycompany.commerce.soitutorialstore.facade.server.commands.ComposeTutorialStoreCmd+MyCompany_All', 'com.mycompany.commerce.soitutorialstore.facade.server.commands.ComposeTutorialStoreAllCmdImpl', 'Local');
    
    insert into cmdreg (STOREENT_ID, INTERFACENAME, CLASSNAME, TARGET) VALUES (0, 'com.mycompany.commerce.soitutorialstore.facade.server.commands.ComposeTutorialStoreCmd+MyCompany_Summary', 'com.mycompany.commerce.soitutorialstore.facade.server.commands.ComposeTutorialStoreSummaryCmdImpl', 'Local');
    
    insert into cmdreg (STOREENT_ID, INTERFACENAME, CLASSNAME, TARGET) VALUES (0, 'com.mycompany.commerce.soitutorialstore.facade.server.commands.ComposeTutorialStoreCmd+MyCompany_Details', 'com.mycompany.commerce.soitutorialstore.facade.server.commands.ComposeTutorialStoreDetailsCmdImpl', 'Local');
    
    insert into cmdreg (STOREENT_ID, INTERFACENAME, CLASSNAME, TARGET) VALUES (0, 'com.mycompany.commerce.soitutorialstore.facade.server.commands.FetchTutorialStoreCmd+/TutorialStore', 'com.mycompany.commerce.soitutorialstore.facade.server.commands.FetchAllTutorialStoreCmdImpl', 'Local');
    
    insert into cmdreg (STOREENT_ID, INTERFACENAME, CLASSNAME, TARGET) VALUES (0, 'com.mycompany.commerce.soitutorialstore.facade.server.commands.FetchTutorialStoreCmd+/TutorialStore/TutorialStoreIdentifier[(UniqueID=)]', 'com.mycompany.commerce.soitutorialstore.facade.server.commands.FetchTutorialStoreByIdCmdImpl', 'Local');