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