Tutorial: Creating a WebSphere Commerce service module > < Previous | Next >
Implementing the component facade
This section refers to implementing the component facade.
- Update the GetTutorialStoreCmdImpl.java class to handle Get requests:
- Open the TutorialStore-Server/ejbModule/com.mycompany.commerce.tutorialstore.facade.server.commands/GetTutorialStoreCmdImpl.java class.
- 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); } }
- Import the remaining TutorialStore-Server code:
- Right-click the com.mycompany.commerce.tutorialstore.facade.server.commands package.
- Select Import > FileSystem. Click Next.
- Browse to the temporary location where you unzipped TutorialStore.zip. Browse to the TutorialStore-Server folder.
- 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.
- Click Finish. Click Yes to All to overwrite any existing files.
- Update the TutorialStore-Server build path:
- Right-click the TutorialStore-Server project and select Properties.
- Select Java Build Path.
- Select Add External Jars.
- 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
- Organize the imports for the TutorialStore-Server project:
- Open the Java perspective in WebSphere Commerce Developer.
- Right-click the TutorialStore-Server\EJBModule folder and select Source.
- Select Organize Imports.
- Save the file.
- Register the Get, Process, Fetch, and Compose commands by running the following SQL statements:
- 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');
- 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');
- 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');
- 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');
- 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');
- 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');
- 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');
- 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');
- Configure message mapping to link the Process Open and Close actions to the WebSphere Commerce StoreOpenCmd and StoreCloseCmd commands:
- Open the WCDE_installdir/xml/messaging/component-services/component-services-user-template.xml file.
- 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>
- Add the TutorialStore configuration to the server:
- Copy WCDE_installdir\xml\config\xsd to workspace_dir\TutorialStore-Server\config.
- Copy workspace_dir\TutorialStore-Server\config\com.mycompany.commerce.tutorialstore to WCDE_installdir\xml\config\.
- Right-click the TutorialStore-Server project and select Refresh.
- Right-click TutorialStore-Server\config and select Run Validation.