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