Subversion Repositories SmartDukaan

Rev

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