Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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