Subversion Repositories SmartDukaan

Rev

Rev 1197 | Rev 1310 | 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
 
1197 varun.gupt 349
	public String getSocialUtilsHtml(long productId, String productName, String requestURL) {
507 rajveer 350
		String htmlString = "";
351
		VelocityContext context = new VelocityContext();
1197 varun.gupt 352
 
507 rajveer 353
		String templateFile = "templates/socialutils.vm";
1197 varun.gupt 354
 
355
		context.put("PRODUCT_ID", productId + "");
356
		context.put("PRODUCT_NAME", productName);
357
		context.put("PRODUCT_URL", requestURL);
358
 
507 rajveer 359
		htmlString = getHtmlFromVelocity(templateFile, context);
360
		return htmlString;
361
	}
974 vikas 362
 
363
	public String getPageTitleHtml(long productId) {
364
		StringBuilder htmlString = new StringBuilder();
989 vikas 365
		String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "TitleSnippet.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 getPageMetaDescriptionHtml(long productId) {
399
		StringBuilder htmlString = new StringBuilder();
989 vikas 400
		String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "MetaDescriptionSnippet.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
	}
432
 
433
	public String getPageMetaKeywordsHtml(long productId) {
434
		StringBuilder htmlString = new StringBuilder();
989 vikas 435
		String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "MetaKeywordsSnippet.html";
974 vikas 436
		File f = new File(filename);
437
 
438
 
439
		FileInputStream fis = null;
440
		try {
441
			fis = new FileInputStream(f);
442
			BufferedReader br = new BufferedReader(new InputStreamReader(fis));
443
			String line;
444
			while((line = br.readLine()) != null){
445
				htmlString.append(line+"\n");
446
			}
447
		} catch (FileNotFoundException e) {
448
			// TODO Auto-generated catch block
449
			e.printStackTrace();
450
		} catch (IOException e) {
451
			// TODO Auto-generated catch block
452
			e.printStackTrace();
453
		}
454
		finally {
455
			if(fis != null) {
456
				try {
457
					fis.close();
458
				} catch (IOException e) {
459
					// TODO Auto-generated catch block
460
					e.printStackTrace();
461
				}
462
			}
463
		}
464
 
465
		return htmlString.toString();
466
	}
507 rajveer 467
 
517 rajveer 468
	public String getMainMenuHtml() {
507 rajveer 469
		String htmlString = "";
470
		VelocityContext context = new VelocityContext();
471
		String templateFile = "templates/mainmenu.vm";
472
		htmlString = getHtmlFromVelocity(templateFile, context);
473
		return htmlString;
474
	}
475
 
476
 
517 rajveer 477
	public String getSearchBarHtml(long itemCounts, long categoryId) {
507 rajveer 478
		String htmlString = "";
479
		VelocityContext context = new VelocityContext();
480
		String templateFile = "templates/searchbar.vm";
550 rajveer 481
 
482
		context.put("itemCount", itemCounts+"");
483
		context.put("categoryId", categoryId+"");
484
 
507 rajveer 485
		htmlString = getHtmlFromVelocity(templateFile, context);
486
		return htmlString;
487
	}
488
 
489
 
490
 
924 vikas 491
	public String getHeaderHtml(boolean isLoggedIn, String  userName, String url) {
550 rajveer 492
		VelocityContext context = new VelocityContext();
555 chandransh 493
		if (isLoggedIn) {
494
			context.put("LOGGED_IN", "TRUE");
495
			context.put("WELCOME_MESSAGE", "Hi, " + userName);
496
		} else {
801 rajveer 497
			context.put("WELCOME_MESSAGE", "Hi, Welcome to Saholic");
924 vikas 498
			context.put("REDIRECT_URL", url);
555 chandransh 499
		}		
507 rajveer 500
 
501
		String templateFile = "templates/header.vm";
550 rajveer 502
 
590 chandransh 503
		return getHtmlFromVelocity(templateFile, context);
507 rajveer 504
	}
505
 
506
 
507
 
650 rajveer 508
	public	String getWidgetDiv(long userId, WidgetType widgetType, String templateFile){
507 rajveer 509
 
555 chandransh 510
		UserContextServiceClient userServiceClient = null;
511
		in.shop2020.model.v1.user.UserContextService.Client client = null;
507 rajveer 512
		Widget widget = null;
513
		try {
555 chandransh 514
			userServiceClient = new UserContextServiceClient();
515
			client = userServiceClient.getClient();
773 rajveer 516
			if(widgetType == WidgetType.MY_RESEARCH && userId != 0){
517
				widget = client.getMyResearch(userId);
518
			}
519
			if(widgetType == WidgetType.BROWSE_HISTORY){
520
				widget = client.getBrowseHistory(userId);
521
			}
522
 
507 rajveer 523
		} catch (Exception e) {
524
			e.printStackTrace();
762 rajveer 525
		}finally{
526
			userServiceClient.closeConnection();
507 rajveer 527
		}
528
 
529
 
530
		List<Map<String, String>> itemDetails = null;
531
 
532
		if(widget != null){
533
			List<WidgetItem> items = widget.getItems();
534
			itemDetails = new ArrayList<Map<String, String>>();
535
 
536
			for(WidgetItem item: items){
537
				Map<String, String> itemDetail = new HashMap<String, String>();
1110 rajveer 538
				String itemSnippet;
507 rajveer 539
 
1110 rajveer 540
					try {
541
						itemSnippet = FileUtils.read( Utils.EXPORT_ENTITIES_PATH + item.getItem_id() + File.separator + "WidgetSnippet.html");
542
					} catch (IOException e) {
543
						e.printStackTrace();
544
						continue;
545
					}
546
 
507 rajveer 547
				itemDetail.put("ITEM_ID", item.getItem_id()+"");
1110 rajveer 548
				itemDetail.put("ITEM_SNIPPET", itemSnippet);
507 rajveer 549
				itemDetails.add(itemDetail);
550
			}
551
		}else{
552
			System.out.println("widget not found");
553
		}
554
 
555
		VelocityContext context = new VelocityContext();
620 rajveer 556
		context.put("userId", userId);
507 rajveer 557
		context.put("itemDetails", itemDetails);
558
 
559
		return getHtmlFromVelocity("templates/"+templateFile, context);
560
	}
561
 
562
 
650 rajveer 563
	public String getOrderDetailsHtml(long orderId) {
507 rajveer 564
		String htmlString = "";
565
		VelocityContext context = new VelocityContext();
566
		String templateFile = "templates/orderdetails.vm";
567
		Order order = null;
517 rajveer 568
		Date orderedOn = null, deliveryEstimate = null;
843 chandransh 569
		Provider provider = null;
507 rajveer 570
		try{
843 chandransh 571
			TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
572
			in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
507 rajveer 573
			order = orderClient.getOrder(orderId);
517 rajveer 574
			orderedOn = new Date(order.getCreated_timestamp());
575
			deliveryEstimate = new Date(order.getExpected_delivery_time());
843 chandransh 576
 
577
			if(order.getLogistics_provider_id() != 0){
578
				LogisticsServiceClient logisticsServiceClient = new LogisticsServiceClient();
579
				in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
580
				provider = logisticsClient.getProvider(order.getLogistics_provider_id());
581
			}
507 rajveer 582
		}catch (Exception e){
583
 
584
		}
517 rajveer 585
 
586
		SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
583 rajveer 587
		SimpleDateFormat dateformat1 = new SimpleDateFormat("dd/MM/yyyy");
507 rajveer 588
		context.put("order", order);
517 rajveer 589
		context.put("orderedOn", dateformat.format(orderedOn));
583 rajveer 590
		context.put("deliveryEstimate", dateformat1.format(deliveryEstimate));
843 chandransh 591
		if(provider!=null){
592
			context.put("providerName", provider.getName());
593
		}
594
 
507 rajveer 595
		htmlString = getHtmlFromVelocity(templateFile, context);
596
		return htmlString;
597
	}
598
 
650 rajveer 599
	public String getMyaccountDetailsHtml(long userId) {
507 rajveer 600
		String htmlString = "";
601
		VelocityContext context = new VelocityContext();
602
		String templateFile = "templates/myaccount.vm";
603
		List<Order> orders = null;
745 chandransh 604
		Map<Long, String> providerNames = new HashMap<Long, String>();
507 rajveer 605
		try{
745 chandransh 606
			TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
607
			in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
507 rajveer 608
			orders = orderClient.getOrdersForCustomer(userId, 0, (new Date()).getTime(), null);
609
 
745 chandransh 610
			LogisticsServiceClient logisticsServiceClient = new LogisticsServiceClient();
611
			in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
612
			List<Provider> providers = logisticsClient.getAllProviders();
613
			for(Provider provider: providers)
614
				providerNames.put(provider.getId(), provider.getName());
507 rajveer 615
		}catch (Exception e){
1275 varun.gupt 616
			e.printStackTrace();
507 rajveer 617
		}
741 rajveer 618
		List<String> orderDate = new ArrayList<String>();
619
		SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
888 chandransh 620
		if(orders!=null && !orders.isEmpty()){
762 rajveer 621
			for(Order order: orders){
622
				Date orderedOn = new Date(order.getCreated_timestamp());
623
				orderDate.add(dateformat.format(orderedOn));
624
			}
741 rajveer 625
		}
507 rajveer 626
		context.put("orders", orders);
741 rajveer 627
		context.put("orderDate", orderDate);
745 chandransh 628
		context.put("providerNames", providerNames);
507 rajveer 629
		htmlString = getHtmlFromVelocity(templateFile, context);
630
		return htmlString;
631
	}
632
 
633
 
650 rajveer 634
	public String getLoginDetailsHtml(long userId) {
507 rajveer 635
		String htmlString = "";
636
		VelocityContext context = new VelocityContext();
637
		String templateFile = "templates/logindetails.vm";
638
		String email = "";
639
		try{
762 rajveer 640
			email = getEmailId(userId);
507 rajveer 641
		}catch (Exception e){
642
 
643
		}
644
		context.put("email", email);
645
		htmlString = getHtmlFromVelocity(templateFile, context);
646
		return htmlString;
647
	}
648
 
762 rajveer 649
	public String getEmailId(long userId){
650
		String email = " ";
651
 
652
		try {
653
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
654
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
655
			if(userClient.getUserById(userId).getEmail() != null){
656
				email = userClient.getUserById(userId).getEmail();
657
			}
658
		} catch (UserContextException e) {
659
			e.printStackTrace();
660
		} catch (TException e) {
661
			e.printStackTrace();
662
		} catch (Exception e) {
663
			e.printStackTrace();
664
		}
665
		return email; 
666
	}
667
 
668
 
595 rajveer 669
	public String getPersonalDetailsHtml(long userId) {
507 rajveer 670
		String htmlString = "";
671
		VelocityContext context = new VelocityContext();
672
		String templateFile = "templates/personaldetails.vm";
673
		String email = "";
517 rajveer 674
		String name = "";
569 rajveer 675
		String dateOfBirth = "";
517 rajveer 676
		String sex = "";
677
		String subscribe = "false";
507 rajveer 678
		UserContextServiceClient userContextServiceClient = null;
679
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
680
		try{
555 chandransh 681
			User user = null;
507 rajveer 682
			userContextServiceClient = new UserContextServiceClient();
683
			userClient = userContextServiceClient.getClient();
555 chandransh 684
			user = userClient.getUserById(userId);
507 rajveer 685
 
555 chandransh 686
			email = user.getCommunicationEmail();
687
			name = user.getName();
517 rajveer 688
 
569 rajveer 689
			dateOfBirth = user.getDateOfBirth();
507 rajveer 690
		}catch (Exception e){
555 chandransh 691
			e.printStackTrace();
507 rajveer 692
		}
517 rajveer 693
		context.put("name", name);
694
		context.put("email", email);
569 rajveer 695
		context.put("dateOfBirth", dateOfBirth+"");
517 rajveer 696
		context.put("subscribe", subscribe);
697
		context.put("sex", sex);
507 rajveer 698
		htmlString = getHtmlFromVelocity(templateFile, context);
699
		return htmlString;
700
	}
701
 
620 rajveer 702
	public String getCompletedOrdersHtml(long userId) {
507 rajveer 703
		String htmlString = "";
704
		VelocityContext context = new VelocityContext();
705
		String templateFile = "templates/completedorders.vm";
706
		TransactionServiceClient transactionServiceClient = null;
707
		in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
708
		List<Order> orders = null;
709
		try{
710
			transactionServiceClient = new TransactionServiceClient();
711
			orderClient = transactionServiceClient.getClient();
712
			orders = orderClient.getOrdersForCustomer(userId, 0, (new Date()).getTime(), OrderStatus.DELIVERY_SUCCESS);
713
 
714
		}catch (Exception e){
715
 
716
		}
717
		context.put("orders", orders);
718
		htmlString = getHtmlFromVelocity(templateFile, context);
719
		return htmlString;
720
	}
595 rajveer 721
	public String getMyaccountHeaderHtml() {
507 rajveer 722
		String htmlString = "";
723
		VelocityContext context = new VelocityContext();
724
		String templateFile = "templates/myaccountheader.vm";
725
		htmlString = getHtmlFromVelocity(templateFile, context);
726
		return htmlString;
727
	}
728
 
650 rajveer 729
	public String getShippingHeaderHtml() {
507 rajveer 730
		String htmlString = "";
731
		VelocityContext context = new VelocityContext();
732
		String templateFile = "templates/shippingheader.vm";
733
		htmlString = getHtmlFromVelocity(templateFile, context);
734
		return htmlString;
735
	}
736
 
822 vikas 737
	public String getShippingAddressDetailsHtml(long userId, String errorMsg){
507 rajveer 738
		String htmlString = "";
739
		VelocityContext context = new VelocityContext();
740
		String templateFile = "templates/shippingaddressdetails.vm";
741
		long defaultAddressId = 0;
517 rajveer 742
		List<Address> addresses = null;
507 rajveer 743
 
744
		UserContextServiceClient userContextServiceClient = null;
745
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
746
		try {
747
			userContextServiceClient = new UserContextServiceClient();
748
			userClient = userContextServiceClient.getClient();
620 rajveer 749
 
750
			addresses = userClient.getAllAddressesForUser(userId);
751
			defaultAddressId = userClient.getDefaultAddressId(userId);
507 rajveer 752
		} catch (Exception e) {
753
			e.printStackTrace();
754
		}
517 rajveer 755
		context.put("defaultAddressId", defaultAddressId+"");
507 rajveer 756
		context.put("addresses", addresses);
822 vikas 757
		context.put("errorMsg", errorMsg);
507 rajveer 758
 
759
		htmlString = getHtmlFromVelocity(templateFile, context);
760
		return htmlString;
761
	}
762
 
650 rajveer 763
	public String getShippingDetailsHtml(long cartId, String errorMsg) {
507 rajveer 764
		String htmlString = "";
765
		VelocityContext context = new VelocityContext();
766
		String templateFile = "templates/shippingdetails.vm";
517 rajveer 767
		List<Map<String,String>> items = null;
507 rajveer 768
		double totalamount= 0.0;
517 rajveer 769
		List<Address> addresses = null;
770
		long defaultAddressId = 0;
555 chandransh 771
 
507 rajveer 772
		CatalogServiceClient catalogServiceClient  = null;
773
		in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = null;
774
		UserContextServiceClient userContextServiceClient = null;
775
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
776
 
777
		try {
778
			catalogServiceClient = new CatalogServiceClient();
779
			catalogClient = catalogServiceClient.getClient();
780
			userContextServiceClient = new UserContextServiceClient();
781
			userClient = userContextServiceClient.getClient();
782
 
783
 
555 chandransh 784
			Cart cart = userClient.getCart(cartId);
507 rajveer 785
			List<Line> lineItems = cart.getLines();
786
 
517 rajveer 787
			if( ! lineItems.isEmpty())
788
			{
789
				items = new ArrayList<Map<String,String>>();
507 rajveer 790
 
517 rajveer 791
				for (Line line : lineItems) {
792
					Map<String, String> itemdetail = new HashMap<String, String>();
637 rajveer 793
					Item item = catalogClient.getItem(line.getItemId());
962 chandransh 794
					String itemName = ((item.getBrand() != null) ? item.getBrand() + " " : "")
517 rajveer 795
										+ ((item.getModelName() != null) ? item.getModelName() + " " : "") 
637 rajveer 796
										+ (( item.getModelNumber() != null ) ? item.getModelNumber() + " " : "" )
797
										+ (( (item.getColor() != null && !item.getColor().trim().equals("NA"))) ? "("+item.getColor()+")" : "" );
517 rajveer 798
 
799
					itemdetail.put("ITEM_NAME", itemName);
800
					itemdetail.put("ITEM_ID", line.getItemId()+"");
801
					itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
802
					itemdetail.put("MRP", ((int)item.getMrp())+"");
536 rajveer 803
					itemdetail.put("SELLING_PRICE", (int)item.getSellingPrice()+"");
804
					itemdetail.put("TOTAL_PRICE", (int)(item.getSellingPrice()*line.getQuantity())+"");
615 chandransh 805
					itemdetail.put("SHIPPING_TIME", line.getEstimate()+"");
536 rajveer 806
					totalamount = totalamount + line.getQuantity()*item.getSellingPrice();
517 rajveer 807
					items.add(itemdetail);				
808
				}
507 rajveer 809
			}
810
 
637 rajveer 811
			addresses = userClient.getAllAddressesForUser(cart.getUserId());
650 rajveer 812
			if(cart.isSetAddressId()){
813
				defaultAddressId = cart.getAddressId();
814
			}else{
815
				defaultAddressId = userClient.getDefaultAddressId(cart.getUserId());
816
			}
507 rajveer 817
 
818
		}catch (Exception e){
819
			e.printStackTrace();
820
		}
821
 
822
		context.put("items", items);
536 rajveer 823
		context.put("totalamount", (int)totalamount+"");
507 rajveer 824
		context.put("addresses", addresses);
517 rajveer 825
		context.put("defaultAddressId", defaultAddressId+"");
572 chandransh 826
		context.put("errorMsg", errorMsg);
507 rajveer 827
		htmlString = getHtmlFromVelocity(templateFile, context);
828
		return htmlString;
829
	}
830
 
831
 
650 rajveer 832
	public String getCartHeaderHtml() {
507 rajveer 833
		String htmlString = "";
834
		VelocityContext context = new VelocityContext();
835
		String templateFile = "templates/cartheader.vm";
836
		htmlString = getHtmlFromVelocity(templateFile, context);
837
		return htmlString;
838
	}
839
 
840
 
786 rajveer 841
	public String getCartDetailsHtml(long userId, long cartId, String errorMsg) {
507 rajveer 842
		String htmlString = "";
843
		VelocityContext context = new VelocityContext();
844
		String templateFile = "templates/cartdetails.vm";
517 rajveer 845
		List<Map<String,String>> items = null;
507 rajveer 846
		double totalamount= 0.0;
847
 
555 chandransh 848
		UserContextServiceClient userServiceClient = null;
849
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
507 rajveer 850
		CatalogServiceClient catalogServiceClient  = null;
851
		in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = null;
786 rajveer 852
		String pincode = "110001";
507 rajveer 853
		try {
854
			catalogServiceClient = new CatalogServiceClient();
855
			catalogClient = catalogServiceClient.getClient();
555 chandransh 856
			userServiceClient = new UserContextServiceClient();
857
			userClient = userServiceClient.getClient();
507 rajveer 858
 
786 rajveer 859
			pincode = userClient.getDefaultPincode(userId);
555 chandransh 860
			Cart cart = userClient.getCart(cartId);
507 rajveer 861
			List<Line> lineItems = cart.getLines();
517 rajveer 862
			if(lineItems.size() != 0){
863
				items = new ArrayList<Map<String,String>>();
864
				for (Line line : lineItems) {
865
 
866
					Map<String, String> itemdetail = new HashMap<String, String>();
637 rajveer 867
					Item item = catalogClient.getItem(line.getItemId());
517 rajveer 868
 
962 chandransh 869
					String itemName = ((item.getBrand() != null) ? item.getBrand() + " " : "")
517 rajveer 870
										+ ((item.getModelName() != null) ? item.getModelName() + " " : "") 
637 rajveer 871
										+ (( item.getModelNumber() != null ) ? item.getModelNumber() + " " : "" )
872
										+ (( (item.getColor() != null && !item.getColor().trim().equals("NA"))) ? "("+item.getColor()+")" : "" );
517 rajveer 873
 
874
					itemdetail.put("ITEM_NAME", itemName);
875
					System.out.println(itemdetail.get("ITEM_NAME"));
876
					itemdetail.put("ITEM_ID", line.getItemId()+"");
805 rajveer 877
					itemdetail.put("CATALOG_ID", item.getCatalogItemId()+"");
517 rajveer 878
					itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
879
					itemdetail.put("MRP", ((int)item.getMrp())+"");
880
					itemdetail.put("SELLING_PRICE", ((int)item.getSellingPrice())+"");
881
					itemdetail.put("TOTAL_PRICE", ((int)((item.getSellingPrice()*line.getQuantity())))+"");
615 chandransh 882
					itemdetail.put("SHIPPING_TIME", line.getEstimate()+"");
517 rajveer 883
					totalamount = totalamount + line.getQuantity()*item.getSellingPrice();
884
					items.add(itemdetail);				
507 rajveer 885
				}
886
			}
887
 
888
		}catch (Exception e){
889
			e.printStackTrace();
890
		}
891
 
892
		context.put("items", items);
517 rajveer 893
		context.put("totalamount", ((int)totalamount)+"");
572 chandransh 894
		context.put("errorMsg", errorMsg);
786 rajveer 895
		context.put("pincode", pincode);
507 rajveer 896
		htmlString = getHtmlFromVelocity(templateFile, context);
897
		return htmlString;
898
	}
899
 
900
	public String getHtmlFromVelocity(String templateFile, VelocityContext context){
901
		Properties p = new Properties();
902
		p.setProperty("resource.loader", "class");
903
		p.setProperty("class.resource.loader.class",
904
		"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
832 rajveer 905
		p.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogSystem"); 
906
 
507 rajveer 907
		try {
908
			Velocity.init(p);
762 rajveer 909
			//Velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, value)
507 rajveer 910
			Template template = Velocity.getTemplate(templateFile);
911
			if(template != null) {
912
				StringWriter writer = new StringWriter();
913
				template.merge(context, writer);
914
				writer.flush();
915
				writer.close();
916
				return writer.toString();
917
			}
918
 
919
			} catch (ResourceNotFoundException e) {
920
				// TODO Auto-generated catch block
921
				e.printStackTrace();
922
			} catch (ParseErrorException e) {
923
				// TODO Auto-generated catch block
924
				e.printStackTrace();
925
			} catch (MethodInvocationException e) {
926
				// TODO Auto-generated catch block
927
				e.printStackTrace();
928
			} catch (IOException e) {
929
				// TODO Auto-generated catch block
930
				e.printStackTrace();
931
			} catch (Exception e) {
932
				// TODO Auto-generated catch block
933
				e.printStackTrace();
934
			}
935
 
936
		return null;
937
	}
938
}
939