Subversion Repositories SmartDukaan

Rev

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