| 4518 |
varun.gupt |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.serving.cache.SnippetCacheWrapper;
|
|
|
4 |
import in.shop2020.serving.cache.EhcacheWrapper.CacheKeys;
|
| 5460 |
phani.kuma |
5 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 4518 |
varun.gupt |
6 |
|
|
|
7 |
import java.util.ArrayList;
|
| 6463 |
rajveer |
8 |
import java.util.Arrays;
|
| 4518 |
varun.gupt |
9 |
import java.util.List;
|
|
|
10 |
|
| 5460 |
phani.kuma |
11 |
import org.apache.log4j.Logger;
|
| 6381 |
rajveer |
12 |
import org.apache.struts2.convention.annotation.Action;
|
|
|
13 |
import org.apache.struts2.convention.annotation.Actions;
|
|
|
14 |
import org.apache.struts2.convention.annotation.Result;
|
| 5460 |
phani.kuma |
15 |
|
| 4518 |
varun.gupt |
16 |
/**
|
|
|
17 |
* @author Varun Gupta
|
|
|
18 |
*/
|
| 4882 |
rajveer |
19 |
@SuppressWarnings("serial")
|
| 6381 |
rajveer |
20 |
@Result(name = "index", location = "clearance-sale-index.vm")
|
| 4518 |
varun.gupt |
21 |
public class ClearanceSaleController extends BaseController {
|
|
|
22 |
|
| 5460 |
phani.kuma |
23 |
private static Logger log = Logger.getLogger(ClearanceSaleController.class);
|
| 6381 |
rajveer |
24 |
private static List<Long> entityIds = new ArrayList<Long>();
|
| 6463 |
rajveer |
25 |
private static List<Long> sonyEntityIds = Arrays.asList(1004874L, 1002111L, 1003428L, 1003376L, 1004882L, 1004204L, 1003426L, 1005156L, 1004429L, 1004842L);
|
| 6483 |
amit.gupta |
26 |
private static List<Long> googleEntityIds = Arrays.asList( 1004202L, 1001674L, 1004207L, 1003235L, 1002294L, 1004874L,1004874L, 1003428L, //Mobiles - Tablets
|
| 6476 |
rajveer |
27 |
1004751L, 1004755L, 1004790L, 1004795L, 1005435L, //Cameras
|
| 6473 |
rajveer |
28 |
1005067L, 1005081L, 1004252L, 1005137L, 1005128L, 1005118L, //Laptops
|
| 6463 |
rajveer |
29 |
1005024L, 1005251L); //Accessories
|
|
|
30 |
|
|
|
31 |
//1005330L, 1005366);
|
| 5460 |
phani.kuma |
32 |
private List<String> snippets = new ArrayList<String>();
|
| 6381 |
rajveer |
33 |
private List<String> sonySnippets = new ArrayList<String>();
|
| 6463 |
rajveer |
34 |
private List<String> googleSnippets = new ArrayList<String>();
|
| 4518 |
varun.gupt |
35 |
|
| 6463 |
rajveer |
36 |
static {
|
| 5460 |
phani.kuma |
37 |
try {
|
| 6381 |
rajveer |
38 |
CatalogClient catalogClientService = new CatalogClient();
|
| 5945 |
mandeep.dh |
39 |
in.shop2020.model.v1.catalog.CatalogService.Client client = catalogClientService.getClient();
|
| 5460 |
phani.kuma |
40 |
log.info("Getting clearance sale products snippets.");
|
|
|
41 |
entityIds = client.getClearanceSaleCatalogIds();
|
|
|
42 |
} catch (Exception e) {
|
|
|
43 |
log.error("Unable to get clearance sale products from inventory service", e);
|
|
|
44 |
}
|
|
|
45 |
}
|
| 6381 |
rajveer |
46 |
|
|
|
47 |
@Actions({
|
|
|
48 |
@Action("/clearance-sale"),
|
| 6463 |
rajveer |
49 |
@Action("/sony"),
|
|
|
50 |
@Action("/google-great-online-shopping-festival")
|
| 6381 |
rajveer |
51 |
})
|
| 4520 |
varun.gupt |
52 |
public String index() {
|
| 4518 |
varun.gupt |
53 |
return "index";
|
|
|
54 |
}
|
|
|
55 |
|
| 6381 |
rajveer |
56 |
public void addEntityId(Long entityId, List<String> snippets) {
|
| 4520 |
varun.gupt |
57 |
|
| 5460 |
phani.kuma |
58 |
String snippet = (String) SnippetCacheWrapper.getSnippet(CacheKeys.CATEGORY_SNIPPET_CACHE_KEY, entityId+"", sourceId);
|
| 4520 |
varun.gupt |
59 |
|
|
|
60 |
if (snippet != null) {
|
| 5460 |
phani.kuma |
61 |
snippets.add(snippet);
|
| 4520 |
varun.gupt |
62 |
}
|
| 4518 |
varun.gupt |
63 |
}
|
|
|
64 |
|
| 5460 |
phani.kuma |
65 |
public List<String> getSnippets() {
|
| 6463 |
rajveer |
66 |
if(request.getRequestURI().contains("google-great-online-shopping-festival")){
|
|
|
67 |
for(long entityId: googleEntityIds){
|
|
|
68 |
addEntityId(entityId, googleSnippets);
|
|
|
69 |
}
|
| 6468 |
rajveer |
70 |
return googleSnippets;
|
| 6463 |
rajveer |
71 |
}else if(request.getRequestURI().contains("sony")){
|
| 6382 |
rajveer |
72 |
for(long entityId: sonyEntityIds){
|
|
|
73 |
addEntityId(entityId, sonySnippets);
|
|
|
74 |
}
|
|
|
75 |
return sonySnippets;
|
|
|
76 |
}else{
|
| 6381 |
rajveer |
77 |
for(long entityId: entityIds){
|
|
|
78 |
addEntityId(entityId, snippets);
|
|
|
79 |
}
|
|
|
80 |
return snippets;
|
|
|
81 |
}
|
| 4520 |
varun.gupt |
82 |
}
|
| 6383 |
rajveer |
83 |
public String getPageTitle(){
|
| 6463 |
rajveer |
84 |
if(request.getRequestURI().contains("google-great-online-shopping-festival")){
|
|
|
85 |
return "Google Great Online Shopping Festival";
|
|
|
86 |
}else if(request.getRequestURI().contains("sony")){
|
| 6383 |
rajveer |
87 |
return "Sony Phones at Best Price";
|
|
|
88 |
} else{
|
|
|
89 |
return "Spice and Micromax Phones at Best Price | Clearance Sale";
|
|
|
90 |
}
|
|
|
91 |
}
|
| 4518 |
varun.gupt |
92 |
}
|