Subversion Repositories SmartDukaan

Rev

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