Subversion Repositories SmartDukaan

Rev

Rev 3173 | Rev 3304 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3173 Rev 3303
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
3
import in.shop2020.serving.services.SolrSearchService;
3
import in.shop2020.serving.services.SolrSearchService;
-
 
4
import in.shop2020.serving.services.SpecialPageConfigurer;
4
import in.shop2020.serving.utils.FileUtils;
5
import in.shop2020.serving.utils.FileUtils;
5
import in.shop2020.serving.utils.Utils;
6
import in.shop2020.serving.utils.Utils;
6
 
7
 
7
import java.io.BufferedReader;
-
 
8
import java.io.File;
8
import java.io.File;
9
import java.io.FileReader;
-
 
10
import java.io.IOException;
9
import java.io.IOException;
11
import java.net.URLEncoder;
10
import java.net.URLEncoder;
12
import java.util.ArrayList;
11
import java.util.ArrayList;
13
import java.util.Arrays;
12
import java.util.Arrays;
14
import java.util.HashMap;
13
import java.util.HashMap;
Line 19... Line 18...
19
 
18
 
20
import org.apache.commons.lang.StringUtils;
19
import org.apache.commons.lang.StringUtils;
21
import org.apache.log4j.Logger;
20
import org.apache.log4j.Logger;
22
import org.apache.struts2.convention.annotation.Result;
21
import org.apache.struts2.convention.annotation.Result;
23
import org.json.JSONException;
22
import org.json.JSONException;
24
import org.json.JSONObject;
-
 
25
 
23
 
26
/**
24
/**
27
 * @author rajveer
25
 * @author rajveer
28
 *
26
 *
29
 */
27
 */
30
@Result(name = "index", location = "special-page-index.vm")
28
@Result(name = "index", location = "special-page-index.vm")
31
public class SpecialPageController extends BaseController {
29
public class SpecialPageController extends BaseController {
32
    private static final long serialVersionUID = 1L;
30
    private static final long serialVersionUID = 1L;
33
    private static Logger log = Logger.getLogger(Class.class);
31
    private static Logger log = Logger.getLogger(Class.class);
34
	private static Map<String, JSONObject> specialPagesDetails;
-
 
35
 
32
 
36
	private static final String[] facetDefIDs = 
33
	private static final String[] facetDefIDs = 
37
	    new String[] {"F_50010","F_50011","F_50002","F_50001",  "F_50006", "F_50007" };
34
	    new String[] {"F_50010","F_50011","F_50002","F_50001",  "F_50006", "F_50007" };
38
 
35
 
39
	private static final String[] facetLabels = 
36
	private static final String[] facetLabels = 
40
	    new String[] {"Category","Sub Category","Price", "Brand", "Data Connectivity", "Camera Resolution" };
37
	    new String[] {"Category","Sub Category","Price", "Brand", "Data Connectivity", "Camera Resolution" };
41
 
38
 
42
	static {
-
 
43
	    try {
-
 
44
	        loadSpecialPagesDetails();
-
 
45
	    }
-
 
46
	    catch (IOException e) {
-
 
47
            log.error("Could not load special pages details", e);
-
 
48
        }
-
 
49
	    catch (JSONException e) {
-
 
50
            log.error("Could not load special pages details", e);
-
 
51
        }
-
 
52
	}
-
 
53
 
-
 
54
	private List<String> results;
39
	private List<String> results;
55
	private Map<String, String> snippets;
40
	private Map<String, String> snippets;
56
	private Map<String, List<String[]>> facets;
41
	private Map<String, List<String[]>> facets;
57
	private List<String[]> crumbs;
42
	private List<String[]> crumbs;
58
 
43
 
Line 69... Line 54...
69
	private long page = 1;
54
	private long page = 1;
70
	private long totalResults;
55
	private long totalResults;
71
	private long beginIndex = 0;
56
	private long beginIndex = 0;
72
	private String url;
57
	private String url;
73
	private String priceUrl = "?";
58
	private String priceUrl = "?";
74
 
-
 
75
	/**
-
 
76
	 * GET /abc/10004
59
	private String uri;
77
	 * 
60
	
78
	 */
-
 
79
//    @Actions({ @Action("/nokia"),
-
 
80
//               @Action("/samsung"),
-
 
81
//               @Action("/spice"),
-
 
82
//               @Action("/blackberry"),
-
 
83
//               @Action("/sony-ericsson"),
-
 
84
//               @Action("/micromax"),
-
 
85
//               @Action("/lg"),
-
 
86
//               @Action("/htc"),
-
 
87
//               @Action("/motorola"),
-
 
88
//               @Action("/dell"),
-
 
89
//               @Action("/apple"),
-
 
90
//               @Action("/android"),
-
 
91
//               @Action("/brand") })
-
 
92
    public String index() throws SecurityException, IOException, JSONException {
61
	public String index() throws SecurityException, IOException, JSONException {
93
	    String uri = request.getRequestURI();
62
		uri = request.getRequestURI();
94
	    log.info("Uri: " + uri);
63
	    log.info("Uri: " + uri);
95
	    specialPageName  = getSpecialPageNameFromUri(uri);
64
	    specialPageName  = SpecialPageConfigurer.getSpecialPageNameFromUri(uri);
96
	    specialPageTitle = getSpecialPageTitleFromUri(uri);
65
	    specialPageTitle = SpecialPageConfigurer.getSpecialPageTitleFromUri(uri);
97
	    query            = getQueryFromUri(uri);
66
	    query            = SpecialPageConfigurer.getQueryFromUri(uri);
98
        
67
        
99
    	String[] fqrys = this.request.getParameterValues("fq");
68
    	String[] fqrys = this.request.getParameterValues("fq");
100
 
69
 
101
    	url = "?";
70
    	url = "?";
102
 
71
 
Line 113... Line 82...
113
    	else {
82
    	else {
114
    		newfqrys = new String[length+1];
83
    		newfqrys = new String[length+1];
115
    	}
84
    	}
116
    	
85
    	
117
    	if(specialPageName.equals("Android")){
86
    	if(specialPageName.equals("Android")){
118
    		newfqrys[0] = "F_50010:" + "(\"Mobile Phones\" OR Tablets)";
87
    		newfqrys[0] = "F_50010:" + "(\"Mobile Phones\") OR Tablets";
119
    	}
88
    	}
120
    	else {
89
    	else {
121
    		newfqrys[0] = "F_50001:" + specialPageName;
90
    		newfqrys[0] = "F_50001:" + specialPageName;
122
    		newfqrys[length] = "F_50010:" + "(\"Mobile Phones\" OR Tablets)";
91
    		newfqrys[length] = "F_50010:" + "(\"Mobile Phones\") OR Tablets";
123
    	}
92
    	}
124
 
93
 
125
    	String urlCrumb = url;
94
    	String urlCrumb = url;
126
    	
95
    	
127
    	this.crumbs = new ArrayList<String[]>();
96
    	this.crumbs = new ArrayList<String[]>();
Line 212... Line 181...
212
    public String getPageMetaDesc() {
181
    public String getPageMetaDesc() {
213
    	return "Best price " + this.facetSelection + this.specialPageName.replaceAll("Phones", "mobile phones") 
182
    	return "Best price " + this.facetSelection + this.specialPageName.replaceAll("Phones", "mobile phones") 
214
    	    + " mobile phones in India. Experience n' buy online. FREE Next Day delivery. Original product - Full manufacturer warranty. Comprehensive reviews."; 
183
    	    + " mobile phones in India. Experience n' buy online. FREE Next Day delivery. Original product - Full manufacturer warranty. Comprehensive reviews."; 
215
    }
184
    }
216
    
185
    
-
 
186
    
217
    public String getPageMetaKeywords() throws JSONException {
187
    public String getPageMetaKeywords() throws JSONException {
218
       	return specialPagesDetails.get(request.getRequestURI()).getString("metaKeywords");
188
       	return SpecialPageConfigurer.getPageMetaKeywords(uri);
219
    }
189
    }
220
    
190
    
221
	public long getBeginIndex(){
191
	public long getBeginIndex(){
222
		if(totalResults>0)
192
		if(totalResults>0)
223
			return beginIndex+1;
193
			return beginIndex+1;
Line 240... Line 210...
240
			}
210
			}
241
    	}
211
    	}
242
		return snippets;
212
		return snippets;
243
    }
213
    }
244
 
214
 
245
    /**
-
 
246
     * Loads all special pages related details
-
 
247
     */
-
 
248
    private static void loadSpecialPagesDetails() throws IOException, JSONException {
-
 
249
        FileReader fr = new FileReader(Utils.EXPORT_ENTITIES_PATH + "../../javascripts/special-pages.json");
-
 
250
        BufferedReader br = new BufferedReader(fr);
-
 
251
        String str = null;
-
 
252
 
-
 
253
        specialPagesDetails = new HashMap<String, JSONObject>();
-
 
254
        while ((str = br.readLine()) != null) {
-
 
255
            JSONObject jsonObject = new JSONObject(str);
-
 
256
            specialPagesDetails.put(jsonObject.getString("saholicURL"),
-
 
257
                    jsonObject);
-
 
258
        }
-
 
259
 
-
 
260
        log.info(specialPagesDetails);
-
 
261
    }
-
 
262
 
-
 
263
    /**
-
 
264
     * Returns true in case a string passed is a special page name
-
 
265
     */
-
 
266
    public static boolean isValidSpecialPage(String specialPage) {
-
 
267
        if (specialPage == null) {
-
 
268
            return false;
-
 
269
        }
-
 
270
 
-
 
271
        return specialPagesDetails.containsKey(specialPage);
-
 
272
    }
-
 
273
 
-
 
274
    private String getQueryFromUri(String uri) throws JSONException {
-
 
275
        return specialPagesDetails.get(uri).getString("searchQuery");
-
 
276
    }
-
 
277
 
-
 
278
    private String getSpecialPageTitleFromUri(String uri) throws JSONException {
-
 
279
        return specialPagesDetails.get(uri).getString("pageTitle");
-
 
280
    }
-
 
281
 
-
 
282
    private String getSpecialPageNameFromUri(String uri) throws JSONException {
-
 
283
        return specialPagesDetails.get(uri).getString("displayName");
-
 
284
    }
-
 
285
 
-
 
286
    public long getCurrentPage() {
215
    public long getCurrentPage() {
287
        return this.page;
216
        return this.page;
288
    }
217
    }
289
 
218
 
290
    public Double getMinPrice() {
219
    public Double getMinPrice() {