Rev 517 | Blame | Last modification | View Log | RSS feed
/****/package in.shop2020.serving.controllers;import in.shop2020.model.v1.widgets.WidgetService.Client;import in.shop2020.serving.pages.PageContentKeys;import in.shop2020.serving.pages.PageEnum;import in.shop2020.serving.services.CategoryManager;import in.shop2020.serving.services.PageLoaderHandler;import in.shop2020.serving.services.SolrSearchService;import in.shop2020.serving.utils.FileUtils;import in.shop2020.thrift.clients.WidgetServiceClient;import in.shop2020.util.Utils;import java.io.File;import java.io.IOException;import java.net.URLEncoder;import java.util.ArrayList;import java.util.Arrays;import java.util.HashMap;import java.util.LinkedHashMap;import java.util.List;import java.util.Map;import java.util.StringTokenizer;import org.apache.commons.lang.StringUtils;import org.apache.juli.logging.Log;import org.apache.juli.logging.LogFactory;import org.apache.struts2.rest.DefaultHttpHeaders;import org.apache.struts2.rest.HttpHeaders;/*** @author rajveer**/public class CategoryController extends BaseController {/****/private static Log log = LogFactory.getLog(CategoryController.class);/****/private Map<String,String> htmlSnippets;private Map<String, String[]> results;private Map<String, String> snippets;private Map<String, List<String[]>> facets;/****/private String id;private String categoryName;private String query;private Double minPrice;private Double maxPrice;/*** GET /category/10004**/public HttpHeaders show() throws SecurityException, IOException {log.info("id=" + id);this.categoryName = CategoryManager.getCategoryManager().getCategoryLabel(Long.parseLong(id));htmlSnippets = new HashMap<String, String>();PageLoaderHandler pageLoader = new PageLoaderHandler();htmlSnippets.put("HEADER", pageLoader.getHeaderHtml(userinfo.getUserId(), userinfo.isSessionId(), userinfo.getNameOfUser()));htmlSnippets.put("MAIN_MENU", pageLoader.getMainMenuHtml());htmlSnippets.put("SEARCH_BAR", pageLoader.getSearchBarHtml(userinfo.getTotalItems(), 10000));htmlSnippets.put("CUSTOMER_SERVICE", pageLoader.getCustomerServiceHtml());htmlSnippets.put("MY_RESEARCH", pageLoader.getMyResearchHtml(userinfo.getUserId(), userinfo.isSessionId()));htmlSnippets.put("FOOTER",pageLoader.getFooterHtml());htmlSnippets.put("CATEGORY_HEADER", pageLoader.getCategoryHeaderSnippet());htmlSnippets.put("MAIN_BANNER", "");htmlSnippets.put("SIDE_BANNER", "");htmlSnippets.put("TAB_BUTTONS", "");htmlSnippets.put("FOOTER", "");String[] facetDefIDs = new String[] {"Category","F_50002","F_50001", "F_50006", "F_50007" };String[] facetLabels = new String[] {"Category","Price", "Brand", "Data Connectivity", "Camera Resolution" };String[] fqrys = this.request.getParameterValues("fq");query = "*";int length = 1;if(fqrys!= null){length += fqrys.length;}String[] newfqrys = new String[length];newfqrys[0] = "F_50001:"+categoryName;for(int i=1; i<length; i++) {newfqrys[i] = fqrys[i-1];}SolrSearchService search = new SolrSearchService(query, newfqrys, facetDefIDs);this.results = new LinkedHashMap<String, String[]>();this.results = search.getResultMap();this.facets = new LinkedHashMap<String, List<String[]>>();String qryString = this.request.getQueryString();log.info("qryString=" + qryString);for (int i=0; i<facetDefIDs.length; i++) {String facetDefID = facetDefIDs[i];String facetLabel = facetLabels[i];HashMap<String, Integer> facetDetailMap = search.getFacetDetails(facetDefID);if(facetDetailMap==null)continue;List<String[]> values = new ArrayList<String[]>();for(String facet: facetDetailMap.keySet()){String drilldownURL = new String();if(qryString != null){drilldownURL = qryString;}drilldownURL = "fq=" + facetDefID + ":" +URLEncoder.encode(facet, "UTF-8");String[] afacet = new String[] { facet,facetDetailMap.get(facet).toString(), drilldownURL };values.add(afacet);}this.facets.put(facetLabel, values);}Map<String, Double> priceMap = search.getPriceStatsMap();if(priceMap != null){this.minPrice = priceMap.get("min");this.maxPrice = priceMap.get("max");}else{this.minPrice = 0.0;this.maxPrice = 0.0;}return new DefaultHttpHeaders("show");}/**** @param id*/public void setId(String id) {StringTokenizer tokenizer = new StringTokenizer(id,"-");while(tokenizer.hasMoreTokens()){this.id = tokenizer.nextToken();}}/****/public String getId() {return this.id;}public String getCategoryName() {return this.categoryName;}public String getHeaderSnippet(){return htmlSnippets.get("HEADER");}public String getMainMenuSnippet(){return htmlSnippets.get("MAIN_MENU");}public String getSearchBarSnippet(){return htmlSnippets.get("SEARCH_BAR");}public String getCustomerServiceSnippet(){return htmlSnippets.get("CUSTOMER_SERVICE");}public String getSearchHeaderSnippet(){return htmlSnippets.get("SEARCH_HEADER");}public String getSearchDetailsSnippet(){return htmlSnippets.get("SEARCH_DETAILS");}public String getMyResearchSnippet(){return htmlSnippets.get("MY_RESEARCH");}public String getFooterSnippet(){return htmlSnippets.get("FOOTER");}public String getJsFileSnippet(){return htmlSnippets.get("JS_FILES");}public String getCssFileSnippet(){return htmlSnippets.get("CSS_FILES");}/**** @return*/public String getQuery() {return this.query;}/**** @return*/public Map<String, String[]> getResults() {return this.results;}/**** @return*/public Map<String, List<String[]>> getFacets() {return this.facets;}public Double getMinPrice() {return this.minPrice;}public Double getMaxPrice() {return this.maxPrice;}public Map<String, String> getSnippets() throws Exception {if(results != null){snippets = new HashMap<String, String>();for(String docId: results.keySet()){snippets.put(docId, FileUtils.read( Utils.EXPORT_ENTITIES_PATH + docId + File.separator +"CategorySnippet.html"));}}return snippets;}}