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