Subversion Repositories SmartDukaan

Rev

Rev 627 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 627 Rev 637
Line 13... Line 13...
13
import java.util.HashMap;
13
import java.util.HashMap;
14
import java.util.List;
14
import java.util.List;
15
import java.util.Map;
15
import java.util.Map;
16
import java.util.Properties;
16
import java.util.Properties;
17
 
17
 
18
import in.shop2020.util.Utils;
-
 
19
 
-
 
20
import org.apache.thrift.TException;
18
import org.apache.thrift.TException;
21
import org.apache.velocity.Template;
19
import org.apache.velocity.Template;
22
import org.apache.velocity.VelocityContext;
20
import org.apache.velocity.VelocityContext;
23
import org.apache.velocity.app.Velocity;
21
import org.apache.velocity.app.Velocity;
24
import org.apache.velocity.exception.MethodInvocationException;
22
import org.apache.velocity.exception.MethodInvocationException;
25
import org.apache.velocity.exception.ParseErrorException;
23
import org.apache.velocity.exception.ParseErrorException;
26
import org.apache.velocity.exception.ResourceNotFoundException;
24
import org.apache.velocity.exception.ResourceNotFoundException;
27
 
25
 
28
 
26
 
29
import in.shop2020.metamodel.definitions.Catalog;
-
 
30
import in.shop2020.metamodel.definitions.DefinitionsContainer;
-
 
31
import in.shop2020.metamodel.definitions.EntityContainer;
-
 
32
import in.shop2020.metamodel.util.ExpandedCategory;
-
 
33
import in.shop2020.metamodel.util.ExpandedEntity;
-
 
34
import in.shop2020.model.v1.catalog.InventoryServiceException;
27
import in.shop2020.model.v1.catalog.InventoryServiceException;
35
import in.shop2020.model.v1.catalog.Item;
28
import in.shop2020.model.v1.catalog.Item;
36
import in.shop2020.model.v1.catalog.InventoryService.Client;
29
import in.shop2020.model.v1.catalog.InventoryService.Client;
37
import in.shop2020.model.v1.order.Order;
30
import in.shop2020.model.v1.order.Order;
38
import in.shop2020.model.v1.order.OrderStatus;
31
import in.shop2020.model.v1.order.OrderStatus;
39
import in.shop2020.model.v1.order.Transaction;
-
 
40
import in.shop2020.model.v1.user.Cart;
32
import in.shop2020.model.v1.user.Cart;
41
import in.shop2020.model.v1.user.Line;
33
import in.shop2020.model.v1.user.Line;
42
import in.shop2020.model.v1.user.LineStatus;
-
 
43
import in.shop2020.model.v1.user.ShoppingCartException;
-
 
44
import in.shop2020.model.v1.user.Address;
34
import in.shop2020.model.v1.user.Address;
45
import in.shop2020.model.v1.user.User;
35
import in.shop2020.model.v1.user.User;
46
import in.shop2020.model.v1.user.UserContextException;
-
 
47
import in.shop2020.model.v1.user.RatingType;
36
import in.shop2020.model.v1.user.RatingType;
48
import in.shop2020.model.v1.user.RatingsWidget;
37
import in.shop2020.model.v1.user.RatingsWidget;
49
import in.shop2020.model.v1.user.Widget;
38
import in.shop2020.model.v1.user.Widget;
50
import in.shop2020.model.v1.user.WidgetItem;
39
import in.shop2020.model.v1.user.WidgetItem;
51
import in.shop2020.model.v1.user.WidgetType;
40
import in.shop2020.model.v1.user.WidgetType;
52
import in.shop2020.serving.page.CategoryPage;
41
import in.shop2020.serving.page.CategoryPage;
53
import in.shop2020.serving.page.MyAccountPage;
-
 
54
import in.shop2020.serving.page.ProductPage;
-
 
55
import in.shop2020.serving.page.ShoppingCartPage;
-
 
56
import in.shop2020.serving.utils.*;
42
import in.shop2020.serving.utils.*;
57
import in.shop2020.thrift.clients.CatalogServiceClient;
43
import in.shop2020.thrift.clients.CatalogServiceClient;
58
import in.shop2020.thrift.clients.TransactionServiceClient;
44
import in.shop2020.thrift.clients.TransactionServiceClient;
59
import in.shop2020.thrift.clients.UserContextServiceClient;
45
import in.shop2020.thrift.clients.UserContextServiceClient;
60
 
46
 
Line 101... Line 87...
101
		System.out.println("CUSTOMER_SERVICE Snippet generated");
87
		System.out.println("CUSTOMER_SERVICE Snippet generated");
102
		
88
		
103
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, isLoggedIn));
89
		htmlSnippet.put("MY_RESEARCH", getMyResearchHtml(userId, isLoggedIn));
104
		System.out.println("MY_RESEARCH Snippet generated");
90
		System.out.println("MY_RESEARCH Snippet generated");
105
 
91
 
-
 
92
		htmlSnippet.put("BROWSE_HISTORY", getBrowseHistoryHtml(userId, isLoggedIn));
-
 
93
		System.out.println("BROWSE_HISTORY Snippet generated");
-
 
94
		
106
		htmlSnippet.put("RECOMMENDATIONS", getRecommendationsHtml());
95
		htmlSnippet.put("RECOMMENDATIONS", getRecommendationsHtml());
107
		System.out.println("RECOMMENDATIONS Snippet generated");
96
		System.out.println("RECOMMENDATIONS Snippet generated");
108
 
97
 
109
		htmlSnippet.put("SIMILAR_PRODUCTS", getSimilarProductsHtml(productId));
98
		htmlSnippet.put("SIMILAR_PRODUCTS", getSimilarProductsHtml(productId));
110
		System.out.println("RECOMMENDATIONS Snippet generated");
99
		System.out.println("RECOMMENDATIONS Snippet generated");
Line 160... Line 149...
160
 
149
 
161
		
150
		
162
		return htmlSnippet;
151
		return htmlSnippet;
163
	}
152
	}
164
	
153
	
165
	private String getRegistrationFormHtml() {
154
	public String getRegistrationFormHtml() {
166
		String htmlString = "";
155
		String htmlString = "";
167
		VelocityContext context = new VelocityContext();
156
		VelocityContext context = new VelocityContext();
168
		String templateFile = "templates/registrationform.vm";
157
		String templateFile = "templates/registrationform.vm";
169
		htmlString = getHtmlFromVelocity(templateFile, context);
158
		htmlString = getHtmlFromVelocity(templateFile, context);
170
		return htmlString;
159
		return htmlString;
171
	}
160
	}
172
 
161
 
-
 
162
	public String getLoginFormHtml() {
-
 
163
		String htmlString = "";
-
 
164
		VelocityContext context = new VelocityContext();
-
 
165
		String templateFile = "templates/loginform.vm";
-
 
166
		htmlString = getHtmlFromVelocity(templateFile, context);
-
 
167
		return htmlString;
-
 
168
	}
173
 
169
 
174
	private String getRegistrationHeaderHtml() {
170
	public String getRegistrationHeaderHtml() {
175
		String htmlString = "";
171
		String htmlString = "";
176
		VelocityContext context = new VelocityContext();
172
		VelocityContext context = new VelocityContext();
177
		String templateFile = "templates/registrationheader.vm";
173
		String templateFile = "templates/registrationheader.vm";
178
		htmlString = getHtmlFromVelocity(templateFile, context);
174
		htmlString = getHtmlFromVelocity(templateFile, context);
179
		return htmlString;
175
		return htmlString;
180
	}
176
	}
181
 
177
 
-
 
178
	public String getLoginHeaderHtml() {
-
 
179
		String htmlString = "";
-
 
180
		VelocityContext context = new VelocityContext();
-
 
181
		String templateFile = "templates/loginheader.vm";
-
 
182
		htmlString = getHtmlFromVelocity(templateFile, context);
-
 
183
		return htmlString;
-
 
184
	}
182
 
185
	
183
	public Map<String,String> getHomePage(Map<String, String> parameters) throws TException {
186
	public Map<String,String> getHomePage(Map<String, String> parameters) throws TException {
184
 
187
 
185
		Map<String,String> htmlSnippet = new HashMap<String, String>();
188
		Map<String,String> htmlSnippet = new HashMap<String, String>();
186
		boolean isLoggedIn = Boolean.parseBoolean(parameters.get("IS_LOGGED_IN"));
189
		boolean isLoggedIn = Boolean.parseBoolean(parameters.get("IS_LOGGED_IN"));
187
		long userId = Long.parseLong(parameters.get("USER_ID"));
190
		long userId = Long.parseLong(parameters.get("USER_ID"));
Line 341... Line 344...
341
	}
344
	}
342
 
345
 
343
 
346
 
344
 
347
 
345
	public String getAccessoriesHtml(long productId) {
348
	public String getAccessoriesHtml(long productId) {
-
 
349
		return "";
346
		return getWidgetDiv(0, WidgetType.ACCESSORIES, "accessories.vm");
350
		//return getWidgetDiv(0, WidgetType.ACCESSORIES, "accessories.vm");
347
	}
351
	}
348
 
352
 
349
 
353
 
350
 
354
 
351
	public String getSimilarProductsHtml(long productId) {
355
	public String getSimilarProductsHtml(long productId) {
-
 
356
		return "";
352
		return getWidgetDiv(0, WidgetType.SIMILAR_ITEMS, "similaritems.vm");
357
		//return getWidgetDiv(0, WidgetType.SIMILAR_ITEMS, "similaritems.vm");
353
	}
358
	}
354
 
359
 
355
 
360
 
356
 
361
 
357
	public String getRecommendationsHtml() {
362
	public String getRecommendationsHtml() {
-
 
363
		return "";
358
		return getWidgetDiv( 0, WidgetType.RECOMMENDED_ITEMS, "recommendations.vm");
364
		//return getWidgetDiv( 0, WidgetType.RECOMMENDED_ITEMS, "recommendations.vm");
359
	}
365
	}
360
 
366
 
361
 
367
 
362
 
368
 
363
	public String getMyResearchHtml(long userId, boolean isLoggedIn) {
369
	public String getMyResearchHtml(long userId, boolean isLoggedIn) {
Line 505... Line 511...
505
		htmlString = getHtmlFromVelocity(templateFile, context);
511
		htmlString = getHtmlFromVelocity(templateFile, context);
506
		return htmlString;
512
		return htmlString;
507
	}
513
	}
508
 
514
 
509
 
515
 
510
 
-
 
511
	public String getProductSummaryHtml(long productId, boolean toBeDecided) {
-
 
512
		CatalogServiceClient catalogServiceClient = null;
-
 
513
		Client client = null;
-
 
514
		String htmlString = "";
-
 
515
 
-
 
516
		UserContextServiceClient userServiceClient = null;
-
 
517
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
-
 
518
		try {
-
 
519
			catalogServiceClient = new CatalogServiceClient();
-
 
520
			client = catalogServiceClient.getClient();
-
 
521
 
-
 
522
			userServiceClient = new UserContextServiceClient();
-
 
523
			userClient = userServiceClient.getClient();
-
 
524
			
-
 
525
			RatingsWidget ratingsWidget = userClient.getRatings(productId, 0);
-
 
526
			Map<RatingType,Double> ratings = ratingsWidget.getRatings();
-
 
527
			//double rating_amazon = ratings.get(RatingType.AMAZON);
-
 
528
			double rating_all  = 0.0;
-
 
529
			if(ratings != null){
-
 
530
				if( ratings.get(RatingType.USER_ALL) != null){
-
 
531
					rating_all = ratings.get(RatingType.USER_ALL);
-
 
532
				}
-
 
533
			}
-
 
534
			
-
 
535
			rating_all = Math.round(rating_all);
-
 
536
			
-
 
537
			Item item = client.getItemByCatalogId(productId);
-
 
538
			
-
 
539
			Double itemPrice = item.getSellingPrice();
-
 
540
			// For an entity
-
 
541
			EntityContainer entContainer = 	Catalog.getInstance().getEntityContainer();
-
 
542
			ExpandedEntity expEntity = entContainer.getExpandedEntity(productId);
-
 
543
			
-
 
544
			String title = expEntity.getBrand() + "" + expEntity.getModelName();
-
 
545
			String categoryName = expEntity.getCategory().getLabel();
-
 
546
			long categoryId = expEntity.getCategory().getID();
-
 
547
			Map<String,String> params = new HashMap<String, String>();
-
 
548
			params.put("TITLE", title);
-
 
549
			params.put("CATEGORY_ID", categoryId+"");
-
 
550
			params.put("CATEGORY_NAME", categoryName);
-
 
551
			params.put("PRICE", itemPrice.toString());
-
 
552
			params.put("RATING_ALL", rating_all+"");
-
 
553
			params.put("PRODUCT_ID", productId+"");
-
 
554
 
-
 
555
			VelocityContext context = new VelocityContext();
-
 
556
			String templateFile = "templates/productsummary.vm";
-
 
557
			context.put("params", params);
-
 
558
			htmlString = getHtmlFromVelocity(templateFile, context);
-
 
559
			
-
 
560
		} catch (Exception e) {
-
 
561
			e.printStackTrace();
-
 
562
		}
-
 
563
	
-
 
564
		return htmlString;
-
 
565
	}
-
 
566
 
-
 
567
 
-
 
568
 
-
 
569
	public String getMainMenuHtml() {
516
	public String getMainMenuHtml() {
570
		String htmlString = "";
517
		String htmlString = "";
571
		VelocityContext context = new VelocityContext();
518
		VelocityContext context = new VelocityContext();
572
		String templateFile = "templates/mainmenu.vm";
519
		String templateFile = "templates/mainmenu.vm";
573
		htmlString = getHtmlFromVelocity(templateFile, context);
520
		htmlString = getHtmlFromVelocity(templateFile, context);
Line 602... Line 549...
602
		
549
		
603
		return getHtmlFromVelocity(templateFile, context);
550
		return getHtmlFromVelocity(templateFile, context);
604
	}
551
	}
605
 
552
 
606
 
553
 
607
 
-
 
608
	public String getSlideGuideDIV(long productId){
-
 
609
		String htmlString = "";
-
 
610
		try {
-
 
611
			VelocityContext context = new VelocityContext();
-
 
612
			String templateFile = "templates/slideguide.vm";
-
 
613
			// For an entity
-
 
614
			EntityContainer entContainer = 	Catalog.getInstance().getEntityContainer();
-
 
615
			ExpandedEntity expEntity = entContainer.getExpandedEntity(productId);
-
 
616
			
-
 
617
			context.put("expentity", expEntity);
-
 
618
			htmlString = getHtmlFromVelocity(templateFile, context);
-
 
619
			} catch (Exception e) {
-
 
620
				e.printStackTrace();
-
 
621
			}
-
 
622
		return htmlString;
-
 
623
	}
-
 
624
 
-
 
625
	
554
	
626
	public CategoryPage getCategoryPage(long categoryId,
-
 
627
			Map<String, String> params){
-
 
628
		// TODO Auto-generated method stub
-
 
629
 
-
 
630
		CategoryPage category = null;
-
 
631
		
-
 
632
		try {
-
 
633
			//set velocity properties
-
 
634
			Velocity.init("velocity/velocity.properties");
-
 
635
			VelocityContext context = new VelocityContext();
-
 
636
 
-
 
637
			String templateFile = "velocity/category.vm";
-
 
638
			
-
 
639
			Template template = null;
-
 
640
 
-
 
641
			// For an category
-
 
642
			DefinitionsContainer defsContainer = 	Catalog.getInstance().getDefinitionsContainer();
-
 
643
			
-
 
644
			ExpandedCategory expCategory = defsContainer.getExpandedCategory(categoryId);
-
 
645
 
-
 
646
			//Utils.logger.info("expCategory=" + expCategory);
-
 
647
				
-
 
648
			context.put("expcategory", expCategory);
-
 
649
			template = Velocity.getTemplate(templateFile);
-
 
650
			
-
 
651
			if(template != null) {
-
 
652
				StringWriter writer = new StringWriter();
-
 
653
 
-
 
654
				template.merge(context, writer);
-
 
655
				writer.flush();
-
 
656
				writer.close();
-
 
657
				
-
 
658
				//Put in the product object
-
 
659
				Map<String,String> htmlSnippet = new HashMap<String, String>();
-
 
660
				htmlSnippet.put("MAIN", writer.toString());
-
 
661
				
-
 
662
				category = new CategoryPage();
-
 
663
				category.setCategoryId(categoryId);
-
 
664
				category.setParams(params);
-
 
665
				category.setHtmlSnippet(htmlSnippet);
-
 
666
				
-
 
667
				Utils.info("Snippet generated");
-
 
668
			}
-
 
669
		} catch (ResourceNotFoundException e) {
-
 
670
			// TODO Auto-generated catch block
-
 
671
			e.printStackTrace();
-
 
672
		} catch (ParseErrorException e) {
-
 
673
			// TODO Auto-generated catch block
-
 
674
			e.printStackTrace();
-
 
675
		} catch (MethodInvocationException e) {
-
 
676
			// TODO Auto-generated catch block
-
 
677
			e.printStackTrace();
-
 
678
		} catch (Exception e) {
-
 
679
			// TODO Auto-generated catch block
-
 
680
			e.printStackTrace();
-
 
681
		}
-
 
682
		
-
 
683
		return category;
-
 
684
	}
-
 
685
 
-
 
686
	private	String getWidgetDiv(long userId, WidgetType widgetType, String templateFile){
555
	private	String getWidgetDiv(long userId, WidgetType widgetType, String templateFile){
687
 
556
 
688
		UserContextServiceClient userServiceClient = null;
557
		UserContextServiceClient userServiceClient = null;
689
		in.shop2020.model.v1.user.UserContextService.Client client = null;
558
		in.shop2020.model.v1.user.UserContextService.Client client = null;
690
		Widget widget = null;
559
		Widget widget = null;
Line 1261... Line 1130...
1261
			{
1130
			{
1262
				items = new ArrayList<Map<String,String>>();
1131
				items = new ArrayList<Map<String,String>>();
1263
				
1132
				
1264
				for (Line line : lineItems) {
1133
				for (Line line : lineItems) {
1265
					Map<String, String> itemdetail = new HashMap<String, String>();
1134
					Map<String, String> itemdetail = new HashMap<String, String>();
1266
					Item item = catalogClient.getItemByCatalogId(line.getItemId());
1135
					Item item = catalogClient.getItem(line.getItemId());
1267
					String itemName = ((item.getManufacturerName() != null) ? item.getManufacturerName() + " " : "")
1136
					String itemName = ((item.getManufacturerName() != null) ? item.getManufacturerName() + " " : "")
1268
										+ ((item.getModelName() != null) ? item.getModelName() + " " : "") 
1137
										+ ((item.getModelName() != null) ? item.getModelName() + " " : "") 
1269
										+ (( item.getModelNumber() != null ) ? item.getModelNumber() : "" );
1138
										+ (( item.getModelNumber() != null ) ? item.getModelNumber() + " " : "" )
-
 
1139
										+ (( (item.getColor() != null && !item.getColor().trim().equals("NA"))) ? "("+item.getColor()+")" : "" );
1270
					
1140
					
1271
					itemdetail.put("ITEM_NAME", itemName);
1141
					itemdetail.put("ITEM_NAME", itemName);
1272
					itemdetail.put("ITEM_ID", line.getItemId()+"");
1142
					itemdetail.put("ITEM_ID", line.getItemId()+"");
1273
					itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
1143
					itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
1274
					itemdetail.put("MRP", ((int)item.getMrp())+"");
1144
					itemdetail.put("MRP", ((int)item.getMrp())+"");
Line 1278... Line 1148...
1278
					totalamount = totalamount + line.getQuantity()*item.getSellingPrice();
1148
					totalamount = totalamount + line.getQuantity()*item.getSellingPrice();
1279
					items.add(itemdetail);				
1149
					items.add(itemdetail);				
1280
				}
1150
				}
1281
			}
1151
			}
1282
			
1152
			
1283
			User user = userClient.getUserById(cart.getUserId());
1153
			addresses = userClient.getAllAddressesForUser(cart.getUserId());
1284
			addresses = user.getAddresses();
-
 
1285
			defaultAddressId = user.getDefaultAddressId();
1154
			defaultAddressId = userClient.getDefaultAddressId(cart.getUserId());
1286
			
1155
			
1287
		}catch (Exception e){
1156
		}catch (Exception e){
1288
			e.printStackTrace();
1157
			e.printStackTrace();
1289
		}
1158
		}
1290
		
1159
		
Line 1370... Line 1239...
1370
			if(lineItems.size() != 0){
1239
			if(lineItems.size() != 0){
1371
				items = new ArrayList<Map<String,String>>();
1240
				items = new ArrayList<Map<String,String>>();
1372
				for (Line line : lineItems) {
1241
				for (Line line : lineItems) {
1373
	
1242
	
1374
					Map<String, String> itemdetail = new HashMap<String, String>();
1243
					Map<String, String> itemdetail = new HashMap<String, String>();
1375
					Item item = catalogClient.getItemByCatalogId(line.getItemId());
1244
					Item item = catalogClient.getItem(line.getItemId());
1376
					
1245
					
1377
					String itemName = ((item.getManufacturerName() != null) ? item.getManufacturerName() + " " : "")
1246
					String itemName = ((item.getManufacturerName() != null) ? item.getManufacturerName() + " " : "")
1378
										+ ((item.getModelName() != null) ? item.getModelName() + " " : "") 
1247
										+ ((item.getModelName() != null) ? item.getModelName() + " " : "") 
1379
										+ (( item.getModelNumber() != null ) ? item.getModelNumber() : "" );
1248
										+ (( item.getModelNumber() != null ) ? item.getModelNumber() + " " : "" )
-
 
1249
										+ (( (item.getColor() != null && !item.getColor().trim().equals("NA"))) ? "("+item.getColor()+")" : "" );
1380
					
1250
					
1381
					itemdetail.put("ITEM_NAME", itemName);
1251
					itemdetail.put("ITEM_NAME", itemName);
1382
					System.out.println(itemdetail.get("ITEM_NAME"));
1252
					System.out.println(itemdetail.get("ITEM_NAME"));
1383
					itemdetail.put("ITEM_ID", line.getItemId()+"");
1253
					itemdetail.put("ITEM_ID", line.getItemId()+"");
1384
					itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
1254
					itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
Line 1461... Line 1331...
1461
			}
1331
			}
1462
	
1332
	
1463
		return null;
1333
		return null;
1464
	}
1334
	}
1465
	
1335
	
1466
	public double getItemMrpByCatalogId(long productId){
-
 
1467
		CatalogServiceClient catalogServiceClient = null;
-
 
1468
		Client client = null;
-
 
1469
		Double itemPrice = 0.0;
-
 
1470
		try {
-
 
1471
			catalogServiceClient = new CatalogServiceClient();
-
 
1472
			client = catalogServiceClient.getClient();
-
 
1473
			Item item = client.getItemByCatalogId(productId);
-
 
1474
			itemPrice = item.getMrp();
-
 
1475
		}
-
 
1476
		catch(Exception e){
-
 
1477
			e.printStackTrace();
-
 
1478
		}
-
 
1479
		return itemPrice;
-
 
1480
	}
-
 
1481
 
-
 
1482
	public double getItemSellingPriceByCatalogId(long productId){
-
 
1483
		CatalogServiceClient catalogServiceClient = null;
-
 
1484
		Client client = null;
-
 
1485
		Double itemPrice = 0.0;
-
 
1486
		try {
-
 
1487
			catalogServiceClient = new CatalogServiceClient();
-
 
1488
			client = catalogServiceClient.getClient();
-
 
1489
			Item item = client.getItemByCatalogId(productId);
-
 
1490
			itemPrice = item.getSellingPrice();
-
 
1491
		}
-
 
1492
		catch(Exception e){
-
 
1493
			e.printStackTrace();
-
 
1494
		}
-
 
1495
		return itemPrice;
-
 
1496
	}
-
 
1497
 
-
 
1498
 
1336
 
1499
	public String getCategoryHeaderSnippet() {
1337
	public String getCategoryHeaderSnippet() {
1500
		String htmlString = "";
1338
		String htmlString = "";
1501
		VelocityContext context = new VelocityContext();
1339
		VelocityContext context = new VelocityContext();
1502
		String templateFile = "templates/categoryheader.vm";
1340
		String templateFile = "templates/categoryheader.vm";