Subversion Repositories SmartDukaan

Rev

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