Tutorial: Creating a WebSphere Commerce service module > < Previous | Next >

 

Implementing the component facade

This section refers to implementing the component facade.

  1. Update the GetTutorialStoreCmdImpl.java class to handle Get requests:

    1. Open the TutorialStore-Server/ejbModule/com.mycompany.commerce.tutorialstore.facade.server.commands/GetTutorialStoreCmdImpl.java class.

    2. Replace the performExpression method with the following code
      /**
      * This method implements the Get expression using the FetchTutorialStore and ComposeTutorialStore task commands.          
      * @see com.ibm.commerce.foundation.server.command.bod.AbstractGetBusinessObjectDocumentCmdImpl#performExpression()
      **/         
      protected void performExpression() throws Exception {
      
      final String METHODNAME = "performExpression()";         
      
      if (com.ibm.commerce.foundation.common.util.logging.LoggingHelper.isEntryExitTraceEnabled(LOGGER))
      {                         
          LOGGER.entering(CLASSNAME, METHODNAME);        
      }
                                     
      com.mycompany.commerce.tutorialstore.facade.datatypes.GetTutorialStoreType getTutorialStoreType = getGetTutorialStore();                 
      SelectionCriteriaMapper selectionCriteria = new SelectionCriteriaMapper(getTutorialStoreType.getDataArea().getGet().getExpression());
      
      // Create and run the appropriate FetchTutorialStore task command based on the XPath expression.                 
      
      FetchTutorialStoreCmd fetchCmd = (FetchTutorialStoreCmd) com.ibm.commerce.foundation.server.command.CommandFactory.getInstance().createCommand(new GenericCommandKeyImpl(FetchTutorialStoreCmd.class.getName(),selectionCriteria.getXPathKey()));
      
      fetchCmd.setGet(getTutorialStoreType.getDataArea().getGet());
      fetchCmd.execute();                                  
      
      // Create and set the response Show BOD.
      com.mycompany.commerce.tutorialstore.facade.datatypes.ShowTutorialStoreType showStore = com.mycompany.commerce.tutorialstore.facade.datatypes.TutorialStoreFactory.eINSTANCE.createShowTutorialStoreType();
      com.mycompany.commerce.tutorialstore.facade.datatypes.DocumentRoot docRoot = com.mycompany.commerce.tutorialstore.facade.datatypes.TutorialStoreFactory.eINSTANCE.createDocumentRoot();
      docRoot.setShowTutorialStore(showStore);
      setShowTutorialStore(showStore);
      showStore.setDataArea(com.mycompany.commerce.tutorialstore.facade.datatypes.TutorialStoreFactory.eINSTANCE.createShowTutorialStoreDataAreaType());
      showStore.getDataArea().setShow(fetchCmd.getShow());
      
      // Create the appropriate ComposeTutorialStore task command based on the access profile.
      ComposeTutorialStoreCmd composeStoreCmd = (ComposeTutorialStoreCmd) com.ibm.commerce.foundation.server.command.CommandFactory.getInstance().createCommand(new GenericCommandKeyImpl(ComposeTutorialStoreCmd.class.getName(),selectionCriteria.getAccessProfile()));
                                       
      // Run the ComposeTutorialStore task command for each store to send to the client.
      java.util.Iterator itr = fetchCmd.getTutorialStores().iterator();
      while (itr.hasNext())
      {                         
          com.ibm.commerce.common.beans.StoreDataBean storeDB = (com.ibm.commerce.common.beans.StoreDataBean) itr.next();
          composeStoreCmd.setTutorialStoreDataBean(storeDB);
          composeStoreCmd.execute();
          showStore.getDataArea().getTutorialStore().add(composeStoreCmd.getTutorialStore());
          composeStoreCmd.reset();
      }      
                                 
      if (com.ibm.commerce.foundation.common.util.logging.LoggingHelper.isEntryExitTraceEnabled(LOGGER))
      {
          LOGGER.exiting(CLASSNAME, METHODNAME);         
      }         
      
        }
      

  2. Import the remaining TutorialStore-Server code:

    1. Right-click the com.mycompany.commerce.tutorialstore.facade.server.commands package.

    2. Select Import > FileSystem. Click Next.

    3. Browse to the temporary location where you unzipped TutorialStore.zip. Browse to the TutorialStore-Server folder.

    4. Select the following files:

      AcknowledgeTutorialStoreBuildCmdImpl.java

      Command to build the Acknowledge BOD after a process action.

      AcknowledgeTutorialStoreBuildErrorCmdImpl.java

      Command to build the Acknowledge BOD error response if the process action fails.

      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.

      ComposeTutorialStoreDetailCmdImpl.java

      Task command to retrieve detail information about a TutorialStore.

      ComposeTutorialStoreSummaryCmdImpl.java

      Task command to retrieve summary information about a TutorialStore.

      FetchAllTutorialStoresCmdImpl.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.

      FetchTutorialStoreByNameCmdImpl.java

      Task command to retrieve a store data bean for the specified store name.

    5. Click Finish. Click Yes to All to overwrite any existing files.

  3. Update the TutorialStore-Server build path:

    1. Right-click the TutorialStore-Server project and select Properties.

    2. Select Java Build Path.

    3. Select Add External Jars.

    4. Add the following:

      • Enablement-BaseComponentsData.jar from WCDE_installdir\wc.modules\ejbs\cloudscape

      • Enablement-RelationshipManagementData.jar from WCDE_installdir\wc.modules\ejbs\cloudscape

      • Enablement-BaseComponentsLogic.jar from workspace_dir\WC

      • Enablement-BusinessContextEngineAdvancedLogic.jar from workspace_dir\WC

      • Enablement-BusinessContextEngineLogic.jar from workspace_dir\WC

      • Enablement-RelationshipManagementLogic.jar from workspace_dir\WC

  4. Organize the imports for the TutorialStore-Server project:

    1. Open the Java perspective in WebSphere Commerce Developer.

    2. Right-click the TutorialStore-Server\EJBModule folder and select Source.

    3. Select Organize Imports.

    4. Save the file.

  5. Register the Get, Process, Fetch, and Compose commands by running the following SQL statements:

    1. insert into cmdreg (STOREENT_ID, INTERFACENAME, CLASSNAME, TARGET) VALUES (0, 'com.mycompany.commerce.tutorialstore.facade.server.commands.GetTutorialStoreCmd', 'com.mycompany.commerce.tutorialstore.facade.server.commands.GetTutorialStoreCmdImpl', 'Local');

    2. insert into cmdreg (STOREENT_ID, INTERFACENAME, CLASSNAME, TARGET) VALUES (0, 'com.mycompany.commerce.tutorialstore.facade.server.commands.ComposeTutorialStoreCmd+All', 'com.mycompany.commerce.tutorialstore.facade.server.commands.ComposeTutorialStoreAllCmdImpl', 'Local');

    3. insert into cmdreg (STOREENT_ID, INTERFACENAME, CLASSNAME, TARGET) VALUES (0, 'com.mycompany.commerce.tutorialstore.facade.server.commands.ComposeTutorialStoreCmd+Detail', 'com.mycompany.commerce.tutorialstore.facade.server.commands.ComposeTutorialStoreDetailCmdImpl', 'Local');

    4. insert into cmdreg (STOREENT_ID, INTERFACENAME, CLASSNAME, TARGET) VALUES (0, 'com.mycompany.commerce.tutorialstore.facade.server.commands.ComposeTutorialStoreCmd+Summary', 'com.mycompany.commerce.tutorialstore.facade.server.commands.ComposeTutorialStoreSummaryCmdImpl', 'Local');

    5. insert into cmdreg (STOREENT_ID, INTERFACENAME, CLASSNAME, TARGET) VALUES (0, 'com.mycompany.commerce.tutorialstore.facade.server.commands.ProcessTutorialStoreCmd', 'com.ibm.commerce.foundation.server.command.soi.MessageMappingCmdImpl', 'Local');

    6. insert into cmdreg (STOREENT_ID, INTERFACENAME, CLASSNAME, TARGET) VALUES (0, 'com.mycompany.commerce.tutorialstore.facade.server.commands.FetchTutorialStoreCmd+/Store', 'com.mycompany.commerce.tutorialstore.facade.server.commands.FetchAllTutorialStoresCmdImpl', 'Local');

    7. insert into cmdreg (STOREENT_ID, INTERFACENAME, CLASSNAME, TARGET) VALUES (0, 'com.mycompany.commerce.tutorialstore.facade.server.commands.FetchTutorialStoreCmd+/Store[StoreIdentifier[ExternalIdentifier[(NameIdentifier=)]]]', 'com.mycompany.commerce.tutorialstore.facade.server.commands.FetchTutorialStoreByNameCmdImpl', 'Local');

    8. insert into cmdreg (STOREENT_ID, INTERFACENAME, CLASSNAME, TARGET) VALUES (0, 'com.mycompany.commerce.tutorialstore.facade.server.commands.FetchTutorialStoreCmd+/Store[StoreIdentifier[(UniqueID=)]]', 'com.mycompany.commerce.tutorialstore.facade.server.commands.FetchTutorialStoreByIdCmdImpl', 'Local');

  6. Configure message mapping to link the Process Open and Close actions to the WebSphere Commerce StoreOpenCmd and StoreCloseCmd commands:

    1. Open the WCDE_installdir/xml/messaging/component-services/component-services-user-template.xml file.

    2. Paste the following code under the <ECTemplate> tag
      <!-- TutorialStore -->
      <TemplateDocument>
      <DocumentType
      version="">ProcessTutorialStore</DocumentType>
      <StartElement>ProcessTutorialStore</StartElement>
      <TemplateTagName>ProcessTutorialStoreMap</TemplateTagName>
      <CommandMapping>
      <Command
      CommandName="com.ibm.commerce.store.commands.StoreOpenCmd"
      Condition='actionCode="Open" '>
      <Constant Field="URL">NoURL</Constant> 
      <Constant FieldInfo='CONTROL'
      Field='responseCommand'>com.mycompany.commerce.tutorialstore.facade.server.commands.AcknowledgeTutorialStoreBuildCmdImpl</Constant>
      <Constant FieldInfo='CONTROL'
      Field='errorCommand'>com.mycompany.commerce.tutorialstore.facade.server.commands.AcknowledgeTutorialStoreBuildCmdImpl</Constant>
      </Command>
      <Command
      CommandName="com.ibm.commerce.store.commands.StoreCloseCmd"
      Condition='actionCode="Close"'>
      <Constant Field="URL">NoURL</Constant> 
      <Constant FieldInfo='CONTROL'
      Field='responseCommand'>com.mycompany.commerce.tutorialstore.facade.server.commands.AcknowledgeTutorialStoreBuildCmdImpl</Constant>
      <Constant FieldInfo='CONTROL'
      Field='errorCommand'>com.mycompany.commerce.tutorialstore.facade.server.commands.AcknowledgeTutorialStoreBuildCmdImpl</Constant>
      </Command> 
      </CommandMapping>
      </TemplateDocument>
      
      <TemplateTag name="ProcessTutorialStoreMap">
      <Tag XPath="ApplicationArea/BusinessContext/ContextData"
      XPathType="USERDATA"/>
      <Tag
      XPath="DataArea/Process/ActionCriteria/ActionExpression@actionCode"
      Field="actionCode" FieldInfo="COMMAND"/>
      <Tag XPath="DataArea/Process/ActionCriteria/ActionExpression"
      Field="actionExpression" FieldInfo="COMMAND"/>
      <Tag XPath="DataArea/TutorialStore/StoreIdentifier/UniqueID"
      Field="targetStoreId"/>
      </TemplateTag> 
      

  7. Add the TutorialStore configuration to the server:

    1. Copy WCDE_installdir\xml\config\xsd to workspace_dir\TutorialStore-Server\config.

    2. Copy workspace_dir\TutorialStore-Server\config\com.mycompany.commerce.tutorialstore to WCDE_installdir\xml\config\.

    3. Right-click the TutorialStore-Server project and select Refresh.

    4. Right-click TutorialStore-Server\config and select Run Validation.

< Previous | Next >