Subversion Repositories SmartDukaan

Rev

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 {
550 rajveer 378
			context.put("WELCOME_MESSAGE", "Hi, Welcome to Shop2020");
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
 
440
 
441
 
650 rajveer 442
	public String getOrderDetailsHtml(long orderId) {
507 rajveer 443
		String htmlString = "";
444
		VelocityContext context = new VelocityContext();
445
		String templateFile = "templates/orderdetails.vm";
446
		TransactionServiceClient transactionServiceClient = null;
447
		in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
448
		Order order = null;
517 rajveer 449
		Date orderedOn = null, deliveryEstimate = null;
507 rajveer 450
		try{
451
			transactionServiceClient = new TransactionServiceClient();
452
			orderClient = transactionServiceClient.getClient();
453
			order = orderClient.getOrder(orderId);
517 rajveer 454
			orderedOn = new Date(order.getCreated_timestamp());
455
			deliveryEstimate = new Date(order.getExpected_delivery_time());
507 rajveer 456
		}catch (Exception e){
457
 
458
		}
517 rajveer 459
 
460
		SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
583 rajveer 461
		SimpleDateFormat dateformat1 = new SimpleDateFormat("dd/MM/yyyy");
507 rajveer 462
		context.put("order", order);
517 rajveer 463
		context.put("orderedOn", dateformat.format(orderedOn));
583 rajveer 464
		context.put("deliveryEstimate", dateformat1.format(deliveryEstimate));
517 rajveer 465
 
466
 
507 rajveer 467
		htmlString = getHtmlFromVelocity(templateFile, context);
468
		return htmlString;
469
	}
470
 
650 rajveer 471
	public String getMyaccountDetailsHtml(long userId) {
507 rajveer 472
		String htmlString = "";
473
		VelocityContext context = new VelocityContext();
474
		String templateFile = "templates/myaccount.vm";
475
		List<Order> orders = null;
745 chandransh 476
		Map<Long, String> providerNames = new HashMap<Long, String>();
507 rajveer 477
		try{
745 chandransh 478
			TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
479
			in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
507 rajveer 480
			orders = orderClient.getOrdersForCustomer(userId, 0, (new Date()).getTime(), null);
481
 
745 chandransh 482
			LogisticsServiceClient logisticsServiceClient = new LogisticsServiceClient();
483
			in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
484
			List<Provider> providers = logisticsClient.getAllProviders();
485
			for(Provider provider: providers)
486
				providerNames.put(provider.getId(), provider.getName());
507 rajveer 487
		}catch (Exception e){
488
 
489
		}
741 rajveer 490
		List<String> orderDate = new ArrayList<String>();
491
		SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
762 rajveer 492
		if(orders==null || orders.isEmpty()){
493
			for(Order order: orders){
494
				Date orderedOn = new Date(order.getCreated_timestamp());
495
				orderDate.add(dateformat.format(orderedOn));
496
			}
741 rajveer 497
		}
507 rajveer 498
		context.put("orders", orders);
741 rajveer 499
		context.put("orderDate", orderDate);
745 chandransh 500
		context.put("providerNames", providerNames);
507 rajveer 501
		htmlString = getHtmlFromVelocity(templateFile, context);
502
		return htmlString;
503
	}
504
 
505
 
650 rajveer 506
	public String getLoginDetailsHtml(long userId) {
507 rajveer 507
		String htmlString = "";
508
		VelocityContext context = new VelocityContext();
509
		String templateFile = "templates/logindetails.vm";
510
		String email = "";
511
		try{
762 rajveer 512
			email = getEmailId(userId);
507 rajveer 513
		}catch (Exception e){
514
 
515
		}
516
		context.put("email", email);
517
		htmlString = getHtmlFromVelocity(templateFile, context);
518
		return htmlString;
519
	}
520
 
762 rajveer 521
	public String getEmailId(long userId){
522
		String email = " ";
523
 
524
		try {
525
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
526
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
527
			if(userClient.getUserById(userId).getEmail() != null){
528
				email = userClient.getUserById(userId).getEmail();
529
			}
530
		} catch (UserContextException e) {
531
			e.printStackTrace();
532
		} catch (TException e) {
533
			e.printStackTrace();
534
		} catch (Exception e) {
535
			e.printStackTrace();
536
		}
537
		return email; 
538
	}
539
 
540
 
595 rajveer 541
	public String getPersonalDetailsHtml(long userId) {
507 rajveer 542
		String htmlString = "";
543
		VelocityContext context = new VelocityContext();
544
		String templateFile = "templates/personaldetails.vm";
545
		String email = "";
517 rajveer 546
		String name = "";
569 rajveer 547
		String dateOfBirth = "";
517 rajveer 548
		String sex = "";
549
		String subscribe = "false";
507 rajveer 550
		UserContextServiceClient userContextServiceClient = null;
551
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
552
		try{
555 chandransh 553
			User user = null;
507 rajveer 554
			userContextServiceClient = new UserContextServiceClient();
555
			userClient = userContextServiceClient.getClient();
555 chandransh 556
			user = userClient.getUserById(userId);
507 rajveer 557
 
555 chandransh 558
			email = user.getCommunicationEmail();
559
			name = user.getName();
517 rajveer 560
 
569 rajveer 561
			dateOfBirth = user.getDateOfBirth();
507 rajveer 562
		}catch (Exception e){
555 chandransh 563
			e.printStackTrace();
507 rajveer 564
		}
517 rajveer 565
		context.put("name", name);
566
		context.put("email", email);
569 rajveer 567
		context.put("dateOfBirth", dateOfBirth+"");
517 rajveer 568
		context.put("subscribe", subscribe);
569
		context.put("sex", sex);
507 rajveer 570
		htmlString = getHtmlFromVelocity(templateFile, context);
571
		return htmlString;
572
	}
573
 
620 rajveer 574
	public String getCompletedOrdersHtml(long userId) {
507 rajveer 575
		String htmlString = "";
576
		VelocityContext context = new VelocityContext();
577
		String templateFile = "templates/completedorders.vm";
578
		TransactionServiceClient transactionServiceClient = null;
579
		in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
580
		List<Order> orders = null;
581
		try{
582
			transactionServiceClient = new TransactionServiceClient();
583
			orderClient = transactionServiceClient.getClient();
584
			orders = orderClient.getOrdersForCustomer(userId, 0, (new Date()).getTime(), OrderStatus.DELIVERY_SUCCESS);
585
 
586
		}catch (Exception e){
587
 
588
		}
589
		context.put("orders", orders);
590
		htmlString = getHtmlFromVelocity(templateFile, context);
591
		return htmlString;
592
	}
595 rajveer 593
	public String getMyaccountHeaderHtml() {
507 rajveer 594
		String htmlString = "";
595
		VelocityContext context = new VelocityContext();
596
		String templateFile = "templates/myaccountheader.vm";
597
		htmlString = getHtmlFromVelocity(templateFile, context);
598
		return htmlString;
599
	}
600
 
650 rajveer 601
	public String getShippingHeaderHtml() {
507 rajveer 602
		String htmlString = "";
603
		VelocityContext context = new VelocityContext();
604
		String templateFile = "templates/shippingheader.vm";
605
		htmlString = getHtmlFromVelocity(templateFile, context);
606
		return htmlString;
607
	}
608
 
650 rajveer 609
	public String getShippingAddressDetailsHtml(long userId){
507 rajveer 610
		String htmlString = "";
611
		VelocityContext context = new VelocityContext();
612
		String templateFile = "templates/shippingaddressdetails.vm";
613
		long defaultAddressId = 0;
517 rajveer 614
		List<Address> addresses = null;
507 rajveer 615
 
616
		UserContextServiceClient userContextServiceClient = null;
617
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
618
		try {
619
			userContextServiceClient = new UserContextServiceClient();
620
			userClient = userContextServiceClient.getClient();
620 rajveer 621
 
622
			addresses = userClient.getAllAddressesForUser(userId);
623
			defaultAddressId = userClient.getDefaultAddressId(userId);
507 rajveer 624
		} catch (Exception e) {
625
			e.printStackTrace();
626
		}
517 rajveer 627
		context.put("defaultAddressId", defaultAddressId+"");
507 rajveer 628
		context.put("addresses", addresses);
629
 
630
		htmlString = getHtmlFromVelocity(templateFile, context);
631
		return htmlString;
632
	}
633
 
650 rajveer 634
	public String getShippingDetailsHtml(long cartId, String errorMsg) {
507 rajveer 635
		String htmlString = "";
636
		VelocityContext context = new VelocityContext();
637
		String templateFile = "templates/shippingdetails.vm";
517 rajveer 638
		List<Map<String,String>> items = null;
507 rajveer 639
		double totalamount= 0.0;
517 rajveer 640
		List<Address> addresses = null;
641
		long defaultAddressId = 0;
555 chandransh 642
 
507 rajveer 643
		CatalogServiceClient catalogServiceClient  = null;
644
		in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = null;
645
		UserContextServiceClient userContextServiceClient = null;
646
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
647
 
648
		try {
649
			catalogServiceClient = new CatalogServiceClient();
650
			catalogClient = catalogServiceClient.getClient();
651
			userContextServiceClient = new UserContextServiceClient();
652
			userClient = userContextServiceClient.getClient();
653
 
654
 
555 chandransh 655
			Cart cart = userClient.getCart(cartId);
507 rajveer 656
			List<Line> lineItems = cart.getLines();
657
 
517 rajveer 658
			if( ! lineItems.isEmpty())
659
			{
660
				items = new ArrayList<Map<String,String>>();
507 rajveer 661
 
517 rajveer 662
				for (Line line : lineItems) {
663
					Map<String, String> itemdetail = new HashMap<String, String>();
637 rajveer 664
					Item item = catalogClient.getItem(line.getItemId());
517 rajveer 665
					String itemName = ((item.getManufacturerName() != null) ? item.getManufacturerName() + " " : "")
666
										+ ((item.getModelName() != null) ? item.getModelName() + " " : "") 
637 rajveer 667
										+ (( item.getModelNumber() != null ) ? item.getModelNumber() + " " : "" )
668
										+ (( (item.getColor() != null && !item.getColor().trim().equals("NA"))) ? "("+item.getColor()+")" : "" );
517 rajveer 669
 
670
					itemdetail.put("ITEM_NAME", itemName);
671
					itemdetail.put("ITEM_ID", line.getItemId()+"");
672
					itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
673
					itemdetail.put("MRP", ((int)item.getMrp())+"");
536 rajveer 674
					itemdetail.put("SELLING_PRICE", (int)item.getSellingPrice()+"");
675
					itemdetail.put("TOTAL_PRICE", (int)(item.getSellingPrice()*line.getQuantity())+"");
615 chandransh 676
					itemdetail.put("SHIPPING_TIME", line.getEstimate()+"");
536 rajveer 677
					totalamount = totalamount + line.getQuantity()*item.getSellingPrice();
517 rajveer 678
					items.add(itemdetail);				
679
				}
507 rajveer 680
			}
681
 
637 rajveer 682
			addresses = userClient.getAllAddressesForUser(cart.getUserId());
650 rajveer 683
			if(cart.isSetAddressId()){
684
				defaultAddressId = cart.getAddressId();
685
			}else{
686
				defaultAddressId = userClient.getDefaultAddressId(cart.getUserId());
687
			}
507 rajveer 688
 
689
		}catch (Exception e){
690
			e.printStackTrace();
691
		}
692
 
693
		context.put("items", items);
536 rajveer 694
		context.put("totalamount", (int)totalamount+"");
507 rajveer 695
		context.put("addresses", addresses);
517 rajveer 696
		context.put("defaultAddressId", defaultAddressId+"");
572 chandransh 697
		context.put("errorMsg", errorMsg);
507 rajveer 698
		htmlString = getHtmlFromVelocity(templateFile, context);
699
		return htmlString;
700
	}
701
 
702
 
650 rajveer 703
	public String getCartHeaderHtml() {
507 rajveer 704
		String htmlString = "";
705
		VelocityContext context = new VelocityContext();
706
		String templateFile = "templates/cartheader.vm";
707
		htmlString = getHtmlFromVelocity(templateFile, context);
708
		return htmlString;
709
	}
710
 
711
 
786 rajveer 712
	public String getCartDetailsHtml(long userId, long cartId, String errorMsg) {
507 rajveer 713
		String htmlString = "";
714
		VelocityContext context = new VelocityContext();
715
		String templateFile = "templates/cartdetails.vm";
517 rajveer 716
		List<Map<String,String>> items = null;
507 rajveer 717
		double totalamount= 0.0;
718
 
555 chandransh 719
		UserContextServiceClient userServiceClient = null;
720
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
507 rajveer 721
		CatalogServiceClient catalogServiceClient  = null;
722
		in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = null;
786 rajveer 723
		String pincode = "110001";
507 rajveer 724
		try {
725
			catalogServiceClient = new CatalogServiceClient();
726
			catalogClient = catalogServiceClient.getClient();
555 chandransh 727
			userServiceClient = new UserContextServiceClient();
728
			userClient = userServiceClient.getClient();
507 rajveer 729
 
786 rajveer 730
			pincode = userClient.getDefaultPincode(userId);
555 chandransh 731
			Cart cart = userClient.getCart(cartId);
507 rajveer 732
			List<Line> lineItems = cart.getLines();
517 rajveer 733
			if(lineItems.size() != 0){
734
				items = new ArrayList<Map<String,String>>();
735
				for (Line line : lineItems) {
736
 
737
					Map<String, String> itemdetail = new HashMap<String, String>();
637 rajveer 738
					Item item = catalogClient.getItem(line.getItemId());
517 rajveer 739
 
740
					String itemName = ((item.getManufacturerName() != null) ? item.getManufacturerName() + " " : "")
741
										+ ((item.getModelName() != null) ? item.getModelName() + " " : "") 
637 rajveer 742
										+ (( item.getModelNumber() != null ) ? item.getModelNumber() + " " : "" )
743
										+ (( (item.getColor() != null && !item.getColor().trim().equals("NA"))) ? "("+item.getColor()+")" : "" );
517 rajveer 744
 
745
					itemdetail.put("ITEM_NAME", itemName);
746
					System.out.println(itemdetail.get("ITEM_NAME"));
747
					itemdetail.put("ITEM_ID", line.getItemId()+"");
748
					itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
749
					itemdetail.put("MRP", ((int)item.getMrp())+"");
750
					itemdetail.put("SELLING_PRICE", ((int)item.getSellingPrice())+"");
751
					itemdetail.put("TOTAL_PRICE", ((int)((item.getSellingPrice()*line.getQuantity())))+"");
615 chandransh 752
					itemdetail.put("SHIPPING_TIME", line.getEstimate()+"");
517 rajveer 753
					totalamount = totalamount + line.getQuantity()*item.getSellingPrice();
754
					items.add(itemdetail);				
507 rajveer 755
				}
756
			}
757
 
758
		}catch (Exception e){
759
			e.printStackTrace();
760
		}
761
 
762
		context.put("items", items);
517 rajveer 763
		context.put("totalamount", ((int)totalamount)+"");
572 chandransh 764
		context.put("errorMsg", errorMsg);
786 rajveer 765
		context.put("pincode", pincode);
507 rajveer 766
		htmlString = getHtmlFromVelocity(templateFile, context);
767
		return htmlString;
768
	}
769
 
770
	public String getHtmlFromVelocity(String templateFile, VelocityContext context){
771
		Properties p = new Properties();
772
		p.setProperty("resource.loader", "class");
773
		p.setProperty("class.resource.loader.class",
774
		"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
762 rajveer 775
		p.setProperty("file.resource.loader.path",
776
		"/home/FTP-shared/upload/");
777
 
507 rajveer 778
		try {
779
			Velocity.init(p);
762 rajveer 780
			//Velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, value)
507 rajveer 781
			Template template = Velocity.getTemplate(templateFile);
782
			if(template != null) {
783
				StringWriter writer = new StringWriter();
784
				template.merge(context, writer);
785
				writer.flush();
786
				writer.close();
787
				return writer.toString();
788
			}
789
 
790
			} catch (ResourceNotFoundException e) {
791
				// TODO Auto-generated catch block
792
				e.printStackTrace();
793
			} catch (ParseErrorException e) {
794
				// TODO Auto-generated catch block
795
				e.printStackTrace();
796
			} catch (MethodInvocationException e) {
797
				// TODO Auto-generated catch block
798
				e.printStackTrace();
799
			} catch (IOException e) {
800
				// TODO Auto-generated catch block
801
				e.printStackTrace();
802
			} catch (Exception e) {
803
				// TODO Auto-generated catch block
804
				e.printStackTrace();
805
			}
806
 
807
		return null;
808
	}
809
 
810
 
517 rajveer 811
	public String getCategoryHeaderSnippet() {
812
		String htmlString = "";
813
		VelocityContext context = new VelocityContext();
814
		String templateFile = "templates/categoryheader.vm";
815
		htmlString = getHtmlFromVelocity(templateFile, context);
816
		return htmlString;
817
	}
818
 
507 rajveer 819
 
820
 
821
}
822