| 317 |
ashish |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.serving.controllers;
|
|
|
5 |
|
| 375 |
ashish |
6 |
import in.shop2020.serving.pages.PageContentKeys;
|
|
|
7 |
import in.shop2020.serving.pages.PageEnum;
|
|
|
8 |
import in.shop2020.serving.pages.PageManager;
|
| 620 |
rajveer |
9 |
import in.shop2020.serving.services.PageLoaderHandler;
|
| 555 |
chandransh |
10 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
|
|
11 |
import in.shop2020.model.v1.user.UserContextService.Client;
|
| 375 |
ashish |
12 |
|
| 317 |
ashish |
13 |
import java.io.IOException;
|
| 375 |
ashish |
14 |
import java.util.HashMap;
|
|
|
15 |
import java.util.Map;
|
| 507 |
rajveer |
16 |
import java.util.StringTokenizer;
|
| 317 |
ashish |
17 |
|
|
|
18 |
import javax.servlet.ServletContext;
|
|
|
19 |
|
|
|
20 |
import org.apache.juli.logging.Log;
|
|
|
21 |
import org.apache.juli.logging.LogFactory;
|
| 507 |
rajveer |
22 |
import org.apache.struts2.convention.annotation.Action;
|
|
|
23 |
import org.apache.struts2.convention.annotation.Actions;
|
| 317 |
ashish |
24 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
25 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
26 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
|
|
27 |
import org.apache.struts2.rest.HttpHeaders;
|
|
|
28 |
import org.apache.struts2.util.ServletContextAware;
|
|
|
29 |
|
|
|
30 |
import com.opensymphony.xwork2.ModelDriven;
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
*
|
|
|
34 |
* @author naveen
|
|
|
35 |
*
|
|
|
36 |
*/
|
|
|
37 |
@Results({
|
| 507 |
rajveer |
38 |
@Result(name="success", location="/entity-show")
|
| 317 |
ashish |
39 |
})
|
|
|
40 |
public class EntityController extends BaseController
|
|
|
41 |
implements ModelDriven<Object>, ServletContextAware {
|
| 507 |
rajveer |
42 |
|
| 375 |
ashish |
43 |
private PageManager pageManager = null;
|
|
|
44 |
|
| 317 |
ashish |
45 |
/**
|
|
|
46 |
*
|
|
|
47 |
*/
|
|
|
48 |
private static Log log = LogFactory.getLog(EntityController.class);
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
*
|
|
|
52 |
*/
|
|
|
53 |
@SuppressWarnings("unused")
|
|
|
54 |
private ServletContext servletContext = null;
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
*
|
|
|
58 |
*/
|
|
|
59 |
private String id;
|
| 375 |
ashish |
60 |
|
| 620 |
rajveer |
61 |
private long productId;
|
| 375 |
ashish |
62 |
|
| 620 |
rajveer |
63 |
private Map<String,String> htmlSnippets = new HashMap<String, String>();;
|
| 375 |
ashish |
64 |
|
| 620 |
rajveer |
65 |
|
| 375 |
ashish |
66 |
public EntityController(){
|
|
|
67 |
super();
|
|
|
68 |
pageManager = PageManager.getPageManager();
|
|
|
69 |
}
|
| 507 |
rajveer |
70 |
|
|
|
71 |
// GET /entity/1000001
|
|
|
72 |
@Actions({
|
|
|
73 |
@Action("/mobiles"),
|
|
|
74 |
@Action("/books"),
|
|
|
75 |
@Action("/mobile"),
|
|
|
76 |
@Action("/entity")
|
|
|
77 |
})
|
| 317 |
ashish |
78 |
public HttpHeaders show() throws SecurityException, IOException {
|
|
|
79 |
log.info("id=" + id);
|
| 449 |
rajveer |
80 |
|
| 620 |
rajveer |
81 |
PageLoaderHandler pageLoader = new PageLoaderHandler();
|
|
|
82 |
|
|
|
83 |
htmlSnippets.put("HEADER", pageLoader.getHeaderHtml(this.userinfo.isLoggedIn(), this.userinfo.getNameOfUser()));
|
|
|
84 |
htmlSnippets.put("MAIN_MENU", pageLoader.getMainMenuHtml());
|
|
|
85 |
htmlSnippets.put("SEARCH_BAR", pageLoader.getSearchBarHtml(userinfo.getTotalItems(), 0));
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
htmlSnippets.put("PRODUCT_SUMMARY", pageLoader.getProductSummaryHtml(productId));
|
|
|
89 |
htmlSnippets.put("SOCIAL_UTILS", pageLoader.getSocialUtilsHtml(productId));
|
|
|
90 |
htmlSnippets.put("SLIDE_GUIDE", pageLoader.getSlideGuideHtml(productId));
|
|
|
91 |
htmlSnippets.put("LOCATOR", pageLoader.getLocatorHtml());
|
|
|
92 |
htmlSnippets.put("REVIEWS", pageLoader.getReviewsHtml(productId));
|
|
|
93 |
|
|
|
94 |
htmlSnippets.put("CUSTOMER_SERVICE", pageLoader.getCustomerServiceHtml());
|
|
|
95 |
htmlSnippets.put("MY_RESEARCH", pageLoader.getMyResearchHtml(userinfo.getUserId(), true));
|
|
|
96 |
htmlSnippets.put("RECOMMENDATIONS", pageLoader.getRecommendationsHtml());
|
|
|
97 |
htmlSnippets.put("SIMILAR_PRODUCTS", pageLoader.getSimilarProductsHtml(productId));
|
|
|
98 |
htmlSnippets.put("ACCESSORIES", pageLoader.getAccessoriesHtml(productId));
|
|
|
99 |
htmlSnippets.put("FOOTER", pageLoader.getFooterHtml());
|
|
|
100 |
htmlSnippets.put("JS_FILES", "");
|
|
|
101 |
htmlSnippets.put("CSS_FILES", "");
|
|
|
102 |
|
| 449 |
rajveer |
103 |
try {
|
| 555 |
chandransh |
104 |
UserContextServiceClient userServiceClient = new UserContextServiceClient();
|
|
|
105 |
Client client = userServiceClient.getClient();
|
| 449 |
rajveer |
106 |
long item_id = Long.parseLong(id);
|
|
|
107 |
boolean isSessionId = userinfo.isSessionId();
|
| 590 |
chandransh |
108 |
long user_id = userinfo.getUserId();
|
| 449 |
rajveer |
109 |
client.updateBrowseHistory(user_id, item_id, isSessionId);
|
|
|
110 |
|
|
|
111 |
} catch (Exception e) {
|
|
|
112 |
// TODO Auto-generated catch block
|
|
|
113 |
e.printStackTrace();
|
|
|
114 |
}
|
|
|
115 |
|
| 620 |
rajveer |
116 |
return new DefaultHttpHeaders("show");
|
| 317 |
ashish |
117 |
}
|
|
|
118 |
|
|
|
119 |
/**
|
|
|
120 |
*
|
|
|
121 |
* @param id
|
|
|
122 |
*/
|
|
|
123 |
public void setId(String id) {
|
| 507 |
rajveer |
124 |
StringTokenizer tokenizer = new StringTokenizer(id,"-");
|
|
|
125 |
while(tokenizer.hasMoreTokens()){
|
|
|
126 |
this.id = tokenizer.nextToken();
|
|
|
127 |
}
|
| 620 |
rajveer |
128 |
this.productId = Long.parseLong(id);
|
| 317 |
ashish |
129 |
}
|
|
|
130 |
|
|
|
131 |
/* (non-Javadoc)
|
|
|
132 |
* @see com.opensymphony.xwork2.ModelDriven#getModel()
|
|
|
133 |
*/
|
|
|
134 |
@Override
|
|
|
135 |
public Object getModel() {
|
| 388 |
rajveer |
136 |
System.out.println(" getModer is called");
|
|
|
137 |
return htmlSnippets;
|
|
|
138 |
//return this.id;
|
| 317 |
ashish |
139 |
}
|
|
|
140 |
|
|
|
141 |
/**
|
|
|
142 |
*
|
|
|
143 |
*/
|
|
|
144 |
@Override
|
|
|
145 |
public void setServletContext(ServletContext servletContext) {
|
|
|
146 |
this.servletContext = servletContext;
|
|
|
147 |
}
|
| 375 |
ashish |
148 |
|
| 387 |
rajveer |
149 |
public Map<String,String> getHtmlSnippets(){
|
| 388 |
rajveer |
150 |
System.out.println(" getHtmlSnippets is called");
|
| 387 |
rajveer |
151 |
return htmlSnippets;
|
| 375 |
ashish |
152 |
}
|
| 388 |
rajveer |
153 |
|
| 449 |
rajveer |
154 |
public String getHeaderSnippet(){
|
|
|
155 |
return htmlSnippets.get("HEADER");
|
| 388 |
rajveer |
156 |
}
|
| 317 |
ashish |
157 |
|
| 449 |
rajveer |
158 |
public String getSlideGuideSnippet(){
|
| 388 |
rajveer |
159 |
return htmlSnippets.get("SLIDE_GUIDE");
|
|
|
160 |
}
|
|
|
161 |
|
| 449 |
rajveer |
162 |
public String getMainMenuSnippet(){
|
|
|
163 |
return htmlSnippets.get("MAIN_MENU");
|
| 388 |
rajveer |
164 |
}
|
| 449 |
rajveer |
165 |
|
|
|
166 |
public String getSearchBarSnippet(){
|
|
|
167 |
return htmlSnippets.get("SEARCH_BAR");
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
public String getProductSummarySnippet(){
|
|
|
171 |
return htmlSnippets.get("PRODUCT_SUMMARY");
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
public String getSocialUtilsSnippet(){
|
|
|
175 |
return htmlSnippets.get("SOCIAL_UTILS");
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
public String getLocatorSnippet(){
|
|
|
179 |
return htmlSnippets.get("LOCATOR");
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
public String getReviewsSnippet(){
|
|
|
183 |
return htmlSnippets.get("REVIEWS");
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
public String getCustomerServiceSnippet(){
|
|
|
187 |
return htmlSnippets.get("CUSTOMER_SERVICE");
|
|
|
188 |
}
|
|
|
189 |
|
|
|
190 |
public String getMyResearchSnippet(){
|
|
|
191 |
return htmlSnippets.get("MY_RESEARCH");
|
|
|
192 |
}
|
|
|
193 |
|
| 388 |
rajveer |
194 |
|
| 449 |
rajveer |
195 |
public String getRecommendationsSnippet(){
|
|
|
196 |
return htmlSnippets.get("RECOMMENDATIONS");
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
public String getSimilarProductsSnippet(){
|
|
|
200 |
return htmlSnippets.get("SIMILAR_PRODUCTS");
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
public String getAccessoriesSnippet(){
|
|
|
204 |
return htmlSnippets.get("ACCESSORIES");
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
public String getFooterSnippet(){
|
|
|
208 |
return htmlSnippets.get("FOOTER");
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
public String getJsFileSnippet(){
|
|
|
212 |
return htmlSnippets.get("JS_FILES");
|
|
|
213 |
}
|
|
|
214 |
|
|
|
215 |
public String getCssFileSnippet(){
|
|
|
216 |
return htmlSnippets.get("CSS_FILES");
|
|
|
217 |
}
|
|
|
218 |
|
| 317 |
ashish |
219 |
}
|