Question

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

Was it helpful?

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;
}

OTHER TIPS

Your code works!! Thank you so much!

Some Remarks about getXPathExpressionString() method:

1.- In order to prepare the expression builder correctly please check get-data-config.xml and get the expression builder by name. Name is the expressionBuilder param in wcf:getData

expressionBuilder="${navigationView}"


<wcf:getData type="com.ibm.commerce.catalog.facade.datatypes.CatalogNavigationViewType" var="catalogNavigationView" 
                expressionBuilder="${navigationView}" varShowVerb="showCatalogNavigationView" 
                maxItems="${pageSize}" recordSetStartNumber="${WCParam.beginIndex}">

Value of ${navigationView} is = "getCatalogNavigationView"

Search this value in get-data-config.xml file and look like this:

<expression-builder>
    <name>getCatalogNavigationView</name>
    <data-type-name>CatalogNavigationView</data-type-name>
    <expression-template>{_wcf.ap='$accessProfile$';_wcf.search.profile='$searchProfile$';_wcf.search.facet.field.limit='$facetLimit$';_wcf.search.term='$searchTerm$';_wcf.search.intent.term='$intentSearchTerm$';_wcf.search.originalterm='$originalSearchTerm$';_wcf.search.category='$categoryId$';_wcf.search.type='$searchType$';_wcf.search.exclude.term='$filterTerm$';_wcf.search.exclude.type='$filterType$';_wcf.search.manufacturer='$manufacturer$';_wcf.search.price.minimum='$minPrice$';_wcf.search.price.maximum='$maxPrice$';_wcf.search.facet='$facet$';_wcf.search.advanced.facet='$advancedFacetList$';_wcf.search.exclude.facet='$filterFacet$';_wcf.search.sort='$orderBy$';_wcf.search.meta='$metaData$';_wcf.search.source='$searchSource$';_wcf.search.store='$physicalStoreIds$'}/CatalogNavigationView</expression-template>
    <param>
        <name>accessProfile</name>
        <value>IBM_Store_CatalogEntrySearch</value>
    </param>
    <param>
        <name>searchType</name>
        <value>0</value>
    </param>
    <param>
        <name>searchSource</name>
        <value>O</value>
    </param>
    <param>
        <name>searchProfile</name>
        <value>IBM_findCatalogEntryByNameAndShortDescription</value>
    </param>
</expression-builder>

source: http://158.85.49.234/WEB-INF/config/com.ibm.commerce.catalog-fep/get-data-config.xml

So this tag : <expression-template> contains the treasure :), i.e the solr query expression.

2.- With this expression-template we could can create a correct expression:

public String getXPathExpressionString() throws JspException, AbstractBusinessObjectDocumentException {

        String expressionTemplate = "{_wcf.ap='$accessProfile$';_wcf.search.profile='$searchProfile$';_wcf.search.category='$categoryId$';_wcf.search.type='$searchType$';_wcf.search.sort='$orderBy$';_wcf.search.source='$searchSource$';_wcf.search.facet='$facet$';_wcf.search.exclude.facet='$filterFacet$';_wcf.search.meta='$metaData$';_wcf.search.price.minimum='$minPrice$';_wcf.search.price.maximum='$maxPrice$'}/CatalogNavigationView";

        ExpressionBuilderConfig expressionBuilderConfig = new ExpressionBuilderConfig();
        expressionBuilderConfig.setName("getCatalogNavigationView");
        expressionBuilderConfig.setDataTypeName("CatalogNavigationView");
        expressionBuilderConfig.setExpressionLanguage("_wcf:XPath");
        expressionBuilderConfig.setExpressionTemplate(expressionTemplate);

        HashMap<String,String[]> parameters = new HashMap<String, String[]>();
        parameters.put("accessProfile", new String[]{"IBM_Store_CatalogEntrySearch"});
        parameters.put("searchProfile", new String[]{"IBM_findCatalogEntryByNameAndShortDescription"});
        parameters.put("searchType", new String[]{"xyz"});
        parameters.put("categoryId",new String[]{ "123"});
        parameters.put("minPrice",new String[]{"0"});

        ExpressionType expressionType = expressionBuilderConfig.buildExpression(parameters);

        return expressionType.getValue();
     }

-------------------------------*-------------------------------------

This can be used to convert websphere ecommerce in a back-end or service provider. With that we can stop using jsp, scriplets, dojo 1.5 and use whatever in front-end layer like current js frameworks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top