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();
545 rajveer 281
			List<Long> items = client.getBestSellers(1, 20);
507 rajveer 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();
545 rajveer 309
			List<Long> items = client.getLatestArrivals(1,20);
507 rajveer 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();
545 rajveer 337
			List<Long> items = client.getBestDeals(1,20);
507 rajveer 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";
550 rajveer 594
 
595
		context.put("itemCount", itemCounts+"");
596
		context.put("categoryId", categoryId+"");
597
 
507 rajveer 598
		htmlString = getHtmlFromVelocity(templateFile, context);
599
		return htmlString;
600
	}
601
 
602
 
603
 
517 rajveer 604
	public String getHeaderHtml(long userId, boolean isSessionId, String  userName) {
507 rajveer 605
		String htmlString = "";
606
		Map<String,String> params = new HashMap<String, String>();
550 rajveer 607
		VelocityContext context = new VelocityContext();
507 rajveer 608
		if(isSessionId){
550 rajveer 609
			context.put("LOGGED_IN", "FALSE");
610
			context.put("WELCOME_MESSAGE", "Hi, Welcome to Shop2020");
507 rajveer 611
		}else
612
		{
550 rajveer 613
			context.put("LOGGED_IN", "TRUE");
614
			context.put("WELCOME_MESSAGE", "Hi, userName");
507 rajveer 615
		}
616
 
550 rajveer 617
 
507 rajveer 618
		String templateFile = "templates/header.vm";
550 rajveer 619
 
507 rajveer 620
		htmlString = getHtmlFromVelocity(templateFile, context);
621
		return htmlString;
622
	}
623
 
624
 
625
 
626
	public String getSlideGuideDIV(long productId){
627
		String htmlString = "";
628
		try {
629
			VelocityContext context = new VelocityContext();
630
			String templateFile = "templates/slideguide.vm";
631
			// For an entity
632
			EntityContainer entContainer = 	Catalog.getInstance().getEntityContainer();
633
			ExpandedEntity expEntity = entContainer.getExpandedEntity(productId);
634
 
635
			context.put("expentity", expEntity);
636
			htmlString = getHtmlFromVelocity(templateFile, context);
637
			} catch (Exception e) {
638
				e.printStackTrace();
639
			}
640
		return htmlString;
641
	}
642
 
643
 
644
	public CategoryPage getCategoryPage(long categoryId,
645
			Map<String, String> params){
646
		// TODO Auto-generated method stub
647
 
648
		CategoryPage category = null;
649
 
650
		try {
651
			//set velocity properties
652
			Velocity.init("velocity/velocity.properties");
653
			VelocityContext context = new VelocityContext();
654
 
655
			String templateFile = "velocity/category.vm";
656
 
657
			Template template = null;
658
 
659
			// For an category
660
			DefinitionsContainer defsContainer = 	Catalog.getInstance().getDefinitionsContainer();
661
 
662
			ExpandedCategory expCategory = defsContainer.getExpandedCategory(categoryId);
663
 
664
			//Utils.logger.info("expCategory=" + expCategory);
665
 
666
			context.put("expcategory", expCategory);
667
			template = Velocity.getTemplate(templateFile);
668
 
669
			if(template != null) {
670
				StringWriter writer = new StringWriter();
671
 
672
				template.merge(context, writer);
673
				writer.flush();
674
				writer.close();
675
 
676
				//Put in the product object
677
				Map<String,String> htmlSnippet = new HashMap<String, String>();
678
				htmlSnippet.put("MAIN", writer.toString());
679
 
680
				category = new CategoryPage();
681
				category.setCategoryId(categoryId);
682
				category.setParams(params);
683
				category.setHtmlSnippet(htmlSnippet);
684
 
685
				Utils.info("Snippet generated");
686
			}
687
		} catch (ResourceNotFoundException e) {
688
			// TODO Auto-generated catch block
689
			e.printStackTrace();
690
		} catch (ParseErrorException e) {
691
			// TODO Auto-generated catch block
692
			e.printStackTrace();
693
		} catch (MethodInvocationException e) {
694
			// TODO Auto-generated catch block
695
			e.printStackTrace();
696
		} catch (Exception e) {
697
			// TODO Auto-generated catch block
698
			e.printStackTrace();
699
		}
700
 
701
		return category;
702
	}
703
 
704
	private	String getPriceDiv(long productId){
705
		CatalogServiceClient catalogServiceClient = null;
706
		Client client = null;
707
		String htmlString = new String();
708
 
709
		WidgetServiceClient widgetServiceClient = null;
710
		in.shop2020.model.v1.widgets.WidgetService.Client widgetClient = null;
711
		try {
712
			catalogServiceClient = new CatalogServiceClient();
713
			client = catalogServiceClient.getClient();
714
 
715
			widgetServiceClient = new WidgetServiceClient();
716
			widgetClient = widgetServiceClient.getClient();
717
 
718
			RatingsWidget ratingsWidget = widgetClient.getRatings(productId, 0);
719
			Map<RatingType,Double> ratings = ratingsWidget.getRatings();
720
			//double rating_amazon = ratings.get(RatingType.AMAZON);
721
			double rating_all  = 0.0;
722
			if(ratings != null){
723
				if( ratings.get(RatingType.USER_ALL) != null){
724
					rating_all = ratings.get(RatingType.USER_ALL);
725
				}
726
			}
727
 
728
			rating_all = Math.round(rating_all);
729
 
730
 
731
			Item item = client.getItemByCatalogId(productId);
732
			Double itemPrice = item.getSellingPrice();
733
 
734
			//set velocity properties
735
			Velocity.init("velocity/velocity.properties");
736
			VelocityContext context = new VelocityContext();
737
 
738
			String templateFile = "velocity/pricediv.vm";
739
 
740
			Template template = null;
741
 
742
			// For an entity
743
			EntityContainer entContainer = 	Catalog.getInstance().getEntityContainer();
744
 
745
			ExpandedEntity expEntity = entContainer.getExpandedEntity(productId);
746
 
747
			//Utils.logger.info("expEntity=" + expEntity);
748
 
749
			String title = expEntity.getBrand() + "" + expEntity.getModelName();
750
			String categoryName = expEntity.getCategory().getLabel();
751
 
752
			Map<String,String> params = new HashMap<String, String>();
753
			params.put("TITLE", title);
754
			params.put("CATEGORY", categoryName);
755
			params.put("PRICE", itemPrice.toString());
756
			params.put("RATING_ALL", rating_all+"");
757
			params.put("PRODUCT_ID", productId+"");
758
 
759
			context.put("params", params);
760
			template = Velocity.getTemplate(templateFile);
761
 
762
			if(template != null) {
763
				StringWriter writer = new StringWriter();
764
 
765
				template.merge(context, writer);
766
				writer.flush();
767
				writer.close();
768
 
769
				System.out.println("PRICE DIV Snippet generated");
770
 
771
				return writer.toString();
772
 
773
			}
774
		} catch (ResourceNotFoundException e) {
775
			// TODO Auto-generated catch block
776
			e.printStackTrace();
777
		} catch (ParseErrorException e) {
778
			// TODO Auto-generated catch block
779
			e.printStackTrace();
780
		} catch (MethodInvocationException e) {
781
			// TODO Auto-generated catch block
782
			e.printStackTrace();
783
		} catch (InventoryServiceException e) {
784
			// TODO Auto-generated catch block
785
			e.printStackTrace();
786
		} catch (TException e) {
787
			// TODO Auto-generated catch block
788
			e.printStackTrace();
789
		} catch (IOException e) {
790
			// TODO Auto-generated catch block
791
			e.printStackTrace();
792
		} catch (Exception e) {
793
			// TODO Auto-generated catch block
794
			e.printStackTrace();
795
		}
796
 
797
		return "Price";
798
	}
799
 
800
	private	String getWidgetDiv(long productId, String userId, WidgetType widgetType, String velocityFileName, Boolean tobeusedLater){
801
		WidgetServiceClient widgetServiceClient = null;
802
		in.shop2020.model.v1.widgets.WidgetService.Client client = null;
803
 
804
		String htmlString = new String();
805
		try {
806
			widgetServiceClient = new WidgetServiceClient();
807
			client = widgetServiceClient.getClient();
808
			long userID;
809
			if(userId.compareTo("") == 0){
810
				userID = 0;
811
			}else{
812
				userID = Long.parseLong(userId);
813
			}
814
			Widget widget = client.getWidget(widgetType, userID, true);
815
 
816
			Utils.logger.info("widget" + widget);
817
 
818
			List<WidgetItem> items = widget.getItems();
819
 
820
			List<Map<String, String>> itemDetails = new ArrayList<Map<String, String>>();
821
 
822
			for(WidgetItem item: items){
823
				Map<String, String> itemDetail = new HashMap<String, String>();
824
				itemDetail.put("ITEM_ID", item.getItem_id()+"");
825
				itemDetail.put("ITEM_SNIPPET", getItemSnippet(item.getItem_id()));
826
				itemDetails.add(itemDetail);
827
			}
828
 
829
 
830
			Velocity.init("velocity/velocity.properties");
831
			VelocityContext context = new VelocityContext();
832
			String templateFile = "velocity/"+velocityFileName.trim();
833
			Template template = null;
834
 
835
 
836
 
837
			context.put("itemDetails", itemDetails);
838
			template = Velocity.getTemplate(templateFile);
839
 
840
			if(template != null) {
841
				StringWriter writer = new StringWriter();
842
				template.merge(context, writer);
843
				writer.flush();
844
				writer.close();
845
 
846
				System.out.println("WIDGET DIV Snippet generated");
847
				return writer.toString();
848
				}
849
		} catch (ResourceNotFoundException e) {
850
			// TODO Auto-generated catch block
851
			e.printStackTrace();
852
		} catch (ParseErrorException e) {
853
			// TODO Auto-generated catch block
854
			e.printStackTrace();
855
		} catch (MethodInvocationException e) {
856
			// TODO Auto-generated catch block
857
			e.printStackTrace();
858
		} catch (IOException e) {
859
			// TODO Auto-generated catch block
860
			e.printStackTrace();
861
		} catch (Exception e) {
862
			// TODO Auto-generated catch block
863
			e.printStackTrace();
864
		}
865
		return "Widget";
866
	}
867
 
868
	private String getItemSnippet(long productId){
869
			StringBuilder htmlString = new StringBuilder();
517 rajveer 870
			String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "WidgetSnippet.html";
507 rajveer 871
			try {
872
				return FileUtils.read(filename);
873
			} catch (Exception e) {
874
				// TODO Auto-generated catch block
875
				e.printStackTrace();
876
			}
877
			return "";
878
		}
879
 
880
 
881
 
882
	private	String getWidgetDiv(String userId, WidgetType widgetType, String templateFile){
883
		long userID;
884
		if(userId.compareTo("") == 0){
885
			userID = 0;
886
		}else{
887
			userID = Long.parseLong(userId);
888
		}
889
 
890
		WidgetServiceClient widgetServiceClient = null;
891
		in.shop2020.model.v1.widgets.WidgetService.Client client = null;
892
		Widget widget = null;
893
		try {
894
			widgetServiceClient = new WidgetServiceClient();
895
			client = widgetServiceClient.getClient();
896
			widget = client.getWidget(widgetType, userID, true);
897
		} catch (Exception e) {
898
			e.printStackTrace();
899
		}
900
 
901
 
902
		List<Map<String, String>> itemDetails = null;
903
 
904
		if(widget != null){
905
			List<WidgetItem> items = widget.getItems();
906
			itemDetails = new ArrayList<Map<String, String>>();
907
 
908
			for(WidgetItem item: items){
909
				Map<String, String> itemDetail = new HashMap<String, String>();
910
 
911
				itemDetail.put("ITEM_ID", item.getItem_id()+"");
912
				try {
517 rajveer 913
					itemDetail.put("ITEM_SNIPPET", FileUtils.read( Utils.EXPORT_ENTITIES_PATH + item.getItem_id() + File.separator + "WidgetSnippet.html"));
507 rajveer 914
				} catch (Exception e) {
915
					// TODO Auto-generated catch block
916
					e.printStackTrace();
917
				}
918
				itemDetails.add(itemDetail);
919
			}
920
		}else{
921
			System.out.println("widget not found");
922
		}
923
 
924
		VelocityContext context = new VelocityContext();
925
		context.put("itemDetails", itemDetails);
926
 
927
		return getHtmlFromVelocity("templates/"+templateFile, context);
928
	}
929
 
930
	/*
931
	private	String getWidgetDiv(long productId, String userId, WidgetType widgetType, String templateFile){
932
		long userID;
933
		if(userId.compareTo("") == 0){
934
			userID = 0;
935
		}else{
936
			userID = Long.parseLong(userId);
937
		}
938
 
939
		WidgetServiceClient widgetServiceClient = null;
940
		in.shop2020.model.v1.widgets.WidgetService.Client client = null;
941
		Widget widget = null;
942
		try {
943
			widgetServiceClient = new WidgetServiceClient();
944
			client = widgetServiceClient.getClient();
945
			widget = client.getWidget(widgetType, userID, true);
946
		} catch (Exception e) {
947
			e.printStackTrace();
948
		}
949
 
950
 
951
		List<Map<String, String>> itemDetails = null;
952
 
953
		if(widget != null){
954
			List<WidgetItem> items = widget.getItems();
955
			itemDetails = new ArrayList<Map<String, String>>();
956
 
957
			for(WidgetItem item: items){
958
				Map<String, String> itemDetail = new HashMap<String, String>();
959
 
960
				itemDetail.put("ITEM_ID", item.getItem_id()+"");
961
				itemDetail.put("ITEM_NAME", "ID"+item.getItem_id());
962
				itemDetail.put("ITEM_SNIPPET", item.getSnippet());
963
				itemDetail.put("ITEM_PRICE", getItemPriceByCatalogId(item.getItem_id())+"");
964
				itemDetails.add(itemDetail);
965
			}
966
		}else{
967
			System.out.println("widget not found");
968
		}
969
 
970
		VelocityContext context = new VelocityContext();
971
		context.put("itemDetails", itemDetails);
972
 
973
		return getHtmlFromVelocity("velocity/"+templateFile, context);
974
	}
975
*/
976
 
977
 
978
	public Map<String, String> getCompletedOrdersPage(long userId, long itemCount,
979
			Map<String, String> params) {
980
		Map<String,String> htmlSnippet = new HashMap<String, String>();
981
		htmlSnippet.put("HEADER", getHeaderHtml(userId, false, ""));
982
		System.out.println("HEADER Snippet generated");
983
 
984
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
985
		System.out.println("MAIN_MENU Snippet generated");
986
 
987
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
988
		System.out.println("SEARCH_BAR Snippet generated");
989
 
990
		htmlSnippet.put("MYACCOUNT_HEADER", getMyaccountHeaderHtml());
991
		System.out.println("MYACCOUNT_HEADER Snippet generated");
992
 
993
		htmlSnippet.put("MYACCOUNT_DETAILS", getCompletedOrdersHtml(userId));
994
		System.out.println("MYACCOUNT_DETAILS Snippet generated");
995
 
996
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
997
		System.out.println("CUSTOMER_SERVICE Snippet generated");
998
 
999
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, false));
1000
		System.out.println("MY_RESEARCH Snippet generated");
1001
 
1002
		htmlSnippet.put("FOOTER", getFooterHtml());
1003
		System.out.println("Footer Snippet generated");
1004
 
1005
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1006
	//	System.out.println("ACCESSORIES Snippet generated")
1007
 
1008
		htmlSnippet.put("JS_FILES", "");
1009
		htmlSnippet.put("CSS_FILES", "");
1010
 
1011
		System.out.println("Returning Generated Responce");
1012
 
1013
 
1014
		return htmlSnippet;
1015
 
1016
	}
1017
 
1018
 
1019
	public Map<String, String> getMyAccountPage(long userId, long itemCount,
1020
			Map<String, String> params) {
1021
		Map<String,String> htmlSnippet = new HashMap<String, String>();
1022
		htmlSnippet.put("HEADER", getHeaderHtml(userId, false, ""));
1023
		System.out.println("HEADER Snippet generated");
1024
 
1025
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
1026
		System.out.println("MAIN_MENU Snippet generated");
1027
 
1028
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
1029
		System.out.println("SEARCH_BAR Snippet generated");
1030
 
1031
		htmlSnippet.put("MYACCOUNT_HEADER", getMyaccountHeaderHtml());
1032
		System.out.println("MYACCOUNT_HEADER Snippet generated");
1033
 
1034
		htmlSnippet.put("MYACCOUNT_DETAILS", getMyaccountDetailsHtml(userId));
1035
		System.out.println("MYACCOUNT_DETAILS Snippet generated");
1036
 
1037
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
1038
		System.out.println("CUSTOMER_SERVICE Snippet generated");
1039
 
1040
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, false));
1041
		System.out.println("MY_RESEARCH Snippet generated");
1042
 
1043
		htmlSnippet.put("FOOTER", getFooterHtml());
1044
		System.out.println("Footer Snippet generated");
1045
 
1046
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1047
	//	System.out.println("ACCESSORIES Snippet generated")
1048
 
1049
		htmlSnippet.put("JS_FILES", "");
1050
		htmlSnippet.put("CSS_FILES", "");
1051
 
1052
		System.out.println("Returning Generated Responce");
1053
 
1054
 
1055
		return htmlSnippet;
1056
	}
1057
 
1058
 
1059
	public Map<String, String> getPersonalDetailsPage(long userId, long itemCount,
1060
			Map<String, String> params) {
1061
		Map<String,String> htmlSnippet = new HashMap<String, String>();
1062
		htmlSnippet.put("HEADER", getHeaderHtml(userId, false, ""));
1063
		System.out.println("HEADER Snippet generated");
1064
 
1065
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
1066
		System.out.println("MAIN_MENU Snippet generated");
1067
 
1068
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
1069
		System.out.println("SEARCH_BAR Snippet generated");
1070
 
1071
		htmlSnippet.put("MYACCOUNT_HEADER", getMyaccountHeaderHtml());
1072
		System.out.println("MYACCOUNT_HEADER Snippet generated");
1073
 
1074
		htmlSnippet.put("PERSONAL_DETAILS", getPersonalDetailsHtml(userId));
1075
		System.out.println("PERSONAL_DETAILS Snippet generated");
1076
 
1077
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
1078
		System.out.println("CUSTOMER_SERVICE Snippet generated");
1079
 
1080
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, false));
1081
		System.out.println("MY_RESEARCH Snippet generated");
1082
 
1083
		htmlSnippet.put("FOOTER", getFooterHtml());
1084
		System.out.println("Footer Snippet generated");
1085
 
1086
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1087
	//	System.out.println("ACCESSORIES Snippet generated")
1088
 
1089
		htmlSnippet.put("JS_FILES", "");
1090
		htmlSnippet.put("CSS_FILES", "");
1091
 
1092
		System.out.println("Returning Generated Responce");
1093
 
1094
 
1095
		return htmlSnippet;
1096
	}
1097
 
1098
	public Map<String, String> getLoginDetailsPage(long userId, long itemCount,
1099
			Map<String, String> params) {
1100
		Map<String,String> htmlSnippet = new HashMap<String, String>();
1101
		htmlSnippet.put("HEADER", getHeaderHtml(userId, false, ""));
1102
		System.out.println("HEADER Snippet generated");
1103
 
1104
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
1105
		System.out.println("MAIN_MENU Snippet generated");
1106
 
1107
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
1108
		System.out.println("SEARCH_BAR Snippet generated");
1109
 
1110
		htmlSnippet.put("MYACCOUNT_HEADER", getMyaccountHeaderHtml());
1111
		System.out.println("MYACCOUNT_HEADER Snippet generated");
1112
 
1113
		htmlSnippet.put("LOGIN_DETAILS", getLoginDetailsHtml(userId));
1114
		System.out.println("LOGIN_DETAILS Snippet generated");
1115
 
1116
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
1117
		System.out.println("CUSTOMER_SERVICE Snippet generated");
1118
 
1119
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, false));
1120
		System.out.println("MY_RESEARCH Snippet generated");
1121
 
1122
		htmlSnippet.put("FOOTER", getFooterHtml());
1123
		System.out.println("Footer Snippet generated");
1124
 
1125
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1126
	//	System.out.println("ACCESSORIES Snippet generated")
1127
 
1128
		htmlSnippet.put("JS_FILES", "");
1129
		htmlSnippet.put("CSS_FILES", "");
1130
 
1131
		System.out.println("Returning Generated Responce");
1132
 
1133
 
1134
		return htmlSnippet;
1135
	}
1136
 
1137
 
1138
 
1139
	public Map<String, String> getOrderDetailsPage(long userId, long itemCount, long orderId,
1140
			Map<String, String> params) {
1141
		Map<String,String> htmlSnippet = new HashMap<String, String>();
1142
		htmlSnippet.put("HEADER", getHeaderHtml(userId, false, ""));
1143
		System.out.println("HEADER Snippet generated");
1144
 
1145
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
1146
		System.out.println("MAIN_MENU Snippet generated");
1147
 
1148
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
1149
		System.out.println("SEARCH_BAR Snippet generated");
1150
 
1151
		htmlSnippet.put("MYACCOUNT_HEADER", getMyaccountHeaderHtml());
1152
		System.out.println("MYACCOUNT_HEADER Snippet generated");
1153
 
1154
		htmlSnippet.put("ORDER_DETAILS", getOrderDetailsHtml(orderId));
1155
		System.out.println("MYACCOUNT_DETAILS Snippet generated");
1156
 
1157
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
1158
		System.out.println("CUSTOMER_SERVICE Snippet generated");
1159
 
1160
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, false));
1161
		System.out.println("MY_RESEARCH Snippet generated");
1162
 
1163
		htmlSnippet.put("FOOTER", getFooterHtml());
1164
		System.out.println("Footer Snippet generated");
1165
 
1166
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1167
	//	System.out.println("ACCESSORIES Snippet generated")
1168
 
1169
		htmlSnippet.put("JS_FILES", "");
1170
		htmlSnippet.put("CSS_FILES", "");
1171
 
1172
		System.out.println("Returning Generated Responce");
1173
 
1174
 
1175
		return htmlSnippet;
1176
	}
1177
 
1178
 
1179
 
1180
	private String getOrderDetailsHtml(long orderId) {
1181
		String htmlString = "";
1182
		VelocityContext context = new VelocityContext();
1183
		String templateFile = "templates/orderdetails.vm";
1184
		TransactionServiceClient transactionServiceClient = null;
1185
		in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
1186
		Order order = null;
517 rajveer 1187
		Date orderedOn = null, deliveryEstimate = null;
507 rajveer 1188
		try{
1189
			transactionServiceClient = new TransactionServiceClient();
1190
			orderClient = transactionServiceClient.getClient();
1191
			order = orderClient.getOrder(orderId);
517 rajveer 1192
			orderedOn = new Date(order.getCreated_timestamp());
1193
			deliveryEstimate = new Date(order.getExpected_delivery_time());
507 rajveer 1194
		}catch (Exception e){
1195
 
1196
		}
517 rajveer 1197
 
1198
		SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
507 rajveer 1199
		context.put("order", order);
517 rajveer 1200
		context.put("orderedOn", dateformat.format(orderedOn));
1201
		context.put("deliveryEstimate", dateformat.format(deliveryEstimate));
1202
 
1203
 
507 rajveer 1204
		htmlString = getHtmlFromVelocity(templateFile, context);
1205
		return htmlString;
1206
	}
1207
 
1208
	private String getMyaccountDetailsHtml(long userId) {
1209
		String htmlString = "";
1210
		VelocityContext context = new VelocityContext();
1211
		String templateFile = "templates/myaccount.vm";
1212
		TransactionServiceClient transactionServiceClient = null;
1213
		in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
1214
		List<Order> orders = null;
1215
		try{
1216
			transactionServiceClient = new TransactionServiceClient();
1217
			orderClient = transactionServiceClient.getClient();
1218
			orders = orderClient.getOrdersForCustomer(userId, 0, (new Date()).getTime(), null);
1219
 
1220
		}catch (Exception e){
1221
 
1222
		}
1223
		context.put("orders", orders);
1224
		htmlString = getHtmlFromVelocity(templateFile, context);
1225
		return htmlString;
1226
	}
1227
 
1228
 
1229
	private String getLoginDetailsHtml(long userId) {
1230
		String htmlString = "";
1231
		VelocityContext context = new VelocityContext();
1232
		String templateFile = "templates/logindetails.vm";
1233
		String email = "";
1234
		UserContextServiceClient userContextServiceClient = null;
1235
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
1236
 
1237
		try{
1238
			userContextServiceClient = new UserContextServiceClient();
1239
			userClient = userContextServiceClient.getClient();
1240
			UserPrimaryInfo primaryInfo = userClient.getPrimaryInfo(userId, false);
1241
			email = primaryInfo.getEmail();
1242
		}catch (Exception e){
1243
 
1244
		}
1245
		context.put("email", email);
1246
		htmlString = getHtmlFromVelocity(templateFile, context);
1247
		return htmlString;
1248
	}
1249
 
1250
	private String getPersonalDetailsHtml(long userId) {
1251
		String htmlString = "";
1252
		VelocityContext context = new VelocityContext();
1253
		String templateFile = "templates/personaldetails.vm";
1254
		String email = "";
517 rajveer 1255
		String name = "";
1256
		int year = 0, month = 0, day = 0;
1257
		String sex = "";
1258
		String subscribe = "false";
507 rajveer 1259
		UserContextServiceClient userContextServiceClient = null;
1260
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
1261
		UserPrimaryInfo primaryInfo = null;
1262
		try{
1263
			userContextServiceClient = new UserContextServiceClient();
1264
			userClient = userContextServiceClient.getClient();
1265
			primaryInfo = userClient.getPrimaryInfo(userId, false);
1266
 
517 rajveer 1267
			email = primaryInfo.getCommunicationEmail();
1268
			name = primaryInfo.getFirstName();
1269
 
1270
			Calendar calendar = Calendar.getInstance();
1271
			calendar.setTimeInMillis(primaryInfo.getDateOfBirth());
1272
			month = calendar.get(Calendar.MONTH);
1273
			year = calendar.get(Calendar.YEAR);
1274
			day = calendar.get(Calendar.DAY_OF_MONTH);
1275
 
507 rajveer 1276
		}catch (Exception e){
1277
 
1278
		}
517 rajveer 1279
		context.put("name", name);
1280
		context.put("email", email);
1281
		context.put("month", month+"");
1282
		context.put("day", day+"");
1283
		context.put("year", year+"");
1284
		context.put("subscribe", subscribe);
1285
		context.put("sex", sex);
507 rajveer 1286
		htmlString = getHtmlFromVelocity(templateFile, context);
1287
		return htmlString;
1288
	}
1289
 
1290
	private String getCompletedOrdersHtml(long userId) {
1291
		String htmlString = "";
1292
		VelocityContext context = new VelocityContext();
1293
		String templateFile = "templates/completedorders.vm";
1294
		TransactionServiceClient transactionServiceClient = null;
1295
		in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
1296
		List<Order> orders = null;
1297
		try{
1298
			transactionServiceClient = new TransactionServiceClient();
1299
			orderClient = transactionServiceClient.getClient();
1300
			orders = orderClient.getOrdersForCustomer(userId, 0, (new Date()).getTime(), OrderStatus.DELIVERY_SUCCESS);
1301
 
1302
		}catch (Exception e){
1303
 
1304
		}
1305
		context.put("orders", orders);
1306
		htmlString = getHtmlFromVelocity(templateFile, context);
1307
		return htmlString;
1308
	}
1309
	private String getMyaccountHeaderHtml() {
1310
		String htmlString = "";
1311
		VelocityContext context = new VelocityContext();
1312
		String templateFile = "templates/myaccountheader.vm";
1313
		htmlString = getHtmlFromVelocity(templateFile, context);
1314
		return htmlString;
1315
	}
1316
 
1317
 
1318
	public Map<String, String> getMyAccountPage_old(long userId,
1319
			Map<String, String> params) {
1320
 
1321
		UserContextServiceClient userContextServiceClient = null;
1322
		in.shop2020.model.v1.user.UserContextService.Client client = null;
1323
		String htmlString = new String();
1324
 
1325
			UserPrimaryInfo userPrimaryInfo;
1326
			try {
1327
				userContextServiceClient = new UserContextServiceClient();
1328
				client = userContextServiceClient.getClient();
1329
				userPrimaryInfo = client.getPrimaryInfo(userId, false);
1330
 
1331
				String templateFile = "templates/myaccounts.vm";
1332
				VelocityContext context = new VelocityContext();	
1333
				context.put("userPrimaryInfo", userPrimaryInfo);
1334
 
1335
				htmlString = getHtmlFromVelocity(templateFile, context);
1336
				System.out.println("My Accounts Snippet generated" + htmlString);
1337
			} catch (UserContextException e) {
1338
				// TODO Auto-generated catch block
1339
				e.printStackTrace();
1340
			} catch (Exception e) {
1341
				// TODO Auto-generated catch block
1342
				e.printStackTrace();
1343
			}
1344
 
1345
			Map<String,String> htmlSnippet = new HashMap<String, String>();
1346
			htmlSnippet.put("My_ACCOUNT", htmlString);
1347
 
1348
			htmlSnippet.put("My_ORDERS", getMyOrdersDiv(userId));
1349
 
1350
			return htmlSnippet;
1351
	}
1352
 
1353
	//ShippingPage
1354
	public Map<String, String> getShippingPage(long userId, boolean isSessionId, long cartId, long itemCount, Map<String, String> params){
1355
		Map<String,String> htmlSnippet = new HashMap<String, String>();
1356
 
1357
		htmlSnippet.put("HEADER", getHeaderHtml(userId, isSessionId, ""));
1358
		System.out.println("HEADER Snippet generated");
1359
 
1360
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
1361
		System.out.println("MAIN_MENU Snippet generated");
1362
 
1363
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
1364
		System.out.println("SEARCH_BAR Snippet generated");
1365
 
1366
		htmlSnippet.put("SHIPPING_HEADER", getShippingHeaderHtml());
1367
		System.out.println("SHIPPING_HEADER Snippet generated");
1368
 
1369
		htmlSnippet.put("SHIPPING_DETAILS", getShippingDetailsHtml(cartId));
1370
		System.out.println("SHIPPING_BAR Snippet generated");
1371
 
1372
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
1373
		System.out.println("CUSTOMER_SERVICE Snippet generated");
1374
 
1375
		htmlSnippet.put("FOOTER", getFooterHtml());
1376
		System.out.println("Footer Snippet generated");
1377
 
1378
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1379
	//	System.out.println("ACCESSORIES Snippet generated")
1380
 
1381
		htmlSnippet.put("JS_FILES", "");
1382
		htmlSnippet.put("CSS_FILES", "");
1383
 
1384
		System.out.println("Returning Generated Responce");
1385
 
1386
		return htmlSnippet;
1387
 
1388
	}
1389
 
1390
	//ShippingPage
1391
	public Map<String, String> getShippingAddressPage(long userId, boolean isSessionId, long cartId, long itemCount, Map<String, String> params){
1392
		Map<String,String> htmlSnippet = new HashMap<String, String>();
1393
 
1394
		htmlSnippet.put("HEADER", getHeaderHtml(userId, isSessionId, ""));
1395
		System.out.println("HEADER Snippet generated");
1396
 
1397
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
1398
		System.out.println("MAIN_MENU Snippet generated");
1399
 
1400
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
1401
		System.out.println("SEARCH_BAR Snippet generated");
1402
 
1403
		htmlSnippet.put("SHIPPING_ADDRESS_HEADER", getMyaccountHeaderHtml());
1404
		System.out.println("SHIPPING_ADDRESS_HEADER Snippet generated");
1405
 
1406
		htmlSnippet.put("SHIPPING_ADDRESS_DETAILS", getShippingAddressDetailsHtml(userId));
1407
		System.out.println("SHIPPING_ADDRESS_BAR Snippet generated");
1408
 
1409
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
1410
		System.out.println("CUSTOMER_SERVICE Snippet generated");
1411
 
1412
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, false));
1413
		System.out.println("MY_RESEARCH Snippet generated");
1414
 
1415
		htmlSnippet.put("FOOTER", getFooterHtml());
1416
		System.out.println("Footer Snippet generated");
1417
 
1418
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1419
	//	System.out.println("ACCESSORIES Snippet generated")
1420
 
1421
		htmlSnippet.put("JS_FILES", "");
1422
		htmlSnippet.put("CSS_FILES", "");
1423
 
1424
		System.out.println("Returning Generated Responce");
1425
 
1426
		return htmlSnippet;
1427
 
1428
	}
1429
 
1430
	private String getShippingHeaderHtml() {
1431
		String htmlString = "";
1432
		VelocityContext context = new VelocityContext();
1433
		String templateFile = "templates/shippingheader.vm";
1434
		htmlString = getHtmlFromVelocity(templateFile, context);
1435
		return htmlString;
1436
	}
1437
 
1438
	private String getShippingAddressDetailsHtml(long userId){
1439
		String htmlString = "";
1440
		VelocityContext context = new VelocityContext();
1441
		String templateFile = "templates/shippingaddressdetails.vm";
1442
		long defaultAddressId = 0;
517 rajveer 1443
		List<Address> addresses = null;
507 rajveer 1444
 
1445
		UserContextServiceClient userContextServiceClient = null;
1446
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
1447
		try {
1448
			userContextServiceClient = new UserContextServiceClient();
1449
			userClient = userContextServiceClient.getClient();
1450
			UserPrimaryInfo primaryInfo = userClient.getPrimaryInfo(userId, false);
1451
			addresses = primaryInfo.getAddresses();
1452
			defaultAddressId = primaryInfo.getDefaultAddressId();
1453
		} catch (Exception e) {
1454
			// TODO Auto-generated catch block
1455
			e.printStackTrace();
1456
		}
517 rajveer 1457
		context.put("defaultAddressId", defaultAddressId+"");
507 rajveer 1458
		context.put("addresses", addresses);
1459
 
1460
		htmlString = getHtmlFromVelocity(templateFile, context);
1461
		return htmlString;
1462
	}
1463
 
1464
	private String getShippingDetailsHtml(long cartId) {
1465
		String htmlString = "";
1466
		VelocityContext context = new VelocityContext();
1467
		String templateFile = "templates/shippingdetails.vm";
517 rajveer 1468
		List<Map<String,String>> items = null;
507 rajveer 1469
		double totalamount= 0.0;
517 rajveer 1470
		List<Address> addresses = null;
1471
		long defaultAddressId = 0;
507 rajveer 1472
		ShoppingCartClient shoppingCartClient = null;
1473
		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = null;
1474
		CatalogServiceClient catalogServiceClient  = null;
1475
		in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = null;
1476
		UserContextServiceClient userContextServiceClient = null;
1477
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
1478
 
1479
		try {
1480
			shoppingCartClient = new ShoppingCartClient();
1481
			cartClient = shoppingCartClient.getClient();
1482
			catalogServiceClient = new CatalogServiceClient();
1483
			catalogClient = catalogServiceClient.getClient();
1484
			userContextServiceClient = new UserContextServiceClient();
1485
			userClient = userContextServiceClient.getClient();
1486
 
1487
 
1488
			Cart cart = cartClient.getCart(cartId);
1489
			List<Line> lineItems = cart.getLines();
1490
 
517 rajveer 1491
			if( ! lineItems.isEmpty())
1492
			{
1493
				items = new ArrayList<Map<String,String>>();
507 rajveer 1494
 
517 rajveer 1495
				for (Line line : lineItems) {
1496
					Map<String, String> itemdetail = new HashMap<String, String>();
1497
					Item item = catalogClient.getItemByCatalogId(line.getItemId());
1498
					String itemName = ((item.getManufacturerName() != null) ? item.getManufacturerName() + " " : "")
1499
										+ ((item.getModelName() != null) ? item.getModelName() + " " : "") 
1500
										+ (( item.getModelNumber() != null ) ? item.getModelNumber() : "" );
1501
 
1502
					itemdetail.put("ITEM_NAME", itemName);
1503
					itemdetail.put("ITEM_ID", line.getItemId()+"");
1504
					itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
1505
					itemdetail.put("MRP", ((int)item.getMrp())+"");
536 rajveer 1506
					itemdetail.put("SELLING_PRICE", (int)item.getSellingPrice()+"");
1507
					itemdetail.put("TOTAL_PRICE", (int)(item.getSellingPrice()*line.getQuantity())+"");
517 rajveer 1508
					itemdetail.put("SHIPPING_TIME", 48+"");
536 rajveer 1509
					totalamount = totalamount + line.getQuantity()*item.getSellingPrice();
517 rajveer 1510
					items.add(itemdetail);				
1511
				}
507 rajveer 1512
			}
1513
 
1514
			UserPrimaryInfo primaryInfo = userClient.getPrimaryInfo(cart.getUserId(), false);
1515
			addresses = primaryInfo.getAddresses();
517 rajveer 1516
			defaultAddressId = primaryInfo.getDefaultAddressId();
507 rajveer 1517
 
1518
		}catch (Exception e){
1519
			e.printStackTrace();
1520
		}
1521
 
1522
		context.put("items", items);
536 rajveer 1523
		context.put("totalamount", (int)totalamount+"");
507 rajveer 1524
		context.put("addresses", addresses);
517 rajveer 1525
		context.put("defaultAddressId", defaultAddressId+"");
507 rajveer 1526
		htmlString = getHtmlFromVelocity(templateFile, context);
1527
		return htmlString;
1528
	}
1529
 
1530
 
1531
	//ShoppingCartPage
1532
	public Map<String, String> getShoppingCartPage(long userId, boolean isSessionId, long cartId, long itemCount, Map<String, String> params){
1533
		Map<String,String> htmlSnippet = new HashMap<String, String>();
1534
 
1535
		htmlSnippet.put("HEADER", getHeaderHtml(userId, isSessionId, ""));
1536
		System.out.println("HEADER Snippet generated");
1537
 
1538
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
1539
		System.out.println("MAIN_MENU Snippet generated");
1540
 
1541
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
1542
		System.out.println("SEARCH_BAR Snippet generated");
1543
 
1544
		htmlSnippet.put("CART_HEADER", getCartHeaderHtml());
1545
		System.out.println("CART_HEADER Snippet generated");
1546
 
1547
		htmlSnippet.put("CART_DETAILS", getCartDetailsHtml(cartId));
1548
		System.out.println("SEARCH_BAR Snippet generated");
1549
 
1550
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
1551
		System.out.println("CUSTOMER_SERVICE Snippet generated");
1552
 
1553
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, isSessionId));
1554
		System.out.println("MY_RESEARCH Snippet generated");
1555
 
1556
		htmlSnippet.put("FOOTER", getFooterHtml());
1557
		System.out.println("Footer Snippet generated");
1558
 
1559
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1560
	//	System.out.println("ACCESSORIES Snippet generated")
1561
 
1562
		htmlSnippet.put("JS_FILES", "");
1563
		htmlSnippet.put("CSS_FILES", "");
1564
 
1565
		System.out.println("Returning Generated Responce");
1566
 
1567
		return htmlSnippet;
1568
 
1569
	}
1570
 
1571
	private String getCartHeaderHtml() {
1572
		String htmlString = "";
1573
		VelocityContext context = new VelocityContext();
1574
		String templateFile = "templates/cartheader.vm";
1575
		htmlString = getHtmlFromVelocity(templateFile, context);
1576
		return htmlString;
1577
	}
1578
 
1579
 
1580
	private String getCartDetailsHtml(long cartId) {
1581
		String htmlString = "";
1582
		VelocityContext context = new VelocityContext();
1583
		String templateFile = "templates/cartdetails.vm";
517 rajveer 1584
		List<Map<String,String>> items = null;
507 rajveer 1585
		double totalamount= 0.0;
1586
 
1587
		ShoppingCartClient shoppingCartClient = null;
1588
		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = null;
1589
		CatalogServiceClient catalogServiceClient  = null;
1590
		in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = null;
1591
 
1592
		try {
1593
			shoppingCartClient = new ShoppingCartClient();
1594
			cartClient = shoppingCartClient.getClient();
1595
			catalogServiceClient = new CatalogServiceClient();
1596
			catalogClient = catalogServiceClient.getClient();
1597
 
1598
			Cart cart = cartClient.getCart(cartId);
1599
			List<Line> lineItems = cart.getLines();
517 rajveer 1600
			if(lineItems.size() != 0){
1601
				items = new ArrayList<Map<String,String>>();
1602
				for (Line line : lineItems) {
1603
 
1604
					Map<String, String> itemdetail = new HashMap<String, String>();
1605
					Item item = catalogClient.getItemByCatalogId(line.getItemId());
1606
 
1607
					String itemName = ((item.getManufacturerName() != null) ? item.getManufacturerName() + " " : "")
1608
										+ ((item.getModelName() != null) ? item.getModelName() + " " : "") 
1609
										+ (( item.getModelNumber() != null ) ? item.getModelNumber() : "" );
1610
 
1611
					itemdetail.put("ITEM_NAME", itemName);
1612
					System.out.println(itemdetail.get("ITEM_NAME"));
1613
					itemdetail.put("ITEM_ID", line.getItemId()+"");
1614
					itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
1615
					itemdetail.put("MRP", ((int)item.getMrp())+"");
1616
					itemdetail.put("SELLING_PRICE", ((int)item.getSellingPrice())+"");
1617
					itemdetail.put("TOTAL_PRICE", ((int)((item.getSellingPrice()*line.getQuantity())))+"");
1618
					itemdetail.put("SHIPPING_TIME", 48+"");
1619
					totalamount = totalamount + line.getQuantity()*item.getSellingPrice();
1620
					items.add(itemdetail);				
507 rajveer 1621
				}
1622
			}
1623
 
1624
		}catch (Exception e){
1625
			e.printStackTrace();
1626
		}
1627
 
1628
		context.put("items", items);
517 rajveer 1629
		context.put("totalamount", ((int)totalamount)+"");
507 rajveer 1630
		htmlString = getHtmlFromVelocity(templateFile, context);
1631
		return htmlString;
1632
	}
1633
 
1634
 
1635
	public Map<String, String> getShoppingCartPage_Old(long userId, boolean isSessionId, Map<String, String> params)
1636
	{
1637
		ShoppingCartClient shoppingCartClient = null;
1638
		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = null;
1639
 
1640
		try {
1641
			shoppingCartClient = new ShoppingCartClient();
1642
			cartClient = shoppingCartClient.getClient();
1643
 
1644
			Cart cart = cartClient.getCurrentCart(userId, isSessionId);
1645
 
1646
			List<Line> lineItems = cart.getLines();
1647
			List<Map<String,String>> items = new ArrayList<Map<String,String>>(); 
1648
 
1649
			for (Line line : lineItems) {
1650
//				long productId = getCatalogIdByItemId(line.getItemId());
1651
				long productId = line.getItemId();
1652
				Map<String, String> productDetails = getProductDetails(productId);
1653
				double mrp = getItemMrpByCatalogId(productId);
1654
				double sellingPrice = getItemSellingPriceByCatalogId(productId);
1655
				double saving = (mrp - sellingPrice)/mrp*100; 
1656
				saving = Math.round(saving);
1657
				Map<String, String> item = new HashMap<String, String>();
1658
				item.put("BRAND_NAME", productDetails.get("BRAND_NAME"));
1659
				item.put("MODEL_NAME", productDetails.get("MODEL_NAME"));
1660
				item.put("MODEL_NUMBER", productDetails.get("MODEL_NUMBER"));
1661
				item.put("ITEM_ID", line.getItemId()+"");
1662
				item.put("ITEM_QUANTITY", line.getQuantity()+"");
1663
				item.put("MRP", mrp+"");
1664
				item.put("SELLING_PRICE", sellingPrice+"");
1665
				item.put("SAVING", sellingPrice+"");
1666
				items.add(item);
1667
			}
1668
 
1669
			String templateFile = "templates/shoppingcart.vm";
1670
			VelocityContext context = new VelocityContext();	
1671
			context.put("items", items);
1672
 
1673
			String htmlString = getHtmlFromVelocity(templateFile, context);
1674
			System.out.println("My Cart Snippet generated" + htmlString);
1675
 
1676
			Map<String,String> htmlSnippet = new HashMap<String, String>();
1677
			htmlSnippet.put("SHOPPING_CART", htmlString);
1678
 
1679
			return htmlSnippet;
1680
 
1681
		} catch (ShoppingCartException e) {
1682
			// TODO Auto-generated catch block
1683
			e.printStackTrace();
1684
		}catch (Exception e) {
1685
			// TODO Auto-generated catch block
1686
			e.printStackTrace();
1687
		}
1688
 
1689
		return null;
1690
	}
1691
 
1692
 
1693
	public long getCatalogIdByItemId(long itemId){
1694
		CatalogServiceClient catalogServiceClient = null;
1695
		Client client = null;
1696
 
1697
		try {
1698
			catalogServiceClient = new CatalogServiceClient();
1699
			client = catalogServiceClient.getClient();
1700
 
1701
			return client.getItem(itemId).getCatalogItemId();
1702
		} catch (InventoryServiceException e) {
1703
			// TODO Auto-generated catch block
1704
			e.printStackTrace();
1705
		} catch (TException e) {
1706
			// TODO Auto-generated catch block
1707
			e.printStackTrace();
1708
		} catch (Exception e) {
1709
			// TODO Auto-generated catch block
1710
			e.printStackTrace();
1711
		}
1712
		return -1;
1713
	}
1714
 
1715
//	private	void addItemToCart(long catalogItemId, long userId) throws Exception{
1716
//		UserContextServiceClient userContextServiceClient = null;
1717
//		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
1718
//		userContextServiceClient = new UserContextServiceClient();
1719
//		userClient = userContextServiceClient.getClient();
1720
//
1721
//		ShoppingCartClient shoppingCartClient = null;
1722
//		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = null;
1723
//		shoppingCartClient = new ShoppingCartClient();
1724
//		cartClient = shoppingCartClient.getClient();
1725
//		
1726
//		Cart cart = cartClient.getCurrentCart(userId);
1727
//		//if user is logged in create  new cart
1728
//		//if( userClient.getState(userId, false).isIsLoggedIn()){
1729
//		if(cart == null){
1730
//			cartClient.createCart(userId);
1731
//			cart = cartClient.getCurrentCart(userId);
1732
//		}
1733
//		cartClient.addItemToCart(cart.getId(), catalogItemId, 1);
1734
//	}
1735
 
1736
		//userClient.getState(userId, isSessionId);
1737
 
1738
//		TransactionServiceClient transactionServiceClient = null;
1739
//		in.shop2020.model.v1.order.TransactionService.Client client = null;
1740
//		
1741
//		Cart cart = cartClient.getCurrentCart(userId);
1742
//		List<Line> lineItems = cart.getLines();
1743
//		
1744
//		Line ln = lineItems.get(0);
1745
//		ln.getItemId();
1746
//		ln.getId();
1747
//		ln.getQuantity();
1748
//		ln.getStatusMessage();
1749
//		long productId = 10;
1750
//		
1751
//		Cart cart = cartClient.getCurrentCart(0);
1752
//		List<Line> lineItems = cart.getLines();
1753
//		Line ln = lineItems.get(0);
1754
//		ln.getItemId();
1755
//		ln.getId();
1756
//		
1757
//		ln.getStatusMessage();
1758
//		
1759
 
1760
	private	Map<String,String> getProductDetails(long productId){
1761
		Map<String, String> productDetails = new HashMap<String, String>();
1762
 
1763
		EntityContainer entContainer = 	Catalog.getInstance().getEntityContainer();
1764
		ExpandedEntity expEntity;
1765
		try {
1766
			expEntity = entContainer.getExpandedEntity(productId);
1767
 
1768
			productDetails.put("BRAND_NAME", expEntity.getBrand());
1769
			productDetails.put("MODEL_NUMBER", expEntity.getModelNumber());
1770
			productDetails.put("MODEL_NAME", expEntity.getModelName());
1771
			productDetails.put("CATEGORY_ID", expEntity.getCategoryID() + "");
1772
			productDetails.put("CATEGORY_NAME", expEntity.getCategory().getLabel());
1773
			productDetails.put("INTRODUCTION_TEXT", expEntity.getSlide(130001).getFreeformContent().getFreeformText());
1774
			return productDetails;
1775
//			expEntity.getBrand();
1776
//			expEntity.getModelNumber();
1777
//			expEntity.getModelName();
1778
//			expEntity.getCategoryID();
1779
//			expEntity.getCategory().getLabel();
1780
//			expEntity.getSlide(130001).getFreeformContent().getFreeformText();
1781
		} catch (Exception e) {
1782
			// TODO Auto-generated catch block
1783
			e.printStackTrace();
1784
		}
1785
 
1786
		return null;
1787
	}
1788
 
1789
 
1790
	private	String getMyOrdersDiv(long userId){
1791
		TransactionServiceClient transactionServiceClient = null;
1792
		in.shop2020.model.v1.order.TransactionService.Client client = null;
1793
		String htmlString = new String();
1794
			try {
1795
				transactionServiceClient = new TransactionServiceClient();
1796
				client = transactionServiceClient.getClient();
1797
				List<Transaction> transactions = client.getTransactionsForCustomer(userId, 0, 0, null);
1798
 
1799
				String templateFile = "templates/myorders.vm";
1800
				VelocityContext context = new VelocityContext();	
1801
				context.put("transactions", transactions);
1802
				if(!transactions.isEmpty()){
1803
					Transaction tn = transactions.get(0);
1804
					java.sql.Date d = new java.sql.Date(tn.getCreatedOn());
1805
					System.out.println("Date is" + d.toString());
1806
				}
1807
				htmlString = getHtmlFromVelocity(templateFile, context);
1808
				System.out.println("Orders Info Snippet generated" + htmlString);
1809
				return htmlString;
1810
 
1811
			} catch (UserContextException e) {
1812
				// TODO Auto-generated catch block
1813
				e.printStackTrace();
1814
			} catch (Exception e) {
1815
				// TODO Auto-generated catch block
1816
				e.printStackTrace();
1817
			}
1818
			return "MY_ORDERS";
1819
	}
1820
 
1821
	public String getHtmlFromVelocity(String templateFile, VelocityContext context){
1822
		Properties p = new Properties();
1823
		p.setProperty("resource.loader", "class");
1824
		p.setProperty("class.resource.loader.class",
1825
		"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
1826
 
1827
 
1828
		try {
1829
			Velocity.init(p);
1830
			Template template = Velocity.getTemplate(templateFile);
1831
			if(template != null) {
1832
				StringWriter writer = new StringWriter();
1833
				template.merge(context, writer);
1834
				writer.flush();
1835
				writer.close();
1836
				return writer.toString();
1837
			}
1838
 
1839
			} catch (ResourceNotFoundException e) {
1840
				// TODO Auto-generated catch block
1841
				e.printStackTrace();
1842
			} catch (ParseErrorException e) {
1843
				// TODO Auto-generated catch block
1844
				e.printStackTrace();
1845
			} catch (MethodInvocationException e) {
1846
				// TODO Auto-generated catch block
1847
				e.printStackTrace();
1848
			} catch (IOException e) {
1849
				// TODO Auto-generated catch block
1850
				e.printStackTrace();
1851
			} catch (Exception e) {
1852
				// TODO Auto-generated catch block
1853
				e.printStackTrace();
1854
			}
1855
 
1856
		return null;
1857
	}
1858
 
1859
	public double getItemMrpByCatalogId(long productId){
1860
		CatalogServiceClient catalogServiceClient = null;
1861
		Client client = null;
1862
		Double itemPrice = 0.0;
1863
		try {
1864
			catalogServiceClient = new CatalogServiceClient();
1865
			client = catalogServiceClient.getClient();
1866
			Item item = client.getItemByCatalogId(productId);
1867
			itemPrice = item.getMrp();
1868
		}
1869
		catch(Exception e){
1870
			e.printStackTrace();
1871
		}
1872
		return itemPrice;
1873
	}
1874
 
1875
	public double getItemSellingPriceByCatalogId(long productId){
1876
		CatalogServiceClient catalogServiceClient = null;
1877
		Client client = null;
1878
		Double itemPrice = 0.0;
1879
		try {
1880
			catalogServiceClient = new CatalogServiceClient();
1881
			client = catalogServiceClient.getClient();
1882
			Item item = client.getItemByCatalogId(productId);
1883
			itemPrice = item.getSellingPrice();
1884
		}
1885
		catch(Exception e){
1886
			e.printStackTrace();
1887
		}
1888
		return itemPrice;
1889
	}
1890
 
517 rajveer 1891
 
1892
	public String getCategoryHeaderSnippet() {
1893
		String htmlString = "";
1894
		VelocityContext context = new VelocityContext();
1895
		String templateFile = "templates/categoryheader.vm";
1896
		htmlString = getHtmlFromVelocity(templateFile, context);
1897
		return htmlString;
1898
	}
1899
 
507 rajveer 1900
 
1901
 
1902
}
1903