| 507 |
rajveer |
1 |
package in.shop2020.serving.services;
|
|
|
2 |
|
|
|
3 |
import java.io.BufferedReader;
|
|
|
4 |
import java.io.File;
|
|
|
5 |
import java.io.FileInputStream;
|
|
|
6 |
import java.io.FileNotFoundException;
|
|
|
7 |
import java.io.IOException;
|
|
|
8 |
import java.io.InputStreamReader;
|
|
|
9 |
import java.io.StringWriter;
|
| 517 |
rajveer |
10 |
import java.text.SimpleDateFormat;
|
| 507 |
rajveer |
11 |
import java.util.ArrayList;
|
|
|
12 |
import java.util.Date;
|
|
|
13 |
import java.util.HashMap;
|
|
|
14 |
import java.util.List;
|
|
|
15 |
import java.util.Map;
|
|
|
16 |
import java.util.Properties;
|
|
|
17 |
|
|
|
18 |
import org.apache.thrift.TException;
|
|
|
19 |
import org.apache.velocity.Template;
|
|
|
20 |
import org.apache.velocity.VelocityContext;
|
|
|
21 |
import org.apache.velocity.app.Velocity;
|
|
|
22 |
import org.apache.velocity.exception.MethodInvocationException;
|
|
|
23 |
import org.apache.velocity.exception.ParseErrorException;
|
|
|
24 |
import org.apache.velocity.exception.ResourceNotFoundException;
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
import in.shop2020.model.v1.catalog.InventoryServiceException;
|
|
|
28 |
import in.shop2020.model.v1.catalog.Item;
|
|
|
29 |
import in.shop2020.model.v1.catalog.InventoryService.Client;
|
|
|
30 |
import in.shop2020.model.v1.order.Order;
|
|
|
31 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 555 |
chandransh |
32 |
import in.shop2020.model.v1.user.Cart;
|
|
|
33 |
import in.shop2020.model.v1.user.Line;
|
| 507 |
rajveer |
34 |
import in.shop2020.model.v1.user.Address;
|
| 555 |
chandransh |
35 |
import in.shop2020.model.v1.user.User;
|
|
|
36 |
import in.shop2020.model.v1.user.RatingType;
|
|
|
37 |
import in.shop2020.model.v1.user.RatingsWidget;
|
|
|
38 |
import in.shop2020.model.v1.user.Widget;
|
|
|
39 |
import in.shop2020.model.v1.user.WidgetItem;
|
|
|
40 |
import in.shop2020.model.v1.user.WidgetType;
|
| 507 |
rajveer |
41 |
import in.shop2020.serving.utils.*;
|
|
|
42 |
import in.shop2020.thrift.clients.CatalogServiceClient;
|
|
|
43 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
|
|
44 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
public class PageLoaderHandler {
|
|
|
48 |
|
| 637 |
rajveer |
49 |
public String getRegistrationFormHtml() {
|
| 507 |
rajveer |
50 |
String htmlString = "";
|
|
|
51 |
VelocityContext context = new VelocityContext();
|
|
|
52 |
String templateFile = "templates/registrationform.vm";
|
|
|
53 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
54 |
return htmlString;
|
|
|
55 |
}
|
|
|
56 |
|
| 637 |
rajveer |
57 |
public String getLoginFormHtml() {
|
|
|
58 |
String htmlString = "";
|
|
|
59 |
VelocityContext context = new VelocityContext();
|
|
|
60 |
String templateFile = "templates/loginform.vm";
|
|
|
61 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
62 |
return htmlString;
|
|
|
63 |
}
|
| 507 |
rajveer |
64 |
|
| 637 |
rajveer |
65 |
public String getRegistrationHeaderHtml() {
|
| 507 |
rajveer |
66 |
String htmlString = "";
|
|
|
67 |
VelocityContext context = new VelocityContext();
|
|
|
68 |
String templateFile = "templates/registrationheader.vm";
|
|
|
69 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
70 |
return htmlString;
|
|
|
71 |
}
|
|
|
72 |
|
| 637 |
rajveer |
73 |
public String getLoginHeaderHtml() {
|
|
|
74 |
String htmlString = "";
|
|
|
75 |
VelocityContext context = new VelocityContext();
|
|
|
76 |
String templateFile = "templates/loginheader.vm";
|
|
|
77 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
78 |
return htmlString;
|
|
|
79 |
}
|
|
|
80 |
|
| 507 |
rajveer |
81 |
|
| 650 |
rajveer |
82 |
public String getMainBannerHtml() {
|
| 507 |
rajveer |
83 |
String htmlString = "";
|
|
|
84 |
VelocityContext context = new VelocityContext();
|
|
|
85 |
String templateFile = "templates/mainbanner.vm";
|
|
|
86 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
87 |
return htmlString;
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
|
| 650 |
rajveer |
91 |
public String getBestSellersHtml() {
|
| 507 |
rajveer |
92 |
String htmlString = "";
|
|
|
93 |
VelocityContext context = new VelocityContext();
|
|
|
94 |
String templateFile = "templates/bestsellers.vm";
|
|
|
95 |
|
|
|
96 |
CatalogServiceClient catalogServiceClient = null;
|
|
|
97 |
Client client = null;
|
|
|
98 |
|
|
|
99 |
try {
|
|
|
100 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
101 |
client = catalogServiceClient.getClient();
|
| 627 |
rajveer |
102 |
List<Long> items = client.getBestSellersCatalogIds(1, 4, -1);
|
| 507 |
rajveer |
103 |
List<String> itemList = new ArrayList<String>();
|
|
|
104 |
for(Long item: items){
|
| 517 |
rajveer |
105 |
itemList.add(FileUtils.read( Utils.EXPORT_ENTITIES_PATH + item + File.separator +"HomeSnippet.html"));
|
| 507 |
rajveer |
106 |
}
|
|
|
107 |
context.put("itemList", itemList);
|
|
|
108 |
|
|
|
109 |
} catch(Exception e){
|
|
|
110 |
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
| 517 |
rajveer |
115 |
return htmlString;
|
|
|
116 |
}
|
| 507 |
rajveer |
117 |
|
|
|
118 |
|
| 650 |
rajveer |
119 |
public String getLatestArrivalsHtml() {
|
| 507 |
rajveer |
120 |
String htmlString = "";
|
|
|
121 |
VelocityContext context = new VelocityContext();
|
|
|
122 |
String templateFile = "templates/latestarrivals.vm";
|
|
|
123 |
|
|
|
124 |
CatalogServiceClient catalogServiceClient = null;
|
|
|
125 |
Client client = null;
|
|
|
126 |
|
|
|
127 |
try {
|
|
|
128 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
129 |
client = catalogServiceClient.getClient();
|
| 627 |
rajveer |
130 |
List<Long> items = client.getLatestArrivalsCatalogIds(1,4,-1);
|
| 507 |
rajveer |
131 |
List<String> itemList = new ArrayList<String>();
|
|
|
132 |
for(Long item: items){
|
| 517 |
rajveer |
133 |
itemList.add(FileUtils.read( Utils.EXPORT_ENTITIES_PATH + item + File.separator +"HomeSnippet.html"));
|
| 507 |
rajveer |
134 |
}
|
|
|
135 |
context.put("itemList", itemList);
|
|
|
136 |
|
|
|
137 |
} catch(Exception e){
|
|
|
138 |
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
|
|
|
142 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
143 |
return htmlString;
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
|
| 650 |
rajveer |
147 |
public String getBestDealsHtml() {
|
| 507 |
rajveer |
148 |
String htmlString = "";
|
|
|
149 |
VelocityContext context = new VelocityContext();
|
|
|
150 |
String templateFile = "templates/bestdeals.vm";
|
|
|
151 |
|
|
|
152 |
CatalogServiceClient catalogServiceClient = null;
|
|
|
153 |
Client client = null;
|
|
|
154 |
|
|
|
155 |
try {
|
|
|
156 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
157 |
client = catalogServiceClient.getClient();
|
| 627 |
rajveer |
158 |
List<Long> items = client.getBestDealsCatalogIds(1,4,-1);
|
| 507 |
rajveer |
159 |
List<String> itemList = new ArrayList<String>();
|
|
|
160 |
for(Long item: items){
|
| 517 |
rajveer |
161 |
itemList.add(FileUtils.read( Utils.EXPORT_ENTITIES_PATH + item + File.separator +"HomeSnippet.html"));
|
| 507 |
rajveer |
162 |
}
|
|
|
163 |
context.put("itemList", itemList);
|
|
|
164 |
|
|
|
165 |
} catch(Exception e){
|
|
|
166 |
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
170 |
return htmlString;
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
|
| 517 |
rajveer |
174 |
public String getFooterHtml() {
|
| 507 |
rajveer |
175 |
String htmlString = "";
|
|
|
176 |
VelocityContext context = new VelocityContext();
|
|
|
177 |
String templateFile = "templates/footer.vm";
|
|
|
178 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
179 |
return htmlString;
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
|
|
|
183 |
|
| 620 |
rajveer |
184 |
public String getAccessoriesHtml(long productId) {
|
| 637 |
rajveer |
185 |
return "";
|
|
|
186 |
//return getWidgetDiv(0, WidgetType.ACCESSORIES, "accessories.vm");
|
| 507 |
rajveer |
187 |
}
|
|
|
188 |
|
|
|
189 |
|
|
|
190 |
|
| 620 |
rajveer |
191 |
public String getSimilarProductsHtml(long productId) {
|
| 637 |
rajveer |
192 |
return "";
|
|
|
193 |
//return getWidgetDiv(0, WidgetType.SIMILAR_ITEMS, "similaritems.vm");
|
| 507 |
rajveer |
194 |
}
|
|
|
195 |
|
|
|
196 |
|
|
|
197 |
|
| 620 |
rajveer |
198 |
public String getRecommendationsHtml() {
|
| 637 |
rajveer |
199 |
return "";
|
|
|
200 |
//return getWidgetDiv( 0, WidgetType.RECOMMENDED_ITEMS, "recommendations.vm");
|
| 507 |
rajveer |
201 |
}
|
|
|
202 |
|
|
|
203 |
|
|
|
204 |
|
| 555 |
chandransh |
205 |
public String getMyResearchHtml(long userId, boolean isLoggedIn) {
|
|
|
206 |
if(isLoggedIn)
|
|
|
207 |
return getWidgetDiv(userId, WidgetType.MY_RESEARCH, "myresearch.vm");
|
|
|
208 |
else
|
|
|
209 |
return getWidgetDiv(0, WidgetType.MY_RESEARCH, "myresearch.vm");
|
| 507 |
rajveer |
210 |
}
|
|
|
211 |
|
| 569 |
rajveer |
212 |
public String getBrowseHistoryHtml(long userId, boolean isLoggedIn) {
|
| 555 |
chandransh |
213 |
if(isLoggedIn)
|
|
|
214 |
return getWidgetDiv(userId, WidgetType.BROWSE_HISTORY, "browsehistory.vm");
|
|
|
215 |
else
|
|
|
216 |
return getWidgetDiv(0, WidgetType.BROWSE_HISTORY, "browsehistory.vm");
|
| 507 |
rajveer |
217 |
}
|
|
|
218 |
|
| 517 |
rajveer |
219 |
public String getCustomerServiceHtml() {
|
| 507 |
rajveer |
220 |
String htmlString = "";
|
|
|
221 |
VelocityContext context = new VelocityContext();
|
|
|
222 |
String templateFile = "templates/customerservice.vm";
|
|
|
223 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
224 |
return htmlString;
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
|
|
|
228 |
|
| 620 |
rajveer |
229 |
public String getReviewsHtml(long productId) {
|
| 507 |
rajveer |
230 |
String htmlString = "";
|
|
|
231 |
VelocityContext context = new VelocityContext();
|
|
|
232 |
Map<String, String> params = new HashMap<String, String>();
|
|
|
233 |
params.put("PRODUCT_ID", productId+"");
|
|
|
234 |
context.put("params", params);
|
|
|
235 |
String templateFile = "templates/reviews.vm";
|
|
|
236 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
237 |
return htmlString;
|
|
|
238 |
}
|
|
|
239 |
|
|
|
240 |
|
|
|
241 |
|
| 620 |
rajveer |
242 |
public String getLocatorHtml() {
|
| 507 |
rajveer |
243 |
String htmlString = "";
|
|
|
244 |
VelocityContext context = new VelocityContext();
|
|
|
245 |
String templateFile = "templates/locator.vm";
|
|
|
246 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
247 |
return htmlString;
|
|
|
248 |
}
|
|
|
249 |
|
|
|
250 |
|
| 620 |
rajveer |
251 |
public String getSlideGuideHtml(long productId) {
|
| 507 |
rajveer |
252 |
StringBuilder htmlString = new StringBuilder();
|
| 517 |
rajveer |
253 |
String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "SlideGuide.html";
|
| 507 |
rajveer |
254 |
File f = new File(filename);
|
|
|
255 |
|
|
|
256 |
|
|
|
257 |
FileInputStream fis = null;
|
|
|
258 |
try {
|
|
|
259 |
fis = new FileInputStream(f);
|
|
|
260 |
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
|
|
|
261 |
String line;
|
|
|
262 |
while((line = br.readLine()) != null){
|
|
|
263 |
htmlString.append(line+"\n");
|
|
|
264 |
}
|
|
|
265 |
} catch (FileNotFoundException e) {
|
|
|
266 |
// TODO Auto-generated catch block
|
|
|
267 |
e.printStackTrace();
|
|
|
268 |
} catch (IOException e) {
|
|
|
269 |
// TODO Auto-generated catch block
|
|
|
270 |
e.printStackTrace();
|
|
|
271 |
}
|
|
|
272 |
finally {
|
|
|
273 |
if(fis != null) {
|
|
|
274 |
try {
|
|
|
275 |
fis.close();
|
|
|
276 |
} catch (IOException e) {
|
|
|
277 |
// TODO Auto-generated catch block
|
|
|
278 |
e.printStackTrace();
|
|
|
279 |
}
|
|
|
280 |
}
|
|
|
281 |
}
|
|
|
282 |
|
|
|
283 |
return htmlString.toString();
|
|
|
284 |
}
|
|
|
285 |
|
| 517 |
rajveer |
286 |
public String getProductSummaryHtml(long productId) {
|
| 507 |
rajveer |
287 |
StringBuilder htmlString = new StringBuilder();
|
| 517 |
rajveer |
288 |
String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "ProductDetail.html";
|
| 507 |
rajveer |
289 |
File f = new File(filename);
|
|
|
290 |
|
|
|
291 |
|
|
|
292 |
FileInputStream fis = null;
|
|
|
293 |
try {
|
|
|
294 |
fis = new FileInputStream(f);
|
|
|
295 |
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
|
|
|
296 |
String line;
|
|
|
297 |
while((line = br.readLine()) != null){
|
|
|
298 |
htmlString.append(line+"\n");
|
|
|
299 |
}
|
|
|
300 |
} catch (FileNotFoundException e) {
|
|
|
301 |
// TODO Auto-generated catch block
|
|
|
302 |
e.printStackTrace();
|
|
|
303 |
} catch (IOException e) {
|
|
|
304 |
// TODO Auto-generated catch block
|
|
|
305 |
e.printStackTrace();
|
|
|
306 |
}
|
|
|
307 |
finally {
|
|
|
308 |
if(fis != null) {
|
|
|
309 |
try {
|
|
|
310 |
fis.close();
|
|
|
311 |
} catch (IOException e) {
|
|
|
312 |
// TODO Auto-generated catch block
|
|
|
313 |
e.printStackTrace();
|
|
|
314 |
}
|
|
|
315 |
}
|
|
|
316 |
}
|
|
|
317 |
|
|
|
318 |
return htmlString.toString();
|
|
|
319 |
}
|
|
|
320 |
|
|
|
321 |
|
| 620 |
rajveer |
322 |
public String getSocialUtilsHtml(long productId) {
|
| 507 |
rajveer |
323 |
String htmlString = "";
|
|
|
324 |
VelocityContext context = new VelocityContext();
|
|
|
325 |
Map<String, String> params = new HashMap<String, String>();
|
|
|
326 |
params.put("PRODUCT_ID", productId+"");
|
|
|
327 |
String templateFile = "templates/socialutils.vm";
|
|
|
328 |
context.put("params", params);
|
|
|
329 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
330 |
return htmlString;
|
|
|
331 |
}
|
|
|
332 |
|
|
|
333 |
|
| 517 |
rajveer |
334 |
public String getMainMenuHtml() {
|
| 507 |
rajveer |
335 |
String htmlString = "";
|
|
|
336 |
VelocityContext context = new VelocityContext();
|
|
|
337 |
String templateFile = "templates/mainmenu.vm";
|
|
|
338 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
339 |
return htmlString;
|
|
|
340 |
}
|
|
|
341 |
|
|
|
342 |
|
| 517 |
rajveer |
343 |
public String getSearchBarHtml(long itemCounts, long categoryId) {
|
| 507 |
rajveer |
344 |
String htmlString = "";
|
|
|
345 |
VelocityContext context = new VelocityContext();
|
|
|
346 |
String templateFile = "templates/searchbar.vm";
|
| 550 |
rajveer |
347 |
|
|
|
348 |
context.put("itemCount", itemCounts+"");
|
|
|
349 |
context.put("categoryId", categoryId+"");
|
|
|
350 |
|
| 507 |
rajveer |
351 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
352 |
return htmlString;
|
|
|
353 |
}
|
|
|
354 |
|
|
|
355 |
|
|
|
356 |
|
| 555 |
chandransh |
357 |
public String getHeaderHtml(boolean isLoggedIn, String userName) {
|
| 550 |
rajveer |
358 |
VelocityContext context = new VelocityContext();
|
| 555 |
chandransh |
359 |
if (isLoggedIn) {
|
|
|
360 |
context.put("LOGGED_IN", "TRUE");
|
|
|
361 |
context.put("WELCOME_MESSAGE", "Hi, " + userName);
|
|
|
362 |
} else {
|
| 550 |
rajveer |
363 |
context.put("WELCOME_MESSAGE", "Hi, Welcome to Shop2020");
|
| 555 |
chandransh |
364 |
}
|
| 507 |
rajveer |
365 |
|
|
|
366 |
String templateFile = "templates/header.vm";
|
| 550 |
rajveer |
367 |
|
| 590 |
chandransh |
368 |
return getHtmlFromVelocity(templateFile, context);
|
| 507 |
rajveer |
369 |
}
|
|
|
370 |
|
|
|
371 |
|
|
|
372 |
|
| 650 |
rajveer |
373 |
public String getWidgetDiv(long userId, WidgetType widgetType, String templateFile){
|
| 507 |
rajveer |
374 |
|
| 555 |
chandransh |
375 |
UserContextServiceClient userServiceClient = null;
|
|
|
376 |
in.shop2020.model.v1.user.UserContextService.Client client = null;
|
| 507 |
rajveer |
377 |
Widget widget = null;
|
|
|
378 |
try {
|
| 555 |
chandransh |
379 |
userServiceClient = new UserContextServiceClient();
|
|
|
380 |
client = userServiceClient.getClient();
|
|
|
381 |
widget = client.getWidget(widgetType, userId, true);
|
| 507 |
rajveer |
382 |
} catch (Exception e) {
|
|
|
383 |
e.printStackTrace();
|
|
|
384 |
}
|
|
|
385 |
|
|
|
386 |
|
|
|
387 |
List<Map<String, String>> itemDetails = null;
|
|
|
388 |
|
|
|
389 |
if(widget != null){
|
|
|
390 |
List<WidgetItem> items = widget.getItems();
|
|
|
391 |
itemDetails = new ArrayList<Map<String, String>>();
|
|
|
392 |
|
|
|
393 |
for(WidgetItem item: items){
|
|
|
394 |
Map<String, String> itemDetail = new HashMap<String, String>();
|
|
|
395 |
|
|
|
396 |
itemDetail.put("ITEM_ID", item.getItem_id()+"");
|
|
|
397 |
try {
|
| 517 |
rajveer |
398 |
itemDetail.put("ITEM_SNIPPET", FileUtils.read( Utils.EXPORT_ENTITIES_PATH + item.getItem_id() + File.separator + "WidgetSnippet.html"));
|
| 507 |
rajveer |
399 |
} catch (Exception e) {
|
|
|
400 |
// TODO Auto-generated catch block
|
|
|
401 |
e.printStackTrace();
|
|
|
402 |
}
|
|
|
403 |
itemDetails.add(itemDetail);
|
|
|
404 |
}
|
|
|
405 |
}else{
|
|
|
406 |
System.out.println("widget not found");
|
|
|
407 |
}
|
|
|
408 |
|
|
|
409 |
VelocityContext context = new VelocityContext();
|
| 620 |
rajveer |
410 |
context.put("userId", userId);
|
| 507 |
rajveer |
411 |
context.put("itemDetails", itemDetails);
|
|
|
412 |
|
|
|
413 |
return getHtmlFromVelocity("templates/"+templateFile, context);
|
|
|
414 |
}
|
|
|
415 |
|
|
|
416 |
|
|
|
417 |
|
|
|
418 |
|
| 650 |
rajveer |
419 |
public String getOrderDetailsHtml(long orderId) {
|
| 507 |
rajveer |
420 |
String htmlString = "";
|
|
|
421 |
VelocityContext context = new VelocityContext();
|
|
|
422 |
String templateFile = "templates/orderdetails.vm";
|
|
|
423 |
TransactionServiceClient transactionServiceClient = null;
|
|
|
424 |
in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
|
|
|
425 |
Order order = null;
|
| 517 |
rajveer |
426 |
Date orderedOn = null, deliveryEstimate = null;
|
| 507 |
rajveer |
427 |
try{
|
|
|
428 |
transactionServiceClient = new TransactionServiceClient();
|
|
|
429 |
orderClient = transactionServiceClient.getClient();
|
|
|
430 |
order = orderClient.getOrder(orderId);
|
| 517 |
rajveer |
431 |
orderedOn = new Date(order.getCreated_timestamp());
|
|
|
432 |
deliveryEstimate = new Date(order.getExpected_delivery_time());
|
| 507 |
rajveer |
433 |
}catch (Exception e){
|
|
|
434 |
|
|
|
435 |
}
|
| 517 |
rajveer |
436 |
|
|
|
437 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
|
| 583 |
rajveer |
438 |
SimpleDateFormat dateformat1 = new SimpleDateFormat("dd/MM/yyyy");
|
| 507 |
rajveer |
439 |
context.put("order", order);
|
| 517 |
rajveer |
440 |
context.put("orderedOn", dateformat.format(orderedOn));
|
| 583 |
rajveer |
441 |
context.put("deliveryEstimate", dateformat1.format(deliveryEstimate));
|
| 517 |
rajveer |
442 |
|
|
|
443 |
|
| 507 |
rajveer |
444 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
445 |
return htmlString;
|
|
|
446 |
}
|
|
|
447 |
|
| 650 |
rajveer |
448 |
public String getMyaccountDetailsHtml(long userId) {
|
| 507 |
rajveer |
449 |
String htmlString = "";
|
|
|
450 |
VelocityContext context = new VelocityContext();
|
|
|
451 |
String templateFile = "templates/myaccount.vm";
|
|
|
452 |
TransactionServiceClient transactionServiceClient = null;
|
|
|
453 |
in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
|
|
|
454 |
List<Order> orders = null;
|
|
|
455 |
try{
|
|
|
456 |
transactionServiceClient = new TransactionServiceClient();
|
|
|
457 |
orderClient = transactionServiceClient.getClient();
|
|
|
458 |
orders = orderClient.getOrdersForCustomer(userId, 0, (new Date()).getTime(), null);
|
|
|
459 |
|
|
|
460 |
}catch (Exception e){
|
|
|
461 |
|
|
|
462 |
}
|
| 741 |
rajveer |
463 |
List<String> orderDate = new ArrayList<String>();
|
|
|
464 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
|
|
|
465 |
for(Order order: orders){
|
|
|
466 |
Date orderedOn = new Date(order.getCreated_timestamp());
|
|
|
467 |
orderDate.add(dateformat.format(orderedOn));
|
|
|
468 |
}
|
| 507 |
rajveer |
469 |
context.put("orders", orders);
|
| 741 |
rajveer |
470 |
context.put("orderDate", orderDate);
|
|
|
471 |
|
| 507 |
rajveer |
472 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
473 |
return htmlString;
|
|
|
474 |
}
|
|
|
475 |
|
|
|
476 |
|
| 650 |
rajveer |
477 |
public String getLoginDetailsHtml(long userId) {
|
| 507 |
rajveer |
478 |
String htmlString = "";
|
|
|
479 |
VelocityContext context = new VelocityContext();
|
|
|
480 |
String templateFile = "templates/logindetails.vm";
|
|
|
481 |
String email = "";
|
|
|
482 |
try{
|
| 555 |
chandransh |
483 |
email = in.shop2020.serving.utils.Utils.getEmailId(userId);
|
| 507 |
rajveer |
484 |
}catch (Exception e){
|
|
|
485 |
|
|
|
486 |
}
|
|
|
487 |
context.put("email", email);
|
|
|
488 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
489 |
return htmlString;
|
|
|
490 |
}
|
|
|
491 |
|
| 595 |
rajveer |
492 |
public String getPersonalDetailsHtml(long userId) {
|
| 507 |
rajveer |
493 |
String htmlString = "";
|
|
|
494 |
VelocityContext context = new VelocityContext();
|
|
|
495 |
String templateFile = "templates/personaldetails.vm";
|
|
|
496 |
String email = "";
|
| 517 |
rajveer |
497 |
String name = "";
|
| 569 |
rajveer |
498 |
String dateOfBirth = "";
|
| 517 |
rajveer |
499 |
String sex = "";
|
|
|
500 |
String subscribe = "false";
|
| 507 |
rajveer |
501 |
UserContextServiceClient userContextServiceClient = null;
|
|
|
502 |
in.shop2020.model.v1.user.UserContextService.Client userClient = null;
|
|
|
503 |
try{
|
| 555 |
chandransh |
504 |
User user = null;
|
| 507 |
rajveer |
505 |
userContextServiceClient = new UserContextServiceClient();
|
|
|
506 |
userClient = userContextServiceClient.getClient();
|
| 555 |
chandransh |
507 |
user = userClient.getUserById(userId);
|
| 507 |
rajveer |
508 |
|
| 555 |
chandransh |
509 |
email = user.getCommunicationEmail();
|
|
|
510 |
name = user.getName();
|
| 517 |
rajveer |
511 |
|
| 569 |
rajveer |
512 |
dateOfBirth = user.getDateOfBirth();
|
| 507 |
rajveer |
513 |
}catch (Exception e){
|
| 555 |
chandransh |
514 |
e.printStackTrace();
|
| 507 |
rajveer |
515 |
}
|
| 517 |
rajveer |
516 |
context.put("name", name);
|
|
|
517 |
context.put("email", email);
|
| 569 |
rajveer |
518 |
context.put("dateOfBirth", dateOfBirth+"");
|
| 517 |
rajveer |
519 |
context.put("subscribe", subscribe);
|
|
|
520 |
context.put("sex", sex);
|
| 507 |
rajveer |
521 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
522 |
return htmlString;
|
|
|
523 |
}
|
|
|
524 |
|
| 620 |
rajveer |
525 |
public String getCompletedOrdersHtml(long userId) {
|
| 507 |
rajveer |
526 |
String htmlString = "";
|
|
|
527 |
VelocityContext context = new VelocityContext();
|
|
|
528 |
String templateFile = "templates/completedorders.vm";
|
|
|
529 |
TransactionServiceClient transactionServiceClient = null;
|
|
|
530 |
in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
|
|
|
531 |
List<Order> orders = null;
|
|
|
532 |
try{
|
|
|
533 |
transactionServiceClient = new TransactionServiceClient();
|
|
|
534 |
orderClient = transactionServiceClient.getClient();
|
|
|
535 |
orders = orderClient.getOrdersForCustomer(userId, 0, (new Date()).getTime(), OrderStatus.DELIVERY_SUCCESS);
|
|
|
536 |
|
|
|
537 |
}catch (Exception e){
|
|
|
538 |
|
|
|
539 |
}
|
|
|
540 |
context.put("orders", orders);
|
|
|
541 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
542 |
return htmlString;
|
|
|
543 |
}
|
| 595 |
rajveer |
544 |
public String getMyaccountHeaderHtml() {
|
| 507 |
rajveer |
545 |
String htmlString = "";
|
|
|
546 |
VelocityContext context = new VelocityContext();
|
|
|
547 |
String templateFile = "templates/myaccountheader.vm";
|
|
|
548 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
549 |
return htmlString;
|
|
|
550 |
}
|
|
|
551 |
|
| 650 |
rajveer |
552 |
public String getShippingHeaderHtml() {
|
| 507 |
rajveer |
553 |
String htmlString = "";
|
|
|
554 |
VelocityContext context = new VelocityContext();
|
|
|
555 |
String templateFile = "templates/shippingheader.vm";
|
|
|
556 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
557 |
return htmlString;
|
|
|
558 |
}
|
|
|
559 |
|
| 650 |
rajveer |
560 |
public String getShippingAddressDetailsHtml(long userId){
|
| 507 |
rajveer |
561 |
String htmlString = "";
|
|
|
562 |
VelocityContext context = new VelocityContext();
|
|
|
563 |
String templateFile = "templates/shippingaddressdetails.vm";
|
|
|
564 |
long defaultAddressId = 0;
|
| 517 |
rajveer |
565 |
List<Address> addresses = null;
|
| 507 |
rajveer |
566 |
|
|
|
567 |
UserContextServiceClient userContextServiceClient = null;
|
|
|
568 |
in.shop2020.model.v1.user.UserContextService.Client userClient = null;
|
|
|
569 |
try {
|
|
|
570 |
userContextServiceClient = new UserContextServiceClient();
|
|
|
571 |
userClient = userContextServiceClient.getClient();
|
| 620 |
rajveer |
572 |
|
|
|
573 |
addresses = userClient.getAllAddressesForUser(userId);
|
|
|
574 |
defaultAddressId = userClient.getDefaultAddressId(userId);
|
| 507 |
rajveer |
575 |
} catch (Exception e) {
|
|
|
576 |
e.printStackTrace();
|
|
|
577 |
}
|
| 517 |
rajveer |
578 |
context.put("defaultAddressId", defaultAddressId+"");
|
| 507 |
rajveer |
579 |
context.put("addresses", addresses);
|
|
|
580 |
|
|
|
581 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
582 |
return htmlString;
|
|
|
583 |
}
|
|
|
584 |
|
| 650 |
rajveer |
585 |
public String getShippingDetailsHtml(long cartId, String errorMsg) {
|
| 507 |
rajveer |
586 |
String htmlString = "";
|
|
|
587 |
VelocityContext context = new VelocityContext();
|
|
|
588 |
String templateFile = "templates/shippingdetails.vm";
|
| 517 |
rajveer |
589 |
List<Map<String,String>> items = null;
|
| 507 |
rajveer |
590 |
double totalamount= 0.0;
|
| 517 |
rajveer |
591 |
List<Address> addresses = null;
|
|
|
592 |
long defaultAddressId = 0;
|
| 555 |
chandransh |
593 |
|
| 507 |
rajveer |
594 |
CatalogServiceClient catalogServiceClient = null;
|
|
|
595 |
in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = null;
|
|
|
596 |
UserContextServiceClient userContextServiceClient = null;
|
|
|
597 |
in.shop2020.model.v1.user.UserContextService.Client userClient = null;
|
|
|
598 |
|
|
|
599 |
try {
|
|
|
600 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
601 |
catalogClient = catalogServiceClient.getClient();
|
|
|
602 |
userContextServiceClient = new UserContextServiceClient();
|
|
|
603 |
userClient = userContextServiceClient.getClient();
|
|
|
604 |
|
|
|
605 |
|
| 555 |
chandransh |
606 |
Cart cart = userClient.getCart(cartId);
|
| 507 |
rajveer |
607 |
List<Line> lineItems = cart.getLines();
|
|
|
608 |
|
| 517 |
rajveer |
609 |
if( ! lineItems.isEmpty())
|
|
|
610 |
{
|
|
|
611 |
items = new ArrayList<Map<String,String>>();
|
| 507 |
rajveer |
612 |
|
| 517 |
rajveer |
613 |
for (Line line : lineItems) {
|
|
|
614 |
Map<String, String> itemdetail = new HashMap<String, String>();
|
| 637 |
rajveer |
615 |
Item item = catalogClient.getItem(line.getItemId());
|
| 517 |
rajveer |
616 |
String itemName = ((item.getManufacturerName() != null) ? item.getManufacturerName() + " " : "")
|
|
|
617 |
+ ((item.getModelName() != null) ? item.getModelName() + " " : "")
|
| 637 |
rajveer |
618 |
+ (( item.getModelNumber() != null ) ? item.getModelNumber() + " " : "" )
|
|
|
619 |
+ (( (item.getColor() != null && !item.getColor().trim().equals("NA"))) ? "("+item.getColor()+")" : "" );
|
| 517 |
rajveer |
620 |
|
|
|
621 |
itemdetail.put("ITEM_NAME", itemName);
|
|
|
622 |
itemdetail.put("ITEM_ID", line.getItemId()+"");
|
|
|
623 |
itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
|
|
|
624 |
itemdetail.put("MRP", ((int)item.getMrp())+"");
|
| 536 |
rajveer |
625 |
itemdetail.put("SELLING_PRICE", (int)item.getSellingPrice()+"");
|
|
|
626 |
itemdetail.put("TOTAL_PRICE", (int)(item.getSellingPrice()*line.getQuantity())+"");
|
| 615 |
chandransh |
627 |
itemdetail.put("SHIPPING_TIME", line.getEstimate()+"");
|
| 536 |
rajveer |
628 |
totalamount = totalamount + line.getQuantity()*item.getSellingPrice();
|
| 517 |
rajveer |
629 |
items.add(itemdetail);
|
|
|
630 |
}
|
| 507 |
rajveer |
631 |
}
|
|
|
632 |
|
| 637 |
rajveer |
633 |
addresses = userClient.getAllAddressesForUser(cart.getUserId());
|
| 650 |
rajveer |
634 |
if(cart.isSetAddressId()){
|
|
|
635 |
defaultAddressId = cart.getAddressId();
|
|
|
636 |
}else{
|
|
|
637 |
defaultAddressId = userClient.getDefaultAddressId(cart.getUserId());
|
|
|
638 |
}
|
| 507 |
rajveer |
639 |
|
|
|
640 |
}catch (Exception e){
|
|
|
641 |
e.printStackTrace();
|
|
|
642 |
}
|
|
|
643 |
|
|
|
644 |
context.put("items", items);
|
| 536 |
rajveer |
645 |
context.put("totalamount", (int)totalamount+"");
|
| 507 |
rajveer |
646 |
context.put("addresses", addresses);
|
| 517 |
rajveer |
647 |
context.put("defaultAddressId", defaultAddressId+"");
|
| 572 |
chandransh |
648 |
context.put("errorMsg", errorMsg);
|
| 507 |
rajveer |
649 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
650 |
return htmlString;
|
|
|
651 |
}
|
|
|
652 |
|
|
|
653 |
|
| 650 |
rajveer |
654 |
public String getCartHeaderHtml() {
|
| 507 |
rajveer |
655 |
String htmlString = "";
|
|
|
656 |
VelocityContext context = new VelocityContext();
|
|
|
657 |
String templateFile = "templates/cartheader.vm";
|
|
|
658 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
659 |
return htmlString;
|
|
|
660 |
}
|
|
|
661 |
|
|
|
662 |
|
| 650 |
rajveer |
663 |
public String getCartDetailsHtml(long cartId, String errorMsg) {
|
| 507 |
rajveer |
664 |
String htmlString = "";
|
|
|
665 |
VelocityContext context = new VelocityContext();
|
|
|
666 |
String templateFile = "templates/cartdetails.vm";
|
| 517 |
rajveer |
667 |
List<Map<String,String>> items = null;
|
| 507 |
rajveer |
668 |
double totalamount= 0.0;
|
|
|
669 |
|
| 555 |
chandransh |
670 |
UserContextServiceClient userServiceClient = null;
|
|
|
671 |
in.shop2020.model.v1.user.UserContextService.Client userClient = null;
|
| 507 |
rajveer |
672 |
CatalogServiceClient catalogServiceClient = null;
|
|
|
673 |
in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = null;
|
|
|
674 |
|
|
|
675 |
try {
|
|
|
676 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
677 |
catalogClient = catalogServiceClient.getClient();
|
| 555 |
chandransh |
678 |
userServiceClient = new UserContextServiceClient();
|
|
|
679 |
userClient = userServiceClient.getClient();
|
| 507 |
rajveer |
680 |
|
| 555 |
chandransh |
681 |
Cart cart = userClient.getCart(cartId);
|
| 507 |
rajveer |
682 |
List<Line> lineItems = cart.getLines();
|
| 517 |
rajveer |
683 |
if(lineItems.size() != 0){
|
|
|
684 |
items = new ArrayList<Map<String,String>>();
|
|
|
685 |
for (Line line : lineItems) {
|
|
|
686 |
|
|
|
687 |
Map<String, String> itemdetail = new HashMap<String, String>();
|
| 637 |
rajveer |
688 |
Item item = catalogClient.getItem(line.getItemId());
|
| 517 |
rajveer |
689 |
|
|
|
690 |
String itemName = ((item.getManufacturerName() != null) ? item.getManufacturerName() + " " : "")
|
|
|
691 |
+ ((item.getModelName() != null) ? item.getModelName() + " " : "")
|
| 637 |
rajveer |
692 |
+ (( item.getModelNumber() != null ) ? item.getModelNumber() + " " : "" )
|
|
|
693 |
+ (( (item.getColor() != null && !item.getColor().trim().equals("NA"))) ? "("+item.getColor()+")" : "" );
|
| 517 |
rajveer |
694 |
|
|
|
695 |
itemdetail.put("ITEM_NAME", itemName);
|
|
|
696 |
System.out.println(itemdetail.get("ITEM_NAME"));
|
|
|
697 |
itemdetail.put("ITEM_ID", line.getItemId()+"");
|
|
|
698 |
itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
|
|
|
699 |
itemdetail.put("MRP", ((int)item.getMrp())+"");
|
|
|
700 |
itemdetail.put("SELLING_PRICE", ((int)item.getSellingPrice())+"");
|
|
|
701 |
itemdetail.put("TOTAL_PRICE", ((int)((item.getSellingPrice()*line.getQuantity())))+"");
|
| 615 |
chandransh |
702 |
itemdetail.put("SHIPPING_TIME", line.getEstimate()+"");
|
| 517 |
rajveer |
703 |
totalamount = totalamount + line.getQuantity()*item.getSellingPrice();
|
|
|
704 |
items.add(itemdetail);
|
| 507 |
rajveer |
705 |
}
|
|
|
706 |
}
|
|
|
707 |
|
|
|
708 |
}catch (Exception e){
|
|
|
709 |
e.printStackTrace();
|
|
|
710 |
}
|
|
|
711 |
|
|
|
712 |
context.put("items", items);
|
| 517 |
rajveer |
713 |
context.put("totalamount", ((int)totalamount)+"");
|
| 572 |
chandransh |
714 |
context.put("errorMsg", errorMsg);
|
| 507 |
rajveer |
715 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
716 |
return htmlString;
|
|
|
717 |
}
|
|
|
718 |
|
|
|
719 |
public String getHtmlFromVelocity(String templateFile, VelocityContext context){
|
|
|
720 |
Properties p = new Properties();
|
|
|
721 |
p.setProperty("resource.loader", "class");
|
|
|
722 |
p.setProperty("class.resource.loader.class",
|
|
|
723 |
"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
|
|
|
724 |
|
|
|
725 |
try {
|
|
|
726 |
Velocity.init(p);
|
|
|
727 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
728 |
if(template != null) {
|
|
|
729 |
StringWriter writer = new StringWriter();
|
|
|
730 |
template.merge(context, writer);
|
|
|
731 |
writer.flush();
|
|
|
732 |
writer.close();
|
|
|
733 |
return writer.toString();
|
|
|
734 |
}
|
|
|
735 |
|
|
|
736 |
} catch (ResourceNotFoundException e) {
|
|
|
737 |
// TODO Auto-generated catch block
|
|
|
738 |
e.printStackTrace();
|
|
|
739 |
} catch (ParseErrorException e) {
|
|
|
740 |
// TODO Auto-generated catch block
|
|
|
741 |
e.printStackTrace();
|
|
|
742 |
} catch (MethodInvocationException e) {
|
|
|
743 |
// TODO Auto-generated catch block
|
|
|
744 |
e.printStackTrace();
|
|
|
745 |
} catch (IOException e) {
|
|
|
746 |
// TODO Auto-generated catch block
|
|
|
747 |
e.printStackTrace();
|
|
|
748 |
} catch (Exception e) {
|
|
|
749 |
// TODO Auto-generated catch block
|
|
|
750 |
e.printStackTrace();
|
|
|
751 |
}
|
|
|
752 |
|
|
|
753 |
return null;
|
|
|
754 |
}
|
|
|
755 |
|
|
|
756 |
|
| 517 |
rajveer |
757 |
public String getCategoryHeaderSnippet() {
|
|
|
758 |
String htmlString = "";
|
|
|
759 |
VelocityContext context = new VelocityContext();
|
|
|
760 |
String templateFile = "templates/categoryheader.vm";
|
|
|
761 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
762 |
return htmlString;
|
|
|
763 |
}
|
|
|
764 |
|
| 507 |
rajveer |
765 |
|
|
|
766 |
|
|
|
767 |
}
|
|
|
768 |
|