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
 
555 chandransh 378
	private String getBrowseHistoryHtml(long userId, boolean isLoggedIn) {
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");
507 rajveer 1194
		context.put("order", order);
517 rajveer 1195
		context.put("orderedOn", dateformat.format(orderedOn));
1196
		context.put("deliveryEstimate", dateformat.format(deliveryEstimate));
1197
 
1198
 
507 rajveer 1199
		htmlString = getHtmlFromVelocity(templateFile, context);
1200
		return htmlString;
1201
	}
1202
 
1203
	private String getMyaccountDetailsHtml(long userId) {
1204
		String htmlString = "";
1205
		VelocityContext context = new VelocityContext();
1206
		String templateFile = "templates/myaccount.vm";
1207
		TransactionServiceClient transactionServiceClient = null;
1208
		in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
1209
		List<Order> orders = null;
1210
		try{
1211
			transactionServiceClient = new TransactionServiceClient();
1212
			orderClient = transactionServiceClient.getClient();
1213
			orders = orderClient.getOrdersForCustomer(userId, 0, (new Date()).getTime(), null);
1214
 
1215
		}catch (Exception e){
1216
 
1217
		}
1218
		context.put("orders", orders);
1219
		htmlString = getHtmlFromVelocity(templateFile, context);
1220
		return htmlString;
1221
	}
1222
 
1223
 
1224
	private String getLoginDetailsHtml(long userId) {
1225
		String htmlString = "";
1226
		VelocityContext context = new VelocityContext();
1227
		String templateFile = "templates/logindetails.vm";
1228
		String email = "";
1229
		UserContextServiceClient userContextServiceClient = null;
1230
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
1231
 
1232
		try{
1233
			userContextServiceClient = new UserContextServiceClient();
1234
			userClient = userContextServiceClient.getClient();
555 chandransh 1235
			email = in.shop2020.serving.utils.Utils.getEmailId(userId);
507 rajveer 1236
		}catch (Exception e){
1237
 
1238
		}
1239
		context.put("email", email);
1240
		htmlString = getHtmlFromVelocity(templateFile, context);
1241
		return htmlString;
1242
	}
1243
 
1244
	private String getPersonalDetailsHtml(long userId) {
1245
		String htmlString = "";
1246
		VelocityContext context = new VelocityContext();
1247
		String templateFile = "templates/personaldetails.vm";
1248
		String email = "";
517 rajveer 1249
		String name = "";
1250
		int year = 0, month = 0, day = 0;
1251
		String sex = "";
1252
		String subscribe = "false";
507 rajveer 1253
		UserContextServiceClient userContextServiceClient = null;
1254
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
1255
		try{
555 chandransh 1256
			User user = null;
507 rajveer 1257
			userContextServiceClient = new UserContextServiceClient();
1258
			userClient = userContextServiceClient.getClient();
555 chandransh 1259
			user = userClient.getUserById(userId);
507 rajveer 1260
 
555 chandransh 1261
			email = user.getCommunicationEmail();
1262
			name = user.getName();
517 rajveer 1263
 
1264
			Calendar calendar = Calendar.getInstance();
555 chandransh 1265
			calendar.setTimeInMillis(user.getDateOfBirth());
517 rajveer 1266
			month = calendar.get(Calendar.MONTH);
1267
			year = calendar.get(Calendar.YEAR);
1268
			day = calendar.get(Calendar.DAY_OF_MONTH);
507 rajveer 1269
		}catch (Exception e){
555 chandransh 1270
			e.printStackTrace();
507 rajveer 1271
		}
517 rajveer 1272
		context.put("name", name);
1273
		context.put("email", email);
1274
		context.put("month", month+"");
1275
		context.put("day", day+"");
1276
		context.put("year", year+"");
1277
		context.put("subscribe", subscribe);
1278
		context.put("sex", sex);
507 rajveer 1279
		htmlString = getHtmlFromVelocity(templateFile, context);
1280
		return htmlString;
1281
	}
1282
 
1283
	private String getCompletedOrdersHtml(long userId) {
1284
		String htmlString = "";
1285
		VelocityContext context = new VelocityContext();
1286
		String templateFile = "templates/completedorders.vm";
1287
		TransactionServiceClient transactionServiceClient = null;
1288
		in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
1289
		List<Order> orders = null;
1290
		try{
1291
			transactionServiceClient = new TransactionServiceClient();
1292
			orderClient = transactionServiceClient.getClient();
1293
			orders = orderClient.getOrdersForCustomer(userId, 0, (new Date()).getTime(), OrderStatus.DELIVERY_SUCCESS);
1294
 
1295
		}catch (Exception e){
1296
 
1297
		}
1298
		context.put("orders", orders);
1299
		htmlString = getHtmlFromVelocity(templateFile, context);
1300
		return htmlString;
1301
	}
1302
	private String getMyaccountHeaderHtml() {
1303
		String htmlString = "";
1304
		VelocityContext context = new VelocityContext();
1305
		String templateFile = "templates/myaccountheader.vm";
1306
		htmlString = getHtmlFromVelocity(templateFile, context);
1307
		return htmlString;
1308
	}
1309
 
1310
	//ShippingPage
555 chandransh 1311
	public Map<String, String> getShippingPage(long userId, boolean isLoggedIn, long cartId, long itemCount, String userName){
507 rajveer 1312
		Map<String,String> htmlSnippet = new HashMap<String, String>();
555 chandransh 1313
 
1314
		htmlSnippet.put("HEADER", getHeaderHtml(isLoggedIn, userName));
507 rajveer 1315
		System.out.println("HEADER Snippet generated");
1316
 
1317
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
1318
		System.out.println("MAIN_MENU Snippet generated");
1319
 
1320
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
1321
		System.out.println("SEARCH_BAR Snippet generated");
1322
 
1323
		htmlSnippet.put("SHIPPING_HEADER", getShippingHeaderHtml());
1324
		System.out.println("SHIPPING_HEADER Snippet generated");
1325
 
1326
		htmlSnippet.put("SHIPPING_DETAILS", getShippingDetailsHtml(cartId));
1327
		System.out.println("SHIPPING_BAR Snippet generated");
1328
 
1329
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
1330
		System.out.println("CUSTOMER_SERVICE Snippet generated");
1331
 
1332
		htmlSnippet.put("FOOTER", getFooterHtml());
1333
		System.out.println("Footer Snippet generated");
1334
 
1335
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1336
	//	System.out.println("ACCESSORIES Snippet generated")
1337
 
1338
		htmlSnippet.put("JS_FILES", "");
1339
		htmlSnippet.put("CSS_FILES", "");
1340
 
1341
		System.out.println("Returning Generated Responce");
1342
 
1343
		return htmlSnippet;
1344
 
1345
	}
1346
 
1347
	//ShippingPage
555 chandransh 1348
	public Map<String, String> getShippingAddressPage(long userId, boolean isLoggedIn, long cartId, long itemCount, String userName){
507 rajveer 1349
		Map<String,String> htmlSnippet = new HashMap<String, String>();
555 chandransh 1350
 
1351
		htmlSnippet.put("HEADER", getHeaderHtml(isLoggedIn, userName));
507 rajveer 1352
		System.out.println("HEADER Snippet generated");
1353
 
1354
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
1355
		System.out.println("MAIN_MENU Snippet generated");
1356
 
1357
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
1358
		System.out.println("SEARCH_BAR Snippet generated");
1359
 
1360
		htmlSnippet.put("SHIPPING_ADDRESS_HEADER", getMyaccountHeaderHtml());
1361
		System.out.println("SHIPPING_ADDRESS_HEADER Snippet generated");
1362
 
1363
		htmlSnippet.put("SHIPPING_ADDRESS_DETAILS", getShippingAddressDetailsHtml(userId));
1364
		System.out.println("SHIPPING_ADDRESS_BAR Snippet generated");
1365
 
1366
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
1367
		System.out.println("CUSTOMER_SERVICE Snippet generated");
1368
 
1369
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, false));
1370
		System.out.println("MY_RESEARCH Snippet generated");
1371
 
1372
		htmlSnippet.put("FOOTER", getFooterHtml());
1373
		System.out.println("Footer Snippet generated");
1374
 
1375
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1376
	//	System.out.println("ACCESSORIES Snippet generated")
1377
 
1378
		htmlSnippet.put("JS_FILES", "");
1379
		htmlSnippet.put("CSS_FILES", "");
1380
 
1381
		System.out.println("Returning Generated Responce");
1382
 
1383
		return htmlSnippet;
1384
 
1385
	}
1386
 
1387
	private String getShippingHeaderHtml() {
1388
		String htmlString = "";
1389
		VelocityContext context = new VelocityContext();
1390
		String templateFile = "templates/shippingheader.vm";
1391
		htmlString = getHtmlFromVelocity(templateFile, context);
1392
		return htmlString;
1393
	}
1394
 
1395
	private String getShippingAddressDetailsHtml(long userId){
1396
		String htmlString = "";
1397
		VelocityContext context = new VelocityContext();
1398
		String templateFile = "templates/shippingaddressdetails.vm";
1399
		long defaultAddressId = 0;
517 rajveer 1400
		List<Address> addresses = null;
507 rajveer 1401
 
1402
		UserContextServiceClient userContextServiceClient = null;
1403
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
1404
		try {
1405
			userContextServiceClient = new UserContextServiceClient();
1406
			userClient = userContextServiceClient.getClient();
555 chandransh 1407
			User user = userClient.getUserById(userId);
1408
			addresses = user.getAddresses();
1409
			defaultAddressId = user.getDefaultAddressId();
507 rajveer 1410
		} catch (Exception e) {
1411
			e.printStackTrace();
1412
		}
517 rajveer 1413
		context.put("defaultAddressId", defaultAddressId+"");
507 rajveer 1414
		context.put("addresses", addresses);
1415
 
1416
		htmlString = getHtmlFromVelocity(templateFile, context);
1417
		return htmlString;
1418
	}
1419
 
1420
	private String getShippingDetailsHtml(long cartId) {
1421
		String htmlString = "";
1422
		VelocityContext context = new VelocityContext();
1423
		String templateFile = "templates/shippingdetails.vm";
517 rajveer 1424
		List<Map<String,String>> items = null;
507 rajveer 1425
		double totalamount= 0.0;
517 rajveer 1426
		List<Address> addresses = null;
1427
		long defaultAddressId = 0;
555 chandransh 1428
 
507 rajveer 1429
		CatalogServiceClient catalogServiceClient  = null;
1430
		in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = null;
1431
		UserContextServiceClient userContextServiceClient = null;
1432
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
1433
 
1434
		try {
1435
			catalogServiceClient = new CatalogServiceClient();
1436
			catalogClient = catalogServiceClient.getClient();
1437
			userContextServiceClient = new UserContextServiceClient();
1438
			userClient = userContextServiceClient.getClient();
1439
 
1440
 
555 chandransh 1441
			Cart cart = userClient.getCart(cartId);
507 rajveer 1442
			List<Line> lineItems = cart.getLines();
1443
 
517 rajveer 1444
			if( ! lineItems.isEmpty())
1445
			{
1446
				items = new ArrayList<Map<String,String>>();
507 rajveer 1447
 
517 rajveer 1448
				for (Line line : lineItems) {
1449
					Map<String, String> itemdetail = new HashMap<String, String>();
1450
					Item item = catalogClient.getItemByCatalogId(line.getItemId());
1451
					String itemName = ((item.getManufacturerName() != null) ? item.getManufacturerName() + " " : "")
1452
										+ ((item.getModelName() != null) ? item.getModelName() + " " : "") 
1453
										+ (( item.getModelNumber() != null ) ? item.getModelNumber() : "" );
1454
 
1455
					itemdetail.put("ITEM_NAME", itemName);
1456
					itemdetail.put("ITEM_ID", line.getItemId()+"");
1457
					itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
1458
					itemdetail.put("MRP", ((int)item.getMrp())+"");
536 rajveer 1459
					itemdetail.put("SELLING_PRICE", (int)item.getSellingPrice()+"");
1460
					itemdetail.put("TOTAL_PRICE", (int)(item.getSellingPrice()*line.getQuantity())+"");
517 rajveer 1461
					itemdetail.put("SHIPPING_TIME", 48+"");
536 rajveer 1462
					totalamount = totalamount + line.getQuantity()*item.getSellingPrice();
517 rajveer 1463
					items.add(itemdetail);				
1464
				}
507 rajveer 1465
			}
1466
 
555 chandransh 1467
			User user = userClient.getUserById(cart.getUserId());
1468
			addresses = user.getAddresses();
1469
			defaultAddressId = user.getDefaultAddressId();
507 rajveer 1470
 
1471
		}catch (Exception e){
1472
			e.printStackTrace();
1473
		}
1474
 
1475
		context.put("items", items);
536 rajveer 1476
		context.put("totalamount", (int)totalamount+"");
507 rajveer 1477
		context.put("addresses", addresses);
517 rajveer 1478
		context.put("defaultAddressId", defaultAddressId+"");
507 rajveer 1479
		htmlString = getHtmlFromVelocity(templateFile, context);
1480
		return htmlString;
1481
	}
1482
 
1483
 
1484
	//ShoppingCartPage
555 chandransh 1485
	public Map<String, String> getShoppingCartPage(long userId, boolean isLoggedIn, long cartId, long itemCount, String userName){
507 rajveer 1486
		Map<String,String> htmlSnippet = new HashMap<String, String>();
555 chandransh 1487
 
1488
		htmlSnippet.put("HEADER", getHeaderHtml(isLoggedIn, userName));
507 rajveer 1489
		System.out.println("HEADER Snippet generated");
1490
 
1491
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
1492
		System.out.println("MAIN_MENU Snippet generated");
1493
 
1494
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
1495
		System.out.println("SEARCH_BAR Snippet generated");
1496
 
1497
		htmlSnippet.put("CART_HEADER", getCartHeaderHtml());
1498
		System.out.println("CART_HEADER Snippet generated");
1499
 
1500
		htmlSnippet.put("CART_DETAILS", getCartDetailsHtml(cartId));
1501
		System.out.println("SEARCH_BAR Snippet generated");
1502
 
1503
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
1504
		System.out.println("CUSTOMER_SERVICE Snippet generated");
1505
 
555 chandransh 1506
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, isLoggedIn));
507 rajveer 1507
		System.out.println("MY_RESEARCH Snippet generated");
1508
 
1509
		htmlSnippet.put("FOOTER", getFooterHtml());
1510
		System.out.println("Footer Snippet generated");
1511
 
1512
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1513
	//	System.out.println("ACCESSORIES Snippet generated")
1514
 
1515
		htmlSnippet.put("JS_FILES", "");
1516
		htmlSnippet.put("CSS_FILES", "");
1517
 
1518
		System.out.println("Returning Generated Responce");
1519
 
1520
		return htmlSnippet;
1521
 
1522
	}
1523
 
1524
	private String getCartHeaderHtml() {
1525
		String htmlString = "";
1526
		VelocityContext context = new VelocityContext();
1527
		String templateFile = "templates/cartheader.vm";
1528
		htmlString = getHtmlFromVelocity(templateFile, context);
1529
		return htmlString;
1530
	}
1531
 
1532
 
1533
	private String getCartDetailsHtml(long cartId) {
1534
		String htmlString = "";
1535
		VelocityContext context = new VelocityContext();
1536
		String templateFile = "templates/cartdetails.vm";
517 rajveer 1537
		List<Map<String,String>> items = null;
507 rajveer 1538
		double totalamount= 0.0;
1539
 
555 chandransh 1540
		UserContextServiceClient userServiceClient = null;
1541
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
507 rajveer 1542
		CatalogServiceClient catalogServiceClient  = null;
1543
		in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = null;
1544
 
1545
		try {
1546
			catalogServiceClient = new CatalogServiceClient();
1547
			catalogClient = catalogServiceClient.getClient();
555 chandransh 1548
			userServiceClient = new UserContextServiceClient();
1549
			userClient = userServiceClient.getClient();
507 rajveer 1550
 
555 chandransh 1551
			Cart cart = userClient.getCart(cartId);
507 rajveer 1552
			List<Line> lineItems = cart.getLines();
517 rajveer 1553
			if(lineItems.size() != 0){
1554
				items = new ArrayList<Map<String,String>>();
1555
				for (Line line : lineItems) {
1556
 
1557
					Map<String, String> itemdetail = new HashMap<String, String>();
1558
					Item item = catalogClient.getItemByCatalogId(line.getItemId());
1559
 
1560
					String itemName = ((item.getManufacturerName() != null) ? item.getManufacturerName() + " " : "")
1561
										+ ((item.getModelName() != null) ? item.getModelName() + " " : "") 
1562
										+ (( item.getModelNumber() != null ) ? item.getModelNumber() : "" );
1563
 
1564
					itemdetail.put("ITEM_NAME", itemName);
1565
					System.out.println(itemdetail.get("ITEM_NAME"));
1566
					itemdetail.put("ITEM_ID", line.getItemId()+"");
1567
					itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
1568
					itemdetail.put("MRP", ((int)item.getMrp())+"");
1569
					itemdetail.put("SELLING_PRICE", ((int)item.getSellingPrice())+"");
1570
					itemdetail.put("TOTAL_PRICE", ((int)((item.getSellingPrice()*line.getQuantity())))+"");
1571
					itemdetail.put("SHIPPING_TIME", 48+"");
1572
					totalamount = totalamount + line.getQuantity()*item.getSellingPrice();
1573
					items.add(itemdetail);				
507 rajveer 1574
				}
1575
			}
1576
 
1577
		}catch (Exception e){
1578
			e.printStackTrace();
1579
		}
1580
 
1581
		context.put("items", items);
517 rajveer 1582
		context.put("totalamount", ((int)totalamount)+"");
507 rajveer 1583
		htmlString = getHtmlFromVelocity(templateFile, context);
1584
		return htmlString;
1585
	}
1586
 
1587
 
1588
	public Map<String, String> getShoppingCartPage_Old(long userId, boolean isSessionId, Map<String, String> params)
1589
	{
555 chandransh 1590
		UserContextServiceClient userServiceClient = null;
1591
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
507 rajveer 1592
 
1593
		try {
555 chandransh 1594
			userServiceClient = new UserContextServiceClient();
1595
			userClient = userServiceClient.getClient();
507 rajveer 1596
 
555 chandransh 1597
			Cart cart = userClient.getCurrentCart(userId);
507 rajveer 1598
 
1599
			List<Line> lineItems = cart.getLines();
1600
			List<Map<String,String>> items = new ArrayList<Map<String,String>>(); 
1601
 
1602
			for (Line line : lineItems) {
1603
//				long productId = getCatalogIdByItemId(line.getItemId());
1604
				long productId = line.getItemId();
1605
				Map<String, String> productDetails = getProductDetails(productId);
1606
				double mrp = getItemMrpByCatalogId(productId);
1607
				double sellingPrice = getItemSellingPriceByCatalogId(productId);
1608
				double saving = (mrp - sellingPrice)/mrp*100; 
1609
				saving = Math.round(saving);
1610
				Map<String, String> item = new HashMap<String, String>();
1611
				item.put("BRAND_NAME", productDetails.get("BRAND_NAME"));
1612
				item.put("MODEL_NAME", productDetails.get("MODEL_NAME"));
1613
				item.put("MODEL_NUMBER", productDetails.get("MODEL_NUMBER"));
1614
				item.put("ITEM_ID", line.getItemId()+"");
1615
				item.put("ITEM_QUANTITY", line.getQuantity()+"");
1616
				item.put("MRP", mrp+"");
1617
				item.put("SELLING_PRICE", sellingPrice+"");
1618
				item.put("SAVING", sellingPrice+"");
1619
				items.add(item);
1620
			}
1621
 
1622
			String templateFile = "templates/shoppingcart.vm";
1623
			VelocityContext context = new VelocityContext();	
1624
			context.put("items", items);
1625
 
1626
			String htmlString = getHtmlFromVelocity(templateFile, context);
1627
			System.out.println("My Cart Snippet generated" + htmlString);
1628
 
1629
			Map<String,String> htmlSnippet = new HashMap<String, String>();
1630
			htmlSnippet.put("SHOPPING_CART", htmlString);
1631
 
1632
			return htmlSnippet;
1633
 
1634
		} catch (ShoppingCartException e) {
1635
			// TODO Auto-generated catch block
1636
			e.printStackTrace();
1637
		}catch (Exception e) {
1638
			// TODO Auto-generated catch block
1639
			e.printStackTrace();
1640
		}
1641
 
1642
		return null;
1643
	}
1644
 
1645
 
1646
	public long getCatalogIdByItemId(long itemId){
1647
		CatalogServiceClient catalogServiceClient = null;
1648
		Client client = null;
1649
 
1650
		try {
1651
			catalogServiceClient = new CatalogServiceClient();
1652
			client = catalogServiceClient.getClient();
1653
 
1654
			return client.getItem(itemId).getCatalogItemId();
1655
		} catch (InventoryServiceException e) {
1656
			// TODO Auto-generated catch block
1657
			e.printStackTrace();
1658
		} catch (TException e) {
1659
			// TODO Auto-generated catch block
1660
			e.printStackTrace();
1661
		} catch (Exception e) {
1662
			// TODO Auto-generated catch block
1663
			e.printStackTrace();
1664
		}
1665
		return -1;
1666
	}
1667
 
1668
//	private	void addItemToCart(long catalogItemId, long userId) throws Exception{
1669
//		UserContextServiceClient userContextServiceClient = null;
1670
//		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
1671
//		userContextServiceClient = new UserContextServiceClient();
1672
//		userClient = userContextServiceClient.getClient();
1673
//
1674
//		ShoppingCartClient shoppingCartClient = null;
1675
//		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = null;
1676
//		shoppingCartClient = new ShoppingCartClient();
1677
//		cartClient = shoppingCartClient.getClient();
1678
//		
1679
//		Cart cart = cartClient.getCurrentCart(userId);
1680
//		//if user is logged in create  new cart
1681
//		//if( userClient.getState(userId, false).isIsLoggedIn()){
1682
//		if(cart == null){
1683
//			cartClient.createCart(userId);
1684
//			cart = cartClient.getCurrentCart(userId);
1685
//		}
1686
//		cartClient.addItemToCart(cart.getId(), catalogItemId, 1);
1687
//	}
1688
 
1689
		//userClient.getState(userId, isSessionId);
1690
 
1691
//		TransactionServiceClient transactionServiceClient = null;
1692
//		in.shop2020.model.v1.order.TransactionService.Client client = null;
1693
//		
1694
//		Cart cart = cartClient.getCurrentCart(userId);
555 chandransh 1695
//		List<LineItem> lineItems = cart.getLines();
507 rajveer 1696
//		
555 chandransh 1697
//		LineItem ln = lineItems.get(0);
507 rajveer 1698
//		ln.getItemId();
1699
//		ln.getId();
1700
//		ln.getQuantity();
1701
//		ln.getStatusMessage();
1702
//		long productId = 10;
1703
//		
1704
//		Cart cart = cartClient.getCurrentCart(0);
555 chandransh 1705
//		List<LineItem> lineItems = cart.getLines();
1706
//		LineItem ln = lineItems.get(0);
507 rajveer 1707
//		ln.getItemId();
1708
//		ln.getId();
1709
//		
1710
//		ln.getStatusMessage();
1711
//		
1712
 
1713
	private	Map<String,String> getProductDetails(long productId){
1714
		Map<String, String> productDetails = new HashMap<String, String>();
1715
 
1716
		EntityContainer entContainer = 	Catalog.getInstance().getEntityContainer();
1717
		ExpandedEntity expEntity;
1718
		try {
1719
			expEntity = entContainer.getExpandedEntity(productId);
1720
 
1721
			productDetails.put("BRAND_NAME", expEntity.getBrand());
1722
			productDetails.put("MODEL_NUMBER", expEntity.getModelNumber());
1723
			productDetails.put("MODEL_NAME", expEntity.getModelName());
1724
			productDetails.put("CATEGORY_ID", expEntity.getCategoryID() + "");
1725
			productDetails.put("CATEGORY_NAME", expEntity.getCategory().getLabel());
1726
			productDetails.put("INTRODUCTION_TEXT", expEntity.getSlide(130001).getFreeformContent().getFreeformText());
1727
			return productDetails;
1728
//			expEntity.getBrand();
1729
//			expEntity.getModelNumber();
1730
//			expEntity.getModelName();
1731
//			expEntity.getCategoryID();
1732
//			expEntity.getCategory().getLabel();
1733
//			expEntity.getSlide(130001).getFreeformContent().getFreeformText();
1734
		} catch (Exception e) {
1735
			// TODO Auto-generated catch block
1736
			e.printStackTrace();
1737
		}
1738
 
1739
		return null;
1740
	}
1741
 
1742
 
1743
	private	String getMyOrdersDiv(long userId){
1744
		TransactionServiceClient transactionServiceClient = null;
1745
		in.shop2020.model.v1.order.TransactionService.Client client = null;
1746
		String htmlString = new String();
1747
			try {
1748
				transactionServiceClient = new TransactionServiceClient();
1749
				client = transactionServiceClient.getClient();
1750
				List<Transaction> transactions = client.getTransactionsForCustomer(userId, 0, 0, null);
1751
 
1752
				String templateFile = "templates/myorders.vm";
1753
				VelocityContext context = new VelocityContext();	
1754
				context.put("transactions", transactions);
1755
				if(!transactions.isEmpty()){
1756
					Transaction tn = transactions.get(0);
1757
					java.sql.Date d = new java.sql.Date(tn.getCreatedOn());
1758
					System.out.println("Date is" + d.toString());
1759
				}
1760
				htmlString = getHtmlFromVelocity(templateFile, context);
1761
				System.out.println("Orders Info Snippet generated" + htmlString);
1762
				return htmlString;
1763
 
1764
			} catch (UserContextException e) {
1765
				// TODO Auto-generated catch block
1766
				e.printStackTrace();
1767
			} catch (Exception e) {
1768
				// TODO Auto-generated catch block
1769
				e.printStackTrace();
1770
			}
1771
			return "MY_ORDERS";
1772
	}
1773
 
1774
	public String getHtmlFromVelocity(String templateFile, VelocityContext context){
1775
		Properties p = new Properties();
1776
		p.setProperty("resource.loader", "class");
1777
		p.setProperty("class.resource.loader.class",
1778
		"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
1779
 
1780
 
1781
		try {
1782
			Velocity.init(p);
1783
			Template template = Velocity.getTemplate(templateFile);
1784
			if(template != null) {
1785
				StringWriter writer = new StringWriter();
1786
				template.merge(context, writer);
1787
				writer.flush();
1788
				writer.close();
1789
				return writer.toString();
1790
			}
1791
 
1792
			} catch (ResourceNotFoundException e) {
1793
				// TODO Auto-generated catch block
1794
				e.printStackTrace();
1795
			} catch (ParseErrorException e) {
1796
				// TODO Auto-generated catch block
1797
				e.printStackTrace();
1798
			} catch (MethodInvocationException e) {
1799
				// TODO Auto-generated catch block
1800
				e.printStackTrace();
1801
			} catch (IOException e) {
1802
				// TODO Auto-generated catch block
1803
				e.printStackTrace();
1804
			} catch (Exception e) {
1805
				// TODO Auto-generated catch block
1806
				e.printStackTrace();
1807
			}
1808
 
1809
		return null;
1810
	}
1811
 
1812
	public double getItemMrpByCatalogId(long productId){
1813
		CatalogServiceClient catalogServiceClient = null;
1814
		Client client = null;
1815
		Double itemPrice = 0.0;
1816
		try {
1817
			catalogServiceClient = new CatalogServiceClient();
1818
			client = catalogServiceClient.getClient();
1819
			Item item = client.getItemByCatalogId(productId);
1820
			itemPrice = item.getMrp();
1821
		}
1822
		catch(Exception e){
1823
			e.printStackTrace();
1824
		}
1825
		return itemPrice;
1826
	}
1827
 
1828
	public double getItemSellingPriceByCatalogId(long productId){
1829
		CatalogServiceClient catalogServiceClient = null;
1830
		Client client = null;
1831
		Double itemPrice = 0.0;
1832
		try {
1833
			catalogServiceClient = new CatalogServiceClient();
1834
			client = catalogServiceClient.getClient();
1835
			Item item = client.getItemByCatalogId(productId);
1836
			itemPrice = item.getSellingPrice();
1837
		}
1838
		catch(Exception e){
1839
			e.printStackTrace();
1840
		}
1841
		return itemPrice;
1842
	}
1843
 
517 rajveer 1844
 
1845
	public String getCategoryHeaderSnippet() {
1846
		String htmlString = "";
1847
		VelocityContext context = new VelocityContext();
1848
		String templateFile = "templates/categoryheader.vm";
1849
		htmlString = getHtmlFromVelocity(templateFile, context);
1850
		return htmlString;
1851
	}
1852
 
507 rajveer 1853
 
1854
 
1855
}
1856