websphere-7websphere-commerce

How to call facade from the command


In IBM WebSphere Commerce How the facade can be called from the command Instead of calling it from jsp. we call it from jsp like

<wcf:getData type="com.ibm.commerce.catalog.facade.datatypes.CatalogNavigationViewType" var="catalogNavigationView" 
            expressionBuilder="${navigationView}" varShowVerb="showCatalogNavigationView" 
            maxItems="${pageSize}" recordSetStartNumber="${WCParam.beginIndex}">
            <wcf:param name="searchProfile" value="${searchProfile}" />
            <wcf:param name="searchTerm" value="${newSearchTerm}" />
            <wcf:param name="intentSearchTerm" value="${intentSearchTerm}" />
            <wcf:param name="searchType" value="${searchType}" />
            <wcf:param name="searchSource" value="${WCParam.searchSource}" />
            <wcf:param name="metaData" value="${WCParam.metaData}" />
            <wcf:param name="orderBy" value="${WCParam.orderBy}" />
            <c:forEach var="facetValue" items="${param.facet}">
                <c:if test="${fn:contains(facetValue , '|')}">   
                    <c:set var="facetValue" value="${fn:replace(facetValue,'|',',')}"/>
                </c:if>
                <wcf:param name="facet" value="${facetValue}" />
            </c:forEach>
            <wcf:param name="advancedFacetList" value="${newAdvancedFacetList}"/>
            <wcf:param name="categoryId" value="${currentCategoryId}" />
            <wcf:param name="filterTerm" value="${newFilterTerm}" />
            <wcf:param name="filterType" value="${WCParam.filterType}" />
            <wcf:param name="filterFacet" value="${removeFacet}" />
            <wcf:param name="manufacturer" value="${newManufacturer}" />
            <wcf:param name="minPrice" value="${WCParam.minPrice}" />
            <wcf:param name="maxPrice" value="${WCParam.maxPrice}" />
            <wcf:contextData name="storeId" data="${WCParam.storeId}" />
            <wcf:contextData name="catalogId" data="${WCParam.catalogId}" />
        </wcf:getData>

This is how we can call it from jsp but I want to call this facade from the command (from the java code) Please give me any suggestion

Thanks Ankit


Solution

  • You can do it like this :

    public someMethod(){
    ....
    CatalogFacadeClient catalogFacadeClient = new CatalogFacadeClient(getBusinessContextType(), null);
    
    GetType getVerb = CatalogFacadeClient.createGetVerb("_wcf:XPath", getXPathExpressionString());
    
    ShowCatalogNavigationViewDataAreaType showDataArea = catalogFacadeClient.getCatalogNavigationView(getVerb);
    response = showDataArea.getCatalogNavigationView();
    ....
    }
    
     public String getXPathExpressionString() {
    
      StringBuffer expression = new StringBuffer();
      expression.append("{_wcf.ap='IBM_Store_CatalogEntrySearch';");
      expression.append("_wcf.search.term='" + toto+ "';");
      expression.append("_wcf.search.spellcheck='false';");
      expression.append("_wcf.search.type='1000';");
      expression.append("_wcf.search.source='Q'}");
      expression.append("/CatalogNavigationView");
    return expression.toString();
    }
    
    protected BusinessContextType getBusinessContextType() {
      BusinessContextType businessContext = CommerceFoundationFactory.eINSTANCE.createBusinessContextType();
      ContextDataType storeId = CommerceFoundationFactory.eINSTANCE.createContextDataType();
      storeId.setName("storeId");
      storeId.setValue(currentStoreId);
      ContextDataType catalogId = CommerceFoundationFactory.eINSTANCE.createContextDataType();
      catalogId.setName("catalogId");
      catalogId.setValue(currentCatalogId);
      ContextDataType langIdContext = CommerceFoundationFactory.eINSTANCE.createContextDataType();
      langIdContext.setName("langId");
      langIdContext.setValue(langId.toString());
      businessContext.getContextData().add(storeId);
      businessContext.getContextData().add(catalogId);
      businessContext.getContextData().add(langIdContext);
    
      return businessContext;
    }