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