Subversion Repositories SmartDukaan

Rev

Rev 1002 | Rev 1110 | Go to most recent revision | Details | Compare with Previous | 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.SimpleDateFormat;
507 rajveer 11
import java.util.ArrayList;
12
import java.util.Date;
13
import java.util.HashMap;
14
import java.util.List;
15
import java.util.Map;
16
import java.util.Properties;
17
 
18
import org.apache.thrift.TException;
19
import org.apache.velocity.Template;
20
import org.apache.velocity.VelocityContext;
21
import org.apache.velocity.app.Velocity;
22
import org.apache.velocity.exception.MethodInvocationException;
23
import org.apache.velocity.exception.ParseErrorException;
24
import org.apache.velocity.exception.ResourceNotFoundException;
25
 
26
 
745 chandransh 27
import in.shop2020.logistics.Provider;
507 rajveer 28
import in.shop2020.model.v1.catalog.InventoryServiceException;
29
import in.shop2020.model.v1.catalog.Item;
30
import in.shop2020.model.v1.catalog.InventoryService.Client;
31
import in.shop2020.model.v1.order.Order;
32
import in.shop2020.model.v1.order.OrderStatus;
555 chandransh 33
import in.shop2020.model.v1.user.Cart;
34
import in.shop2020.model.v1.user.Line;
507 rajveer 35
import in.shop2020.model.v1.user.Address;
555 chandransh 36
import in.shop2020.model.v1.user.User;
37
import in.shop2020.model.v1.user.RatingType;
38
import in.shop2020.model.v1.user.RatingsWidget;
762 rajveer 39
import in.shop2020.model.v1.user.UserContextException;
555 chandransh 40
import in.shop2020.model.v1.user.Widget;
41
import in.shop2020.model.v1.user.WidgetItem;
42
import in.shop2020.model.v1.user.WidgetType;
507 rajveer 43
import in.shop2020.serving.utils.*;
44
import in.shop2020.thrift.clients.CatalogServiceClient;
745 chandransh 45
import in.shop2020.thrift.clients.LogisticsServiceClient;
507 rajveer 46
import in.shop2020.thrift.clients.TransactionServiceClient;
47
import in.shop2020.thrift.clients.UserContextServiceClient;
48
 
49
 
50
public class PageLoaderHandler {
51
 
637 rajveer 52
	public String getRegistrationFormHtml() {
507 rajveer 53
		String htmlString = "";
54
		VelocityContext context = new VelocityContext();
55
		String templateFile = "templates/registrationform.vm";
56
		htmlString = getHtmlFromVelocity(templateFile, context);
57
		return htmlString;
58
	}
59
 
637 rajveer 60
	public String getLoginFormHtml() {
61
		String htmlString = "";
62
		VelocityContext context = new VelocityContext();
63
		String templateFile = "templates/loginform.vm";
64
		htmlString = getHtmlFromVelocity(templateFile, context);
65
		return htmlString;
66
	}
507 rajveer 67
 
637 rajveer 68
	public String getRegistrationHeaderHtml() {
507 rajveer 69
		String htmlString = "";
70
		VelocityContext context = new VelocityContext();
71
		String templateFile = "templates/registrationheader.vm";
72
		htmlString = getHtmlFromVelocity(templateFile, context);
73
		return htmlString;
74
	}
75
 
637 rajveer 76
	public String getLoginHeaderHtml() {
77
		String htmlString = "";
78
		VelocityContext context = new VelocityContext();
79
		String templateFile = "templates/loginheader.vm";
80
		htmlString = getHtmlFromVelocity(templateFile, context);
81
		return htmlString;
82
	}
83
 
507 rajveer 84
 
650 rajveer 85
	public String getMainBannerHtml() {
507 rajveer 86
		String htmlString = "";
87
		VelocityContext context = new VelocityContext();
88
		String templateFile = "templates/mainbanner.vm";
89
		htmlString = getHtmlFromVelocity(templateFile, context);
90
		return htmlString;
91
	}
92
 
93
 
650 rajveer 94
	public String getBestSellersHtml() {
507 rajveer 95
		String htmlString = "";
96
		VelocityContext context = new VelocityContext();
97
		String templateFile = "templates/bestsellers.vm";
98
 
99
		CatalogServiceClient catalogServiceClient = null;
100
		Client client = null;
101
 
102
		try {
103
			catalogServiceClient = new CatalogServiceClient();
104
			client = catalogServiceClient.getClient();
627 rajveer 105
			List<Long> items = client.getBestSellersCatalogIds(1, 4, -1);
507 rajveer 106
			List<String> itemList = new ArrayList<String>();
107
			for(Long item: items){
517 rajveer 108
				itemList.add(FileUtils.read( Utils.EXPORT_ENTITIES_PATH + item + File.separator +"HomeSnippet.html"));
507 rajveer 109
			}
110
			context.put("itemList", itemList);
111
 
112
		} catch(Exception e){
113
 
114
		}
762 rajveer 115
		/*
116
		finally{
117
			catalogServiceClient.closeConnection();
118
		}
119
		*/
507 rajveer 120
 
121
 
122
		htmlString = getHtmlFromVelocity(templateFile, context);
517 rajveer 123
		return htmlString;	
124
	}
507 rajveer 125
 
126
 
650 rajveer 127
	public String getLatestArrivalsHtml() {
507 rajveer 128
		String htmlString = "";
129
		VelocityContext context = new VelocityContext();
130
		String templateFile = "templates/latestarrivals.vm";
131
 
132
		CatalogServiceClient catalogServiceClient = null;
133
		Client client = null;
134
 
135
		try {
136
			catalogServiceClient = new CatalogServiceClient();
137
			client = catalogServiceClient.getClient();
1002 chandransh 138
			List<Long> items = client.getLatestArrivalsCatalogIds(1, 4, 10003);
507 rajveer 139
			List<String> itemList = new ArrayList<String>();
140
			for(Long item: items){
968 chandransh 141
				try{
142
					itemList.add(FileUtils.read( Utils.EXPORT_ENTITIES_PATH + item + File.separator +"HomeSnippet.html"));
143
				}catch(IOException ioex){
144
					ioex.printStackTrace();
145
				}
507 rajveer 146
			}
147
			context.put("itemList", itemList);
148
 
149
		} catch(Exception e){
968 chandransh 150
			e.printStackTrace();
762 rajveer 151
		}finally{
152
			catalogServiceClient.closeConnection();
507 rajveer 153
		}
154
 
155
		htmlString = getHtmlFromVelocity(templateFile, context);
156
		return htmlString;
157
	}
158
 
159
 
650 rajveer 160
	public String getBestDealsHtml() {
507 rajveer 161
		String htmlString = "";
162
		VelocityContext context = new VelocityContext();
163
		String templateFile = "templates/bestdeals.vm";
164
 
165
		CatalogServiceClient catalogServiceClient = null;
166
		Client client = null;
167
 
168
		try {
169
			catalogServiceClient = new CatalogServiceClient();
170
			client = catalogServiceClient.getClient();
627 rajveer 171
			List<Long> items = client.getBestDealsCatalogIds(1,4,-1);
507 rajveer 172
			List<String> itemList = new ArrayList<String>();
173
			for(Long item: items){
517 rajveer 174
				itemList.add(FileUtils.read( Utils.EXPORT_ENTITIES_PATH + item + File.separator +"HomeSnippet.html"));
507 rajveer 175
			}
176
			context.put("itemList", itemList);
177
 
786 rajveer 178
		} catch (InventoryServiceException e) {
179
			// TODO Auto-generated catch block
180
			e.printStackTrace();
181
		} catch (TException e) {
182
			// TODO Auto-generated catch block
183
			e.printStackTrace();
184
		} catch (Exception e) {
185
			// TODO Auto-generated catch block
186
			e.printStackTrace();
187
		} finally{
762 rajveer 188
			catalogServiceClient.closeConnection();
507 rajveer 189
		}
190
 
191
		htmlString = getHtmlFromVelocity(templateFile, context);
192
		return htmlString;
193
	}
194
 
195
 
517 rajveer 196
	public String getFooterHtml() {
507 rajveer 197
		String htmlString = "";
198
		VelocityContext context = new VelocityContext();
199
		String templateFile = "templates/footer.vm";
200
		htmlString = getHtmlFromVelocity(templateFile, context);
201
		return htmlString;
202
	}
203
 
204
 
205
 
620 rajveer 206
	public String getAccessoriesHtml(long productId) {
637 rajveer 207
		return "";
208
		//return getWidgetDiv(0, WidgetType.ACCESSORIES, "accessories.vm");
507 rajveer 209
	}
210
 
211
 
212
 
620 rajveer 213
	public String getSimilarProductsHtml(long productId) {
637 rajveer 214
		return "";
215
		//return getWidgetDiv(0, WidgetType.SIMILAR_ITEMS, "similaritems.vm");
507 rajveer 216
	}
217
 
218
 
219
 
620 rajveer 220
	public String getRecommendationsHtml() {
637 rajveer 221
		return "";
222
		//return getWidgetDiv( 0, WidgetType.RECOMMENDED_ITEMS, "recommendations.vm");
507 rajveer 223
	}
224
 
225
 
226
 
555 chandransh 227
	public String getMyResearchHtml(long userId, boolean isLoggedIn) {
228
		if(isLoggedIn)
229
			return getWidgetDiv(userId, WidgetType.MY_RESEARCH, "myresearch.vm");
230
		else
231
			return getWidgetDiv(0, WidgetType.MY_RESEARCH, "myresearch.vm");
507 rajveer 232
	}
233
 
569 rajveer 234
	public String getBrowseHistoryHtml(long userId, boolean isLoggedIn) {
768 rajveer 235
		return getWidgetDiv(userId, WidgetType.BROWSE_HISTORY, "browsehistory.vm");
507 rajveer 236
	}
237
 
517 rajveer 238
	public String getCustomerServiceHtml() {
507 rajveer 239
		String htmlString = "";
240
		VelocityContext context = new VelocityContext();
241
		String templateFile = "templates/customerservice.vm";
242
		htmlString = getHtmlFromVelocity(templateFile, context);
243
		return htmlString;
244
	}
245
 
246
 
247
 
620 rajveer 248
	public String getReviewsHtml(long productId) {
507 rajveer 249
		String htmlString = "";
250
		VelocityContext context = new VelocityContext();
251
		Map<String, String> params = new HashMap<String, String>();
252
		params.put("PRODUCT_ID", productId+"");
253
		context.put("params", params);
254
		String templateFile = "templates/reviews.vm";
255
		htmlString = getHtmlFromVelocity(templateFile, context);
256
		return htmlString;
257
	}
258
 
259
 
260
 
620 rajveer 261
	public String getLocatorHtml() {
507 rajveer 262
		String htmlString = "";
263
		VelocityContext context = new VelocityContext();
264
		String templateFile = "templates/locator.vm";
265
		htmlString = getHtmlFromVelocity(templateFile, context);
266
		return htmlString;
267
	}
268
 
269
 
620 rajveer 270
	public String getSlideGuideHtml(long productId) {
507 rajveer 271
		StringBuilder htmlString = new StringBuilder();
517 rajveer 272
		String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "SlideGuide.html";
507 rajveer 273
		File f = new File(filename);
274
 
275
 
276
		FileInputStream fis = null;
277
		try {
278
			fis = new FileInputStream(f);
279
			BufferedReader br = new BufferedReader(new InputStreamReader(fis));
280
			String line;
281
			while((line = br.readLine()) != null){
282
				htmlString.append(line+"\n");
283
			}
284
		} catch (FileNotFoundException e) {
285
			// TODO Auto-generated catch block
286
			e.printStackTrace();
287
		} catch (IOException e) {
288
			// TODO Auto-generated catch block
289
			e.printStackTrace();
290
		}
291
		finally {
292
			if(fis != null) {
293
				try {
294
					fis.close();
295
				} catch (IOException e) {
296
					// TODO Auto-generated catch block
297
					e.printStackTrace();
298
				}
299
			}
300
		}
301
 
302
		return htmlString.toString();
303
	}
304
 
517 rajveer 305
	public String getProductSummaryHtml(long productId) {
507 rajveer 306
		StringBuilder htmlString = new StringBuilder();
517 rajveer 307
		String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "ProductDetail.html";
507 rajveer 308
		File f = new File(filename);
309
 
310
 
311
		FileInputStream fis = null;
312
		try {
313
			fis = new FileInputStream(f);
314
			BufferedReader br = new BufferedReader(new InputStreamReader(fis));
315
			String line;
316
			while((line = br.readLine()) != null){
317
				htmlString.append(line+"\n");
318
			}
319
		} catch (FileNotFoundException e) {
320
			// TODO Auto-generated catch block
321
			e.printStackTrace();
322
		} catch (IOException e) {
323
			// TODO Auto-generated catch block
324
			e.printStackTrace();
325
		}
326
		finally {
327
			if(fis != null) {
328
				try {
329
					fis.close();
330
				} catch (IOException e) {
331
					// TODO Auto-generated catch block
332
					e.printStackTrace();
333
				}
334
			}
335
		}
336
 
337
		return htmlString.toString();
338
	}
339
 
340
 
620 rajveer 341
	public String getSocialUtilsHtml(long productId) {
507 rajveer 342
		String htmlString = "";
343
		VelocityContext context = new VelocityContext();
344
		Map<String, String> params = new HashMap<String, String>();
345
		params.put("PRODUCT_ID", productId+"");
346
		String templateFile = "templates/socialutils.vm";
347
		context.put("params", params);
348
		htmlString = getHtmlFromVelocity(templateFile, context);
349
		return htmlString;
350
	}
974 vikas 351
 
352
	public String getPageTitleHtml(long productId) {
353
		StringBuilder htmlString = new StringBuilder();
989 vikas 354
		String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "TitleSnippet.html";
974 vikas 355
		File f = new File(filename);
356
 
357
 
358
		FileInputStream fis = null;
359
		try {
360
			fis = new FileInputStream(f);
361
			BufferedReader br = new BufferedReader(new InputStreamReader(fis));
362
			String line;
363
			while((line = br.readLine()) != null){
364
				htmlString.append(line+"\n");
365
			}
366
		} catch (FileNotFoundException e) {
367
			// TODO Auto-generated catch block
368
			e.printStackTrace();
369
		} catch (IOException e) {
370
			// TODO Auto-generated catch block
371
			e.printStackTrace();
372
		}
373
		finally {
374
			if(fis != null) {
375
				try {
376
					fis.close();
377
				} catch (IOException e) {
378
					// TODO Auto-generated catch block
379
					e.printStackTrace();
380
				}
381
			}
382
		}
383
 
384
		return htmlString.toString();
385
	}
386
 
387
	public String getPageMetaDescriptionHtml(long productId) {
388
		StringBuilder htmlString = new StringBuilder();
989 vikas 389
		String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "MetaDescriptionSnippet.html";
974 vikas 390
		File f = new File(filename);
391
 
392
 
393
		FileInputStream fis = null;
394
		try {
395
			fis = new FileInputStream(f);
396
			BufferedReader br = new BufferedReader(new InputStreamReader(fis));
397
			String line;
398
			while((line = br.readLine()) != null){
399
				htmlString.append(line+"\n");
400
			}
401
		} catch (FileNotFoundException e) {
402
			// TODO Auto-generated catch block
403
			e.printStackTrace();
404
		} catch (IOException e) {
405
			// TODO Auto-generated catch block
406
			e.printStackTrace();
407
		}
408
		finally {
409
			if(fis != null) {
410
				try {
411
					fis.close();
412
				} catch (IOException e) {
413
					// TODO Auto-generated catch block
414
					e.printStackTrace();
415
				}
416
			}
417
		}
418
 
419
		return htmlString.toString();
420
	}
421
 
422
	public String getPageMetaKeywordsHtml(long productId) {
423
		StringBuilder htmlString = new StringBuilder();
989 vikas 424
		String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "MetaKeywordsSnippet.html";
974 vikas 425
		File f = new File(filename);
426
 
427
 
428
		FileInputStream fis = null;
429
		try {
430
			fis = new FileInputStream(f);
431
			BufferedReader br = new BufferedReader(new InputStreamReader(fis));
432
			String line;
433
			while((line = br.readLine()) != null){
434
				htmlString.append(line+"\n");
435
			}
436
		} catch (FileNotFoundException e) {
437
			// TODO Auto-generated catch block
438
			e.printStackTrace();
439
		} catch (IOException e) {
440
			// TODO Auto-generated catch block
441
			e.printStackTrace();
442
		}
443
		finally {
444
			if(fis != null) {
445
				try {
446
					fis.close();
447
				} catch (IOException e) {
448
					// TODO Auto-generated catch block
449
					e.printStackTrace();
450
				}
451
			}
452
		}
453
 
454
		return htmlString.toString();
455
	}
507 rajveer 456
 
517 rajveer 457
	public String getMainMenuHtml() {
507 rajveer 458
		String htmlString = "";
459
		VelocityContext context = new VelocityContext();
460
		String templateFile = "templates/mainmenu.vm";
461
		htmlString = getHtmlFromVelocity(templateFile, context);
462
		return htmlString;
463
	}
464
 
465
 
517 rajveer 466
	public String getSearchBarHtml(long itemCounts, long categoryId) {
507 rajveer 467
		String htmlString = "";
468
		VelocityContext context = new VelocityContext();
469
		String templateFile = "templates/searchbar.vm";
550 rajveer 470
 
471
		context.put("itemCount", itemCounts+"");
472
		context.put("categoryId", categoryId+"");
473
 
507 rajveer 474
		htmlString = getHtmlFromVelocity(templateFile, context);
475
		return htmlString;
476
	}
477
 
478
 
479
 
924 vikas 480
	public String getHeaderHtml(boolean isLoggedIn, String  userName, String url) {
550 rajveer 481
		VelocityContext context = new VelocityContext();
555 chandransh 482
		if (isLoggedIn) {
483
			context.put("LOGGED_IN", "TRUE");
484
			context.put("WELCOME_MESSAGE", "Hi, " + userName);
485
		} else {
801 rajveer 486
			context.put("WELCOME_MESSAGE", "Hi, Welcome to Saholic");
924 vikas 487
			context.put("REDIRECT_URL", url);
555 chandransh 488
		}		
507 rajveer 489
 
490
		String templateFile = "templates/header.vm";
550 rajveer 491
 
590 chandransh 492
		return getHtmlFromVelocity(templateFile, context);
507 rajveer 493
	}
494
 
495
 
496
 
650 rajveer 497
	public	String getWidgetDiv(long userId, WidgetType widgetType, String templateFile){
507 rajveer 498
 
555 chandransh 499
		UserContextServiceClient userServiceClient = null;
500
		in.shop2020.model.v1.user.UserContextService.Client client = null;
507 rajveer 501
		Widget widget = null;
502
		try {
555 chandransh 503
			userServiceClient = new UserContextServiceClient();
504
			client = userServiceClient.getClient();
773 rajveer 505
			if(widgetType == WidgetType.MY_RESEARCH && userId != 0){
506
				widget = client.getMyResearch(userId);
507
			}
508
			if(widgetType == WidgetType.BROWSE_HISTORY){
509
				widget = client.getBrowseHistory(userId);
510
			}
511
 
507 rajveer 512
		} catch (Exception e) {
513
			e.printStackTrace();
762 rajveer 514
		}finally{
515
			userServiceClient.closeConnection();
507 rajveer 516
		}
517
 
518
 
519
		List<Map<String, String>> itemDetails = null;
520
 
521
		if(widget != null){
522
			List<WidgetItem> items = widget.getItems();
523
			itemDetails = new ArrayList<Map<String, String>>();
524
 
525
			for(WidgetItem item: items){
526
				Map<String, String> itemDetail = new HashMap<String, String>();
527
 
528
				itemDetail.put("ITEM_ID", item.getItem_id()+"");
529
				try {
517 rajveer 530
					itemDetail.put("ITEM_SNIPPET", FileUtils.read( Utils.EXPORT_ENTITIES_PATH + item.getItem_id() + File.separator + "WidgetSnippet.html"));
507 rajveer 531
				} catch (Exception e) {
532
					// TODO Auto-generated catch block
533
					e.printStackTrace();
534
				}
535
				itemDetails.add(itemDetail);
536
			}
537
		}else{
538
			System.out.println("widget not found");
539
		}
540
 
541
		VelocityContext context = new VelocityContext();
620 rajveer 542
		context.put("userId", userId);
507 rajveer 543
		context.put("itemDetails", itemDetails);
544
 
545
		return getHtmlFromVelocity("templates/"+templateFile, context);
546
	}
547
 
548
 
650 rajveer 549
	public String getOrderDetailsHtml(long orderId) {
507 rajveer 550
		String htmlString = "";
551
		VelocityContext context = new VelocityContext();
552
		String templateFile = "templates/orderdetails.vm";
553
		Order order = null;
517 rajveer 554
		Date orderedOn = null, deliveryEstimate = null;
843 chandransh 555
		Provider provider = null;
507 rajveer 556
		try{
843 chandransh 557
			TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
558
			in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
507 rajveer 559
			order = orderClient.getOrder(orderId);
517 rajveer 560
			orderedOn = new Date(order.getCreated_timestamp());
561
			deliveryEstimate = new Date(order.getExpected_delivery_time());
843 chandransh 562
 
563
			if(order.getLogistics_provider_id() != 0){
564
				LogisticsServiceClient logisticsServiceClient = new LogisticsServiceClient();
565
				in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
566
				provider = logisticsClient.getProvider(order.getLogistics_provider_id());
567
			}
507 rajveer 568
		}catch (Exception e){
569
 
570
		}
517 rajveer 571
 
572
		SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
583 rajveer 573
		SimpleDateFormat dateformat1 = new SimpleDateFormat("dd/MM/yyyy");
507 rajveer 574
		context.put("order", order);
517 rajveer 575
		context.put("orderedOn", dateformat.format(orderedOn));
583 rajveer 576
		context.put("deliveryEstimate", dateformat1.format(deliveryEstimate));
843 chandransh 577
		if(provider!=null){
578
			context.put("providerName", provider.getName());
579
		}
580
 
507 rajveer 581
		htmlString = getHtmlFromVelocity(templateFile, context);
582
		return htmlString;
583
	}
584
 
650 rajveer 585
	public String getMyaccountDetailsHtml(long userId) {
507 rajveer 586
		String htmlString = "";
587
		VelocityContext context = new VelocityContext();
588
		String templateFile = "templates/myaccount.vm";
589
		List<Order> orders = null;
745 chandransh 590
		Map<Long, String> providerNames = new HashMap<Long, String>();
507 rajveer 591
		try{
745 chandransh 592
			TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
593
			in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
507 rajveer 594
			orders = orderClient.getOrdersForCustomer(userId, 0, (new Date()).getTime(), null);
595
 
745 chandransh 596
			LogisticsServiceClient logisticsServiceClient = new LogisticsServiceClient();
597
			in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
598
			List<Provider> providers = logisticsClient.getAllProviders();
599
			for(Provider provider: providers)
600
				providerNames.put(provider.getId(), provider.getName());
507 rajveer 601
		}catch (Exception e){
602
 
603
		}
741 rajveer 604
		List<String> orderDate = new ArrayList<String>();
605
		SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
888 chandransh 606
		if(orders!=null && !orders.isEmpty()){
762 rajveer 607
			for(Order order: orders){
608
				Date orderedOn = new Date(order.getCreated_timestamp());
609
				orderDate.add(dateformat.format(orderedOn));
610
			}
741 rajveer 611
		}
507 rajveer 612
		context.put("orders", orders);
741 rajveer 613
		context.put("orderDate", orderDate);
745 chandransh 614
		context.put("providerNames", providerNames);
507 rajveer 615
		htmlString = getHtmlFromVelocity(templateFile, context);
616
		return htmlString;
617
	}
618
 
619
 
650 rajveer 620
	public String getLoginDetailsHtml(long userId) {
507 rajveer 621
		String htmlString = "";
622
		VelocityContext context = new VelocityContext();
623
		String templateFile = "templates/logindetails.vm";
624
		String email = "";
625
		try{
762 rajveer 626
			email = getEmailId(userId);
507 rajveer 627
		}catch (Exception e){
628
 
629
		}
630
		context.put("email", email);
631
		htmlString = getHtmlFromVelocity(templateFile, context);
632
		return htmlString;
633
	}
634
 
762 rajveer 635
	public String getEmailId(long userId){
636
		String email = " ";
637
 
638
		try {
639
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
640
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
641
			if(userClient.getUserById(userId).getEmail() != null){
642
				email = userClient.getUserById(userId).getEmail();
643
			}
644
		} catch (UserContextException e) {
645
			e.printStackTrace();
646
		} catch (TException e) {
647
			e.printStackTrace();
648
		} catch (Exception e) {
649
			e.printStackTrace();
650
		}
651
		return email; 
652
	}
653
 
654
 
595 rajveer 655
	public String getPersonalDetailsHtml(long userId) {
507 rajveer 656
		String htmlString = "";
657
		VelocityContext context = new VelocityContext();
658
		String templateFile = "templates/personaldetails.vm";
659
		String email = "";
517 rajveer 660
		String name = "";
569 rajveer 661
		String dateOfBirth = "";
517 rajveer 662
		String sex = "";
663
		String subscribe = "false";
507 rajveer 664
		UserContextServiceClient userContextServiceClient = null;
665
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
666
		try{
555 chandransh 667
			User user = null;
507 rajveer 668
			userContextServiceClient = new UserContextServiceClient();
669
			userClient = userContextServiceClient.getClient();
555 chandransh 670
			user = userClient.getUserById(userId);
507 rajveer 671
 
555 chandransh 672
			email = user.getCommunicationEmail();
673
			name = user.getName();
517 rajveer 674
 
569 rajveer 675
			dateOfBirth = user.getDateOfBirth();
507 rajveer 676
		}catch (Exception e){
555 chandransh 677
			e.printStackTrace();
507 rajveer 678
		}
517 rajveer 679
		context.put("name", name);
680
		context.put("email", email);
569 rajveer 681
		context.put("dateOfBirth", dateOfBirth+"");
517 rajveer 682
		context.put("subscribe", subscribe);
683
		context.put("sex", sex);
507 rajveer 684
		htmlString = getHtmlFromVelocity(templateFile, context);
685
		return htmlString;
686
	}
687
 
620 rajveer 688
	public String getCompletedOrdersHtml(long userId) {
507 rajveer 689
		String htmlString = "";
690
		VelocityContext context = new VelocityContext();
691
		String templateFile = "templates/completedorders.vm";
692
		TransactionServiceClient transactionServiceClient = null;
693
		in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
694
		List<Order> orders = null;
695
		try{
696
			transactionServiceClient = new TransactionServiceClient();
697
			orderClient = transactionServiceClient.getClient();
698
			orders = orderClient.getOrdersForCustomer(userId, 0, (new Date()).getTime(), OrderStatus.DELIVERY_SUCCESS);
699
 
700
		}catch (Exception e){
701
 
702
		}
703
		context.put("orders", orders);
704
		htmlString = getHtmlFromVelocity(templateFile, context);
705
		return htmlString;
706
	}
595 rajveer 707
	public String getMyaccountHeaderHtml() {
507 rajveer 708
		String htmlString = "";
709
		VelocityContext context = new VelocityContext();
710
		String templateFile = "templates/myaccountheader.vm";
711
		htmlString = getHtmlFromVelocity(templateFile, context);
712
		return htmlString;
713
	}
714
 
650 rajveer 715
	public String getShippingHeaderHtml() {
507 rajveer 716
		String htmlString = "";
717
		VelocityContext context = new VelocityContext();
718
		String templateFile = "templates/shippingheader.vm";
719
		htmlString = getHtmlFromVelocity(templateFile, context);
720
		return htmlString;
721
	}
722
 
822 vikas 723
	public String getShippingAddressDetailsHtml(long userId, String errorMsg){
507 rajveer 724
		String htmlString = "";
725
		VelocityContext context = new VelocityContext();
726
		String templateFile = "templates/shippingaddressdetails.vm";
727
		long defaultAddressId = 0;
517 rajveer 728
		List<Address> addresses = null;
507 rajveer 729
 
730
		UserContextServiceClient userContextServiceClient = null;
731
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
732
		try {
733
			userContextServiceClient = new UserContextServiceClient();
734
			userClient = userContextServiceClient.getClient();
620 rajveer 735
 
736
			addresses = userClient.getAllAddressesForUser(userId);
737
			defaultAddressId = userClient.getDefaultAddressId(userId);
507 rajveer 738
		} catch (Exception e) {
739
			e.printStackTrace();
740
		}
517 rajveer 741
		context.put("defaultAddressId", defaultAddressId+"");
507 rajveer 742
		context.put("addresses", addresses);
822 vikas 743
		context.put("errorMsg", errorMsg);
507 rajveer 744
 
745
		htmlString = getHtmlFromVelocity(templateFile, context);
746
		return htmlString;
747
	}
748
 
650 rajveer 749
	public String getShippingDetailsHtml(long cartId, String errorMsg) {
507 rajveer 750
		String htmlString = "";
751
		VelocityContext context = new VelocityContext();
752
		String templateFile = "templates/shippingdetails.vm";
517 rajveer 753
		List<Map<String,String>> items = null;
507 rajveer 754
		double totalamount= 0.0;
517 rajveer 755
		List<Address> addresses = null;
756
		long defaultAddressId = 0;
555 chandransh 757
 
507 rajveer 758
		CatalogServiceClient catalogServiceClient  = null;
759
		in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = null;
760
		UserContextServiceClient userContextServiceClient = null;
761
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
762
 
763
		try {
764
			catalogServiceClient = new CatalogServiceClient();
765
			catalogClient = catalogServiceClient.getClient();
766
			userContextServiceClient = new UserContextServiceClient();
767
			userClient = userContextServiceClient.getClient();
768
 
769
 
555 chandransh 770
			Cart cart = userClient.getCart(cartId);
507 rajveer 771
			List<Line> lineItems = cart.getLines();
772
 
517 rajveer 773
			if( ! lineItems.isEmpty())
774
			{
775
				items = new ArrayList<Map<String,String>>();
507 rajveer 776
 
517 rajveer 777
				for (Line line : lineItems) {
778
					Map<String, String> itemdetail = new HashMap<String, String>();
637 rajveer 779
					Item item = catalogClient.getItem(line.getItemId());
962 chandransh 780
					String itemName = ((item.getBrand() != null) ? item.getBrand() + " " : "")
517 rajveer 781
										+ ((item.getModelName() != null) ? item.getModelName() + " " : "") 
637 rajveer 782
										+ (( item.getModelNumber() != null ) ? item.getModelNumber() + " " : "" )
783
										+ (( (item.getColor() != null && !item.getColor().trim().equals("NA"))) ? "("+item.getColor()+")" : "" );
517 rajveer 784
 
785
					itemdetail.put("ITEM_NAME", itemName);
786
					itemdetail.put("ITEM_ID", line.getItemId()+"");
787
					itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
788
					itemdetail.put("MRP", ((int)item.getMrp())+"");
536 rajveer 789
					itemdetail.put("SELLING_PRICE", (int)item.getSellingPrice()+"");
790
					itemdetail.put("TOTAL_PRICE", (int)(item.getSellingPrice()*line.getQuantity())+"");
615 chandransh 791
					itemdetail.put("SHIPPING_TIME", line.getEstimate()+"");
536 rajveer 792
					totalamount = totalamount + line.getQuantity()*item.getSellingPrice();
517 rajveer 793
					items.add(itemdetail);				
794
				}
507 rajveer 795
			}
796
 
637 rajveer 797
			addresses = userClient.getAllAddressesForUser(cart.getUserId());
650 rajveer 798
			if(cart.isSetAddressId()){
799
				defaultAddressId = cart.getAddressId();
800
			}else{
801
				defaultAddressId = userClient.getDefaultAddressId(cart.getUserId());
802
			}
507 rajveer 803
 
804
		}catch (Exception e){
805
			e.printStackTrace();
806
		}
807
 
808
		context.put("items", items);
536 rajveer 809
		context.put("totalamount", (int)totalamount+"");
507 rajveer 810
		context.put("addresses", addresses);
517 rajveer 811
		context.put("defaultAddressId", defaultAddressId+"");
572 chandransh 812
		context.put("errorMsg", errorMsg);
507 rajveer 813
		htmlString = getHtmlFromVelocity(templateFile, context);
814
		return htmlString;
815
	}
816
 
817
 
650 rajveer 818
	public String getCartHeaderHtml() {
507 rajveer 819
		String htmlString = "";
820
		VelocityContext context = new VelocityContext();
821
		String templateFile = "templates/cartheader.vm";
822
		htmlString = getHtmlFromVelocity(templateFile, context);
823
		return htmlString;
824
	}
825
 
826
 
786 rajveer 827
	public String getCartDetailsHtml(long userId, long cartId, String errorMsg) {
507 rajveer 828
		String htmlString = "";
829
		VelocityContext context = new VelocityContext();
830
		String templateFile = "templates/cartdetails.vm";
517 rajveer 831
		List<Map<String,String>> items = null;
507 rajveer 832
		double totalamount= 0.0;
833
 
555 chandransh 834
		UserContextServiceClient userServiceClient = null;
835
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
507 rajveer 836
		CatalogServiceClient catalogServiceClient  = null;
837
		in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = null;
786 rajveer 838
		String pincode = "110001";
507 rajveer 839
		try {
840
			catalogServiceClient = new CatalogServiceClient();
841
			catalogClient = catalogServiceClient.getClient();
555 chandransh 842
			userServiceClient = new UserContextServiceClient();
843
			userClient = userServiceClient.getClient();
507 rajveer 844
 
786 rajveer 845
			pincode = userClient.getDefaultPincode(userId);
555 chandransh 846
			Cart cart = userClient.getCart(cartId);
507 rajveer 847
			List<Line> lineItems = cart.getLines();
517 rajveer 848
			if(lineItems.size() != 0){
849
				items = new ArrayList<Map<String,String>>();
850
				for (Line line : lineItems) {
851
 
852
					Map<String, String> itemdetail = new HashMap<String, String>();
637 rajveer 853
					Item item = catalogClient.getItem(line.getItemId());
517 rajveer 854
 
962 chandransh 855
					String itemName = ((item.getBrand() != null) ? item.getBrand() + " " : "")
517 rajveer 856
										+ ((item.getModelName() != null) ? item.getModelName() + " " : "") 
637 rajveer 857
										+ (( item.getModelNumber() != null ) ? item.getModelNumber() + " " : "" )
858
										+ (( (item.getColor() != null && !item.getColor().trim().equals("NA"))) ? "("+item.getColor()+")" : "" );
517 rajveer 859
 
860
					itemdetail.put("ITEM_NAME", itemName);
861
					System.out.println(itemdetail.get("ITEM_NAME"));
862
					itemdetail.put("ITEM_ID", line.getItemId()+"");
805 rajveer 863
					itemdetail.put("CATALOG_ID", item.getCatalogItemId()+"");
517 rajveer 864
					itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
865
					itemdetail.put("MRP", ((int)item.getMrp())+"");
866
					itemdetail.put("SELLING_PRICE", ((int)item.getSellingPrice())+"");
867
					itemdetail.put("TOTAL_PRICE", ((int)((item.getSellingPrice()*line.getQuantity())))+"");
615 chandransh 868
					itemdetail.put("SHIPPING_TIME", line.getEstimate()+"");
517 rajveer 869
					totalamount = totalamount + line.getQuantity()*item.getSellingPrice();
870
					items.add(itemdetail);				
507 rajveer 871
				}
872
			}
873
 
874
		}catch (Exception e){
875
			e.printStackTrace();
876
		}
877
 
878
		context.put("items", items);
517 rajveer 879
		context.put("totalamount", ((int)totalamount)+"");
572 chandransh 880
		context.put("errorMsg", errorMsg);
786 rajveer 881
		context.put("pincode", pincode);
507 rajveer 882
		htmlString = getHtmlFromVelocity(templateFile, context);
883
		return htmlString;
884
	}
885
 
886
	public String getHtmlFromVelocity(String templateFile, VelocityContext context){
887
		Properties p = new Properties();
888
		p.setProperty("resource.loader", "class");
889
		p.setProperty("class.resource.loader.class",
890
		"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
832 rajveer 891
		p.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogSystem"); 
892
 
507 rajveer 893
		try {
894
			Velocity.init(p);
762 rajveer 895
			//Velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, value)
507 rajveer 896
			Template template = Velocity.getTemplate(templateFile);
897
			if(template != null) {
898
				StringWriter writer = new StringWriter();
899
				template.merge(context, writer);
900
				writer.flush();
901
				writer.close();
902
				return writer.toString();
903
			}
904
 
905
			} catch (ResourceNotFoundException e) {
906
				// TODO Auto-generated catch block
907
				e.printStackTrace();
908
			} catch (ParseErrorException e) {
909
				// TODO Auto-generated catch block
910
				e.printStackTrace();
911
			} catch (MethodInvocationException e) {
912
				// TODO Auto-generated catch block
913
				e.printStackTrace();
914
			} catch (IOException e) {
915
				// TODO Auto-generated catch block
916
				e.printStackTrace();
917
			} catch (Exception e) {
918
				// TODO Auto-generated catch block
919
				e.printStackTrace();
920
			}
921
 
922
		return null;
923
	}
924
}
925