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