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
 
620 rajveer 350
	public String getAccessoriesHtml(long productId) {
555 chandransh 351
		return getWidgetDiv(0, WidgetType.ACCESSORIES, "accessories.vm");
507 rajveer 352
	}
353
 
354
 
355
 
620 rajveer 356
	public String getSimilarProductsHtml(long productId) {
555 chandransh 357
		return getWidgetDiv(0, WidgetType.SIMILAR_ITEMS, "similaritems.vm");
507 rajveer 358
	}
359
 
360
 
361
 
620 rajveer 362
	public 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
 
620 rajveer 392
	public String getReviewsHtml(long productId) {
507 rajveer 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
 
620 rajveer 405
	public String getLocatorHtml() {
507 rajveer 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
 
620 rajveer 432
	public String getSlideGuideHtml(long productId) {
507 rajveer 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
 
620 rajveer 503
	public String getSocialUtilsHtml(long productId) {
507 rajveer 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
 
620 rajveer 516
	public String getProductSummaryHtml(long productId, boolean toBeDecided) {
507 rajveer 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();
620 rajveer 904
		context.put("userId", userId);
507 rajveer 905
		context.put("itemDetails", itemDetails);
906
 
907
		return getHtmlFromVelocity("templates/"+templateFile, context);
908
	}
909
 
910
	/*
911
	private	String getWidgetDiv(long productId, String userId, WidgetType widgetType, String templateFile){
912
		long userID;
913
		if(userId.compareTo("") == 0){
914
			userID = 0;
915
		}else{
916
			userID = Long.parseLong(userId);
917
		}
918
 
919
		WidgetServiceClient widgetServiceClient = null;
920
		in.shop2020.model.v1.widgets.WidgetService.Client client = null;
921
		Widget widget = null;
922
		try {
923
			widgetServiceClient = new WidgetServiceClient();
924
			client = widgetServiceClient.getClient();
925
			widget = client.getWidget(widgetType, userID, true);
926
		} catch (Exception e) {
927
			e.printStackTrace();
928
		}
929
 
930
 
931
		List<Map<String, String>> itemDetails = null;
932
 
933
		if(widget != null){
934
			List<WidgetItem> items = widget.getItems();
935
			itemDetails = new ArrayList<Map<String, String>>();
936
 
937
			for(WidgetItem item: items){
938
				Map<String, String> itemDetail = new HashMap<String, String>();
939
 
940
				itemDetail.put("ITEM_ID", item.getItem_id()+"");
941
				itemDetail.put("ITEM_NAME", "ID"+item.getItem_id());
942
				itemDetail.put("ITEM_SNIPPET", item.getSnippet());
943
				itemDetail.put("ITEM_PRICE", getItemPriceByCatalogId(item.getItem_id())+"");
944
				itemDetails.add(itemDetail);
945
			}
946
		}else{
947
			System.out.println("widget not found");
948
		}
949
 
950
		VelocityContext context = new VelocityContext();
951
		context.put("itemDetails", itemDetails);
952
 
953
		return getHtmlFromVelocity("velocity/"+templateFile, context);
954
	}
955
*/
956
 
957
 
958
	public Map<String, String> getCompletedOrdersPage(long userId, long itemCount,
959
			Map<String, String> params) {
960
		Map<String,String> htmlSnippet = new HashMap<String, String>();
555 chandransh 961
 
962
		htmlSnippet.put("HEADER", getHeaderHtml(false, ""));
507 rajveer 963
		System.out.println("HEADER Snippet generated");
964
 
965
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
966
		System.out.println("MAIN_MENU Snippet generated");
967
 
968
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
969
		System.out.println("SEARCH_BAR Snippet generated");
970
 
971
		htmlSnippet.put("MYACCOUNT_HEADER", getMyaccountHeaderHtml());
972
		System.out.println("MYACCOUNT_HEADER Snippet generated");
973
 
974
		htmlSnippet.put("MYACCOUNT_DETAILS", getCompletedOrdersHtml(userId));
975
		System.out.println("MYACCOUNT_DETAILS Snippet generated");
976
 
977
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
978
		System.out.println("CUSTOMER_SERVICE Snippet generated");
979
 
980
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, false));
981
		System.out.println("MY_RESEARCH Snippet generated");
620 rajveer 982
 
983
		htmlSnippet.put("BROWSE_HISTORY", getBrowseHistoryHtml(userId, false));
984
		System.out.println("BROWSE_HISTORY Snippet generated");
985
 
507 rajveer 986
		htmlSnippet.put("FOOTER", getFooterHtml());
987
		System.out.println("Footer Snippet generated");
988
 
989
		htmlSnippet.put("JS_FILES", "");
990
		htmlSnippet.put("CSS_FILES", "");
991
 
992
		System.out.println("Returning Generated Responce");
993
 
994
 
995
		return htmlSnippet;
996
 
997
	}
998
 
999
 
555 chandransh 1000
	public Map<String, String> getMyAccountPage(long userId, long itemCount, String userName, boolean isLoggedIn)
1001
	{
1002
 
507 rajveer 1003
		Map<String,String> htmlSnippet = new HashMap<String, String>();
555 chandransh 1004
 
1005
		htmlSnippet.put("HEADER", getHeaderHtml(isLoggedIn, userName));
507 rajveer 1006
		System.out.println("HEADER Snippet generated");
1007
 
1008
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
1009
		System.out.println("MAIN_MENU Snippet generated");
1010
 
1011
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
1012
		System.out.println("SEARCH_BAR Snippet generated");
1013
 
1014
		htmlSnippet.put("MYACCOUNT_HEADER", getMyaccountHeaderHtml());
1015
		System.out.println("MYACCOUNT_HEADER Snippet generated");
1016
 
1017
		htmlSnippet.put("MYACCOUNT_DETAILS", getMyaccountDetailsHtml(userId));
1018
		System.out.println("MYACCOUNT_DETAILS Snippet generated");
1019
 
1020
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
1021
		System.out.println("CUSTOMER_SERVICE Snippet generated");
1022
 
1023
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, false));
1024
		System.out.println("MY_RESEARCH Snippet generated");
620 rajveer 1025
 
1026
		htmlSnippet.put("BROWSE_HISTORY", getBrowseHistoryHtml(userId, false));
1027
		System.out.println("BROWSE_HISTORY Snippet generated");
507 rajveer 1028
 
1029
		htmlSnippet.put("FOOTER", getFooterHtml());
1030
		System.out.println("Footer Snippet generated");
1031
 
1032
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1033
	//	System.out.println("ACCESSORIES Snippet generated")
1034
 
1035
		htmlSnippet.put("JS_FILES", "");
1036
		htmlSnippet.put("CSS_FILES", "");
1037
 
1038
		System.out.println("Returning Generated Responce");
555 chandransh 1039
 
507 rajveer 1040
		return htmlSnippet;
1041
	}
1042
 
1043
 
555 chandransh 1044
	public Map<String, String> getPersonalDetailsPage(long userId, long itemCount, String userName, boolean isLoggedIn)
1045
	{
507 rajveer 1046
		Map<String,String> htmlSnippet = new HashMap<String, String>();
555 chandransh 1047
 
1048
		htmlSnippet.put("HEADER", getHeaderHtml(isLoggedIn, userName));
507 rajveer 1049
		System.out.println("HEADER Snippet generated");
1050
 
1051
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
1052
		System.out.println("MAIN_MENU Snippet generated");
1053
 
1054
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
1055
		System.out.println("SEARCH_BAR Snippet generated");
1056
 
1057
		htmlSnippet.put("MYACCOUNT_HEADER", getMyaccountHeaderHtml());
1058
		System.out.println("MYACCOUNT_HEADER Snippet generated");
1059
 
1060
		htmlSnippet.put("PERSONAL_DETAILS", getPersonalDetailsHtml(userId));
1061
		System.out.println("PERSONAL_DETAILS Snippet generated");
1062
 
1063
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
1064
		System.out.println("CUSTOMER_SERVICE Snippet generated");
1065
 
1066
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, false));
1067
		System.out.println("MY_RESEARCH Snippet generated");
1068
 
620 rajveer 1069
		htmlSnippet.put("BROWSE_HISTORY", getBrowseHistoryHtml(userId, false));
1070
		System.out.println("BROWSE_HISTORY Snippet generated");
1071
 
507 rajveer 1072
		htmlSnippet.put("FOOTER", getFooterHtml());
1073
		System.out.println("Footer Snippet generated");
1074
 
1075
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1076
	//	System.out.println("ACCESSORIES Snippet generated")
1077
 
1078
		htmlSnippet.put("JS_FILES", "");
1079
		htmlSnippet.put("CSS_FILES", "");
1080
 
1081
		System.out.println("Returning Generated Responce");
1082
 
1083
 
1084
		return htmlSnippet;
1085
	}
1086
 
555 chandransh 1087
	public Map<String, String> getLoginDetailsPage(long userId, long itemCount, String userName, boolean isLoggedIn)
1088
	{
507 rajveer 1089
		Map<String,String> htmlSnippet = new HashMap<String, String>();
555 chandransh 1090
 
1091
		htmlSnippet.put("HEADER", getHeaderHtml(isLoggedIn, userName));
507 rajveer 1092
		System.out.println("HEADER Snippet generated");
1093
 
1094
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
1095
		System.out.println("MAIN_MENU Snippet generated");
1096
 
1097
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
1098
		System.out.println("SEARCH_BAR Snippet generated");
1099
 
1100
		htmlSnippet.put("MYACCOUNT_HEADER", getMyaccountHeaderHtml());
1101
		System.out.println("MYACCOUNT_HEADER Snippet generated");
1102
 
1103
		htmlSnippet.put("LOGIN_DETAILS", getLoginDetailsHtml(userId));
1104
		System.out.println("LOGIN_DETAILS Snippet generated");
1105
 
1106
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
1107
		System.out.println("CUSTOMER_SERVICE Snippet generated");
1108
 
1109
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, false));
1110
		System.out.println("MY_RESEARCH Snippet generated");
1111
 
620 rajveer 1112
		htmlSnippet.put("BROWSE_HISTORY", getBrowseHistoryHtml(userId, false));
1113
		System.out.println("BROWSE_HISTORY Snippet generated");
1114
 
507 rajveer 1115
		htmlSnippet.put("FOOTER", getFooterHtml());
1116
		System.out.println("Footer Snippet generated");
1117
 
1118
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1119
	//	System.out.println("ACCESSORIES Snippet generated")
1120
 
1121
		htmlSnippet.put("JS_FILES", "");
1122
		htmlSnippet.put("CSS_FILES", "");
1123
 
1124
		System.out.println("Returning Generated Responce");
1125
 
1126
 
1127
		return htmlSnippet;
1128
	}
1129
 
1130
 
1131
 
1132
	public Map<String, String> getOrderDetailsPage(long userId, long itemCount, long orderId,
555 chandransh 1133
			Map<String, String> parameters) {
507 rajveer 1134
		Map<String,String> htmlSnippet = new HashMap<String, String>();
555 chandransh 1135
		boolean isLoggedIn = Boolean.parseBoolean(parameters.get("IS_LOGGED_IN"));
1136
		String userName = parameters.get("USER_NAME");
1137
 
1138
		htmlSnippet.put("HEADER", getHeaderHtml(isLoggedIn, userName));
507 rajveer 1139
		System.out.println("HEADER Snippet generated");
1140
 
1141
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
1142
		System.out.println("MAIN_MENU Snippet generated");
1143
 
1144
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
1145
		System.out.println("SEARCH_BAR Snippet generated");
1146
 
1147
		htmlSnippet.put("MYACCOUNT_HEADER", getMyaccountHeaderHtml());
1148
		System.out.println("MYACCOUNT_HEADER Snippet generated");
1149
 
1150
		htmlSnippet.put("ORDER_DETAILS", getOrderDetailsHtml(orderId));
1151
		System.out.println("MYACCOUNT_DETAILS Snippet generated");
1152
 
1153
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
1154
		System.out.println("CUSTOMER_SERVICE Snippet generated");
1155
 
1156
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, false));
1157
		System.out.println("MY_RESEARCH Snippet generated");
1158
 
620 rajveer 1159
		htmlSnippet.put("BROWSE_HISTORY", getBrowseHistoryHtml(userId, false));
1160
		System.out.println("BROWSE_HISTORY Snippet generated");
1161
 
507 rajveer 1162
		htmlSnippet.put("FOOTER", getFooterHtml());
1163
		System.out.println("Footer Snippet generated");
1164
 
1165
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1166
	//	System.out.println("ACCESSORIES Snippet generated")
1167
 
1168
		htmlSnippet.put("JS_FILES", "");
1169
		htmlSnippet.put("CSS_FILES", "");
1170
 
1171
		System.out.println("Returning Generated Responce");
1172
 
1173
 
1174
		return htmlSnippet;
1175
	}
1176
 
1177
 
1178
 
1179
	private String getOrderDetailsHtml(long orderId) {
1180
		String htmlString = "";
1181
		VelocityContext context = new VelocityContext();
1182
		String templateFile = "templates/orderdetails.vm";
1183
		TransactionServiceClient transactionServiceClient = null;
1184
		in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
1185
		Order order = null;
517 rajveer 1186
		Date orderedOn = null, deliveryEstimate = null;
507 rajveer 1187
		try{
1188
			transactionServiceClient = new TransactionServiceClient();
1189
			orderClient = transactionServiceClient.getClient();
1190
			order = orderClient.getOrder(orderId);
517 rajveer 1191
			orderedOn = new Date(order.getCreated_timestamp());
1192
			deliveryEstimate = new Date(order.getExpected_delivery_time());
507 rajveer 1193
		}catch (Exception e){
1194
 
1195
		}
517 rajveer 1196
 
1197
		SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
583 rajveer 1198
		SimpleDateFormat dateformat1 = new SimpleDateFormat("dd/MM/yyyy");
507 rajveer 1199
		context.put("order", order);
517 rajveer 1200
		context.put("orderedOn", dateformat.format(orderedOn));
583 rajveer 1201
		context.put("deliveryEstimate", dateformat1.format(deliveryEstimate));
517 rajveer 1202
 
1203
 
507 rajveer 1204
		htmlString = getHtmlFromVelocity(templateFile, context);
1205
		return htmlString;
1206
	}
1207
 
1208
	private String getMyaccountDetailsHtml(long userId) {
1209
		String htmlString = "";
1210
		VelocityContext context = new VelocityContext();
1211
		String templateFile = "templates/myaccount.vm";
1212
		TransactionServiceClient transactionServiceClient = null;
1213
		in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
1214
		List<Order> orders = null;
1215
		try{
1216
			transactionServiceClient = new TransactionServiceClient();
1217
			orderClient = transactionServiceClient.getClient();
1218
			orders = orderClient.getOrdersForCustomer(userId, 0, (new Date()).getTime(), null);
1219
 
1220
		}catch (Exception e){
1221
 
1222
		}
1223
		context.put("orders", orders);
1224
		htmlString = getHtmlFromVelocity(templateFile, context);
1225
		return htmlString;
1226
	}
1227
 
1228
 
1229
	private String getLoginDetailsHtml(long userId) {
1230
		String htmlString = "";
1231
		VelocityContext context = new VelocityContext();
1232
		String templateFile = "templates/logindetails.vm";
1233
		String email = "";
1234
		UserContextServiceClient userContextServiceClient = null;
1235
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
1236
 
1237
		try{
1238
			userContextServiceClient = new UserContextServiceClient();
1239
			userClient = userContextServiceClient.getClient();
555 chandransh 1240
			email = in.shop2020.serving.utils.Utils.getEmailId(userId);
507 rajveer 1241
		}catch (Exception e){
1242
 
1243
		}
1244
		context.put("email", email);
1245
		htmlString = getHtmlFromVelocity(templateFile, context);
1246
		return htmlString;
1247
	}
1248
 
595 rajveer 1249
	public String getPersonalDetailsHtml(long userId) {
507 rajveer 1250
		String htmlString = "";
1251
		VelocityContext context = new VelocityContext();
1252
		String templateFile = "templates/personaldetails.vm";
1253
		String email = "";
517 rajveer 1254
		String name = "";
569 rajveer 1255
		String dateOfBirth = "";
517 rajveer 1256
		String sex = "";
1257
		String subscribe = "false";
507 rajveer 1258
		UserContextServiceClient userContextServiceClient = null;
1259
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
1260
		try{
555 chandransh 1261
			User user = null;
507 rajveer 1262
			userContextServiceClient = new UserContextServiceClient();
1263
			userClient = userContextServiceClient.getClient();
555 chandransh 1264
			user = userClient.getUserById(userId);
507 rajveer 1265
 
555 chandransh 1266
			email = user.getCommunicationEmail();
1267
			name = user.getName();
517 rajveer 1268
 
569 rajveer 1269
			dateOfBirth = user.getDateOfBirth();
507 rajveer 1270
		}catch (Exception e){
555 chandransh 1271
			e.printStackTrace();
507 rajveer 1272
		}
517 rajveer 1273
		context.put("name", name);
1274
		context.put("email", email);
569 rajveer 1275
		context.put("dateOfBirth", dateOfBirth+"");
517 rajveer 1276
		context.put("subscribe", subscribe);
1277
		context.put("sex", sex);
507 rajveer 1278
		htmlString = getHtmlFromVelocity(templateFile, context);
1279
		return htmlString;
1280
	}
1281
 
620 rajveer 1282
	public String getCompletedOrdersHtml(long userId) {
507 rajveer 1283
		String htmlString = "";
1284
		VelocityContext context = new VelocityContext();
1285
		String templateFile = "templates/completedorders.vm";
1286
		TransactionServiceClient transactionServiceClient = null;
1287
		in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
1288
		List<Order> orders = null;
1289
		try{
1290
			transactionServiceClient = new TransactionServiceClient();
1291
			orderClient = transactionServiceClient.getClient();
1292
			orders = orderClient.getOrdersForCustomer(userId, 0, (new Date()).getTime(), OrderStatus.DELIVERY_SUCCESS);
1293
 
1294
		}catch (Exception e){
1295
 
1296
		}
1297
		context.put("orders", orders);
1298
		htmlString = getHtmlFromVelocity(templateFile, context);
1299
		return htmlString;
1300
	}
595 rajveer 1301
	public String getMyaccountHeaderHtml() {
507 rajveer 1302
		String htmlString = "";
1303
		VelocityContext context = new VelocityContext();
1304
		String templateFile = "templates/myaccountheader.vm";
1305
		htmlString = getHtmlFromVelocity(templateFile, context);
1306
		return htmlString;
1307
	}
1308
 
1309
	//ShippingPage
572 chandransh 1310
	public Map<String, String> getShippingPage(long userId, boolean isLoggedIn, long cartId, long itemCount, String userName, String errorMsg){
507 rajveer 1311
		Map<String,String> htmlSnippet = new HashMap<String, String>();
555 chandransh 1312
 
1313
		htmlSnippet.put("HEADER", getHeaderHtml(isLoggedIn, userName));
507 rajveer 1314
		System.out.println("HEADER Snippet generated");
1315
 
1316
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
1317
		System.out.println("MAIN_MENU Snippet generated");
1318
 
1319
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
1320
		System.out.println("SEARCH_BAR Snippet generated");
1321
 
1322
		htmlSnippet.put("SHIPPING_HEADER", getShippingHeaderHtml());
1323
		System.out.println("SHIPPING_HEADER Snippet generated");
1324
 
572 chandransh 1325
		htmlSnippet.put("SHIPPING_DETAILS", getShippingDetailsHtml(cartId, errorMsg));
507 rajveer 1326
		System.out.println("SHIPPING_BAR Snippet generated");
1327
 
1328
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
1329
		System.out.println("CUSTOMER_SERVICE Snippet generated");
1330
 
1331
		htmlSnippet.put("FOOTER", getFooterHtml());
1332
		System.out.println("Footer Snippet generated");
1333
 
1334
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1335
	//	System.out.println("ACCESSORIES Snippet generated")
1336
 
1337
		htmlSnippet.put("JS_FILES", "");
1338
		htmlSnippet.put("CSS_FILES", "");
1339
 
1340
		System.out.println("Returning Generated Responce");
1341
 
1342
		return htmlSnippet;
1343
 
1344
	}
1345
 
1346
	//ShippingPage
555 chandransh 1347
	public Map<String, String> getShippingAddressPage(long userId, boolean isLoggedIn, long cartId, long itemCount, String userName){
507 rajveer 1348
		Map<String,String> htmlSnippet = new HashMap<String, String>();
555 chandransh 1349
 
1350
		htmlSnippet.put("HEADER", getHeaderHtml(isLoggedIn, userName));
507 rajveer 1351
		System.out.println("HEADER Snippet generated");
1352
 
1353
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
1354
		System.out.println("MAIN_MENU Snippet generated");
1355
 
1356
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
1357
		System.out.println("SEARCH_BAR Snippet generated");
1358
 
1359
		htmlSnippet.put("SHIPPING_ADDRESS_HEADER", getMyaccountHeaderHtml());
1360
		System.out.println("SHIPPING_ADDRESS_HEADER Snippet generated");
1361
 
1362
		htmlSnippet.put("SHIPPING_ADDRESS_DETAILS", getShippingAddressDetailsHtml(userId));
1363
		System.out.println("SHIPPING_ADDRESS_BAR Snippet generated");
1364
 
1365
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
1366
		System.out.println("CUSTOMER_SERVICE Snippet generated");
1367
 
1368
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, false));
1369
		System.out.println("MY_RESEARCH Snippet generated");
1370
 
620 rajveer 1371
		htmlSnippet.put("BROWSE_HISTORY", getBrowseHistoryHtml(userId, isLoggedIn));
1372
		System.out.println("BROWSE_HISTORY Snippet generated");
1373
 
507 rajveer 1374
		htmlSnippet.put("FOOTER", getFooterHtml());
1375
		System.out.println("Footer Snippet generated");
1376
 
1377
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1378
	//	System.out.println("ACCESSORIES Snippet generated")
1379
 
1380
		htmlSnippet.put("JS_FILES", "");
1381
		htmlSnippet.put("CSS_FILES", "");
1382
 
1383
		System.out.println("Returning Generated Responce");
1384
 
1385
		return htmlSnippet;
1386
 
1387
	}
1388
 
1389
	private String getShippingHeaderHtml() {
1390
		String htmlString = "";
1391
		VelocityContext context = new VelocityContext();
1392
		String templateFile = "templates/shippingheader.vm";
1393
		htmlString = getHtmlFromVelocity(templateFile, context);
1394
		return htmlString;
1395
	}
1396
 
1397
	private String getShippingAddressDetailsHtml(long userId){
1398
		String htmlString = "";
1399
		VelocityContext context = new VelocityContext();
1400
		String templateFile = "templates/shippingaddressdetails.vm";
1401
		long defaultAddressId = 0;
517 rajveer 1402
		List<Address> addresses = null;
507 rajveer 1403
 
1404
		UserContextServiceClient userContextServiceClient = null;
1405
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
1406
		try {
1407
			userContextServiceClient = new UserContextServiceClient();
1408
			userClient = userContextServiceClient.getClient();
620 rajveer 1409
 
1410
			addresses = userClient.getAllAddressesForUser(userId);
1411
			defaultAddressId = userClient.getDefaultAddressId(userId);
507 rajveer 1412
		} catch (Exception e) {
1413
			e.printStackTrace();
1414
		}
517 rajveer 1415
		context.put("defaultAddressId", defaultAddressId+"");
507 rajveer 1416
		context.put("addresses", addresses);
1417
 
1418
		htmlString = getHtmlFromVelocity(templateFile, context);
1419
		return htmlString;
1420
	}
1421
 
572 chandransh 1422
	private String getShippingDetailsHtml(long cartId, String errorMsg) {
507 rajveer 1423
		String htmlString = "";
1424
		VelocityContext context = new VelocityContext();
1425
		String templateFile = "templates/shippingdetails.vm";
517 rajveer 1426
		List<Map<String,String>> items = null;
507 rajveer 1427
		double totalamount= 0.0;
517 rajveer 1428
		List<Address> addresses = null;
1429
		long defaultAddressId = 0;
555 chandransh 1430
 
507 rajveer 1431
		CatalogServiceClient catalogServiceClient  = null;
1432
		in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = null;
1433
		UserContextServiceClient userContextServiceClient = null;
1434
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
1435
 
1436
		try {
1437
			catalogServiceClient = new CatalogServiceClient();
1438
			catalogClient = catalogServiceClient.getClient();
1439
			userContextServiceClient = new UserContextServiceClient();
1440
			userClient = userContextServiceClient.getClient();
1441
 
1442
 
555 chandransh 1443
			Cart cart = userClient.getCart(cartId);
507 rajveer 1444
			List<Line> lineItems = cart.getLines();
1445
 
517 rajveer 1446
			if( ! lineItems.isEmpty())
1447
			{
1448
				items = new ArrayList<Map<String,String>>();
507 rajveer 1449
 
517 rajveer 1450
				for (Line line : lineItems) {
1451
					Map<String, String> itemdetail = new HashMap<String, String>();
1452
					Item item = catalogClient.getItemByCatalogId(line.getItemId());
1453
					String itemName = ((item.getManufacturerName() != null) ? item.getManufacturerName() + " " : "")
1454
										+ ((item.getModelName() != null) ? item.getModelName() + " " : "") 
1455
										+ (( item.getModelNumber() != null ) ? item.getModelNumber() : "" );
1456
 
1457
					itemdetail.put("ITEM_NAME", itemName);
1458
					itemdetail.put("ITEM_ID", line.getItemId()+"");
1459
					itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
1460
					itemdetail.put("MRP", ((int)item.getMrp())+"");
536 rajveer 1461
					itemdetail.put("SELLING_PRICE", (int)item.getSellingPrice()+"");
1462
					itemdetail.put("TOTAL_PRICE", (int)(item.getSellingPrice()*line.getQuantity())+"");
615 chandransh 1463
					itemdetail.put("SHIPPING_TIME", line.getEstimate()+"");
536 rajveer 1464
					totalamount = totalamount + line.getQuantity()*item.getSellingPrice();
517 rajveer 1465
					items.add(itemdetail);				
1466
				}
507 rajveer 1467
			}
1468
 
555 chandransh 1469
			User user = userClient.getUserById(cart.getUserId());
1470
			addresses = user.getAddresses();
1471
			defaultAddressId = user.getDefaultAddressId();
507 rajveer 1472
 
1473
		}catch (Exception e){
1474
			e.printStackTrace();
1475
		}
1476
 
1477
		context.put("items", items);
536 rajveer 1478
		context.put("totalamount", (int)totalamount+"");
507 rajveer 1479
		context.put("addresses", addresses);
517 rajveer 1480
		context.put("defaultAddressId", defaultAddressId+"");
572 chandransh 1481
		context.put("errorMsg", errorMsg);
507 rajveer 1482
		htmlString = getHtmlFromVelocity(templateFile, context);
1483
		return htmlString;
1484
	}
1485
 
1486
 
1487
	//ShoppingCartPage
572 chandransh 1488
	public Map<String, String> getShoppingCartPage(long userId, boolean isLoggedIn, long cartId, long itemCount, String userName, String errorMsg){
507 rajveer 1489
		Map<String,String> htmlSnippet = new HashMap<String, String>();
555 chandransh 1490
 
1491
		htmlSnippet.put("HEADER", getHeaderHtml(isLoggedIn, userName));
507 rajveer 1492
		System.out.println("HEADER Snippet generated");
1493
 
1494
		htmlSnippet.put("MAIN_MENU", getMainMenuHtml());
1495
		System.out.println("MAIN_MENU Snippet generated");
1496
 
1497
		htmlSnippet.put("SEARCH_BAR", getSearchBarHtml(itemCount, 0));
1498
		System.out.println("SEARCH_BAR Snippet generated");
1499
 
1500
		htmlSnippet.put("CART_HEADER", getCartHeaderHtml());
1501
		System.out.println("CART_HEADER Snippet generated");
1502
 
572 chandransh 1503
		htmlSnippet.put("CART_DETAILS", getCartDetailsHtml(cartId, errorMsg));
507 rajveer 1504
		System.out.println("SEARCH_BAR Snippet generated");
1505
 
1506
		htmlSnippet.put("CUSTOMER_SERVICE", getCustomerServiceHtml());
1507
		System.out.println("CUSTOMER_SERVICE Snippet generated");
1508
 
555 chandransh 1509
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, isLoggedIn));
507 rajveer 1510
		System.out.println("MY_RESEARCH Snippet generated");
1511
 
1512
		htmlSnippet.put("FOOTER", getFooterHtml());
1513
		System.out.println("Footer Snippet generated");
1514
 
1515
	//	htmlSnippet.put("WIDGET_DIV", getWidgetDiv(productId,"", WidgetType.ACCESSORIES));
1516
	//	System.out.println("ACCESSORIES Snippet generated")
1517
 
1518
		htmlSnippet.put("JS_FILES", "");
1519
		htmlSnippet.put("CSS_FILES", "");
1520
 
1521
		System.out.println("Returning Generated Responce");
1522
 
1523
		return htmlSnippet;
1524
 
1525
	}
1526
 
1527
	private String getCartHeaderHtml() {
1528
		String htmlString = "";
1529
		VelocityContext context = new VelocityContext();
1530
		String templateFile = "templates/cartheader.vm";
1531
		htmlString = getHtmlFromVelocity(templateFile, context);
1532
		return htmlString;
1533
	}
1534
 
1535
 
572 chandransh 1536
	private String getCartDetailsHtml(long cartId, String errorMsg) {
507 rajveer 1537
		String htmlString = "";
1538
		VelocityContext context = new VelocityContext();
1539
		String templateFile = "templates/cartdetails.vm";
517 rajveer 1540
		List<Map<String,String>> items = null;
507 rajveer 1541
		double totalamount= 0.0;
1542
 
555 chandransh 1543
		UserContextServiceClient userServiceClient = null;
1544
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
507 rajveer 1545
		CatalogServiceClient catalogServiceClient  = null;
1546
		in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = null;
1547
 
1548
		try {
1549
			catalogServiceClient = new CatalogServiceClient();
1550
			catalogClient = catalogServiceClient.getClient();
555 chandransh 1551
			userServiceClient = new UserContextServiceClient();
1552
			userClient = userServiceClient.getClient();
507 rajveer 1553
 
555 chandransh 1554
			Cart cart = userClient.getCart(cartId);
507 rajveer 1555
			List<Line> lineItems = cart.getLines();
517 rajveer 1556
			if(lineItems.size() != 0){
1557
				items = new ArrayList<Map<String,String>>();
1558
				for (Line line : lineItems) {
1559
 
1560
					Map<String, String> itemdetail = new HashMap<String, String>();
1561
					Item item = catalogClient.getItemByCatalogId(line.getItemId());
1562
 
1563
					String itemName = ((item.getManufacturerName() != null) ? item.getManufacturerName() + " " : "")
1564
										+ ((item.getModelName() != null) ? item.getModelName() + " " : "") 
1565
										+ (( item.getModelNumber() != null ) ? item.getModelNumber() : "" );
1566
 
1567
					itemdetail.put("ITEM_NAME", itemName);
1568
					System.out.println(itemdetail.get("ITEM_NAME"));
1569
					itemdetail.put("ITEM_ID", line.getItemId()+"");
1570
					itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
1571
					itemdetail.put("MRP", ((int)item.getMrp())+"");
1572
					itemdetail.put("SELLING_PRICE", ((int)item.getSellingPrice())+"");
1573
					itemdetail.put("TOTAL_PRICE", ((int)((item.getSellingPrice()*line.getQuantity())))+"");
615 chandransh 1574
					itemdetail.put("SHIPPING_TIME", line.getEstimate()+"");
517 rajveer 1575
					totalamount = totalamount + line.getQuantity()*item.getSellingPrice();
1576
					items.add(itemdetail);				
507 rajveer 1577
				}
1578
			}
1579
 
1580
		}catch (Exception e){
1581
			e.printStackTrace();
1582
		}
1583
 
1584
		context.put("items", items);
517 rajveer 1585
		context.put("totalamount", ((int)totalamount)+"");
572 chandransh 1586
		context.put("errorMsg", errorMsg);
507 rajveer 1587
		htmlString = getHtmlFromVelocity(templateFile, context);
1588
		return htmlString;
1589
	}
1590
 
1591
 
1592
	public Map<String, String> getShoppingCartPage_Old(long userId, boolean isSessionId, Map<String, String> params)
1593
	{
555 chandransh 1594
		UserContextServiceClient userServiceClient = null;
1595
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
507 rajveer 1596
 
1597
		try {
555 chandransh 1598
			userServiceClient = new UserContextServiceClient();
1599
			userClient = userServiceClient.getClient();
507 rajveer 1600
 
555 chandransh 1601
			Cart cart = userClient.getCurrentCart(userId);
507 rajveer 1602
 
1603
			List<Line> lineItems = cart.getLines();
1604
			List<Map<String,String>> items = new ArrayList<Map<String,String>>(); 
1605
 
1606
			for (Line line : lineItems) {
1607
//				long productId = getCatalogIdByItemId(line.getItemId());
1608
				long productId = line.getItemId();
1609
				Map<String, String> productDetails = getProductDetails(productId);
1610
				double mrp = getItemMrpByCatalogId(productId);
1611
				double sellingPrice = getItemSellingPriceByCatalogId(productId);
1612
				double saving = (mrp - sellingPrice)/mrp*100; 
1613
				saving = Math.round(saving);
1614
				Map<String, String> item = new HashMap<String, String>();
1615
				item.put("BRAND_NAME", productDetails.get("BRAND_NAME"));
1616
				item.put("MODEL_NAME", productDetails.get("MODEL_NAME"));
1617
				item.put("MODEL_NUMBER", productDetails.get("MODEL_NUMBER"));
1618
				item.put("ITEM_ID", line.getItemId()+"");
1619
				item.put("ITEM_QUANTITY", line.getQuantity()+"");
1620
				item.put("MRP", mrp+"");
1621
				item.put("SELLING_PRICE", sellingPrice+"");
1622
				item.put("SAVING", sellingPrice+"");
1623
				items.add(item);
1624
			}
1625
 
1626
			String templateFile = "templates/shoppingcart.vm";
1627
			VelocityContext context = new VelocityContext();	
1628
			context.put("items", items);
1629
 
1630
			String htmlString = getHtmlFromVelocity(templateFile, context);
1631
			System.out.println("My Cart Snippet generated" + htmlString);
1632
 
1633
			Map<String,String> htmlSnippet = new HashMap<String, String>();
1634
			htmlSnippet.put("SHOPPING_CART", htmlString);
1635
 
1636
			return htmlSnippet;
1637
 
1638
		} catch (ShoppingCartException e) {
1639
			// TODO Auto-generated catch block
1640
			e.printStackTrace();
1641
		}catch (Exception e) {
1642
			// TODO Auto-generated catch block
1643
			e.printStackTrace();
1644
		}
1645
 
1646
		return null;
1647
	}
1648
 
1649
 
1650
	public long getCatalogIdByItemId(long itemId){
1651
		CatalogServiceClient catalogServiceClient = null;
1652
		Client client = null;
1653
 
1654
		try {
1655
			catalogServiceClient = new CatalogServiceClient();
1656
			client = catalogServiceClient.getClient();
1657
 
1658
			return client.getItem(itemId).getCatalogItemId();
1659
		} catch (InventoryServiceException e) {
1660
			// TODO Auto-generated catch block
1661
			e.printStackTrace();
1662
		} catch (TException e) {
1663
			// TODO Auto-generated catch block
1664
			e.printStackTrace();
1665
		} catch (Exception e) {
1666
			// TODO Auto-generated catch block
1667
			e.printStackTrace();
1668
		}
1669
		return -1;
1670
	}
1671
 
1672
//	private	void addItemToCart(long catalogItemId, long userId) throws Exception{
1673
//		UserContextServiceClient userContextServiceClient = null;
1674
//		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
1675
//		userContextServiceClient = new UserContextServiceClient();
1676
//		userClient = userContextServiceClient.getClient();
1677
//
1678
//		ShoppingCartClient shoppingCartClient = null;
1679
//		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = null;
1680
//		shoppingCartClient = new ShoppingCartClient();
1681
//		cartClient = shoppingCartClient.getClient();
1682
//		
1683
//		Cart cart = cartClient.getCurrentCart(userId);
1684
//		//if user is logged in create  new cart
1685
//		//if( userClient.getState(userId, false).isIsLoggedIn()){
1686
//		if(cart == null){
1687
//			cartClient.createCart(userId);
1688
//			cart = cartClient.getCurrentCart(userId);
1689
//		}
1690
//		cartClient.addItemToCart(cart.getId(), catalogItemId, 1);
1691
//	}
1692
 
1693
		//userClient.getState(userId, isSessionId);
1694
 
1695
//		TransactionServiceClient transactionServiceClient = null;
1696
//		in.shop2020.model.v1.order.TransactionService.Client client = null;
1697
//		
1698
//		Cart cart = cartClient.getCurrentCart(userId);
555 chandransh 1699
//		List<LineItem> lineItems = cart.getLines();
507 rajveer 1700
//		
555 chandransh 1701
//		LineItem ln = lineItems.get(0);
507 rajveer 1702
//		ln.getItemId();
1703
//		ln.getId();
1704
//		ln.getQuantity();
1705
//		ln.getStatusMessage();
1706
//		long productId = 10;
1707
//		
1708
//		Cart cart = cartClient.getCurrentCart(0);
555 chandransh 1709
//		List<LineItem> lineItems = cart.getLines();
1710
//		LineItem ln = lineItems.get(0);
507 rajveer 1711
//		ln.getItemId();
1712
//		ln.getId();
1713
//		
1714
//		ln.getStatusMessage();
1715
//		
1716
 
1717
	private	Map<String,String> getProductDetails(long productId){
1718
		Map<String, String> productDetails = new HashMap<String, String>();
1719
 
1720
		EntityContainer entContainer = 	Catalog.getInstance().getEntityContainer();
1721
		ExpandedEntity expEntity;
1722
		try {
1723
			expEntity = entContainer.getExpandedEntity(productId);
1724
 
1725
			productDetails.put("BRAND_NAME", expEntity.getBrand());
1726
			productDetails.put("MODEL_NUMBER", expEntity.getModelNumber());
1727
			productDetails.put("MODEL_NAME", expEntity.getModelName());
1728
			productDetails.put("CATEGORY_ID", expEntity.getCategoryID() + "");
1729
			productDetails.put("CATEGORY_NAME", expEntity.getCategory().getLabel());
1730
			productDetails.put("INTRODUCTION_TEXT", expEntity.getSlide(130001).getFreeformContent().getFreeformText());
1731
			return productDetails;
1732
//			expEntity.getBrand();
1733
//			expEntity.getModelNumber();
1734
//			expEntity.getModelName();
1735
//			expEntity.getCategoryID();
1736
//			expEntity.getCategory().getLabel();
1737
//			expEntity.getSlide(130001).getFreeformContent().getFreeformText();
1738
		} catch (Exception e) {
1739
			// TODO Auto-generated catch block
1740
			e.printStackTrace();
1741
		}
1742
 
1743
		return null;
1744
	}
1745
 
1746
 
1747
	private	String getMyOrdersDiv(long userId){
1748
		TransactionServiceClient transactionServiceClient = null;
1749
		in.shop2020.model.v1.order.TransactionService.Client client = null;
1750
		String htmlString = new String();
1751
			try {
1752
				transactionServiceClient = new TransactionServiceClient();
1753
				client = transactionServiceClient.getClient();
1754
				List<Transaction> transactions = client.getTransactionsForCustomer(userId, 0, 0, null);
1755
 
1756
				String templateFile = "templates/myorders.vm";
1757
				VelocityContext context = new VelocityContext();	
1758
				context.put("transactions", transactions);
1759
				if(!transactions.isEmpty()){
1760
					Transaction tn = transactions.get(0);
1761
					java.sql.Date d = new java.sql.Date(tn.getCreatedOn());
1762
					System.out.println("Date is" + d.toString());
1763
				}
1764
				htmlString = getHtmlFromVelocity(templateFile, context);
1765
				System.out.println("Orders Info Snippet generated" + htmlString);
1766
				return htmlString;
1767
 
1768
			} catch (UserContextException e) {
1769
				// TODO Auto-generated catch block
1770
				e.printStackTrace();
1771
			} catch (Exception e) {
1772
				// TODO Auto-generated catch block
1773
				e.printStackTrace();
1774
			}
1775
			return "MY_ORDERS";
1776
	}
1777
 
1778
	public String getHtmlFromVelocity(String templateFile, VelocityContext context){
1779
		Properties p = new Properties();
1780
		p.setProperty("resource.loader", "class");
1781
		p.setProperty("class.resource.loader.class",
1782
		"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
1783
 
1784
 
1785
		try {
1786
			Velocity.init(p);
1787
			Template template = Velocity.getTemplate(templateFile);
1788
			if(template != null) {
1789
				StringWriter writer = new StringWriter();
1790
				template.merge(context, writer);
1791
				writer.flush();
1792
				writer.close();
1793
				return writer.toString();
1794
			}
1795
 
1796
			} catch (ResourceNotFoundException e) {
1797
				// TODO Auto-generated catch block
1798
				e.printStackTrace();
1799
			} catch (ParseErrorException e) {
1800
				// TODO Auto-generated catch block
1801
				e.printStackTrace();
1802
			} catch (MethodInvocationException e) {
1803
				// TODO Auto-generated catch block
1804
				e.printStackTrace();
1805
			} catch (IOException e) {
1806
				// TODO Auto-generated catch block
1807
				e.printStackTrace();
1808
			} catch (Exception e) {
1809
				// TODO Auto-generated catch block
1810
				e.printStackTrace();
1811
			}
1812
 
1813
		return null;
1814
	}
1815
 
1816
	public double getItemMrpByCatalogId(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.getMrp();
1825
		}
1826
		catch(Exception e){
1827
			e.printStackTrace();
1828
		}
1829
		return itemPrice;
1830
	}
1831
 
1832
	public double getItemSellingPriceByCatalogId(long productId){
1833
		CatalogServiceClient catalogServiceClient = null;
1834
		Client client = null;
1835
		Double itemPrice = 0.0;
1836
		try {
1837
			catalogServiceClient = new CatalogServiceClient();
1838
			client = catalogServiceClient.getClient();
1839
			Item item = client.getItemByCatalogId(productId);
1840
			itemPrice = item.getSellingPrice();
1841
		}
1842
		catch(Exception e){
1843
			e.printStackTrace();
1844
		}
1845
		return itemPrice;
1846
	}
1847
 
517 rajveer 1848
 
1849
	public String getCategoryHeaderSnippet() {
1850
		String htmlString = "";
1851
		VelocityContext context = new VelocityContext();
1852
		String templateFile = "templates/categoryheader.vm";
1853
		htmlString = getHtmlFromVelocity(templateFile, context);
1854
		return htmlString;
1855
	}
1856
 
507 rajveer 1857
 
1858
 
1859
}
1860