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