Subversion Repositories SmartDukaan

Rev

Rev 1034 | Rev 1184 | 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>();
1110 rajveer 527
				String itemSnippet;
507 rajveer 528
 
1110 rajveer 529
					try {
530
						itemSnippet = FileUtils.read( Utils.EXPORT_ENTITIES_PATH + item.getItem_id() + File.separator + "WidgetSnippet.html");
531
					} catch (IOException e) {
532
						e.printStackTrace();
533
						continue;
534
					}
535
 
507 rajveer 536
				itemDetail.put("ITEM_ID", item.getItem_id()+"");
1110 rajveer 537
				itemDetail.put("ITEM_SNIPPET", itemSnippet);
507 rajveer 538
				itemDetails.add(itemDetail);
539
			}
540
		}else{
541
			System.out.println("widget not found");
542
		}
543
 
544
		VelocityContext context = new VelocityContext();
620 rajveer 545
		context.put("userId", userId);
507 rajveer 546
		context.put("itemDetails", itemDetails);
547
 
548
		return getHtmlFromVelocity("templates/"+templateFile, context);
549
	}
550
 
551
 
650 rajveer 552
	public String getOrderDetailsHtml(long orderId) {
507 rajveer 553
		String htmlString = "";
554
		VelocityContext context = new VelocityContext();
555
		String templateFile = "templates/orderdetails.vm";
556
		Order order = null;
517 rajveer 557
		Date orderedOn = null, deliveryEstimate = null;
843 chandransh 558
		Provider provider = null;
507 rajveer 559
		try{
843 chandransh 560
			TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
561
			in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
507 rajveer 562
			order = orderClient.getOrder(orderId);
517 rajveer 563
			orderedOn = new Date(order.getCreated_timestamp());
564
			deliveryEstimate = new Date(order.getExpected_delivery_time());
843 chandransh 565
 
566
			if(order.getLogistics_provider_id() != 0){
567
				LogisticsServiceClient logisticsServiceClient = new LogisticsServiceClient();
568
				in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
569
				provider = logisticsClient.getProvider(order.getLogistics_provider_id());
570
			}
507 rajveer 571
		}catch (Exception e){
572
 
573
		}
517 rajveer 574
 
575
		SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
583 rajveer 576
		SimpleDateFormat dateformat1 = new SimpleDateFormat("dd/MM/yyyy");
507 rajveer 577
		context.put("order", order);
517 rajveer 578
		context.put("orderedOn", dateformat.format(orderedOn));
583 rajveer 579
		context.put("deliveryEstimate", dateformat1.format(deliveryEstimate));
843 chandransh 580
		if(provider!=null){
581
			context.put("providerName", provider.getName());
582
		}
583
 
507 rajveer 584
		htmlString = getHtmlFromVelocity(templateFile, context);
585
		return htmlString;
586
	}
587
 
650 rajveer 588
	public String getMyaccountDetailsHtml(long userId) {
507 rajveer 589
		String htmlString = "";
590
		VelocityContext context = new VelocityContext();
591
		String templateFile = "templates/myaccount.vm";
592
		List<Order> orders = null;
745 chandransh 593
		Map<Long, String> providerNames = new HashMap<Long, String>();
507 rajveer 594
		try{
745 chandransh 595
			TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
596
			in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
507 rajveer 597
			orders = orderClient.getOrdersForCustomer(userId, 0, (new Date()).getTime(), null);
598
 
745 chandransh 599
			LogisticsServiceClient logisticsServiceClient = new LogisticsServiceClient();
600
			in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
601
			List<Provider> providers = logisticsClient.getAllProviders();
602
			for(Provider provider: providers)
603
				providerNames.put(provider.getId(), provider.getName());
507 rajveer 604
		}catch (Exception e){
605
 
606
		}
741 rajveer 607
		List<String> orderDate = new ArrayList<String>();
608
		SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
888 chandransh 609
		if(orders!=null && !orders.isEmpty()){
762 rajveer 610
			for(Order order: orders){
611
				Date orderedOn = new Date(order.getCreated_timestamp());
612
				orderDate.add(dateformat.format(orderedOn));
613
			}
741 rajveer 614
		}
507 rajveer 615
		context.put("orders", orders);
741 rajveer 616
		context.put("orderDate", orderDate);
745 chandransh 617
		context.put("providerNames", providerNames);
507 rajveer 618
		htmlString = getHtmlFromVelocity(templateFile, context);
619
		return htmlString;
620
	}
621
 
622
 
650 rajveer 623
	public String getLoginDetailsHtml(long userId) {
507 rajveer 624
		String htmlString = "";
625
		VelocityContext context = new VelocityContext();
626
		String templateFile = "templates/logindetails.vm";
627
		String email = "";
628
		try{
762 rajveer 629
			email = getEmailId(userId);
507 rajveer 630
		}catch (Exception e){
631
 
632
		}
633
		context.put("email", email);
634
		htmlString = getHtmlFromVelocity(templateFile, context);
635
		return htmlString;
636
	}
637
 
762 rajveer 638
	public String getEmailId(long userId){
639
		String email = " ";
640
 
641
		try {
642
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
643
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
644
			if(userClient.getUserById(userId).getEmail() != null){
645
				email = userClient.getUserById(userId).getEmail();
646
			}
647
		} catch (UserContextException e) {
648
			e.printStackTrace();
649
		} catch (TException e) {
650
			e.printStackTrace();
651
		} catch (Exception e) {
652
			e.printStackTrace();
653
		}
654
		return email; 
655
	}
656
 
657
 
595 rajveer 658
	public String getPersonalDetailsHtml(long userId) {
507 rajveer 659
		String htmlString = "";
660
		VelocityContext context = new VelocityContext();
661
		String templateFile = "templates/personaldetails.vm";
662
		String email = "";
517 rajveer 663
		String name = "";
569 rajveer 664
		String dateOfBirth = "";
517 rajveer 665
		String sex = "";
666
		String subscribe = "false";
507 rajveer 667
		UserContextServiceClient userContextServiceClient = null;
668
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
669
		try{
555 chandransh 670
			User user = null;
507 rajveer 671
			userContextServiceClient = new UserContextServiceClient();
672
			userClient = userContextServiceClient.getClient();
555 chandransh 673
			user = userClient.getUserById(userId);
507 rajveer 674
 
555 chandransh 675
			email = user.getCommunicationEmail();
676
			name = user.getName();
517 rajveer 677
 
569 rajveer 678
			dateOfBirth = user.getDateOfBirth();
507 rajveer 679
		}catch (Exception e){
555 chandransh 680
			e.printStackTrace();
507 rajveer 681
		}
517 rajveer 682
		context.put("name", name);
683
		context.put("email", email);
569 rajveer 684
		context.put("dateOfBirth", dateOfBirth+"");
517 rajveer 685
		context.put("subscribe", subscribe);
686
		context.put("sex", sex);
507 rajveer 687
		htmlString = getHtmlFromVelocity(templateFile, context);
688
		return htmlString;
689
	}
690
 
620 rajveer 691
	public String getCompletedOrdersHtml(long userId) {
507 rajveer 692
		String htmlString = "";
693
		VelocityContext context = new VelocityContext();
694
		String templateFile = "templates/completedorders.vm";
695
		TransactionServiceClient transactionServiceClient = null;
696
		in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
697
		List<Order> orders = null;
698
		try{
699
			transactionServiceClient = new TransactionServiceClient();
700
			orderClient = transactionServiceClient.getClient();
701
			orders = orderClient.getOrdersForCustomer(userId, 0, (new Date()).getTime(), OrderStatus.DELIVERY_SUCCESS);
702
 
703
		}catch (Exception e){
704
 
705
		}
706
		context.put("orders", orders);
707
		htmlString = getHtmlFromVelocity(templateFile, context);
708
		return htmlString;
709
	}
595 rajveer 710
	public String getMyaccountHeaderHtml() {
507 rajveer 711
		String htmlString = "";
712
		VelocityContext context = new VelocityContext();
713
		String templateFile = "templates/myaccountheader.vm";
714
		htmlString = getHtmlFromVelocity(templateFile, context);
715
		return htmlString;
716
	}
717
 
650 rajveer 718
	public String getShippingHeaderHtml() {
507 rajveer 719
		String htmlString = "";
720
		VelocityContext context = new VelocityContext();
721
		String templateFile = "templates/shippingheader.vm";
722
		htmlString = getHtmlFromVelocity(templateFile, context);
723
		return htmlString;
724
	}
725
 
822 vikas 726
	public String getShippingAddressDetailsHtml(long userId, String errorMsg){
507 rajveer 727
		String htmlString = "";
728
		VelocityContext context = new VelocityContext();
729
		String templateFile = "templates/shippingaddressdetails.vm";
730
		long defaultAddressId = 0;
517 rajveer 731
		List<Address> addresses = null;
507 rajveer 732
 
733
		UserContextServiceClient userContextServiceClient = null;
734
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
735
		try {
736
			userContextServiceClient = new UserContextServiceClient();
737
			userClient = userContextServiceClient.getClient();
620 rajveer 738
 
739
			addresses = userClient.getAllAddressesForUser(userId);
740
			defaultAddressId = userClient.getDefaultAddressId(userId);
507 rajveer 741
		} catch (Exception e) {
742
			e.printStackTrace();
743
		}
517 rajveer 744
		context.put("defaultAddressId", defaultAddressId+"");
507 rajveer 745
		context.put("addresses", addresses);
822 vikas 746
		context.put("errorMsg", errorMsg);
507 rajveer 747
 
748
		htmlString = getHtmlFromVelocity(templateFile, context);
749
		return htmlString;
750
	}
751
 
650 rajveer 752
	public String getShippingDetailsHtml(long cartId, String errorMsg) {
507 rajveer 753
		String htmlString = "";
754
		VelocityContext context = new VelocityContext();
755
		String templateFile = "templates/shippingdetails.vm";
517 rajveer 756
		List<Map<String,String>> items = null;
507 rajveer 757
		double totalamount= 0.0;
517 rajveer 758
		List<Address> addresses = null;
759
		long defaultAddressId = 0;
555 chandransh 760
 
507 rajveer 761
		CatalogServiceClient catalogServiceClient  = null;
762
		in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = null;
763
		UserContextServiceClient userContextServiceClient = null;
764
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
765
 
766
		try {
767
			catalogServiceClient = new CatalogServiceClient();
768
			catalogClient = catalogServiceClient.getClient();
769
			userContextServiceClient = new UserContextServiceClient();
770
			userClient = userContextServiceClient.getClient();
771
 
772
 
555 chandransh 773
			Cart cart = userClient.getCart(cartId);
507 rajveer 774
			List<Line> lineItems = cart.getLines();
775
 
517 rajveer 776
			if( ! lineItems.isEmpty())
777
			{
778
				items = new ArrayList<Map<String,String>>();
507 rajveer 779
 
517 rajveer 780
				for (Line line : lineItems) {
781
					Map<String, String> itemdetail = new HashMap<String, String>();
637 rajveer 782
					Item item = catalogClient.getItem(line.getItemId());
962 chandransh 783
					String itemName = ((item.getBrand() != null) ? item.getBrand() + " " : "")
517 rajveer 784
										+ ((item.getModelName() != null) ? item.getModelName() + " " : "") 
637 rajveer 785
										+ (( item.getModelNumber() != null ) ? item.getModelNumber() + " " : "" )
786
										+ (( (item.getColor() != null && !item.getColor().trim().equals("NA"))) ? "("+item.getColor()+")" : "" );
517 rajveer 787
 
788
					itemdetail.put("ITEM_NAME", itemName);
789
					itemdetail.put("ITEM_ID", line.getItemId()+"");
790
					itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
791
					itemdetail.put("MRP", ((int)item.getMrp())+"");
536 rajveer 792
					itemdetail.put("SELLING_PRICE", (int)item.getSellingPrice()+"");
793
					itemdetail.put("TOTAL_PRICE", (int)(item.getSellingPrice()*line.getQuantity())+"");
615 chandransh 794
					itemdetail.put("SHIPPING_TIME", line.getEstimate()+"");
536 rajveer 795
					totalamount = totalamount + line.getQuantity()*item.getSellingPrice();
517 rajveer 796
					items.add(itemdetail);				
797
				}
507 rajveer 798
			}
799
 
637 rajveer 800
			addresses = userClient.getAllAddressesForUser(cart.getUserId());
650 rajveer 801
			if(cart.isSetAddressId()){
802
				defaultAddressId = cart.getAddressId();
803
			}else{
804
				defaultAddressId = userClient.getDefaultAddressId(cart.getUserId());
805
			}
507 rajveer 806
 
807
		}catch (Exception e){
808
			e.printStackTrace();
809
		}
810
 
811
		context.put("items", items);
536 rajveer 812
		context.put("totalamount", (int)totalamount+"");
507 rajveer 813
		context.put("addresses", addresses);
517 rajveer 814
		context.put("defaultAddressId", defaultAddressId+"");
572 chandransh 815
		context.put("errorMsg", errorMsg);
507 rajveer 816
		htmlString = getHtmlFromVelocity(templateFile, context);
817
		return htmlString;
818
	}
819
 
820
 
650 rajveer 821
	public String getCartHeaderHtml() {
507 rajveer 822
		String htmlString = "";
823
		VelocityContext context = new VelocityContext();
824
		String templateFile = "templates/cartheader.vm";
825
		htmlString = getHtmlFromVelocity(templateFile, context);
826
		return htmlString;
827
	}
828
 
829
 
786 rajveer 830
	public String getCartDetailsHtml(long userId, long cartId, String errorMsg) {
507 rajveer 831
		String htmlString = "";
832
		VelocityContext context = new VelocityContext();
833
		String templateFile = "templates/cartdetails.vm";
517 rajveer 834
		List<Map<String,String>> items = null;
507 rajveer 835
		double totalamount= 0.0;
836
 
555 chandransh 837
		UserContextServiceClient userServiceClient = null;
838
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
507 rajveer 839
		CatalogServiceClient catalogServiceClient  = null;
840
		in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = null;
786 rajveer 841
		String pincode = "110001";
507 rajveer 842
		try {
843
			catalogServiceClient = new CatalogServiceClient();
844
			catalogClient = catalogServiceClient.getClient();
555 chandransh 845
			userServiceClient = new UserContextServiceClient();
846
			userClient = userServiceClient.getClient();
507 rajveer 847
 
786 rajveer 848
			pincode = userClient.getDefaultPincode(userId);
555 chandransh 849
			Cart cart = userClient.getCart(cartId);
507 rajveer 850
			List<Line> lineItems = cart.getLines();
517 rajveer 851
			if(lineItems.size() != 0){
852
				items = new ArrayList<Map<String,String>>();
853
				for (Line line : lineItems) {
854
 
855
					Map<String, String> itemdetail = new HashMap<String, String>();
637 rajveer 856
					Item item = catalogClient.getItem(line.getItemId());
517 rajveer 857
 
962 chandransh 858
					String itemName = ((item.getBrand() != null) ? item.getBrand() + " " : "")
517 rajveer 859
										+ ((item.getModelName() != null) ? item.getModelName() + " " : "") 
637 rajveer 860
										+ (( item.getModelNumber() != null ) ? item.getModelNumber() + " " : "" )
861
										+ (( (item.getColor() != null && !item.getColor().trim().equals("NA"))) ? "("+item.getColor()+")" : "" );
517 rajveer 862
 
863
					itemdetail.put("ITEM_NAME", itemName);
864
					System.out.println(itemdetail.get("ITEM_NAME"));
865
					itemdetail.put("ITEM_ID", line.getItemId()+"");
805 rajveer 866
					itemdetail.put("CATALOG_ID", item.getCatalogItemId()+"");
517 rajveer 867
					itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
868
					itemdetail.put("MRP", ((int)item.getMrp())+"");
869
					itemdetail.put("SELLING_PRICE", ((int)item.getSellingPrice())+"");
870
					itemdetail.put("TOTAL_PRICE", ((int)((item.getSellingPrice()*line.getQuantity())))+"");
615 chandransh 871
					itemdetail.put("SHIPPING_TIME", line.getEstimate()+"");
517 rajveer 872
					totalamount = totalamount + line.getQuantity()*item.getSellingPrice();
873
					items.add(itemdetail);				
507 rajveer 874
				}
875
			}
876
 
877
		}catch (Exception e){
878
			e.printStackTrace();
879
		}
880
 
881
		context.put("items", items);
517 rajveer 882
		context.put("totalamount", ((int)totalamount)+"");
572 chandransh 883
		context.put("errorMsg", errorMsg);
786 rajveer 884
		context.put("pincode", pincode);
507 rajveer 885
		htmlString = getHtmlFromVelocity(templateFile, context);
886
		return htmlString;
887
	}
888
 
889
	public String getHtmlFromVelocity(String templateFile, VelocityContext context){
890
		Properties p = new Properties();
891
		p.setProperty("resource.loader", "class");
892
		p.setProperty("class.resource.loader.class",
893
		"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
832 rajveer 894
		p.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogSystem"); 
895
 
507 rajveer 896
		try {
897
			Velocity.init(p);
762 rajveer 898
			//Velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, value)
507 rajveer 899
			Template template = Velocity.getTemplate(templateFile);
900
			if(template != null) {
901
				StringWriter writer = new StringWriter();
902
				template.merge(context, writer);
903
				writer.flush();
904
				writer.close();
905
				return writer.toString();
906
			}
907
 
908
			} catch (ResourceNotFoundException e) {
909
				// TODO Auto-generated catch block
910
				e.printStackTrace();
911
			} catch (ParseErrorException e) {
912
				// TODO Auto-generated catch block
913
				e.printStackTrace();
914
			} catch (MethodInvocationException e) {
915
				// TODO Auto-generated catch block
916
				e.printStackTrace();
917
			} catch (IOException e) {
918
				// TODO Auto-generated catch block
919
				e.printStackTrace();
920
			} catch (Exception e) {
921
				// TODO Auto-generated catch block
922
				e.printStackTrace();
923
			}
924
 
925
		return null;
926
	}
927
}
928