Warranty suggestion Java class
The following page contains the sample code of
the Warranty suggestion Java class for use in the tutorial Adding
suggestion groups to the auto-suggest menu. The tutorial uses the
following code to create a Java class that will return all of the
possible values for your navigation suggestion grouping for the warranty
type. The class finds all possible values and populates the information
into the storefront JSP business objects.
package com.mycompany.commerce.search;
import java.math.BigInteger;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Logger;
import com.ibm.commerce.catalog.facade.client.CatalogNavigationViewFacadeClient;
import com.ibm.commerce.catalog.facade.datatypes.CatalogFactory;
import com.ibm.commerce.catalog.facade.datatypes.CatalogNavigationViewType;
import com.ibm.commerce.catalog.facade.datatypes.ShowCatalogNavigationViewDataAreaType;
import com.ibm.commerce.catalog.facade.datatypes.SuggestionEntryViewType;
import com.ibm.commerce.catalog.facade.datatypes.SuggestionViewType;
import com.ibm.commerce.catalog.facade.server.services.search.suggestion.solr.AbstractNavigationSuggestion;
import com.ibm.commerce.catalog.facade.server.services.search.suggestion.solr.NavigationSuggestion;
import com.ibm.commerce.foundation.client.facade.bod.AbstractBusinessObjectDocumentFacadeClient;
import com.ibm.commerce.foundation.client.util.oagis.RelationalExpression;
import com.ibm.commerce.foundation.client.util.oagis.SelectionCriteriaHelper;
import com.ibm.commerce.foundation.common.util.logging.LoggingHelper;
import com.ibm.commerce.foundation.server.services.search.SearchServiceConstants;
import com.ibm.commerce.oagis9.datatypes.GetType;
public class WarrantySuggestion extends AbstractNavigationSuggestion implements
NavigationSuggestion {
/*
* The class name
*/
private static final String CLASSNAME = WarrantySuggestion.class.getName();
/*
* The logger used for logging.
*/
private static final Logger LOGGER = LoggingHelper.getLogger(WarrantySuggestion.class);
/**
* {@inheritDoc}
*/
public void populateSuggestion(String profile, SuggestionViewType suggestionCategory) {
final String METHODNAME = "populateSuggestion";
if (LoggingHelper.isEntryExitTraceEnabled(LOGGER)) {
LOGGER.entering(CLASSNAME, METHODNAME, new Object[] {
profile, suggestionCategory });
}
List entries = suggestionCategory.getEntry();
//--------------------------------------------------------------------------//
// Fetch all of the warranties for the given store and catalog
//--------------------------------------------------------------------------//
SelectionCriteriaHelper selectionCriteriaHelper = new SelectionCriteriaHelper("/CatalogNavigationView");
selectionCriteriaHelper.addAccessProfile("IBM_Store_CatalogEntrySearch");
// set search profile
selectionCriteriaHelper.addNameValuePair(
new RelationalExpression(SearchServiceConstants.CTRL_PARAM_SEARCH_PROFILE,
"x_MyCompany_findNavigationSuggestion_Warranty",
RelationalExpression.STR_EQ_OPERATOR));
// set search profile
selectionCriteriaHelper.addNameValuePair(
new RelationalExpression(SearchServiceConstants.CTRL_PARAM_SEARCH_FACET_FIELD,
"wartype_ntk_cs",
RelationalExpression.STR_EQ_OPERATOR));
CatalogNavigationViewFacadeClient catNavFacadeClient = getCatalogNavigationViewFacadeClient();
GetType getVerb = AbstractBusinessObjectDocumentFacadeClient.createGetVerb(
selectionCriteriaHelper.getSelectionCriteriaExpression());
getVerb.setRecordSetStartNumber(BigInteger.ZERO);
// Call the catalog navigation view web service
ShowCatalogNavigationViewDataAreaType dataArea = callGetCatalogNavigationViewService(catNavFacadeClient, getVerb);
if(dataArea!=null) {
suggestionCategory.setIdentifier("myID");
suggestionCategory.setLabel("Warranty");
List<CatalogNavigationViewType> lstResult = dataArea
.getCatalogNavigationView();
if (lstResult != null && lstResult.size() > 0) {
CatalogNavigationViewType cnv = lstResult.get(0);
List facets = cnv.getFacetView();
Iterator it = facets.iterator();
while(it.hasNext()) {
com.ibm.commerce.catalog.facade.datatypes.FacetViewType
facet = (com.ibm.commerce.catalog.facade.datatypes.FacetViewType) it.next();
String facetName = facet.getName();
String facetValue = facet.getValue();
suggestionCategory.setLabel(facetName);
List facetEntries = facet.getEntry();
Iterator entryIt = facetEntries.iterator();
while(entryIt.hasNext()) {
com.ibm.commerce.catalog.facade.datatypes.FacetEntryViewType
facetEntry = (com.ibm.commerce.catalog.facade.datatypes.FacetEntryViewType)
entryIt.next();
String facetEntryLabel = facetEntry.getLabel();
String facetEntryValue = facetEntry.getValue();
SuggestionEntryViewType entry = CatalogFactory.eINSTANCE.createSuggestionEntryViewType();
entry.setName(facetEntryLabel);
entry.setValue(facetEntryValue);
entries.add(entry);
}
}
}
} // end if(dataArea!=null)
// Exit trace
if (LoggingHelper.isEntryExitTraceEnabled(LOGGER)) {
LOGGER.exiting(CLASSNAME, METHODNAME);
}
}
}