| Line 5... |
Line 5... |
| 5 |
|
5 |
|
| 6 |
|
6 |
|
| 7 |
import in.shop2020.datalogger.EventType;
|
7 |
import in.shop2020.datalogger.EventType;
|
| 8 |
import in.shop2020.model.v1.catalog.Item;
|
8 |
import in.shop2020.model.v1.catalog.Item;
|
| 9 |
import in.shop2020.model.v1.user.UserContextService.Client;
|
9 |
import in.shop2020.model.v1.user.UserContextService.Client;
|
| - |
|
10 |
import in.shop2020.serving.utils.EhcacheWrapper;
|
| 10 |
import in.shop2020.thrift.clients.CatalogClient;
|
11 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 11 |
import in.shop2020.thrift.clients.UserClient;
|
12 |
import in.shop2020.thrift.clients.UserClient;
|
| 12 |
import in.shop2020.utils.DataLogger;
|
13 |
import in.shop2020.utils.DataLogger;
|
| 13 |
|
14 |
|
| 14 |
import java.io.IOException;
|
15 |
import java.io.IOException;
|
| - |
|
16 |
import java.util.HashMap;
|
| 15 |
import java.util.Map;
|
17 |
import java.util.Map;
|
| 16 |
import java.util.StringTokenizer;
|
18 |
import java.util.StringTokenizer;
|
| 17 |
|
19 |
|
| - |
|
20 |
import net.sf.ehcache.CacheManager;
|
| - |
|
21 |
|
| 18 |
import org.apache.log4j.Logger;
|
22 |
import org.apache.log4j.Logger;
|
| 19 |
import org.apache.struts2.convention.annotation.Action;
|
23 |
import org.apache.struts2.convention.annotation.Action;
|
| 20 |
import org.apache.struts2.convention.annotation.Actions;
|
24 |
import org.apache.struts2.convention.annotation.Actions;
|
| 21 |
import org.apache.struts2.convention.annotation.Result;
|
25 |
import org.apache.struts2.convention.annotation.Result;
|
| 22 |
import org.apache.struts2.convention.annotation.Results;
|
26 |
import org.apache.struts2.convention.annotation.Results;
|
| Line 34... |
Line 38... |
| 34 |
@Result(name = "redirect", location = "${redirectUrl}", type = "redirect")
|
38 |
@Result(name = "redirect", location = "${redirectUrl}", type = "redirect")
|
| 35 |
})
|
39 |
})
|
| 36 |
public class EntityController extends BaseController {
|
40 |
public class EntityController extends BaseController {
|
| 37 |
|
41 |
|
| 38 |
private static final long serialVersionUID = 1L;
|
42 |
private static final long serialVersionUID = 1L;
|
| 39 |
|
- |
|
| 40 |
private static Logger log = Logger.getLogger(Class.class);
|
43 |
private static Logger log = Logger.getLogger(Class.class);
|
| 41 |
/**
|
44 |
|
| - |
|
45 |
private static final String PRODUCT_PROERTIES_SNIPPET_KEY = "PRODUCT_PROPERTIES";
|
| - |
|
46 |
private static final String PRODUCT_SUMMARY_SNIPPET_KEY = "PRODUCT_SUMMARY";
|
| - |
|
47 |
private static final String PRODUCT_SLIDEGUIDE_KEY = "SLIDEGUIDE";
|
| 42 |
*
|
48 |
|
| 43 |
*/
|
- |
|
| 44 |
private String id;
|
49 |
private String id;
|
| 45 |
private String redirectUrl;
|
50 |
private String redirectUrl;
|
| 46 |
private long productId;
|
51 |
private long productId;
|
| 47 |
private boolean isMobile = false;
|
52 |
private boolean isMobile = false;
|
| 48 |
|
53 |
|
| - |
|
54 |
private Map<String, String> snippets;
|
| - |
|
55 |
|
| 49 |
public EntityController(){
|
56 |
public EntityController(){
|
| 50 |
super();
|
57 |
super();
|
| 51 |
}
|
58 |
}
|
| 52 |
|
59 |
|
| 53 |
// GET /*/1000001
|
60 |
// GET /*/1000001
|
| Line 65... |
Line 72... |
| 65 |
String metaDescription = "";
|
72 |
String metaDescription = "";
|
| 66 |
String pageTitle = "";
|
73 |
String pageTitle = "";
|
| 67 |
String productName = "";
|
74 |
String productName = "";
|
| 68 |
String displayAccessories = "FALSE";
|
75 |
String displayAccessories = "FALSE";
|
| 69 |
try {
|
76 |
try {
|
| - |
|
77 |
setSnippets();
|
| - |
|
78 |
htmlSnippets.put("PRODUCT_PROPERTIES", snippets.get(PRODUCT_PROERTIES_SNIPPET_KEY));
|
| 70 |
JSONObject productPropertiesInJson = new JSONObject(pageLoader.getProductPropertiesHtml(productId).trim());
|
79 |
JSONObject productPropertiesInJson = new JSONObject(htmlSnippets.get("PRODUCT_PROPERTIES"));
|
| 71 |
entityUrl = productPropertiesInJson.getString("entityUrl");
|
80 |
entityUrl = productPropertiesInJson.getString("entityUrl");
|
| 72 |
metaDescription = productPropertiesInJson.getString("metaDescription");
|
81 |
metaDescription = productPropertiesInJson.getString("metaDescription");
|
| 73 |
metaKeywords = productPropertiesInJson.getString("metaKeywords");
|
82 |
metaKeywords = productPropertiesInJson.getString("metaKeywords");
|
| 74 |
pageTitle = productPropertiesInJson.getString("title");
|
83 |
pageTitle = productPropertiesInJson.getString("title");
|
| 75 |
productName = productPropertiesInJson.getString("name");
|
84 |
productName = productPropertiesInJson.getString("name");
|
| Line 98... |
Line 107... |
| 98 |
}
|
107 |
}
|
| 99 |
|
108 |
|
| 100 |
//Extracting base url
|
109 |
//Extracting base url
|
| 101 |
String rootUrl = currentUrl.split("/")[2];
|
110 |
String rootUrl = currentUrl.split("/")[2];
|
| 102 |
|
111 |
|
| 103 |
htmlSnippets.put("PRODUCT_SUMMARY", pageLoader.getProductSummaryHtml(productId));
|
112 |
htmlSnippets.put("PRODUCT_SUMMARY", snippets.get(PRODUCT_SUMMARY_SNIPPET_KEY));
|
| 104 |
htmlSnippets.put("PRODUCT_ID", productId + "");
|
113 |
htmlSnippets.put("PRODUCT_ID", productId + "");
|
| 105 |
htmlSnippets.put("PRODUCT_NAME", productName);
|
114 |
htmlSnippets.put("PRODUCT_NAME", productName);
|
| 106 |
htmlSnippets.put("PRODUCT_URL", currentUrl);
|
115 |
htmlSnippets.put("PRODUCT_URL", currentUrl);
|
| 107 |
htmlSnippets.put("ROOT_URL", "http://" + rootUrl);
|
116 |
htmlSnippets.put("ROOT_URL", "http://" + rootUrl);
|
| 108 |
htmlSnippets.put("SLIDE_GUIDE", pageLoader.getSlideGuideHtml(productId));
|
117 |
htmlSnippets.put("SLIDE_GUIDE", snippets.get(PRODUCT_SLIDEGUIDE_KEY));
|
| 109 |
htmlSnippets.put("PAGE_TITLE", pageTitle.trim());
|
118 |
htmlSnippets.put("PAGE_TITLE", pageTitle.trim());
|
| 110 |
htmlSnippets.put("PAGE_METADESC", metaDescription);
|
119 |
htmlSnippets.put("PAGE_METADESC", metaDescription);
|
| 111 |
htmlSnippets.put("PAGE_METAKEYWORDS", metaKeywords);
|
120 |
htmlSnippets.put("PAGE_METAKEYWORDS", metaKeywords);
|
| 112 |
if(displayAccessories.equals("TRUE")){
|
121 |
if(displayAccessories.equals("TRUE")){
|
| 113 |
setMobile(true);
|
122 |
setMobile(true);
|
| Line 128... |
Line 137... |
| 128 |
|
137 |
|
| 129 |
DataLogger.logData(EventType.PRODUCT_VIEW, getSessionId(), userinfo.getUserId(), userinfo.getEmail(),
|
138 |
DataLogger.logData(EventType.PRODUCT_VIEW, getSessionId(), userinfo.getUserId(), userinfo.getEmail(),
|
| 130 |
productName, Long.toString(productId));
|
139 |
productName, Long.toString(productId));
|
| 131 |
return "show";
|
140 |
return "show";
|
| 132 |
}
|
141 |
}
|
| 133 |
|
142 |
|
| 134 |
/**
|
143 |
/**
|
| 135 |
*
|
144 |
*
|
| 136 |
* @param id
|
145 |
* @param id
|
| 137 |
*/
|
146 |
*/
|
| 138 |
public void setId(String id) {
|
147 |
public void setId(String id) {
|
| Line 199... |
Line 208... |
| 199 |
* @return the isMobile
|
208 |
* @return the isMobile
|
| 200 |
*/
|
209 |
*/
|
| 201 |
public boolean isMobile() {
|
210 |
public boolean isMobile() {
|
| 202 |
return isMobile;
|
211 |
return isMobile;
|
| 203 |
}
|
212 |
}
|
| - |
|
213 |
|
| - |
|
214 |
private void setSnippets() {
|
| - |
|
215 |
EhcacheWrapper<Long, Map<String, String>> productSnippetsCache = new EhcacheWrapper<Long, Map<String, String>>(
|
| - |
|
216 |
EhcacheWrapper.PRODUCT_PAGE_SNIPPET_CACHE_NAME, CacheManager.create());
|
| - |
|
217 |
snippets = productSnippetsCache.get(productId);
|
| - |
|
218 |
if (snippets == null) {
|
| - |
|
219 |
log.info("Getting product snippet for :" + productId);
|
| - |
|
220 |
snippets = new HashMap<String, String>();
|
| - |
|
221 |
snippets.put(PRODUCT_PROERTIES_SNIPPET_KEY, pageLoader.getProductPropertiesHtml(productId).trim());
|
| - |
|
222 |
snippets.put(PRODUCT_SUMMARY_SNIPPET_KEY, pageLoader.getProductSummaryHtml(productId));
|
| - |
|
223 |
snippets.put(PRODUCT_SLIDEGUIDE_KEY, pageLoader.getSlideGuideHtml(productId));
|
| - |
|
224 |
productSnippetsCache.put(productId, snippets);
|
| - |
|
225 |
return;
|
| - |
|
226 |
}
|
| - |
|
227 |
log.info("Loaded from cache product snippet for :" + productId);
|
| - |
|
228 |
}
|
| - |
|
229 |
|
| 204 |
}
|
230 |
}
|
| 205 |
|
231 |
|