Implementing the client library

In this step, you add convenience methods that hide the complexity of creating the different ProcessTutorialStore requests.

Procedure

  1. In the Enterprise Explorer view, Go to SOITutorialStore-Client/src/com.mycompany.commerce.soitutorialstore.facade
  2. Open the SOITutorialStoreFacadeConstants class for editing.
  3. Add the following constants to represent the open store and close store process actions.
    
    /**
    * The Open Store process action.
    */
     public static final String PROCESS_ACTION_OPEN = "Open";
    
    /**
    * The Close Store process action.
    */
     public static final String PROCESS_ACTION_CLOSE = "Close";
    
  4. Save your changes and close the file.
  5. Go to com.mycompany.commerce.soitutorialstore.facade.client.
  6. Open the SOITutorialStoreFacadeClient class for editing.
  7. Add the following client methods that build the appropriate BOD:
    
    /**
     * This method composes a Process BOD with an Action of 'Close' and sends
     * the BOD to the TutorialStore-Server.
     */
    public AcknowledgeTutorialStoreDataAreaType closeStore(String storeId) {
      final String METHODNAME = "closeStore(String storeId)";
    
      ProcessTutorialStoreType processTutorialStore = getSOITutorialStoreFactory()
      .createProcessTutorialStoreType();
      ProcessTutorialStoreDataAreaType dataArea = getSOITutorialStoreFactory()
      .createProcessTutorialStoreDataAreaType();
      processTutorialStore.setDataArea(dataArea);
    
      java.util.List expressions = new ArrayList();
      expressions.add(createActionExpression(
        SOITutorialStoreFacadeConstants.PROCESS_ACTION_CLOSE,
        SelectionCriteriaHelper.STR_XPATH_LANG,
        SOITutorialStoreFacadeConstants.XPATH_STORE));
      dataArea.setProcess(createProcessVerb(expressions));
    
      StoreIdentifierType storeIdentifier = CommerceFoundationFactory.eINSTANCE
        .createStoreIdentifierType();
      storeIdentifier.setUniqueID(storeId);
    
      TutorialStoreType tutorialStore = getSOITutorialStoreFactory()
      .createTutorialStoreType();
      tutorialStore.setStoreIdentifier(storeIdentifier);
      dataArea.getTutorialStore().add(tutorialStore);
    
      AcknowledgeTutorialStoreDataAreaType acknowledgeTutorialStoreDataArea = processTutorialStore(
        processTutorialStore).getDataArea();
    
      return acknowledgeTutorialStoreDataArea;
    }
    
    /**
     * This method composes a Process BOD with an Action of 'Open' and sends the
     * BOD to the TutorialStore-Server.
     */
    public AcknowledgeTutorialStoreDataAreaType openStore(String storeId) {
      final String METHODNAME = "openStore(String storeId)";
    
      ProcessTutorialStoreType processStore = getSOITutorialStoreFactory()
      .createProcessTutorialStoreType();
      ProcessTutorialStoreDataAreaType dataArea = getSOITutorialStoreFactory()
      .createProcessTutorialStoreDataAreaType();
      processStore.setDataArea(dataArea);
    
      java.util.List expressions = new ArrayList();
      expressions.add(createActionExpression(
        SOITutorialStoreFacadeConstants.PROCESS_ACTION_OPEN,
        SelectionCriteriaHelper.STR_XPATH_LANG,
        SOITutorialStoreFacadeConstants.XPATH_STORE));
      dataArea.setProcess(createProcessVerb(expressions));
    
      StoreIdentifierType storeIdentifier = CommerceFoundationFactory.eINSTANCE
        .createStoreIdentifierType();
      storeIdentifier.setUniqueID(storeId);
    
      TutorialStoreType tutorialStore = getSOITutorialStoreFactory()
      .createTutorialStoreType();
      tutorialStore.setStoreIdentifier(storeIdentifier);
      dataArea.getTutorialStore().add(tutorialStore);
    
      AcknowledgeTutorialStoreDataAreaType acknowledgeStoreDataArea = processTutorialStore(
        processStore).getDataArea();
    
      return acknowledgeStoreDataArea;
    }
    
  8. Save your changes and close the file.
  9. Organize the imports for the SOITutorialStore-Client project:
    1. Open the Java perspective in WebSphere Commerce Developer.
    2. Right-click the SOITutorialStore-Client\src folder.
    3. Select Source > Organize Imports.