| 317 |
ashish |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.serving.controllers;
|
|
|
5 |
|
| 387 |
rajveer |
6 |
|
| 449 |
rajveer |
7 |
import in.shop2020.model.v1.widgets.WidgetService.Client;
|
| 375 |
ashish |
8 |
import in.shop2020.serving.pages.PageContentKeys;
|
|
|
9 |
import in.shop2020.serving.pages.PageEnum;
|
|
|
10 |
import in.shop2020.serving.pages.PageManager;
|
| 449 |
rajveer |
11 |
import in.shop2020.thrift.clients.WidgetServiceClient;
|
| 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 |
|
| 387 |
rajveer |
61 |
private Map<String,String> htmlSnippets;
|
| 375 |
ashish |
62 |
|
|
|
63 |
|
|
|
64 |
public EntityController(){
|
|
|
65 |
super();
|
|
|
66 |
pageManager = PageManager.getPageManager();
|
|
|
67 |
}
|
| 507 |
rajveer |
68 |
|
|
|
69 |
// GET /entity/1000001
|
|
|
70 |
@Actions({
|
|
|
71 |
@Action("/mobiles"),
|
|
|
72 |
@Action("/books"),
|
|
|
73 |
@Action("/mobile"),
|
|
|
74 |
@Action("/entity")
|
|
|
75 |
})
|
| 317 |
ashish |
76 |
public HttpHeaders show() throws SecurityException, IOException {
|
|
|
77 |
log.info("id=" + id);
|
| 375 |
ashish |
78 |
Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
|
| 449 |
rajveer |
79 |
|
| 375 |
ashish |
80 |
params.put(PageContentKeys.ENTITY_ID, id);
|
| 449 |
rajveer |
81 |
params.put(PageContentKeys.USER_ID, new Long(userinfo.getUserId()).toString());
|
|
|
82 |
params.put(PageContentKeys.CART_ID, new Long(userinfo.getCartId()).toString());
|
|
|
83 |
params.put(PageContentKeys.SESSION_ID, new Long(userinfo.getSessionId()).toString());
|
|
|
84 |
params.put(PageContentKeys.USER_NAME, userinfo.getNameOfUser());
|
| 458 |
rajveer |
85 |
params.put(PageContentKeys.ITEM_COUNT, new Long(userinfo.getTotalItems()).toString());
|
| 387 |
rajveer |
86 |
|
| 449 |
rajveer |
87 |
htmlSnippets = pageManager.getPageContents(PageEnum.PRODUCT_PAGE, params);
|
|
|
88 |
|
|
|
89 |
|
| 387 |
rajveer |
90 |
System.out.println(htmlSnippets);
|
| 449 |
rajveer |
91 |
// To update the browse history of the user
|
|
|
92 |
try {
|
|
|
93 |
WidgetServiceClient widgetServiceClient = new WidgetServiceClient();
|
|
|
94 |
Client client = widgetServiceClient.getClient();
|
|
|
95 |
long item_id = Long.parseLong(id);
|
|
|
96 |
boolean isSessionId = userinfo.isSessionId();
|
|
|
97 |
long user_id = 0;
|
|
|
98 |
if(userinfo.isLoggedIn())
|
|
|
99 |
user_id = userinfo.getUserId();
|
|
|
100 |
else
|
|
|
101 |
user_id = userinfo.getSessionId();
|
|
|
102 |
client.updateBrowseHistory(user_id, item_id, isSessionId);
|
|
|
103 |
|
|
|
104 |
} catch (Exception e) {
|
|
|
105 |
// TODO Auto-generated catch block
|
|
|
106 |
e.printStackTrace();
|
|
|
107 |
}
|
|
|
108 |
|
| 317 |
ashish |
109 |
/*
|
|
|
110 |
String contextPath = this.servletContext.getContextPath();
|
|
|
111 |
log.info("contextPath=" + contextPath);
|
|
|
112 |
|
|
|
113 |
String realPath = this.servletContext.getRealPath("/");
|
|
|
114 |
log.info("realPath=" + realPath);
|
|
|
115 |
|
|
|
116 |
String path = this.servletContext.getRealPath(
|
|
|
117 |
"/WEB-INF/testdir/test.txt");
|
|
|
118 |
|
|
|
119 |
log.info("path=" + path);
|
|
|
120 |
|
|
|
121 |
FileReader fr = new FileReader(new File(path));
|
|
|
122 |
LineNumberReader lnr = new LineNumberReader(fr);
|
|
|
123 |
|
|
|
124 |
String line = lnr.readLine();
|
|
|
125 |
log.info("line=" + line);
|
|
|
126 |
*/
|
|
|
127 |
return new DefaultHttpHeaders("show");
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
/**
|
|
|
131 |
*
|
|
|
132 |
* @param id
|
|
|
133 |
*/
|
|
|
134 |
public void setId(String id) {
|
| 507 |
rajveer |
135 |
StringTokenizer tokenizer = new StringTokenizer(id,"-");
|
|
|
136 |
while(tokenizer.hasMoreTokens()){
|
|
|
137 |
this.id = tokenizer.nextToken();
|
|
|
138 |
}
|
| 317 |
ashish |
139 |
}
|
|
|
140 |
|
|
|
141 |
/* (non-Javadoc)
|
|
|
142 |
* @see com.opensymphony.xwork2.ModelDriven#getModel()
|
|
|
143 |
*/
|
|
|
144 |
@Override
|
|
|
145 |
public Object getModel() {
|
| 388 |
rajveer |
146 |
System.out.println(" getModer is called");
|
|
|
147 |
return htmlSnippets;
|
|
|
148 |
//return this.id;
|
| 317 |
ashish |
149 |
}
|
|
|
150 |
|
|
|
151 |
/**
|
|
|
152 |
*
|
|
|
153 |
*/
|
|
|
154 |
@Override
|
|
|
155 |
public void setServletContext(ServletContext servletContext) {
|
|
|
156 |
this.servletContext = servletContext;
|
|
|
157 |
}
|
| 375 |
ashish |
158 |
|
| 387 |
rajveer |
159 |
public Map<String,String> getHtmlSnippets(){
|
| 388 |
rajveer |
160 |
System.out.println(" getHtmlSnippets is called");
|
| 387 |
rajveer |
161 |
return htmlSnippets;
|
| 375 |
ashish |
162 |
}
|
| 388 |
rajveer |
163 |
|
| 449 |
rajveer |
164 |
public String getHeaderSnippet(){
|
|
|
165 |
return htmlSnippets.get("HEADER");
|
| 388 |
rajveer |
166 |
}
|
| 317 |
ashish |
167 |
|
| 449 |
rajveer |
168 |
public String getSlideGuideSnippet(){
|
| 388 |
rajveer |
169 |
return htmlSnippets.get("SLIDE_GUIDE");
|
|
|
170 |
}
|
|
|
171 |
|
| 449 |
rajveer |
172 |
public String getMainMenuSnippet(){
|
|
|
173 |
return htmlSnippets.get("MAIN_MENU");
|
| 388 |
rajveer |
174 |
}
|
| 449 |
rajveer |
175 |
|
|
|
176 |
public String getSearchBarSnippet(){
|
|
|
177 |
return htmlSnippets.get("SEARCH_BAR");
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
public String getProductSummarySnippet(){
|
|
|
181 |
return htmlSnippets.get("PRODUCT_SUMMARY");
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
public String getSocialUtilsSnippet(){
|
|
|
185 |
return htmlSnippets.get("SOCIAL_UTILS");
|
|
|
186 |
}
|
|
|
187 |
|
|
|
188 |
public String getLocatorSnippet(){
|
|
|
189 |
return htmlSnippets.get("LOCATOR");
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
public String getReviewsSnippet(){
|
|
|
193 |
return htmlSnippets.get("REVIEWS");
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
public String getCustomerServiceSnippet(){
|
|
|
197 |
return htmlSnippets.get("CUSTOMER_SERVICE");
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
public String getMyResearchSnippet(){
|
|
|
201 |
return htmlSnippets.get("MY_RESEARCH");
|
|
|
202 |
}
|
|
|
203 |
|
| 388 |
rajveer |
204 |
|
| 449 |
rajveer |
205 |
public String getRecommendationsSnippet(){
|
|
|
206 |
return htmlSnippets.get("RECOMMENDATIONS");
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
public String getSimilarProductsSnippet(){
|
|
|
210 |
return htmlSnippets.get("SIMILAR_PRODUCTS");
|
|
|
211 |
}
|
|
|
212 |
|
|
|
213 |
public String getAccessoriesSnippet(){
|
|
|
214 |
return htmlSnippets.get("ACCESSORIES");
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
public String getFooterSnippet(){
|
|
|
218 |
return htmlSnippets.get("FOOTER");
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
public String getJsFileSnippet(){
|
|
|
222 |
return htmlSnippets.get("JS_FILES");
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
public String getCssFileSnippet(){
|
|
|
226 |
return htmlSnippets.get("CSS_FILES");
|
|
|
227 |
}
|
|
|
228 |
|
| 317 |
ashish |
229 |
}
|