Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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.DateFormat;
11
import java.text.SimpleDateFormat;
507 rajveer 12
import java.util.ArrayList;
517 rajveer 13
import java.util.Calendar;
507 rajveer 14
import java.util.Date;
15
import java.util.HashMap;
16
import java.util.List;
17
import java.util.Map;
18
import java.util.Properties;
19
import java.util.Set;
20
 
21
 
22
import in.shop2020.util.Utils;
23
 
24
import org.apache.thrift.TException;
25
import org.apache.velocity.Template;
26
import org.apache.velocity.VelocityContext;
27
import org.apache.velocity.app.Velocity;
28
import org.apache.velocity.exception.MethodInvocationException;
29
import org.apache.velocity.exception.ParseErrorException;
30
import org.apache.velocity.exception.ResourceNotFoundException;
31
 
32
 
33
import in.shop2020.metamodel.definitions.Catalog;
34
import in.shop2020.metamodel.definitions.DefinitionsContainer;
35
import in.shop2020.metamodel.definitions.EntityContainer;
36
import in.shop2020.metamodel.util.ExpandedCategory;
37
import in.shop2020.metamodel.util.ExpandedEntity;
38
import in.shop2020.model.v1.catalog.InventoryServiceException;
39
import in.shop2020.model.v1.catalog.Item;
40
import in.shop2020.model.v1.catalog.InventoryService.Client;
41
import in.shop2020.model.v1.order.Order;
42
import in.shop2020.model.v1.order.OrderStatus;
43
import in.shop2020.model.v1.order.Transaction;
555 chandransh 44
import in.shop2020.model.v1.user.Cart;
45
import in.shop2020.model.v1.user.Line;
46
import in.shop2020.model.v1.user.LineStatus;
47
import in.shop2020.model.v1.user.ShoppingCartException;
507 rajveer 48
import in.shop2020.model.v1.user.Address;
555 chandransh 49
import in.shop2020.model.v1.user.User;
507 rajveer 50
import in.shop2020.model.v1.user.UserContextException;
555 chandransh 51
import in.shop2020.model.v1.user.RatingType;
52
import in.shop2020.model.v1.user.RatingsWidget;
53
import in.shop2020.model.v1.user.Widget;
54
import in.shop2020.model.v1.user.WidgetItem;
55
import in.shop2020.model.v1.user.WidgetType;
507 rajveer 56
import in.shop2020.serving.page.CategoryPage;
57
import in.shop2020.serving.page.MyAccountPage;
58
import in.shop2020.serving.page.ProductPage;
59
import in.shop2020.serving.page.ShoppingCartPage;
60
import in.shop2020.serving.utils.*;
61
import in.shop2020.thrift.clients.CatalogServiceClient;
62
import in.shop2020.thrift.clients.TransactionServiceClient;
63
import in.shop2020.thrift.clients.UserContextServiceClient;
64
 
65
 
66
public class PageLoaderHandler {
67
 
68
	public Map<String,String> getProductPage(long productId, Map<String, String> params) throws TException {
69
 
70
		Map<String,String> htmlSnippet = new HashMap<String, String>();
71
 
555 chandransh 72
		boolean isLoggedIn = Boolean.parseBoolean(params.get("IS_LOGGED_IN"));
507 rajveer 73
		long userId = Long.parseLong(params.get("USER_ID"));
74
		String userName = params.get("USER_NAME");
75
 
76
		long categoryId = 100000;
77
		long itemCount = Long.parseLong(params.get("ITEM_COUNT"));
78
		//product.setCategoryId(categoryId);
79
 
555 chandransh 80
		htmlSnippet.put("HEADER", getHeaderHtml(isLoggedIn, userName));
507 rajveer 81
		System.out.println("HEADER Snippet generated");
82
 
83
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
84
		System.out.println("MAIN_MENU Snippet generated");
85
 
86
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, categoryId));
87
		System.out.println("SEARCH_BAR Snippet generated");
88
 
89
		htmlSnippet.put("PRODUCT_SUMMARY", getProductSummaryHtml(productId));
90
		System.out.println("PRODUCT_SUMMARY Snippet generated");
91
 
92
		htmlSnippet.put("SOCIAL_UTILS", getSocialUtilsHtml(productId));
93
		System.out.println("SOCIAL_UTILS Snippet generated");
94
 
95
		htmlSnippet.put("SLIDE_GUIDE", getSlideGuideHtml(productId));
96
		System.out.println("SLIDE GUIDE Snippet generated");
97
 
98
		htmlSnippet.put("LOCATOR", getLocatorHtml());
99
		System.out.println("LOCATOR Snippet generated");
100
 
101
		htmlSnippet.put("REVIEWS", getReviewsHtml(productId));
102
		System.out.println("REVIEWS Snippet generated");
103
 
104
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
105
		System.out.println("CUSTOMER_SERVICE Snippet generated");
106
 
555 chandransh 107
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, isLoggedIn));
507 rajveer 108
		System.out.println("MY_RESEARCH Snippet generated");
109
 
110
		htmlSnippet.put("RECOMMENDATIONS", getRecommendationsHtml());
111
		System.out.println("RECOMMENDATIONS Snippet generated");
112
 
113
		htmlSnippet.put("SIMILAR_PRODUCTS", getSimilarProductsHtml(productId));
114
		System.out.println("RECOMMENDATIONS Snippet generated");
115
 
116
		htmlSnippet.put("ACCESSORIES", getAccessoriesHtml(productId));
117
		System.out.println("ACCESSORIES Snippet generated");
118
 
119
		htmlSnippet.put("FOOTER", getFooterHtml());
120
		System.out.println("Footer Snippet generated");
121
 
122
//		htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
123
//		System.out.println("ACCESSORIES Snippet generated")
124
 
125
		htmlSnippet.put("JS_FILES", "");
126
		htmlSnippet.put("CSS_FILES", "");
127
 
128
		System.out.println("Returning Generated Responce");
129
 
130
		return htmlSnippet;
131
	}
132
 
133
 
134
	public Map<String, String> getRegisterPage(Map<String, String> parameters) {
135
		Map<String,String> htmlSnippet = new HashMap<String, String>();
555 chandransh 136
		boolean isLoggedIn = Boolean.parseBoolean(parameters.get("IS_LOGGED_IN"));
507 rajveer 137
		long userId = Long.parseLong(parameters.get("USER_ID"));
138
		String userName = parameters.get("USER_NAME");
139
		long itemCount = Long.parseLong(parameters.get("ITEM_COUNT"));
140
 
555 chandransh 141
		htmlSnippet.put("HEADER", getHeaderHtml(isLoggedIn, userName));
507 rajveer 142
		System.out.println("HEADER Snippet generated");
143
 
144
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
145
		System.out.println("MAIN_MENU Snippet generated");
146
 
147
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
148
		System.out.println("SEARCH_BAR Snippet generated");
149
 
150
		htmlSnippet.put("REGISTRATION_HEADER", getRegistrationHeaderHtml());
151
		System.out.println("REGISTRATION_HEADER Snippet generated");
152
 
153
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
154
		System.out.println("CUSTOMER_SERVICE Snippet generated");
155
 
156
		htmlSnippet.put("REGISTRATION_FORM", getRegistrationFormHtml());
157
		System.out.println("REGISTRATION_FORM Snippet generated");
158
 
159
		htmlSnippet.put("FOOTER", getFooterHtml());
160
		System.out.println("Footer Snippet generated");
161
 
162
		htmlSnippet.put("JS_FILES", "");
163
		htmlSnippet.put("CSS_FILES", "");
164
 
165
 
166
		return htmlSnippet;
167
	}
168
 
169
	private String getRegistrationFormHtml() {
170
		String htmlString = "";
171
		VelocityContext context = new VelocityContext();
172
		String templateFile = "templates/registrationform.vm";
173
		htmlString = getHtmlFromVelocity(templateFile, context);
174
		return htmlString;
175
	}
176
 
177
 
178
	private String getRegistrationHeaderHtml() {
179
		String htmlString = "";
180
		VelocityContext context = new VelocityContext();
181
		String templateFile = "templates/registrationheader.vm";
182
		htmlString = getHtmlFromVelocity(templateFile, context);
183
		return htmlString;
184
	}
185
 
186
 
555 chandransh 187
	public Map<String,String> getHomePage(Map<String, String> parameters) throws TException {
507 rajveer 188
 
189
		Map<String,String> htmlSnippet = new HashMap<String, String>();
555 chandransh 190
		boolean isLoggedIn = Boolean.parseBoolean(parameters.get("IS_LOGGED_IN"));
191
		long userId = Long.parseLong(parameters.get("USER_ID"));
192
		String userName = parameters.get("USER_NAME");
193
		long itemCount = Long.parseLong(parameters.get("ITEM_COUNT"));
507 rajveer 194
 
195
		long categoryId = 100000;
196
		//product.setCategoryId(categoryId);
197
 
555 chandransh 198
		htmlSnippet.put("HEADER", getHeaderHtml(isLoggedIn, userName));
507 rajveer 199
		System.out.println("HEADER Snippet generated");
200
 
555 chandransh 201
 
507 rajveer 202
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
203
		System.out.println("MAIN_MENU Snippet generated");
204
 
205
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, categoryId));
206
		System.out.println("SEARCH_BAR Snippet generated");
207
 
208
		htmlSnippet.put("MAIN_BANNER", getMainBannerHtml());
209
		System.out.println("LOCATOR Snippet generated");
210
 
211
		htmlSnippet.put("BEST_DEALS", getBestDealsHtml());
212
		System.out.println("BEST_DEALS Snippet generated");
213
 
214
		htmlSnippet.put("LATEST_ARRIVALS", getLatestArrivalsHtml());
215
		System.out.println("LATEST_ARRIVALS Snippet generated");
216
 
217
		htmlSnippet.put("BEST_SELLERS", getBestSellersHtml());
218
		System.out.println("BEST_SELLERS Snippet generated");
219
 
220
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
221
		System.out.println("CUSTOMER_SERVICE Snippet generated");
222
 
555 chandransh 223
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, isLoggedIn));
507 rajveer 224
		System.out.println("MY_RESEARCH Snippet generated");
225
 
226
		htmlSnippet.put("RECOMMENDATIONS", getRecommendationsHtml());
227
		System.out.println("RECOMMENDATIONS Snippet generated");
228
 
555 chandransh 229
		htmlSnippet.put("BROWSE_HISTORY", getBrowseHistoryHtml(userId, isLoggedIn));
507 rajveer 230
		System.out.println("RECOMMENDATIONS Snippet generated");
231
 
232
		htmlSnippet.put("FOOTER", getFooterHtml());
233
		System.out.println("Footer Snippet generated");
234
 
235
//		htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
236
//		System.out.println("ACCESSORIES Snippet generated")
237
 
238
		htmlSnippet.put("JS_FILES", "");
239
		htmlSnippet.put("CSS_FILES", "");
240
 
241
		System.out.println("Returning Generated Responce");
242
 
243
		return htmlSnippet;
244
	}
245
 
246
 
247
	private String getMainBannerHtml() {
248
		String htmlString = "";
249
		VelocityContext context = new VelocityContext();
250
		String templateFile = "templates/mainbanner.vm";
251
		htmlString = getHtmlFromVelocity(templateFile, context);
252
		return htmlString;
253
	}
254
 
255
 
256
	private String getBestSellersHtml() {
257
		String htmlString = "";
258
		VelocityContext context = new VelocityContext();
259
		String templateFile = "templates/bestsellers.vm";
260
 
261
		CatalogServiceClient catalogServiceClient = null;
262
		Client client = null;
263
 
264
		try {
265
			catalogServiceClient = new CatalogServiceClient();
266
			client = catalogServiceClient.getClient();
624 chandransh 267
			List<Long> items = client.getBestSellersCatalogIds(1, 20, -1);
507 rajveer 268
			List<String> itemList = new ArrayList<String>();
269
			for(Long item: items){
517 rajveer 270
				itemList.add(FileUtils.read( Utils.EXPORT_ENTITIES_PATH + item + File.separator +"HomeSnippet.html"));
507 rajveer 271
			}
272
			context.put("itemList", itemList);
273
 
274
		} catch(Exception e){
275
 
276
		}
277
 
278
 
279
		htmlString = getHtmlFromVelocity(templateFile, context);
517 rajveer 280
		return htmlString;	
281
	}
507 rajveer 282
 
283
 
284
	private String getLatestArrivalsHtml() {
285
		String htmlString = "";
286
		VelocityContext context = new VelocityContext();
287
		String templateFile = "templates/latestarrivals.vm";
288
 
289
		CatalogServiceClient catalogServiceClient = null;
290
		Client client = null;
291
 
292
		try {
293
			catalogServiceClient = new CatalogServiceClient();
294
			client = catalogServiceClient.getClient();
624 chandransh 295
			List<Long> items = client.getLatestArrivalsCatalogIds(1, 20, -1);
507 rajveer 296
			List<String> itemList = new ArrayList<String>();
297
			for(Long item: items){
517 rajveer 298
				itemList.add(FileUtils.read( Utils.EXPORT_ENTITIES_PATH + item + File.separator +"HomeSnippet.html"));
507 rajveer 299
			}
300
			context.put("itemList", itemList);
301
 
302
		} catch(Exception e){
303
 
304
		}
305
 
306
 
307
		htmlString = getHtmlFromVelocity(templateFile, context);
308
		return htmlString;
309
	}
310
 
311
 
312
	private String getBestDealsHtml() {
313
		String htmlString = "";
314
		VelocityContext context = new VelocityContext();
315
		String templateFile = "templates/bestdeals.vm";
316
 
317
		CatalogServiceClient catalogServiceClient = null;
318
		Client client = null;
319
 
320
		try {
321
			catalogServiceClient = new CatalogServiceClient();
322
			client = catalogServiceClient.getClient();
624 chandransh 323
			List<Long> items = client.getBestDealsCatalogIds(1, 20, -1);
507 rajveer 324
			List<String> itemList = new ArrayList<String>();
325
			for(Long item: items){
517 rajveer 326
				itemList.add(FileUtils.read( Utils.EXPORT_ENTITIES_PATH + item + File.separator +"HomeSnippet.html"));
507 rajveer 327
			}
328
			context.put("itemList", itemList);
329
 
330
		} catch(Exception e){
331
 
332
		}
333
 
334
		htmlString = getHtmlFromVelocity(templateFile, context);
335
		return htmlString;
336
	}
337
 
338
 
517 rajveer 339
	public String getFooterHtml() {
507 rajveer 340
		String htmlString = "";
341
		VelocityContext context = new VelocityContext();
342
		String templateFile = "templates/footer.vm";
343
		htmlString = getHtmlFromVelocity(templateFile, context);
344
		return htmlString;
345
	}
346
 
347
 
348
 
620 rajveer 349
	public String getAccessoriesHtml(long productId) {
555 chandransh 350
		return getWidgetDiv(0, WidgetType.ACCESSORIES, "accessories.vm");
507 rajveer 351
	}
352
 
353
 
354
 
620 rajveer 355
	public String getSimilarProductsHtml(long productId) {
555 chandransh 356
		return getWidgetDiv(0, WidgetType.SIMILAR_ITEMS, "similaritems.vm");
507 rajveer 357
	}
358
 
359
 
360
 
620 rajveer 361
	public String getRecommendationsHtml() {
555 chandransh 362
		return getWidgetDiv( 0, WidgetType.RECOMMENDED_ITEMS, "recommendations.vm");
507 rajveer 363
	}
364
 
365
 
366
 
555 chandransh 367
	public String getMyResearchHtml(long userId, boolean isLoggedIn) {
368
		if(isLoggedIn)
369
			return getWidgetDiv(userId, WidgetType.MY_RESEARCH, "myresearch.vm");
370
		else
371
			return getWidgetDiv(0, WidgetType.MY_RESEARCH, "myresearch.vm");
507 rajveer 372
	}
373
 
569 rajveer 374
	public String getBrowseHistoryHtml(long userId, boolean isLoggedIn) {
555 chandransh 375
		if(isLoggedIn)
376
			return getWidgetDiv(userId, WidgetType.BROWSE_HISTORY, "browsehistory.vm");
377
		else
378
			return getWidgetDiv(0, WidgetType.BROWSE_HISTORY, "browsehistory.vm");
507 rajveer 379
	}
380
 
517 rajveer 381
	public String getCustomerServiceHtml() {
507 rajveer 382
		String htmlString = "";
383
		VelocityContext context = new VelocityContext();
384
		String templateFile = "templates/customerservice.vm";
385
		htmlString = getHtmlFromVelocity(templateFile, context);
386
		return htmlString;
387
	}
388
 
389
 
390
 
620 rajveer 391
	public String getReviewsHtml(long productId) {
507 rajveer 392
		String htmlString = "";
393
		VelocityContext context = new VelocityContext();
394
		Map<String, String> params = new HashMap<String, String>();
395
		params.put("PRODUCT_ID", productId+"");
396
		context.put("params", params);
397
		String templateFile = "templates/reviews.vm";
398
		htmlString = getHtmlFromVelocity(templateFile, context);
399
		return htmlString;
400
	}
401
 
402
 
403
 
620 rajveer 404
	public String getLocatorHtml() {
507 rajveer 405
		String htmlString = "";
406
		VelocityContext context = new VelocityContext();
407
		String templateFile = "templates/locator.vm";
408
		htmlString = getHtmlFromVelocity(templateFile, context);
409
		return htmlString;
410
	}
411
 
412
 
413
 
414
//	private String getSlideGuideHtml(long productId) {
415
//		String htmlString = "";
416
//		try {
417
//			VelocityContext context = new VelocityContext();
418
//			String templateFile = "velocity/slideguide.vm";
419
//			// For an entity
420
//			EntityContainer entContainer = 	Catalog.getInstance().getEntityContainer();
421
//			ExpandedEntity expEntity = entContainer.getExpandedEntity(productId);
422
//			
423
//			context.put("expentity", expEntity);
424
//			htmlString = getHtmlFromVelocity(templateFile, context);
425
//			} catch (Exception e) {
426
//				e.printStackTrace();
427
//			}
428
//		return htmlString;
429
//	}
430
 
620 rajveer 431
	public String getSlideGuideHtml(long productId) {
507 rajveer 432
		StringBuilder htmlString = new StringBuilder();
517 rajveer 433
		String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "SlideGuide.html";
507 rajveer 434
		File f = new File(filename);
435
 
436
 
437
		FileInputStream fis = null;
438
		try {
439
			fis = new FileInputStream(f);
440
			BufferedReader br = new BufferedReader(new InputStreamReader(fis));
441
			String line;
442
			while((line = br.readLine()) != null){
443
				htmlString.append(line+"\n");
444
			}
445
		} catch (FileNotFoundException e) {
446
			// TODO Auto-generated catch block
447
			e.printStackTrace();
448
		} catch (IOException e) {
449
			// TODO Auto-generated catch block
450
			e.printStackTrace();
451
		}
452
		finally {
453
			if(fis != null) {
454
				try {
455
					fis.close();
456
				} catch (IOException e) {
457
					// TODO Auto-generated catch block
458
					e.printStackTrace();
459
				}
460
			}
461
		}
462
 
463
		return htmlString.toString();
464
	}
465
 
517 rajveer 466
	public String getProductSummaryHtml(long productId) {
507 rajveer 467
		StringBuilder htmlString = new StringBuilder();
517 rajveer 468
		String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "ProductDetail.html";
507 rajveer 469
		File f = new File(filename);
470
 
471
 
472
		FileInputStream fis = null;
473
		try {
474
			fis = new FileInputStream(f);
475
			BufferedReader br = new BufferedReader(new InputStreamReader(fis));
476
			String line;
477
			while((line = br.readLine()) != null){
478
				htmlString.append(line+"\n");
479
			}
480
		} catch (FileNotFoundException e) {
481
			// TODO Auto-generated catch block
482
			e.printStackTrace();
483
		} catch (IOException e) {
484
			// TODO Auto-generated catch block
485
			e.printStackTrace();
486
		}
487
		finally {
488
			if(fis != null) {
489
				try {
490
					fis.close();
491
				} catch (IOException e) {
492
					// TODO Auto-generated catch block
493
					e.printStackTrace();
494
				}
495
			}
496
		}
497
 
498
		return htmlString.toString();
499
	}
500
 
501
 
620 rajveer 502
	public String getSocialUtilsHtml(long productId) {
507 rajveer 503
		String htmlString = "";
504
		VelocityContext context = new VelocityContext();
505
		Map<String, String> params = new HashMap<String, String>();
506
		params.put("PRODUCT_ID", productId+"");
507
		String templateFile = "templates/socialutils.vm";
508
		context.put("params", params);
509
		htmlString = getHtmlFromVelocity(templateFile, context);
510
		return htmlString;
511
	}
512
 
513
 
514
 
620 rajveer 515
	public String getProductSummaryHtml(long productId, boolean toBeDecided) {
507 rajveer 516
		CatalogServiceClient catalogServiceClient = null;
517
		Client client = null;
518
		String htmlString = "";
519
 
555 chandransh 520
		UserContextServiceClient userServiceClient = null;
521
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
507 rajveer 522
		try {
523
			catalogServiceClient = new CatalogServiceClient();
524
			client = catalogServiceClient.getClient();
525
 
555 chandransh 526
			userServiceClient = new UserContextServiceClient();
527
			userClient = userServiceClient.getClient();
507 rajveer 528
 
555 chandransh 529
			RatingsWidget ratingsWidget = userClient.getRatings(productId, 0);
507 rajveer 530
			Map<RatingType,Double> ratings = ratingsWidget.getRatings();
531
			//double rating_amazon = ratings.get(RatingType.AMAZON);
532
			double rating_all  = 0.0;
533
			if(ratings != null){
534
				if( ratings.get(RatingType.USER_ALL) != null){
535
					rating_all = ratings.get(RatingType.USER_ALL);
536
				}
537
			}
538
 
539
			rating_all = Math.round(rating_all);
540
 
541
			Item item = client.getItemByCatalogId(productId);
542
 
543
			Double itemPrice = item.getSellingPrice();
544
			// For an entity
545
			EntityContainer entContainer = 	Catalog.getInstance().getEntityContainer();
546
			ExpandedEntity expEntity = entContainer.getExpandedEntity(productId);
547
 
548
			String title = expEntity.getBrand() + "" + expEntity.getModelName();
549
			String categoryName = expEntity.getCategory().getLabel();
550
			long categoryId = expEntity.getCategory().getID();
551
			Map<String,String> params = new HashMap<String, String>();
552
			params.put("TITLE", title);
553
			params.put("CATEGORY_ID", categoryId+"");
554
			params.put("CATEGORY_NAME", categoryName);
555
			params.put("PRICE", itemPrice.toString());
556
			params.put("RATING_ALL", rating_all+"");
557
			params.put("PRODUCT_ID", productId+"");
558
 
559
			VelocityContext context = new VelocityContext();
560
			String templateFile = "templates/productsummary.vm";
561
			context.put("params", params);
562
			htmlString = getHtmlFromVelocity(templateFile, context);
563
 
564
		} catch (Exception e) {
565
			e.printStackTrace();
566
		}
567
 
568
		return htmlString;
569
	}
570
 
571
 
572
 
517 rajveer 573
	public String getMainMenuHtml() {
507 rajveer 574
		String htmlString = "";
575
		VelocityContext context = new VelocityContext();
576
		String templateFile = "templates/mainmenu.vm";
577
		htmlString = getHtmlFromVelocity(templateFile, context);
578
		return htmlString;
579
	}
580
 
581
 
517 rajveer 582
	public String getSearchBarHtml(long itemCounts, long categoryId) {
507 rajveer 583
		String htmlString = "";
584
		VelocityContext context = new VelocityContext();
585
		String templateFile = "templates/searchbar.vm";
550 rajveer 586
 
587
		context.put("itemCount", itemCounts+"");
588
		context.put("categoryId", categoryId+"");
589
 
507 rajveer 590
		htmlString = getHtmlFromVelocity(templateFile, context);
591
		return htmlString;
592
	}
593
 
594
 
595
 
555 chandransh 596
	public String getHeaderHtml(boolean isLoggedIn, String  userName) {
550 rajveer 597
		VelocityContext context = new VelocityContext();
555 chandransh 598
		if (isLoggedIn) {
599
			context.put("LOGGED_IN", "TRUE");
600
			context.put("WELCOME_MESSAGE", "Hi, " + userName);
601
		} else {
550 rajveer 602
			context.put("LOGGED_IN", "FALSE");
603
			context.put("WELCOME_MESSAGE", "Hi, Welcome to Shop2020");
555 chandransh 604
		}		
507 rajveer 605
 
606
		String templateFile = "templates/header.vm";
550 rajveer 607
 
590 chandransh 608
		return getHtmlFromVelocity(templateFile, context);
507 rajveer 609
	}
610
 
611
 
612
 
613
	public String getSlideGuideDIV(long productId){
614
		String htmlString = "";
615
		try {
616
			VelocityContext context = new VelocityContext();
617
			String templateFile = "templates/slideguide.vm";
618
			// For an entity
619
			EntityContainer entContainer = 	Catalog.getInstance().getEntityContainer();
620
			ExpandedEntity expEntity = entContainer.getExpandedEntity(productId);
621
 
622
			context.put("expentity", expEntity);
623
			htmlString = getHtmlFromVelocity(templateFile, context);
624
			} catch (Exception e) {
625
				e.printStackTrace();
626
			}
627
		return htmlString;
628
	}
629
 
630
 
631
	public CategoryPage getCategoryPage(long categoryId,
632
			Map<String, String> params){
633
		// TODO Auto-generated method stub
634
 
635
		CategoryPage category = null;
636
 
637
		try {
638
			//set velocity properties
639
			Velocity.init("velocity/velocity.properties");
640
			VelocityContext context = new VelocityContext();
641
 
642
			String templateFile = "velocity/category.vm";
643
 
644
			Template template = null;
645
 
646
			// For an category
647
			DefinitionsContainer defsContainer = 	Catalog.getInstance().getDefinitionsContainer();
648
 
649
			ExpandedCategory expCategory = defsContainer.getExpandedCategory(categoryId);
650
 
651
			//Utils.logger.info("expCategory=" + expCategory);
652
 
653
			context.put("expcategory", expCategory);
654
			template = Velocity.getTemplate(templateFile);
655
 
656
			if(template != null) {
657
				StringWriter writer = new StringWriter();
658
 
659
				template.merge(context, writer);
660
				writer.flush();
661
				writer.close();
662
 
663
				//Put in the product object
664
				Map<String,String> htmlSnippet = new HashMap<String, String>();
665
				htmlSnippet.put("MAIN", writer.toString());
666
 
667
				category = new CategoryPage();
668
				category.setCategoryId(categoryId);
669
				category.setParams(params);
670
				category.setHtmlSnippet(htmlSnippet);
671
 
672
				Utils.info("Snippet generated");
673
			}
674
		} catch (ResourceNotFoundException e) {
675
			// TODO Auto-generated catch block
676
			e.printStackTrace();
677
		} catch (ParseErrorException e) {
678
			// TODO Auto-generated catch block
679
			e.printStackTrace();
680
		} catch (MethodInvocationException e) {
681
			// TODO Auto-generated catch block
682
			e.printStackTrace();
683
		} catch (Exception e) {
684
			// TODO Auto-generated catch block
685
			e.printStackTrace();
686
		}
687
 
688
		return category;
689
	}
690
 
691
	private	String getPriceDiv(long productId){
692
		CatalogServiceClient catalogServiceClient = null;
693
		Client client = null;
694
 
555 chandransh 695
		UserContextServiceClient userServiceClient = null;
696
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
507 rajveer 697
		try {
698
			catalogServiceClient = new CatalogServiceClient();
699
			client = catalogServiceClient.getClient();
700
 
555 chandransh 701
			userServiceClient = new UserContextServiceClient();
702
			userClient = userServiceClient.getClient();
507 rajveer 703
 
555 chandransh 704
			RatingsWidget ratingsWidget = userClient.getRatings(productId, 0);
507 rajveer 705
			Map<RatingType,Double> ratings = ratingsWidget.getRatings();
706
			//double rating_amazon = ratings.get(RatingType.AMAZON);
707
			double rating_all  = 0.0;
708
			if(ratings != null){
709
				if( ratings.get(RatingType.USER_ALL) != null){
710
					rating_all = ratings.get(RatingType.USER_ALL);
711
				}
712
			}
713
 
714
			rating_all = Math.round(rating_all);
715
 
716
 
717
			Item item = client.getItemByCatalogId(productId);
718
			Double itemPrice = item.getSellingPrice();
719
 
720
			//set velocity properties
721
			Velocity.init("velocity/velocity.properties");
722
			VelocityContext context = new VelocityContext();
723
 
724
			String templateFile = "velocity/pricediv.vm";
725
 
726
			Template template = null;
727
 
728
			// For an entity
729
			EntityContainer entContainer = 	Catalog.getInstance().getEntityContainer();
730
 
731
			ExpandedEntity expEntity = entContainer.getExpandedEntity(productId);
732
 
733
			//Utils.logger.info("expEntity=" + expEntity);
734
 
735
			String title = expEntity.getBrand() + "" + expEntity.getModelName();
736
			String categoryName = expEntity.getCategory().getLabel();
737
 
738
			Map<String,String> params = new HashMap<String, String>();
739
			params.put("TITLE", title);
740
			params.put("CATEGORY", categoryName);
741
			params.put("PRICE", itemPrice.toString());
742
			params.put("RATING_ALL", rating_all+"");
743
			params.put("PRODUCT_ID", productId+"");
744
 
745
			context.put("params", params);
746
			template = Velocity.getTemplate(templateFile);
747
 
748
			if(template != null) {
749
				StringWriter writer = new StringWriter();
750
 
751
				template.merge(context, writer);
752
				writer.flush();
753
				writer.close();
754
 
755
				System.out.println("PRICE DIV Snippet generated");
756
 
757
				return writer.toString();
758
 
759
			}
760
		} catch (ResourceNotFoundException e) {
761
			// TODO Auto-generated catch block
762
			e.printStackTrace();
763
		} catch (ParseErrorException e) {
764
			// TODO Auto-generated catch block
765
			e.printStackTrace();
766
		} catch (MethodInvocationException e) {
767
			// TODO Auto-generated catch block
768
			e.printStackTrace();
769
		} catch (InventoryServiceException e) {
770
			// TODO Auto-generated catch block
771
			e.printStackTrace();
772
		} catch (TException e) {
773
			// TODO Auto-generated catch block
774
			e.printStackTrace();
775
		} catch (IOException e) {
776
			// TODO Auto-generated catch block
777
			e.printStackTrace();
778
		} catch (Exception e) {
779
			// TODO Auto-generated catch block
780
			e.printStackTrace();
781
		}
782
 
783
		return "Price";
784
	}
785
 
786
	private	String getWidgetDiv(long productId, String userId, WidgetType widgetType, String velocityFileName, Boolean tobeusedLater){
555 chandransh 787
		UserContextServiceClient userServiceClient = null;
788
		in.shop2020.model.v1.user.UserContextService.Client client = null;
507 rajveer 789
 
790
		try {
555 chandransh 791
			userServiceClient = new UserContextServiceClient();
792
			client = userServiceClient.getClient();
507 rajveer 793
			long userID;
794
			if(userId.compareTo("") == 0){
795
				userID = 0;
796
			}else{
797
				userID = Long.parseLong(userId);
798
			}
799
			Widget widget = client.getWidget(widgetType, userID, true);
800
 
801
			Utils.logger.info("widget" + widget);
802
 
803
			List<WidgetItem> items = widget.getItems();
804
 
805
			List<Map<String, String>> itemDetails = new ArrayList<Map<String, String>>();
806
 
807
			for(WidgetItem item: items){
808
				Map<String, String> itemDetail = new HashMap<String, String>();
809
				itemDetail.put("ITEM_ID", item.getItem_id()+"");
810
				itemDetail.put("ITEM_SNIPPET", getItemSnippet(item.getItem_id()));
811
				itemDetails.add(itemDetail);
812
			}
813
 
814
 
815
			Velocity.init("velocity/velocity.properties");
816
			VelocityContext context = new VelocityContext();
817
			String templateFile = "velocity/"+velocityFileName.trim();
818
			Template template = null;
819
 
820
 
821
 
822
			context.put("itemDetails", itemDetails);
823
			template = Velocity.getTemplate(templateFile);
824
 
825
			if(template != null) {
826
				StringWriter writer = new StringWriter();
827
				template.merge(context, writer);
828
				writer.flush();
829
				writer.close();
830
 
831
				System.out.println("WIDGET DIV Snippet generated");
832
				return writer.toString();
833
				}
834
		} catch (ResourceNotFoundException e) {
835
			// TODO Auto-generated catch block
836
			e.printStackTrace();
837
		} catch (ParseErrorException e) {
838
			// TODO Auto-generated catch block
839
			e.printStackTrace();
840
		} catch (MethodInvocationException e) {
841
			// TODO Auto-generated catch block
842
			e.printStackTrace();
843
		} catch (IOException e) {
844
			// TODO Auto-generated catch block
845
			e.printStackTrace();
846
		} catch (Exception e) {
847
			// TODO Auto-generated catch block
848
			e.printStackTrace();
849
		}
850
		return "Widget";
851
	}
852
 
853
	private String getItemSnippet(long productId){
517 rajveer 854
			String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "WidgetSnippet.html";
507 rajveer 855
			try {
856
				return FileUtils.read(filename);
857
			} catch (Exception e) {
858
				// TODO Auto-generated catch block
859
				e.printStackTrace();
860
			}
861
			return "";
862
		}
863
 
864
 
865
 
555 chandransh 866
	private	String getWidgetDiv(long userId, WidgetType widgetType, String templateFile){
507 rajveer 867
 
555 chandransh 868
		UserContextServiceClient userServiceClient = null;
869
		in.shop2020.model.v1.user.UserContextService.Client client = null;
507 rajveer 870
		Widget widget = null;
871
		try {
555 chandransh 872
			userServiceClient = new UserContextServiceClient();
873
			client = userServiceClient.getClient();
874
			widget = client.getWidget(widgetType, userId, true);
507 rajveer 875
		} catch (Exception e) {
876
			e.printStackTrace();
877
		}
878
 
879
 
880
		List<Map<String, String>> itemDetails = null;
881
 
882
		if(widget != null){
883
			List<WidgetItem> items = widget.getItems();
884
			itemDetails = new ArrayList<Map<String, String>>();
885
 
886
			for(WidgetItem item: items){
887
				Map<String, String> itemDetail = new HashMap<String, String>();
888
 
889
				itemDetail.put("ITEM_ID", item.getItem_id()+"");
890
				try {
517 rajveer 891
					itemDetail.put("ITEM_SNIPPET", FileUtils.read( Utils.EXPORT_ENTITIES_PATH + item.getItem_id() + File.separator + "WidgetSnippet.html"));
507 rajveer 892
				} catch (Exception e) {
893
					// TODO Auto-generated catch block
894
					e.printStackTrace();
895
				}
896
				itemDetails.add(itemDetail);
897
			}
898
		}else{
899
			System.out.println("widget not found");
900
		}
901
 
902
		VelocityContext context = new VelocityContext();
620 rajveer 903
		context.put("userId", userId);
507 rajveer 904
		context.put("itemDetails", itemDetails);
905
 
906
		return getHtmlFromVelocity("templates/"+templateFile, context);
907
	}
908
 
909
	/*
910
	private	String getWidgetDiv(long productId, String userId, WidgetType widgetType, String templateFile){
911
		long userID;
912
		if(userId.compareTo("") == 0){
913
			userID = 0;
914
		}else{
915
			userID = Long.parseLong(userId);
916
		}
917
 
918
		WidgetServiceClient widgetServiceClient = null;
919
		in.shop2020.model.v1.widgets.WidgetService.Client client = null;
920
		Widget widget = null;
921
		try {
922
			widgetServiceClient = new WidgetServiceClient();
923
			client = widgetServiceClient.getClient();
924
			widget = client.getWidget(widgetType, userID, true);
925
		} catch (Exception e) {
926
			e.printStackTrace();
927
		}
928
 
929
 
930
		List<Map<String, String>> itemDetails = null;
931
 
932
		if(widget != null){
933
			List<WidgetItem> items = widget.getItems();
934
			itemDetails = new ArrayList<Map<String, String>>();
935
 
936
			for(WidgetItem item: items){
937
				Map<String, String> itemDetail = new HashMap<String, String>();
938
 
939
				itemDetail.put("ITEM_ID", item.getItem_id()+"");
940
				itemDetail.put("ITEM_NAME", "ID"+item.getItem_id());
941
				itemDetail.put("ITEM_SNIPPET", item.getSnippet());
942
				itemDetail.put("ITEM_PRICE", getItemPriceByCatalogId(item.getItem_id())+"");
943
				itemDetails.add(itemDetail);
944
			}
945
		}else{
946
			System.out.println("widget not found");
947
		}
948
 
949
		VelocityContext context = new VelocityContext();
950
		context.put("itemDetails", itemDetails);
951
 
952
		return getHtmlFromVelocity("velocity/"+templateFile, context);
953
	}
954
*/
955
 
956
 
957
	public Map<String, String> getCompletedOrdersPage(long userId, long itemCount,
958
			Map<String, String> params) {
959
		Map<String,String> htmlSnippet = new HashMap<String, String>();
555 chandransh 960
 
961
		htmlSnippet.put("HEADER", getHeaderHtml(false, ""));
507 rajveer 962
		System.out.println("HEADER Snippet generated");
963
 
964
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
965
		System.out.println("MAIN_MENU Snippet generated");
966
 
967
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
968
		System.out.println("SEARCH_BAR Snippet generated");
969
 
970
		htmlSnippet.put("MYACCOUNT_HEADER", getMyaccountHeaderHtml());
971
		System.out.println("MYACCOUNT_HEADER Snippet generated");
972
 
973
		htmlSnippet.put("MYACCOUNT_DETAILS", getCompletedOrdersHtml(userId));
974
		System.out.println("MYACCOUNT_DETAILS Snippet generated");
975
 
976
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
977
		System.out.println("CUSTOMER_SERVICE Snippet generated");
978
 
979
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, false));
980
		System.out.println("MY_RESEARCH Snippet generated");
620 rajveer 981
 
982
		htmlSnippet.put("BROWSE_HISTORY", getBrowseHistoryHtml(userId, false));
983
		System.out.println("BROWSE_HISTORY Snippet generated");
984
 
507 rajveer 985
		htmlSnippet.put("FOOTER", getFooterHtml());
986
		System.out.println("Footer Snippet generated");
987
 
988
		htmlSnippet.put("JS_FILES", "");
989
		htmlSnippet.put("CSS_FILES", "");
990
 
991
		System.out.println("Returning Generated Responce");
992
 
993
 
994
		return htmlSnippet;
995
 
996
	}
997
 
998
 
555 chandransh 999
	public Map<String, String> getMyAccountPage(long userId, long itemCount, String userName, boolean isLoggedIn)
1000
	{
1001
 
507 rajveer 1002
		Map<String,String> htmlSnippet = new HashMap<String, String>();
555 chandransh 1003
 
1004
		htmlSnippet.put("HEADER", getHeaderHtml(isLoggedIn, userName));
507 rajveer 1005
		System.out.println("HEADER Snippet generated");
1006
 
1007
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
1008
		System.out.println("MAIN_MENU Snippet generated");
1009
 
1010
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
1011
		System.out.println("SEARCH_BAR Snippet generated");
1012
 
1013
		htmlSnippet.put("MYACCOUNT_HEADER", getMyaccountHeaderHtml());
1014
		System.out.println("MYACCOUNT_HEADER Snippet generated");
1015
 
1016
		htmlSnippet.put("MYACCOUNT_DETAILS", getMyaccountDetailsHtml(userId));
1017
		System.out.println("MYACCOUNT_DETAILS Snippet generated");
1018
 
1019
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
1020
		System.out.println("CUSTOMER_SERVICE Snippet generated");
1021
 
1022
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, false));
1023
		System.out.println("MY_RESEARCH Snippet generated");
620 rajveer 1024
 
1025
		htmlSnippet.put("BROWSE_HISTORY", getBrowseHistoryHtml(userId, false));
1026
		System.out.println("BROWSE_HISTORY Snippet generated");
507 rajveer 1027
 
1028
		htmlSnippet.put("FOOTER", getFooterHtml());
1029
		System.out.println("Footer Snippet generated");
1030
 
1031
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1032
	//	System.out.println("ACCESSORIES Snippet generated")
1033
 
1034
		htmlSnippet.put("JS_FILES", "");
1035
		htmlSnippet.put("CSS_FILES", "");
1036
 
1037
		System.out.println("Returning Generated Responce");
555 chandransh 1038
 
507 rajveer 1039
		return htmlSnippet;
1040
	}
1041
 
1042
 
555 chandransh 1043
	public Map<String, String> getPersonalDetailsPage(long userId, long itemCount, String userName, boolean isLoggedIn)
1044
	{
507 rajveer 1045
		Map<String,String> htmlSnippet = new HashMap<String, String>();
555 chandransh 1046
 
1047
		htmlSnippet.put("HEADER", getHeaderHtml(isLoggedIn, userName));
507 rajveer 1048
		System.out.println("HEADER Snippet generated");
1049
 
1050
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
1051
		System.out.println("MAIN_MENU Snippet generated");
1052
 
1053
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
1054
		System.out.println("SEARCH_BAR Snippet generated");
1055
 
1056
		htmlSnippet.put("MYACCOUNT_HEADER", getMyaccountHeaderHtml());
1057
		System.out.println("MYACCOUNT_HEADER Snippet generated");
1058
 
1059
		htmlSnippet.put("PERSONAL_DETAILS", getPersonalDetailsHtml(userId));
1060
		System.out.println("PERSONAL_DETAILS Snippet generated");
1061
 
1062
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
1063
		System.out.println("CUSTOMER_SERVICE Snippet generated");
1064
 
1065
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, false));
1066
		System.out.println("MY_RESEARCH Snippet generated");
1067
 
620 rajveer 1068
		htmlSnippet.put("BROWSE_HISTORY", getBrowseHistoryHtml(userId, false));
1069
		System.out.println("BROWSE_HISTORY Snippet generated");
1070
 
507 rajveer 1071
		htmlSnippet.put("FOOTER", getFooterHtml());
1072
		System.out.println("Footer Snippet generated");
1073
 
1074
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1075
	//	System.out.println("ACCESSORIES Snippet generated")
1076
 
1077
		htmlSnippet.put("JS_FILES", "");
1078
		htmlSnippet.put("CSS_FILES", "");
1079
 
1080
		System.out.println("Returning Generated Responce");
1081
 
1082
 
1083
		return htmlSnippet;
1084
	}
1085
 
555 chandransh 1086
	public Map<String, String> getLoginDetailsPage(long userId, long itemCount, String userName, boolean isLoggedIn)
1087
	{
507 rajveer 1088
		Map<String,String> htmlSnippet = new HashMap<String, String>();
555 chandransh 1089
 
1090
		htmlSnippet.put("HEADER", getHeaderHtml(isLoggedIn, userName));
507 rajveer 1091
		System.out.println("HEADER Snippet generated");
1092
 
1093
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
1094
		System.out.println("MAIN_MENU Snippet generated");
1095
 
1096
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
1097
		System.out.println("SEARCH_BAR Snippet generated");
1098
 
1099
		htmlSnippet.put("MYACCOUNT_HEADER", getMyaccountHeaderHtml());
1100
		System.out.println("MYACCOUNT_HEADER Snippet generated");
1101
 
1102
		htmlSnippet.put("LOGIN_DETAILS", getLoginDetailsHtml(userId));
1103
		System.out.println("LOGIN_DETAILS Snippet generated");
1104
 
1105
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
1106
		System.out.println("CUSTOMER_SERVICE Snippet generated");
1107
 
1108
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, false));
1109
		System.out.println("MY_RESEARCH Snippet generated");
1110
 
620 rajveer 1111
		htmlSnippet.put("BROWSE_HISTORY", getBrowseHistoryHtml(userId, false));
1112
		System.out.println("BROWSE_HISTORY Snippet generated");
1113
 
507 rajveer 1114
		htmlSnippet.put("FOOTER", getFooterHtml());
1115
		System.out.println("Footer Snippet generated");
1116
 
1117
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1118
	//	System.out.println("ACCESSORIES Snippet generated")
1119
 
1120
		htmlSnippet.put("JS_FILES", "");
1121
		htmlSnippet.put("CSS_FILES", "");
1122
 
1123
		System.out.println("Returning Generated Responce");
1124
 
1125
 
1126
		return htmlSnippet;
1127
	}
1128
 
1129
 
1130
 
1131
	public Map<String, String> getOrderDetailsPage(long userId, long itemCount, long orderId,
555 chandransh 1132
			Map<String, String> parameters) {
507 rajveer 1133
		Map<String,String> htmlSnippet = new HashMap<String, String>();
555 chandransh 1134
		boolean isLoggedIn = Boolean.parseBoolean(parameters.get("IS_LOGGED_IN"));
1135
		String userName = parameters.get("USER_NAME");
1136
 
1137
		htmlSnippet.put("HEADER", getHeaderHtml(isLoggedIn, userName));
507 rajveer 1138
		System.out.println("HEADER Snippet generated");
1139
 
1140
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
1141
		System.out.println("MAIN_MENU Snippet generated");
1142
 
1143
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
1144
		System.out.println("SEARCH_BAR Snippet generated");
1145
 
1146
		htmlSnippet.put("MYACCOUNT_HEADER", getMyaccountHeaderHtml());
1147
		System.out.println("MYACCOUNT_HEADER Snippet generated");
1148
 
1149
		htmlSnippet.put("ORDER_DETAILS", getOrderDetailsHtml(orderId));
1150
		System.out.println("MYACCOUNT_DETAILS Snippet generated");
1151
 
1152
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
1153
		System.out.println("CUSTOMER_SERVICE Snippet generated");
1154
 
1155
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, false));
1156
		System.out.println("MY_RESEARCH Snippet generated");
1157
 
620 rajveer 1158
		htmlSnippet.put("BROWSE_HISTORY", getBrowseHistoryHtml(userId, false));
1159
		System.out.println("BROWSE_HISTORY Snippet generated");
1160
 
507 rajveer 1161
		htmlSnippet.put("FOOTER", getFooterHtml());
1162
		System.out.println("Footer Snippet generated");
1163
 
1164
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1165
	//	System.out.println("ACCESSORIES Snippet generated")
1166
 
1167
		htmlSnippet.put("JS_FILES", "");
1168
		htmlSnippet.put("CSS_FILES", "");
1169
 
1170
		System.out.println("Returning Generated Responce");
1171
 
1172
 
1173
		return htmlSnippet;
1174
	}
1175
 
1176
 
1177
 
1178
	private String getOrderDetailsHtml(long orderId) {
1179
		String htmlString = "";
1180
		VelocityContext context = new VelocityContext();
1181
		String templateFile = "templates/orderdetails.vm";
1182
		TransactionServiceClient transactionServiceClient = null;
1183
		in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
1184
		Order order = null;
517 rajveer 1185
		Date orderedOn = null, deliveryEstimate = null;
507 rajveer 1186
		try{
1187
			transactionServiceClient = new TransactionServiceClient();
1188
			orderClient = transactionServiceClient.getClient();
1189
			order = orderClient.getOrder(orderId);
517 rajveer 1190
			orderedOn = new Date(order.getCreated_timestamp());
1191
			deliveryEstimate = new Date(order.getExpected_delivery_time());
507 rajveer 1192
		}catch (Exception e){
1193
 
1194
		}
517 rajveer 1195
 
1196
		SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
583 rajveer 1197
		SimpleDateFormat dateformat1 = new SimpleDateFormat("dd/MM/yyyy");
507 rajveer 1198
		context.put("order", order);
517 rajveer 1199
		context.put("orderedOn", dateformat.format(orderedOn));
583 rajveer 1200
		context.put("deliveryEstimate", dateformat1.format(deliveryEstimate));
517 rajveer 1201
 
1202
 
507 rajveer 1203
		htmlString = getHtmlFromVelocity(templateFile, context);
1204
		return htmlString;
1205
	}
1206
 
1207
	private String getMyaccountDetailsHtml(long userId) {
1208
		String htmlString = "";
1209
		VelocityContext context = new VelocityContext();
1210
		String templateFile = "templates/myaccount.vm";
1211
		TransactionServiceClient transactionServiceClient = null;
1212
		in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
1213
		List<Order> orders = null;
1214
		try{
1215
			transactionServiceClient = new TransactionServiceClient();
1216
			orderClient = transactionServiceClient.getClient();
1217
			orders = orderClient.getOrdersForCustomer(userId, 0, (new Date()).getTime(), null);
1218
 
1219
		}catch (Exception e){
1220
 
1221
		}
1222
		context.put("orders", orders);
1223
		htmlString = getHtmlFromVelocity(templateFile, context);
1224
		return htmlString;
1225
	}
1226
 
1227
 
1228
	private String getLoginDetailsHtml(long userId) {
1229
		String htmlString = "";
1230
		VelocityContext context = new VelocityContext();
1231
		String templateFile = "templates/logindetails.vm";
1232
		String email = "";
1233
		UserContextServiceClient userContextServiceClient = null;
1234
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
1235
 
1236
		try{
1237
			userContextServiceClient = new UserContextServiceClient();
1238
			userClient = userContextServiceClient.getClient();
555 chandransh 1239
			email = in.shop2020.serving.utils.Utils.getEmailId(userId);
507 rajveer 1240
		}catch (Exception e){
1241
 
1242
		}
1243
		context.put("email", email);
1244
		htmlString = getHtmlFromVelocity(templateFile, context);
1245
		return htmlString;
1246
	}
1247
 
595 rajveer 1248
	public String getPersonalDetailsHtml(long userId) {
507 rajveer 1249
		String htmlString = "";
1250
		VelocityContext context = new VelocityContext();
1251
		String templateFile = "templates/personaldetails.vm";
1252
		String email = "";
517 rajveer 1253
		String name = "";
569 rajveer 1254
		String dateOfBirth = "";
517 rajveer 1255
		String sex = "";
1256
		String subscribe = "false";
507 rajveer 1257
		UserContextServiceClient userContextServiceClient = null;
1258
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
1259
		try{
555 chandransh 1260
			User user = null;
507 rajveer 1261
			userContextServiceClient = new UserContextServiceClient();
1262
			userClient = userContextServiceClient.getClient();
555 chandransh 1263
			user = userClient.getUserById(userId);
507 rajveer 1264
 
555 chandransh 1265
			email = user.getCommunicationEmail();
1266
			name = user.getName();
517 rajveer 1267
 
569 rajveer 1268
			dateOfBirth = user.getDateOfBirth();
507 rajveer 1269
		}catch (Exception e){
555 chandransh 1270
			e.printStackTrace();
507 rajveer 1271
		}
517 rajveer 1272
		context.put("name", name);
1273
		context.put("email", email);
569 rajveer 1274
		context.put("dateOfBirth", dateOfBirth+"");
517 rajveer 1275
		context.put("subscribe", subscribe);
1276
		context.put("sex", sex);
507 rajveer 1277
		htmlString = getHtmlFromVelocity(templateFile, context);
1278
		return htmlString;
1279
	}
1280
 
620 rajveer 1281
	public String getCompletedOrdersHtml(long userId) {
507 rajveer 1282
		String htmlString = "";
1283
		VelocityContext context = new VelocityContext();
1284
		String templateFile = "templates/completedorders.vm";
1285
		TransactionServiceClient transactionServiceClient = null;
1286
		in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
1287
		List<Order> orders = null;
1288
		try{
1289
			transactionServiceClient = new TransactionServiceClient();
1290
			orderClient = transactionServiceClient.getClient();
1291
			orders = orderClient.getOrdersForCustomer(userId, 0, (new Date()).getTime(), OrderStatus.DELIVERY_SUCCESS);
1292
 
1293
		}catch (Exception e){
1294
 
1295
		}
1296
		context.put("orders", orders);
1297
		htmlString = getHtmlFromVelocity(templateFile, context);
1298
		return htmlString;
1299
	}
595 rajveer 1300
	public String getMyaccountHeaderHtml() {
507 rajveer 1301
		String htmlString = "";
1302
		VelocityContext context = new VelocityContext();
1303
		String templateFile = "templates/myaccountheader.vm";
1304
		htmlString = getHtmlFromVelocity(templateFile, context);
1305
		return htmlString;
1306
	}
1307
 
1308
	//ShippingPage
572 chandransh 1309
	public Map<String, String> getShippingPage(long userId, boolean isLoggedIn, long cartId, long itemCount, String userName, String errorMsg){
507 rajveer 1310
		Map<String,String> htmlSnippet = new HashMap<String, String>();
555 chandransh 1311
 
1312
		htmlSnippet.put("HEADER", getHeaderHtml(isLoggedIn, userName));
507 rajveer 1313
		System.out.println("HEADER Snippet generated");
1314
 
1315
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
1316
		System.out.println("MAIN_MENU Snippet generated");
1317
 
1318
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
1319
		System.out.println("SEARCH_BAR Snippet generated");
1320
 
1321
		htmlSnippet.put("SHIPPING_HEADER", getShippingHeaderHtml());
1322
		System.out.println("SHIPPING_HEADER Snippet generated");
1323
 
572 chandransh 1324
		htmlSnippet.put("SHIPPING_DETAILS", getShippingDetailsHtml(cartId, errorMsg));
507 rajveer 1325
		System.out.println("SHIPPING_BAR Snippet generated");
1326
 
1327
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
1328
		System.out.println("CUSTOMER_SERVICE Snippet generated");
1329
 
1330
		htmlSnippet.put("FOOTER", getFooterHtml());
1331
		System.out.println("Footer Snippet generated");
1332
 
1333
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1334
	//	System.out.println("ACCESSORIES Snippet generated")
1335
 
1336
		htmlSnippet.put("JS_FILES", "");
1337
		htmlSnippet.put("CSS_FILES", "");
1338
 
1339
		System.out.println("Returning Generated Responce");
1340
 
1341
		return htmlSnippet;
1342
 
1343
	}
1344
 
1345
	//ShippingPage
555 chandransh 1346
	public Map<String, String> getShippingAddressPage(long userId, boolean isLoggedIn, long cartId, long itemCount, String userName){
507 rajveer 1347
		Map<String,String> htmlSnippet = new HashMap<String, String>();
555 chandransh 1348
 
1349
		htmlSnippet.put("HEADER", getHeaderHtml(isLoggedIn, userName));
507 rajveer 1350
		System.out.println("HEADER Snippet generated");
1351
 
1352
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
1353
		System.out.println("MAIN_MENU Snippet generated");
1354
 
1355
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
1356
		System.out.println("SEARCH_BAR Snippet generated");
1357
 
1358
		htmlSnippet.put("SHIPPING_ADDRESS_HEADER", getMyaccountHeaderHtml());
1359
		System.out.println("SHIPPING_ADDRESS_HEADER Snippet generated");
1360
 
1361
		htmlSnippet.put("SHIPPING_ADDRESS_DETAILS", getShippingAddressDetailsHtml(userId));
1362
		System.out.println("SHIPPING_ADDRESS_BAR Snippet generated");
1363
 
1364
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
1365
		System.out.println("CUSTOMER_SERVICE Snippet generated");
1366
 
1367
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, false));
1368
		System.out.println("MY_RESEARCH Snippet generated");
1369
 
620 rajveer 1370
		htmlSnippet.put("BROWSE_HISTORY", getBrowseHistoryHtml(userId, isLoggedIn));
1371
		System.out.println("BROWSE_HISTORY Snippet generated");
1372
 
507 rajveer 1373
		htmlSnippet.put("FOOTER", getFooterHtml());
1374
		System.out.println("Footer Snippet generated");
1375
 
1376
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1377
	//	System.out.println("ACCESSORIES Snippet generated")
1378
 
1379
		htmlSnippet.put("JS_FILES", "");
1380
		htmlSnippet.put("CSS_FILES", "");
1381
 
1382
		System.out.println("Returning Generated Responce");
1383
 
1384
		return htmlSnippet;
1385
 
1386
	}
1387
 
1388
	private String getShippingHeaderHtml() {
1389
		String htmlString = "";
1390
		VelocityContext context = new VelocityContext();
1391
		String templateFile = "templates/shippingheader.vm";
1392
		htmlString = getHtmlFromVelocity(templateFile, context);
1393
		return htmlString;
1394
	}
1395
 
1396
	private String getShippingAddressDetailsHtml(long userId){
1397
		String htmlString = "";
1398
		VelocityContext context = new VelocityContext();
1399
		String templateFile = "templates/shippingaddressdetails.vm";
1400
		long defaultAddressId = 0;
517 rajveer 1401
		List<Address> addresses = null;
507 rajveer 1402
 
1403
		UserContextServiceClient userContextServiceClient = null;
1404
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
1405
		try {
1406
			userContextServiceClient = new UserContextServiceClient();
1407
			userClient = userContextServiceClient.getClient();
620 rajveer 1408
 
1409
			addresses = userClient.getAllAddressesForUser(userId);
1410
			defaultAddressId = userClient.getDefaultAddressId(userId);
507 rajveer 1411
		} catch (Exception e) {
1412
			e.printStackTrace();
1413
		}
517 rajveer 1414
		context.put("defaultAddressId", defaultAddressId+"");
507 rajveer 1415
		context.put("addresses", addresses);
1416
 
1417
		htmlString = getHtmlFromVelocity(templateFile, context);
1418
		return htmlString;
1419
	}
1420
 
572 chandransh 1421
	private String getShippingDetailsHtml(long cartId, String errorMsg) {
507 rajveer 1422
		String htmlString = "";
1423
		VelocityContext context = new VelocityContext();
1424
		String templateFile = "templates/shippingdetails.vm";
517 rajveer 1425
		List<Map<String,String>> items = null;
507 rajveer 1426
		double totalamount= 0.0;
517 rajveer 1427
		List<Address> addresses = null;
1428
		long defaultAddressId = 0;
555 chandransh 1429
 
507 rajveer 1430
		CatalogServiceClient catalogServiceClient  = null;
1431
		in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = null;
1432
		UserContextServiceClient userContextServiceClient = null;
1433
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
1434
 
1435
		try {
1436
			catalogServiceClient = new CatalogServiceClient();
1437
			catalogClient = catalogServiceClient.getClient();
1438
			userContextServiceClient = new UserContextServiceClient();
1439
			userClient = userContextServiceClient.getClient();
1440
 
1441
 
555 chandransh 1442
			Cart cart = userClient.getCart(cartId);
507 rajveer 1443
			List<Line> lineItems = cart.getLines();
1444
 
517 rajveer 1445
			if( ! lineItems.isEmpty())
1446
			{
1447
				items = new ArrayList<Map<String,String>>();
507 rajveer 1448
 
517 rajveer 1449
				for (Line line : lineItems) {
1450
					Map<String, String> itemdetail = new HashMap<String, String>();
1451
					Item item = catalogClient.getItemByCatalogId(line.getItemId());
1452
					String itemName = ((item.getManufacturerName() != null) ? item.getManufacturerName() + " " : "")
1453
										+ ((item.getModelName() != null) ? item.getModelName() + " " : "") 
1454
										+ (( item.getModelNumber() != null ) ? item.getModelNumber() : "" );
1455
 
1456
					itemdetail.put("ITEM_NAME", itemName);
1457
					itemdetail.put("ITEM_ID", line.getItemId()+"");
1458
					itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
1459
					itemdetail.put("MRP", ((int)item.getMrp())+"");
536 rajveer 1460
					itemdetail.put("SELLING_PRICE", (int)item.getSellingPrice()+"");
1461
					itemdetail.put("TOTAL_PRICE", (int)(item.getSellingPrice()*line.getQuantity())+"");
615 chandransh 1462
					itemdetail.put("SHIPPING_TIME", line.getEstimate()+"");
536 rajveer 1463
					totalamount = totalamount + line.getQuantity()*item.getSellingPrice();
517 rajveer 1464
					items.add(itemdetail);				
1465
				}
507 rajveer 1466
			}
1467
 
555 chandransh 1468
			User user = userClient.getUserById(cart.getUserId());
1469
			addresses = user.getAddresses();
1470
			defaultAddressId = user.getDefaultAddressId();
507 rajveer 1471
 
1472
		}catch (Exception e){
1473
			e.printStackTrace();
1474
		}
1475
 
1476
		context.put("items", items);
536 rajveer 1477
		context.put("totalamount", (int)totalamount+"");
507 rajveer 1478
		context.put("addresses", addresses);
517 rajveer 1479
		context.put("defaultAddressId", defaultAddressId+"");
572 chandransh 1480
		context.put("errorMsg", errorMsg);
507 rajveer 1481
		htmlString = getHtmlFromVelocity(templateFile, context);
1482
		return htmlString;
1483
	}
1484
 
1485
 
1486
	//ShoppingCartPage
572 chandransh 1487
	public Map<String, String> getShoppingCartPage(long userId, boolean isLoggedIn, long cartId, long itemCount, String userName, String errorMsg){
507 rajveer 1488
		Map<String,String> htmlSnippet = new HashMap<String, String>();
555 chandransh 1489
 
1490
		htmlSnippet.put("HEADER", getHeaderHtml(isLoggedIn, userName));
507 rajveer 1491
		System.out.println("HEADER Snippet generated");
1492
 
1493
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
1494
		System.out.println("MAIN_MENU Snippet generated");
1495
 
1496
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
1497
		System.out.println("SEARCH_BAR Snippet generated");
1498
 
1499
		htmlSnippet.put("CART_HEADER", getCartHeaderHtml());
1500
		System.out.println("CART_HEADER Snippet generated");
1501
 
572 chandransh 1502
		htmlSnippet.put("CART_DETAILS", getCartDetailsHtml(cartId, errorMsg));
507 rajveer 1503
		System.out.println("SEARCH_BAR Snippet generated");
1504
 
1505
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
1506
		System.out.println("CUSTOMER_SERVICE Snippet generated");
1507
 
555 chandransh 1508
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, isLoggedIn));
507 rajveer 1509
		System.out.println("MY_RESEARCH Snippet generated");
1510
 
1511
		htmlSnippet.put("FOOTER", getFooterHtml());
1512
		System.out.println("Footer Snippet generated");
1513
 
1514
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1515
	//	System.out.println("ACCESSORIES Snippet generated")
1516
 
1517
		htmlSnippet.put("JS_FILES", "");
1518
		htmlSnippet.put("CSS_FILES", "");
1519
 
1520
		System.out.println("Returning Generated Responce");
1521
 
1522
		return htmlSnippet;
1523
 
1524
	}
1525
 
1526
	private String getCartHeaderHtml() {
1527
		String htmlString = "";
1528
		VelocityContext context = new VelocityContext();
1529
		String templateFile = "templates/cartheader.vm";
1530
		htmlString = getHtmlFromVelocity(templateFile, context);
1531
		return htmlString;
1532
	}
1533
 
1534
 
572 chandransh 1535
	private String getCartDetailsHtml(long cartId, String errorMsg) {
507 rajveer 1536
		String htmlString = "";
1537
		VelocityContext context = new VelocityContext();
1538
		String templateFile = "templates/cartdetails.vm";
517 rajveer 1539
		List<Map<String,String>> items = null;
507 rajveer 1540
		double totalamount= 0.0;
1541
 
555 chandransh 1542
		UserContextServiceClient userServiceClient = null;
1543
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
507 rajveer 1544
		CatalogServiceClient catalogServiceClient  = null;
1545
		in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = null;
1546
 
1547
		try {
1548
			catalogServiceClient = new CatalogServiceClient();
1549
			catalogClient = catalogServiceClient.getClient();
555 chandransh 1550
			userServiceClient = new UserContextServiceClient();
1551
			userClient = userServiceClient.getClient();
507 rajveer 1552
 
555 chandransh 1553
			Cart cart = userClient.getCart(cartId);
507 rajveer 1554
			List<Line> lineItems = cart.getLines();
517 rajveer 1555
			if(lineItems.size() != 0){
1556
				items = new ArrayList<Map<String,String>>();
1557
				for (Line line : lineItems) {
1558
 
1559
					Map<String, String> itemdetail = new HashMap<String, String>();
1560
					Item item = catalogClient.getItemByCatalogId(line.getItemId());
1561
 
1562
					String itemName = ((item.getManufacturerName() != null) ? item.getManufacturerName() + " " : "")
1563
										+ ((item.getModelName() != null) ? item.getModelName() + " " : "") 
1564
										+ (( item.getModelNumber() != null ) ? item.getModelNumber() : "" );
1565
 
1566
					itemdetail.put("ITEM_NAME", itemName);
1567
					System.out.println(itemdetail.get("ITEM_NAME"));
1568
					itemdetail.put("ITEM_ID", line.getItemId()+"");
1569
					itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
1570
					itemdetail.put("MRP", ((int)item.getMrp())+"");
1571
					itemdetail.put("SELLING_PRICE", ((int)item.getSellingPrice())+"");
1572
					itemdetail.put("TOTAL_PRICE", ((int)((item.getSellingPrice()*line.getQuantity())))+"");
615 chandransh 1573
					itemdetail.put("SHIPPING_TIME", line.getEstimate()+"");
517 rajveer 1574
					totalamount = totalamount + line.getQuantity()*item.getSellingPrice();
1575
					items.add(itemdetail);				
507 rajveer 1576
				}
1577
			}
1578
 
1579
		}catch (Exception e){
1580
			e.printStackTrace();
1581
		}
1582
 
1583
		context.put("items", items);
517 rajveer 1584
		context.put("totalamount", ((int)totalamount)+"");
572 chandransh 1585
		context.put("errorMsg", errorMsg);
507 rajveer 1586
		htmlString = getHtmlFromVelocity(templateFile, context);
1587
		return htmlString;
1588
	}
1589
 
1590
 
1591
	public Map<String, String> getShoppingCartPage_Old(long userId, boolean isSessionId, Map<String, String> params)
1592
	{
555 chandransh 1593
		UserContextServiceClient userServiceClient = null;
1594
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
507 rajveer 1595
 
1596
		try {
555 chandransh 1597
			userServiceClient = new UserContextServiceClient();
1598
			userClient = userServiceClient.getClient();
507 rajveer 1599
 
555 chandransh 1600
			Cart cart = userClient.getCurrentCart(userId);
507 rajveer 1601
 
1602
			List<Line> lineItems = cart.getLines();
1603
			List<Map<String,String>> items = new ArrayList<Map<String,String>>(); 
1604
 
1605
			for (Line line : lineItems) {
1606
//				long productId = getCatalogIdByItemId(line.getItemId());
1607
				long productId = line.getItemId();
1608
				Map<String, String> productDetails = getProductDetails(productId);
1609
				double mrp = getItemMrpByCatalogId(productId);
1610
				double sellingPrice = getItemSellingPriceByCatalogId(productId);
1611
				double saving = (mrp - sellingPrice)/mrp*100; 
1612
				saving = Math.round(saving);
1613
				Map<String, String> item = new HashMap<String, String>();
1614
				item.put("BRAND_NAME", productDetails.get("BRAND_NAME"));
1615
				item.put("MODEL_NAME", productDetails.get("MODEL_NAME"));
1616
				item.put("MODEL_NUMBER", productDetails.get("MODEL_NUMBER"));
1617
				item.put("ITEM_ID", line.getItemId()+"");
1618
				item.put("ITEM_QUANTITY", line.getQuantity()+"");
1619
				item.put("MRP", mrp+"");
1620
				item.put("SELLING_PRICE", sellingPrice+"");
1621
				item.put("SAVING", sellingPrice+"");
1622
				items.add(item);
1623
			}
1624
 
1625
			String templateFile = "templates/shoppingcart.vm";
1626
			VelocityContext context = new VelocityContext();	
1627
			context.put("items", items);
1628
 
1629
			String htmlString = getHtmlFromVelocity(templateFile, context);
1630
			System.out.println("My Cart Snippet generated" + htmlString);
1631
 
1632
			Map<String,String> htmlSnippet = new HashMap<String, String>();
1633
			htmlSnippet.put("SHOPPING_CART", htmlString);
1634
 
1635
			return htmlSnippet;
1636
 
1637
		} catch (ShoppingCartException e) {
1638
			// TODO Auto-generated catch block
1639
			e.printStackTrace();
1640
		}catch (Exception e) {
1641
			// TODO Auto-generated catch block
1642
			e.printStackTrace();
1643
		}
1644
 
1645
		return null;
1646
	}
1647
 
1648
 
1649
	public long getCatalogIdByItemId(long itemId){
1650
		CatalogServiceClient catalogServiceClient = null;
1651
		Client client = null;
1652
 
1653
		try {
1654
			catalogServiceClient = new CatalogServiceClient();
1655
			client = catalogServiceClient.getClient();
1656
 
1657
			return client.getItem(itemId).getCatalogItemId();
1658
		} catch (InventoryServiceException e) {
1659
			// TODO Auto-generated catch block
1660
			e.printStackTrace();
1661
		} catch (TException e) {
1662
			// TODO Auto-generated catch block
1663
			e.printStackTrace();
1664
		} catch (Exception e) {
1665
			// TODO Auto-generated catch block
1666
			e.printStackTrace();
1667
		}
1668
		return -1;
1669
	}
1670
 
1671
//	private	void addItemToCart(long catalogItemId, long userId) throws Exception{
1672
//		UserContextServiceClient userContextServiceClient = null;
1673
//		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
1674
//		userContextServiceClient = new UserContextServiceClient();
1675
//		userClient = userContextServiceClient.getClient();
1676
//
1677
//		ShoppingCartClient shoppingCartClient = null;
1678
//		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = null;
1679
//		shoppingCartClient = new ShoppingCartClient();
1680
//		cartClient = shoppingCartClient.getClient();
1681
//		
1682
//		Cart cart = cartClient.getCurrentCart(userId);
1683
//		//if user is logged in create  new cart
1684
//		//if( userClient.getState(userId, false).isIsLoggedIn()){
1685
//		if(cart == null){
1686
//			cartClient.createCart(userId);
1687
//			cart = cartClient.getCurrentCart(userId);
1688
//		}
1689
//		cartClient.addItemToCart(cart.getId(), catalogItemId, 1);
1690
//	}
1691
 
1692
		//userClient.getState(userId, isSessionId);
1693
 
1694
//		TransactionServiceClient transactionServiceClient = null;
1695
//		in.shop2020.model.v1.order.TransactionService.Client client = null;
1696
//		
1697
//		Cart cart = cartClient.getCurrentCart(userId);
555 chandransh 1698
//		List<LineItem> lineItems = cart.getLines();
507 rajveer 1699
//		
555 chandransh 1700
//		LineItem ln = lineItems.get(0);
507 rajveer 1701
//		ln.getItemId();
1702
//		ln.getId();
1703
//		ln.getQuantity();
1704
//		ln.getStatusMessage();
1705
//		long productId = 10;
1706
//		
1707
//		Cart cart = cartClient.getCurrentCart(0);
555 chandransh 1708
//		List<LineItem> lineItems = cart.getLines();
1709
//		LineItem ln = lineItems.get(0);
507 rajveer 1710
//		ln.getItemId();
1711
//		ln.getId();
1712
//		
1713
//		ln.getStatusMessage();
1714
//		
1715
 
1716
	private	Map<String,String> getProductDetails(long productId){
1717
		Map<String, String> productDetails = new HashMap<String, String>();
1718
 
1719
		EntityContainer entContainer = 	Catalog.getInstance().getEntityContainer();
1720
		ExpandedEntity expEntity;
1721
		try {
1722
			expEntity = entContainer.getExpandedEntity(productId);
1723
 
1724
			productDetails.put("BRAND_NAME", expEntity.getBrand());
1725
			productDetails.put("MODEL_NUMBER", expEntity.getModelNumber());
1726
			productDetails.put("MODEL_NAME", expEntity.getModelName());
1727
			productDetails.put("CATEGORY_ID", expEntity.getCategoryID() + "");
1728
			productDetails.put("CATEGORY_NAME", expEntity.getCategory().getLabel());
1729
			productDetails.put("INTRODUCTION_TEXT", expEntity.getSlide(130001).getFreeformContent().getFreeformText());
1730
			return productDetails;
1731
//			expEntity.getBrand();
1732
//			expEntity.getModelNumber();
1733
//			expEntity.getModelName();
1734
//			expEntity.getCategoryID();
1735
//			expEntity.getCategory().getLabel();
1736
//			expEntity.getSlide(130001).getFreeformContent().getFreeformText();
1737
		} catch (Exception e) {
1738
			// TODO Auto-generated catch block
1739
			e.printStackTrace();
1740
		}
1741
 
1742
		return null;
1743
	}
1744
 
1745
 
1746
	private	String getMyOrdersDiv(long userId){
1747
		TransactionServiceClient transactionServiceClient = null;
1748
		in.shop2020.model.v1.order.TransactionService.Client client = null;
1749
		String htmlString = new String();
1750
			try {
1751
				transactionServiceClient = new TransactionServiceClient();
1752
				client = transactionServiceClient.getClient();
1753
				List<Transaction> transactions = client.getTransactionsForCustomer(userId, 0, 0, null);
1754
 
1755
				String templateFile = "templates/myorders.vm";
1756
				VelocityContext context = new VelocityContext();	
1757
				context.put("transactions", transactions);
1758
				if(!transactions.isEmpty()){
1759
					Transaction tn = transactions.get(0);
1760
					java.sql.Date d = new java.sql.Date(tn.getCreatedOn());
1761
					System.out.println("Date is" + d.toString());
1762
				}
1763
				htmlString = getHtmlFromVelocity(templateFile, context);
1764
				System.out.println("Orders Info Snippet generated" + htmlString);
1765
				return htmlString;
1766
 
1767
			} catch (UserContextException e) {
1768
				// TODO Auto-generated catch block
1769
				e.printStackTrace();
1770
			} catch (Exception e) {
1771
				// TODO Auto-generated catch block
1772
				e.printStackTrace();
1773
			}
1774
			return "MY_ORDERS";
1775
	}
1776
 
1777
	public String getHtmlFromVelocity(String templateFile, VelocityContext context){
1778
		Properties p = new Properties();
1779
		p.setProperty("resource.loader", "class");
1780
		p.setProperty("class.resource.loader.class",
1781
		"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
1782
 
1783
 
1784
		try {
1785
			Velocity.init(p);
1786
			Template template = Velocity.getTemplate(templateFile);
1787
			if(template != null) {
1788
				StringWriter writer = new StringWriter();
1789
				template.merge(context, writer);
1790
				writer.flush();
1791
				writer.close();
1792
				return writer.toString();
1793
			}
1794
 
1795
			} catch (ResourceNotFoundException e) {
1796
				// TODO Auto-generated catch block
1797
				e.printStackTrace();
1798
			} catch (ParseErrorException e) {
1799
				// TODO Auto-generated catch block
1800
				e.printStackTrace();
1801
			} catch (MethodInvocationException e) {
1802
				// TODO Auto-generated catch block
1803
				e.printStackTrace();
1804
			} catch (IOException e) {
1805
				// TODO Auto-generated catch block
1806
				e.printStackTrace();
1807
			} catch (Exception e) {
1808
				// TODO Auto-generated catch block
1809
				e.printStackTrace();
1810
			}
1811
 
1812
		return null;
1813
	}
1814
 
1815
	public double getItemMrpByCatalogId(long productId){
1816
		CatalogServiceClient catalogServiceClient = null;
1817
		Client client = null;
1818
		Double itemPrice = 0.0;
1819
		try {
1820
			catalogServiceClient = new CatalogServiceClient();
1821
			client = catalogServiceClient.getClient();
1822
			Item item = client.getItemByCatalogId(productId);
1823
			itemPrice = item.getMrp();
1824
		}
1825
		catch(Exception e){
1826
			e.printStackTrace();
1827
		}
1828
		return itemPrice;
1829
	}
1830
 
1831
	public double getItemSellingPriceByCatalogId(long productId){
1832
		CatalogServiceClient catalogServiceClient = null;
1833
		Client client = null;
1834
		Double itemPrice = 0.0;
1835
		try {
1836
			catalogServiceClient = new CatalogServiceClient();
1837
			client = catalogServiceClient.getClient();
1838
			Item item = client.getItemByCatalogId(productId);
1839
			itemPrice = item.getSellingPrice();
1840
		}
1841
		catch(Exception e){
1842
			e.printStackTrace();
1843
		}
1844
		return itemPrice;
1845
	}
1846
 
517 rajveer 1847
 
1848
	public String getCategoryHeaderSnippet() {
1849
		String htmlString = "";
1850
		VelocityContext context = new VelocityContext();
1851
		String templateFile = "templates/categoryheader.vm";
1852
		htmlString = getHtmlFromVelocity(templateFile, context);
1853
		return htmlString;
1854
	}
1855
 
507 rajveer 1856
 
1857
 
1858
}
1859