Subversion Repositories SmartDukaan

Rev

Rev 317 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 317 Rev 517
Line 1... Line 1...
1
/**
1
/**
2
 * 
2
 * 
3
 */
3
 */
4
package in.shop2020.serving.controllers;
4
package in.shop2020.serving.controllers;
5
 
5
 
-
 
6
import in.shop2020.model.v1.widgets.WidgetService.Client;
-
 
7
import in.shop2020.serving.pages.PageContentKeys;
-
 
8
import in.shop2020.serving.pages.PageEnum;
-
 
9
import in.shop2020.serving.services.PageLoaderHandler;
-
 
10
import in.shop2020.serving.services.SolrSearchService;
-
 
11
import in.shop2020.serving.utils.FileUtils;
-
 
12
import in.shop2020.thrift.clients.WidgetServiceClient;
-
 
13
import in.shop2020.util.Utils;
-
 
14
 
-
 
15
import java.io.File;
6
import java.io.IOException;
16
import java.io.IOException;
-
 
17
import java.net.URLEncoder;
-
 
18
import java.util.ArrayList;
-
 
19
import java.util.Arrays;
-
 
20
import java.util.HashMap;
-
 
21
import java.util.LinkedHashMap;
-
 
22
import java.util.List;
-
 
23
import java.util.Map;
7
 
24
 
-
 
25
import org.apache.commons.lang.StringUtils;
8
import org.apache.juli.logging.Log;
26
import org.apache.juli.logging.Log;
9
import org.apache.juli.logging.LogFactory;
27
import org.apache.juli.logging.LogFactory;
10
import org.apache.struts2.rest.DefaultHttpHeaders;
28
import org.apache.struts2.rest.DefaultHttpHeaders;
11
import org.apache.struts2.rest.HttpHeaders;
29
import org.apache.struts2.rest.HttpHeaders;
12
 
30
 
13
/**
31
/**
14
 * @author naveen
32
 * @author rajveer
15
 *
33
 *
16
 */
34
 */
17
public class CategoryController extends BaseController {
35
public class CategoryController extends BaseController {
18
	
36
	
19
	/**
37
	/**
20
	 * 
38
	 * 
21
	 */
39
	 */
22
	private static Log log = LogFactory.getLog(CategoryController.class);
40
	private static Log log = LogFactory.getLog(CategoryController.class);
23
	
41
 
-
 
42
	/**
-
 
43
	 * 
-
 
44
	 */
-
 
45
	private Map<String,String> htmlSnippets;
-
 
46
	private Map<String, String[]> results;
-
 
47
	private Map<String, String> snippets;
-
 
48
	private Map<String, List<String[]>> facets;
24
	/**
49
	/**
25
	 * 
50
	 * 
26
	 */
51
	 */
27
	private String id;
52
	private String id;
28
	
53
	
-
 
54
	private String query;
-
 
55
	
-
 
56
	private Double minPrice;
-
 
57
	private Double maxPrice;
-
 
58
	
29
	/**
59
	/**
30
	 * GET /category/10004
60
	 * GET /category/10004
31
	 * 
61
	 * 
32
	 */
62
	 */
33
    public HttpHeaders show() throws SecurityException, IOException {
63
    public HttpHeaders show() throws SecurityException, IOException {
34
    	log.info("id=" + id);
64
    	log.info("id=" + id);
-
 
65
    	htmlSnippets = new HashMap<String, String>();
-
 
66
    	PageLoaderHandler pageLoader = new PageLoaderHandler();
-
 
67
		
-
 
68
		htmlSnippets.put("HEADER", pageLoader.getHeaderHtml(userinfo.getUserId(), userinfo.isSessionId(), userinfo.getNameOfUser()));
-
 
69
		htmlSnippets.put("MAIN_MENU", pageLoader.getMainMenuHtml());
-
 
70
		htmlSnippets.put("SEARCH_BAR", pageLoader.getSearchBarHtml(userinfo.getTotalItems(), 10000));
-
 
71
		htmlSnippets.put("CUSTOMER_SERVICE", pageLoader.getCustomerServiceHtml());
-
 
72
		htmlSnippets.put("MY_RESEARCH", pageLoader.getMyResearchHtml(userinfo.getUserId(), userinfo.isSessionId()));
-
 
73
		htmlSnippets.put("FOOTER",pageLoader.getFooterHtml());
-
 
74
		
-
 
75
		htmlSnippets.put("CATEGORY_HEADER", pageLoader.getCategoryHeaderSnippet());
-
 
76
		htmlSnippets.put("MAIN_BANNER", "");
-
 
77
		htmlSnippets.put("SIDE_BANNER", "");
-
 
78
		htmlSnippets.put("TAB_BUTTONS", "");
-
 
79
		htmlSnippets.put("FOOTER", "");
-
 
80
 
-
 
81
 
-
 
82
		
-
 
83
		String[] facetDefIDs = new String[] {"Category","F_50002","F_50001",  "F_50006", "F_50007" };
-
 
84
    	
-
 
85
    	String[] facetLabels = new String[] {"Category","Price", "Brand", "Data Connectivity", "Camera Resolution" 	};
-
 
86
 
-
 
87
    	String[] fqrys = this.request.getParameterValues("fq");
-
 
88
    	query = "*";
-
 
89
    	
-
 
90
    	SolrSearchService search = new SolrSearchService(query, fqrys, facetDefIDs);
-
 
91
    	this.results = new LinkedHashMap<String, String[]>();
-
 
92
    	this.results =  search.getResultMap(); 
-
 
93
 
-
 
94
    	
-
 
95
    	
-
 
96
    	
-
 
97
    	this.facets = new LinkedHashMap<String, List<String[]>>();
-
 
98
    	String qryString = this.request.getQueryString();
-
 
99
    	log.info("qryString=" + qryString);
-
 
100
    	
-
 
101
    	for (int i=0; i<facetDefIDs.length; i++) {
-
 
102
    		String facetDefID = facetDefIDs[i];
-
 
103
    		String facetLabel = facetLabels[i];
-
 
104
    		HashMap<String, Integer> facetDetailMap = search.getFacetDetails(facetDefID);
-
 
105
    		if(facetDetailMap==null)
-
 
106
    			continue;
-
 
107
    		List<String[]> values = new ArrayList<String[]>();
-
 
108
    		for(String facet: facetDetailMap.keySet()){
-
 
109
      			String drilldownURL = "fq=" + facetDefID + ":" + 
-
 
110
    				URLEncoder.encode(facet, "UTF-8"); 
-
 
111
      			String[] afacet = new String[] { facet, 
-
 
112
      					facetDetailMap.get(facet).toString(), drilldownURL  };
-
 
113
      			values.add(afacet);    
-
 
114
      		  
-
 
115
    		}
-
 
116
    		
-
 
117
    		this.facets.put(facetLabel, values);
-
 
118
    	}
-
 
119
    	
-
 
120
    	
-
 
121
    	Map<String, Double> priceMap = search.getPriceStatsMap();
-
 
122
    	if(priceMap != null){
-
 
123
    		this.minPrice = priceMap.get("min");
-
 
124
    		this.maxPrice = priceMap.get("max");
-
 
125
    	}else{
-
 
126
    		this.minPrice = 0.0;
-
 
127
    		this.maxPrice = 0.0;
-
 
128
    	}
35
 
129
 
36
        return new DefaultHttpHeaders("show");
130
        return new DefaultHttpHeaders("show");
37
    }
131
    }
38
    
132
    
39
    /**
133
    /**
Line 48... Line 142...
48
     * 
142
     * 
49
     */
143
     */
50
    public String getId() {
144
    public String getId() {
51
    	return this.id;
145
    	return this.id;
52
    }
146
    }
-
 
147
    
-
 
148
    public String getHeaderSnippet(){
-
 
149
		return htmlSnippets.get("HEADER");
-
 
150
	}
-
 
151
	
-
 
152
	public String getMainMenuSnippet(){
-
 
153
		return htmlSnippets.get("MAIN_MENU");
-
 
154
	}
-
 
155
	
-
 
156
	public String getSearchBarSnippet(){
-
 
157
		return htmlSnippets.get("SEARCH_BAR");
-
 
158
	}
-
 
159
			
-
 
160
	public String getCustomerServiceSnippet(){
-
 
161
		return htmlSnippets.get("CUSTOMER_SERVICE");
-
 
162
	}
-
 
163
	
-
 
164
	public String getSearchHeaderSnippet(){
-
 
165
		return htmlSnippets.get("SEARCH_HEADER");
-
 
166
	}
-
 
167
	
-
 
168
	public String getSearchDetailsSnippet(){
-
 
169
		return htmlSnippets.get("SEARCH_DETAILS");
-
 
170
	}
-
 
171
	
-
 
172
	public String getMyResearchSnippet(){
-
 
173
		return htmlSnippets.get("MY_RESEARCH");
-
 
174
	}
-
 
175
				
-
 
176
	public String getFooterSnippet(){
-
 
177
		return htmlSnippets.get("FOOTER");
-
 
178
	}
-
 
179
	
-
 
180
	public String getJsFileSnippet(){
-
 
181
		return htmlSnippets.get("JS_FILES");
-
 
182
	}
-
 
183
	
-
 
184
	public String getCssFileSnippet(){
-
 
185
		return htmlSnippets.get("CSS_FILES");
-
 
186
	}
-
 
187
 
-
 
188
    /**
-
 
189
     * 
-
 
190
     * @return
-
 
191
     */
-
 
192
    public String getQuery() {
-
 
193
    	return this.query;
-
 
194
    }
-
 
195
    
-
 
196
    
-
 
197
    /**
-
 
198
     * 
-
 
199
     * @return
-
 
200
     */
-
 
201
    public Map<String, String[]> getResults() {
-
 
202
    	return this.results;
-
 
203
    }
-
 
204
    
-
 
205
    /**
-
 
206
     * 
-
 
207
     * @return
-
 
208
     */
-
 
209
    public Map<String, List<String[]>> getFacets() {
-
 
210
    	return this.facets;
-
 
211
    }
-
 
212
    
-
 
213
    public Double getMinPrice() {
-
 
214
    	return this.minPrice;
-
 
215
    }
-
 
216
    
-
 
217
    public Double getMaxPrice() {
-
 
218
    	return this.maxPrice;
-
 
219
    }
-
 
220
    
-
 
221
    public Map<String, String> getSnippets() throws Exception {
-
 
222
    	if(results != null){
-
 
223
    		snippets = new HashMap<String, String>();	
-
 
224
	    	for(String docId: results.keySet()){
-
 
225
				snippets.put(docId, FileUtils.read( Utils.EXPORT_ENTITIES_PATH + docId + File.separator +"SearchSnippet.html"));
-
 
226
			}
-
 
227
    	}
-
 
228
		return snippets;
-
 
229
    }
-
 
230
 
53
}
231
}