Subversion Repositories SmartDukaan

Rev

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

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