Subversion Repositories SmartDukaan

Rev

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