Subversion Repositories SmartDukaan

Rev

Rev 5347 | Rev 5355 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1678 rajveer 1
package in.shop2020.util;
2
 
5113 amit.gupta 3
import in.shop2020.logistics.DeliveryType;
4
import in.shop2020.logistics.LogisticsInfo;
5
import in.shop2020.logistics.LogisticsService;
4188 varun.gupt 6
import in.shop2020.metamodel.core.Entity;
4802 amit.gupta 7
import in.shop2020.metamodel.definitions.Catalog;
8
import in.shop2020.metamodel.definitions.DefinitionsContainer;
4188 varun.gupt 9
import in.shop2020.metamodel.util.CreationUtils;
1678 rajveer 10
import in.shop2020.model.v1.catalog.Item;
4188 varun.gupt 11
import in.shop2020.model.v1.catalog.status;
12
import in.shop2020.model.v1.user.ItemCouponDiscount;
13
import in.shop2020.thrift.clients.CatalogClient;
5113 amit.gupta 14
import in.shop2020.thrift.clients.LogisticsClient;
4188 varun.gupt 15
import in.shop2020.thrift.clients.PromotionClient;
16
 
2130 rajveer 17
import java.io.File;
1678 rajveer 18
import java.util.ArrayList;
4188 varun.gupt 19
import java.util.Date;
4143 varun.gupt 20
import java.util.HashMap;
1678 rajveer 21
import java.util.List;
22
import java.util.Map;
23
 
4202 varun.gupt 24
import org.apache.commons.lang.StringEscapeUtils;
1678 rajveer 25
import org.apache.commons.lang.StringUtils;
4143 varun.gupt 26
import org.json.JSONObject;
1678 rajveer 27
 
28
/**
29
 * Command line utility to generate xml file for partners
30
 * 
31
 * @author rajveer
32
 *
33
 */
34
public class ProductListGenerator {
35
 
36
	private String[] xmlIndentation = {"", "    ", "        ", "            ","                "};
2367 rajveer 37
	public Map<Long, List<Item>> entityIdItemMap;
5113 amit.gupta 38
	private static final String DEFAULT_PINCODE = "110001";
4802 amit.gupta 39
	DefinitionsContainer defContainer = Catalog.getInstance().getDefinitionsContainer();
1678 rajveer 40
 
2367 rajveer 41
	public ProductListGenerator(Map<Long, List<Item>> entityIdItemMap) throws Exception {
42
		this.entityIdItemMap = entityIdItemMap;
1678 rajveer 43
	}
44
 
45
 
46
	/**
2367 rajveer 47
	 * Get the url of the entity
1678 rajveer 48
	 * @param expEntity
49
	 * @return url
50
	 */
2367 rajveer 51
	private String getProductURL(long entityId, Item item){
4802 amit.gupta 52
		//long rootCategoryId = catm.getCategory(item.getCategory()).getParent_category_id();
53
		in.shop2020.metamodel.definitions.Category parentCategory = defContainer.getCategory(item.getCategory()).getParentCategory();
54
 
55
		String url = "http://www.saholic.com/" + parentCategory.getLabel().toLowerCase().replace(' ', '-') + "/";
2367 rajveer 56
		String productUrl = ((item.getBrand() != null) ? item.getBrand().trim() + " " : "").toLowerCase().replace(' ', '-')
57
        + "-" + ((item.getModelName() != null) ? item.getModelName().trim() + " " : "").toLowerCase().replace(' ', '-') 
58
	    + "-" + (( item.getModelNumber() != null ) ? item.getModelNumber().trim() + " ": "" ).toLowerCase().replace(' ', '-')
59
        + "-" + entityId;
1678 rajveer 60
		productUrl = productUrl.replaceAll("/", "-");
61
		url = url + productUrl;
2367 rajveer 62
		url = url.replaceAll("-+", "-");
1678 rajveer 63
		return url;
64
	}
65
 
2367 rajveer 66
 
67
 
1678 rajveer 68
	/**
3964 rajveer 69
	 * Get the minimum mrp of the items
70
	 * @param items
71
	 * @return
72
	 */
73
	private double getMinMRP(List<Item> items){
74
        double minPrice = Double.MAX_VALUE;
75
        for(Item item: items){
76
            if(minPrice > item.getMrp()){
77
                minPrice =  item.getMrp();
78
            }
79
        }
80
        return minPrice;
81
    }
82
 
83
 
84
 
85
	/**
2367 rajveer 86
	 * Get the minimum price of the items
87
	 * @param items
88
	 * @return
89
	 */
90
	private double getMinPrice(List<Item> items){
91
        double minPrice = Double.MAX_VALUE;
92
        for(Item item: items){
93
            if(minPrice > item.getSellingPrice()){
94
                minPrice = item.getSellingPrice();
95
            }
96
        }
97
        return minPrice;
98
    }
99
 
100
	/**
101
	 * Check whether product is mobile or not
102
	 * @param item
103
	 * @return
104
	 */
105
	private boolean isMobile(Item item){
4802 amit.gupta 106
		in.shop2020.metamodel.definitions.Category parentCategory = defContainer.getCategory(item.getCategory()).getParentCategory();
107
		return parentCategory.getID() == Utils.MOBILE_PHONES_CATAGORY;
2367 rajveer 108
	}
109
 
110
	/**
5229 varun.gupt 111
	 * Checks whether a product is tablet or not
112
	 */
113
	private boolean isTablet(Item item) {
114
		in.shop2020.metamodel.definitions.Category parentCategory = defContainer.getCategory(item.getCategory()).getParentCategory();
115
		return parentCategory.getID() == Utils.TABLETS_CATEGORY;
116
	}
117
 
118
	/**
4143 varun.gupt 119
	 * Checks whether a product is laptop or not
120
	 */
121
	private boolean isLaptop(Item item) {
4802 amit.gupta 122
		in.shop2020.metamodel.definitions.Category parentCategory = defContainer.getCategory(item.getCategory()).getParentCategory();
123
		return parentCategory.getID() == Utils.LAPTOPS_CATEGORY;
4143 varun.gupt 124
	}
125
 
126
	/**
2367 rajveer 127
	 * 
128
	 * @param item
129
	 * @return
130
	 */
131
	private String getProductTitle(Item item){
2542 rajveer 132
		String title = ((item.getBrand() != null) ? item.getBrand().trim() + " " : "")
133
		+ ((item.getModelName() != null) ? item.getModelName().trim() + " " : "")
134
		+ (( item.getModelNumber() != null ) ? item.getModelNumber().trim() : "" );
2561 rajveer 135
		title = title.replaceAll("  ", " ");
2367 rajveer 136
		return title;
137
	}
138
 
139
	/**
1678 rajveer 140
	 * get xml feed for partner sites
141
	 * @param irDataXMLSnippets
142
	 * @throws Exception
143
	 */
2367 rajveer 144
	private void getProductsXML(ArrayList<String> irDataXMLSnippets) throws Exception{
5113 amit.gupta 145
		LogisticsService.Client prod_client = null;
5350 varun.gupt 146
		Map<Long, ItemCouponDiscount> couponsAndDiscounts = new HashMap<Long, ItemCouponDiscount>();
147
 
5113 amit.gupta 148
		try {
149
			LogisticsClient logistics_prod = new LogisticsClient("logistics_service_prod_server_host","logistics_service_prod_server_port");
150
			prod_client = logistics_prod.getClient();
5350 varun.gupt 151
 
152
			List<Long> itemIds = new ArrayList<Long>();
153
 
154
			for(Long entityId: entityIdItemMap.keySet()){
155
 
156
				List<Item> items = entityIdItemMap.get(entityId);
157
				Item firstItem = items.get(0);
158
 
159
				if(isMobile(firstItem) || isLaptop(firstItem)) {
160
					itemIds.add(firstItem.getId());
161
				}
162
			}
163
 
164
			PromotionClient promotionClient = new PromotionClient();
165
			in.shop2020.model.v1.user.PromotionService.Client promotionServiceClient = promotionClient.getClient();
166
 
167
			List<ItemCouponDiscount> itemsCouponsAndDiscounts = promotionServiceClient.getItemDiscountMap(itemIds);
168
 
169
			for (ItemCouponDiscount itemCouponDiscount: itemsCouponsAndDiscounts) {
170
				couponsAndDiscounts.put(itemCouponDiscount.getItemId(), itemCouponDiscount);
171
			}
172
 
5113 amit.gupta 173
		} catch (Exception e) {
174
			prod_client = null;
5350 varun.gupt 175
			Utils.info("Logistics estimations can't be fetched as Logistics Service is inaccessible" + e);
5113 amit.gupta 176
		}
5350 varun.gupt 177
 
2367 rajveer 178
		for(Long entityId: entityIdItemMap.keySet()){
179
			List<Item> items = entityIdItemMap.get(entityId);
180
			Item firstItem = items.get(0);
5229 varun.gupt 181
 
182
			if(!isMobile(firstItem) && !isTablet(firstItem))	{
1678 rajveer 183
				continue;
184
			}
185
 
186
			irDataXMLSnippets.add(this.xmlIndentation[1] + "<products>");	
187
 
2367 rajveer 188
			irDataXMLSnippets.add(this.xmlIndentation[2] + "<ProductSKU>" + entityId + "</ProductSKU>");
1678 rajveer 189
 
2367 rajveer 190
			String title = getProductTitle(firstItem);
1678 rajveer 191
			irDataXMLSnippets.add(this.xmlIndentation[2] + "<ProductName>" + title + "</ProductName>");
192
 
2367 rajveer 193
			String url = getProductURL(entityId, firstItem);
3929 mandeep.dh 194
 
195
			String imageUrl = "http://static" + ((entityId+1)%3) + ".saholic.com" + File.separator + "images" + File.separator +
196
			                  "website" + File.separator + entityId + File.separator + "icon.jpg";
197
 
1678 rajveer 198
			irDataXMLSnippets.add(this.xmlIndentation[2] + "<ProductURL>" + url + "</ProductURL>");
199
 
5350 varun.gupt 200
			double minPrice = getMinPrice(items);
1678 rajveer 201
 
5350 varun.gupt 202
			if(couponsAndDiscounts.containsKey(firstItem.getId()))	{
203
 
204
				int discountedPrice = (int)(minPrice - couponsAndDiscounts.get(firstItem.getId()).getDiscount());
205
				irDataXMLSnippets.add(this.xmlIndentation[2] + "<ProductPrice>" + discountedPrice + "</ProductPrice>");
206
 
207
			} else	{
208
				irDataXMLSnippets.add(this.xmlIndentation[2] + "<ProductPrice>" + minPrice + "</ProductPrice>");
209
			}
210
 
3964 rajveer 211
			irDataXMLSnippets.add(this.xmlIndentation[2] + "<ProductMRP>" + getMinMRP(items) + "</ProductMRP>");
212
 
5113 amit.gupta 213
			LogisticsInfo logisticsInfo = null;
214
			if(prod_client != null){
215
				try {
216
					Long itemId = prod_client.getEntityLogisticsEstimation(
217
							entityId, DEFAULT_PINCODE, DeliveryType.PREPAID)
218
							.get(0);
219
					logisticsInfo = prod_client.getLogisticsEstimation(itemId,
220
							DEFAULT_PINCODE, DeliveryType.PREPAID);
221
					irDataXMLSnippets.add(this.xmlIndentation[2] + "<ProductDeliveryEstimate>" + logisticsInfo.getDeliveryTime() + "</ProductDeliveryEstimate>");
222
				} catch (Exception e1) {
223
					Utils.info("Unable to get Estimation for Entity: " + entityId + "\n" + e1);
224
				}
225
			}
2130 rajveer 226
			irDataXMLSnippets.add(this.xmlIndentation[2] + "<ProductImageURL>" + imageUrl + "</ProductImageURL>");
227
 
1678 rajveer 228
			irDataXMLSnippets.add(this.xmlIndentation[1] + "</products>");		
229
		}
230
	}
231
 
232
	/**
233
	 * Generate the xml list of all the active phones and store in a file
234
	 * @throws Exception
235
	 */
2227 rajveer 236
	public void generateProductsListXML() throws Exception {
1678 rajveer 237
		ArrayList<String> productXMLSnippets = new ArrayList<String>();
238
		productXMLSnippets.add("<saholic.com>");
239
 
240
		getProductsXML(productXMLSnippets);
241
 
242
		productXMLSnippets.add("</saholic.com>");
243
 
244
		String productDataXML = StringUtils.join(productXMLSnippets, "\n");
245
 
246
		Utils.info(productDataXML);
247
 
248
		// Write it to file
2130 rajveer 249
		String productXMLFilename = Utils.EXPORT_PARTNERS_CONTENT_PATH + "saholicmobilephones.xml";
1678 rajveer 250
		DBUtils.store(productDataXML, productXMLFilename);
251
	}
2227 rajveer 252
 
253
 
254
 
255
 
256
	/**
257
	 * get xml feed for partner sites
258
	 * @param irDataXMLSnippets
259
	 * @throws Exception
260
	 */
261
	private void getProductsJavascript(StringBuffer sb) throws Exception{
4143 varun.gupt 262
 
5347 amit.gupta 263
		Map<String, Map<String, Long>> products = new HashMap<String, Map<String,Long>>();
2367 rajveer 264
 
5347 amit.gupta 265
		for(Map.Entry<Long, List<Item>> entry : entityIdItemMap.entrySet())	{
266
			Item item = entry.getValue().get(0);
267
			in.shop2020.metamodel.definitions.Category parentCategory = defContainer.getCategory(item.getCategory()).getParentCategory();
4143 varun.gupt 268
 
5347 amit.gupta 269
			if(parentCategory.isComparable()){
270
				String parentCat = parentCategory.getLabel();
271
				if(!products.containsKey(parentCategory.getLabel())){
272
					Map<String, Long> catMap = new HashMap<String, Long>();
273
					products.put(parentCat, catMap);
274
				}
275
				products.get(parentCat).put(getProductTitle(item), entry.getKey());
2227 rajveer 276
			}
277
		}
4143 varun.gupt 278
		sb.append(new JSONObject(products));
2227 rajveer 279
	}
280
 
281
 
282
	/**
283
	 * Generate the javascript list of all the active phones and store in a file
284
	 * @throws Exception
285
	 */
286
	public void generateProductListJavascript() throws Exception {
287
		StringBuffer productsJavascript = new StringBuffer();
288
 
4143 varun.gupt 289
		productsJavascript.append("var productIdNames=");
2227 rajveer 290
 
291
		getProductsJavascript(productsJavascript);
292
 
4143 varun.gupt 293
		productsJavascript.append(";");
2227 rajveer 294
 
295
		// Write it to file
296
		String productXMLFilename = Utils.EXPORT_JAVASCRIPT_CONTENT_PATH + "saholicmobilephones.js";
297
		DBUtils.store(productsJavascript.toString(), productXMLFilename);
298
	}
4188 varun.gupt 299
 
300
    private void populateEntityIdItemMap(List<Item> items){
301
        Date toDate = new Date();
302
        for(Item item: items){
303
            //TODO Can be removed as we are checking in calling function
304
            if(!(item.getItemStatus()==status.ACTIVE || item.getItemStatus()==status.CONTENT_COMPLETE || item.getItemStatus() == status.PAUSED)){
305
                continue;
306
            }
307
            if(toDate.getTime() < item.getStartDate() ||  item.getSellingPrice() == 0){
308
                continue;
309
            }
310
            List<Item> itemList = entityIdItemMap.get(item.getCatalogItemId());
311
            if(itemList == null){
312
                itemList = new ArrayList<Item>();
313
            }
314
            itemList.add(item);
315
            entityIdItemMap.put(item.getCatalogItemId(), itemList);
316
        }
317
 
318
        //Remove all items which have not been updated since last content generation.
319
        List<Long> removeEntities = new ArrayList<Long>();
320
        for(Long entityId:entityIdItemMap.keySet()){
321
            boolean isValidEntity = false;
322
            //If any one of the items has been updated before current timestamp, than we generate content for whole entity
323
            for(Item item: entityIdItemMap.get(entityId)){
324
                if(item.getUpdatedOn() > 0){
325
                    isValidEntity = true;
326
                }
327
            }
328
            if(!isValidEntity){
329
                removeEntities.add(entityId);
330
            }
331
        }
332
        for(Long entityId: removeEntities){
333
            entityIdItemMap.remove(entityId);
334
        }
335
    }
5229 varun.gupt 336
 
337
    /**
338
     * Generate XML feed for mobile site
339
     * @throws Exception
340
     */
341
    public void generateXMLFeedForMobileSite() throws Exception	{
342
    	List<String> productXMLSnippets = new ArrayList<String>();
343
		productXMLSnippets.add("<Products>");
344
		List<Long> itemIds = new ArrayList<Long>();
345
 
346
		for(Long entityId: entityIdItemMap.keySet()){
347
			List<Item> items = entityIdItemMap.get(entityId);
348
			Item firstItem = items.get(0);
349
			Utils.info("first Item: " + firstItem);
350
 
351
			if(isMobile(firstItem) || isLaptop(firstItem)) {
352
				itemIds.add(firstItem.getId());
353
			}
354
		}
4188 varun.gupt 355
 
5229 varun.gupt 356
		List<String> descriptions = new ArrayList<String>();
357
		descriptions.add("8MP camera, Super AMOLED Plus display, Android Gingerbread");
358
		descriptions.add("Android OS v2.2 Froyo, 800MHz processor, 3.5\" capacitive display");
359
		descriptions.add("Dual-SIM, Wi-Fi, Bluetooth, Social networking &amp; IM");
360
		descriptions.add("Android Gingerbread, Facebook button, 5MP camera");
361
		descriptions.add("Android Gingerbread, 1GHz processor, 3.7\" Gorilla Glass display");
362
		descriptions.add("2GB RAM, 500GB HDD, Intel Core 2 Duo T6570 processor, DOS");
363
		descriptions.add("4GB RAM, 500GB HDD, Intel Core i5 2410M processor, Windows 7 Basic");
364
		descriptions.add("3.2\" touchscreen, 2MP camera, IM &amp; social networking");
365
 
366
		for(Long entityId: entityIdItemMap.keySet()) {
367
			List<Item> items = entityIdItemMap.get(entityId);
368
			Item firstItem = items.get(0);
369
 
370
			if(!isMobile(firstItem) && !isLaptop(firstItem)){
371
				continue;
372
			}
4188 varun.gupt 373
 
5229 varun.gupt 374
			String url = getProductURL(entityId, firstItem);
375
			String imageUrl = "http://www.saholic.com/images/website" + File.separator + entityId + File.separator + "thumbnail.jpg";
376
			String description = descriptions.get((int) (8 * Math.random()));
377
			double minPrice = getMinPrice(items);
378
 
379
			String productType = "";
380
 
381
			if (firstItem.getCategory() == 10001 || firstItem.getCategory() == 10002 || firstItem.getCategory() == 10003 || firstItem.getCategory() == 10004 || firstItem.getCategory() == 10005)	{
382
				productType = "Mobile Phone";
383
 
384
			} else if (firstItem.getCategory() == 10010)	{
385
				productType = "Tablet";
386
 
387
			} else if (firstItem.getCategory() == 10050)	{
388
				productType = "Laptop";
389
			}
390
 
391
			productXMLSnippets.add(this.xmlIndentation[1] + "<Product>");	
392
 
393
			productXMLSnippets.add(this.xmlIndentation[2] + "<ID>" + entityId + "</ID>");
394
			productXMLSnippets.add(this.xmlIndentation[2] + "<Type>" + productType + "</Type>");
395
			productXMLSnippets.add(this.xmlIndentation[2] + "<Brand>" + firstItem.getBrand() + "</Brand>");
396
			productXMLSnippets.add(this.xmlIndentation[2] + "<ModelName>" + firstItem.getModelName() + "</ModelName>");
397
			productXMLSnippets.add(this.xmlIndentation[2] + "<ModelNumber>" + firstItem.getModelNumber() + "</ModelNumber>");
398
			productXMLSnippets.add(this.xmlIndentation[2] + "<URL>" + url + "</URL>");
399
			productXMLSnippets.add(this.xmlIndentation[2] + "<ImageURL>" + imageUrl + "</ImageURL>");
400
			productXMLSnippets.add(this.xmlIndentation[2] + "<ShortDesc>" + description + "</ShortDesc>");
401
			productXMLSnippets.add(this.xmlIndentation[2] + "<MRP>" + firstItem.getMrp() + "</MRP>");
402
			productXMLSnippets.add(this.xmlIndentation[2] + "<SellingPrice>" + (int)minPrice  + "</SellingPrice>");
403
 
404
			productXMLSnippets.add(this.xmlIndentation[1] + "</Product>");
405
		}
406
 
407
		productXMLSnippets.add("</Products>");
408
 
409
		String productDataXML = StringUtils.join(productXMLSnippets, "\n");
410
 
411
		Utils.info(productDataXML);
412
 
413
		// Write it to file
414
		String productXMLFilename = Utils.EXPORT_PARTNERS_CONTENT_PATH + "msitedata.xml";
415
		DBUtils.store(productDataXML, productXMLFilename);
416
    }
417
 
4188 varun.gupt 418
	/**
419
	 * Generate the xml list of all the active phones and store in a file
420
	 * @throws Exception
421
	 */
422
	public void generateProductXMLForDisplayAds() throws Exception {
4384 varun.gupt 423
		Utils.info("Generating Product XML for display ads");
4188 varun.gupt 424
		List<String> productXMLSnippets = new ArrayList<String>();
425
		productXMLSnippets.add("<saholic.com>");
426
		List<Long> itemIds = new ArrayList<Long>();
4384 varun.gupt 427
 
428
		Utils.info("Entity Ids: " + entityIdItemMap.keySet());
4188 varun.gupt 429
 
430
		for(Long entityId: entityIdItemMap.keySet()){
431
			List<Item> items = entityIdItemMap.get(entityId);
432
			Item firstItem = items.get(0);
4384 varun.gupt 433
			Utils.info("first Item: " + firstItem);
434
 
4383 varun.gupt 435
			if(isMobile(firstItem) || isLaptop(firstItem)) {
4188 varun.gupt 436
				itemIds.add(firstItem.getId());
437
			}
438
		}
439
 
440
		PromotionClient promotionClient = new PromotionClient();
441
		in.shop2020.model.v1.user.PromotionService.Client promotionServiceClient = promotionClient.getClient();
442
 
443
		List<ItemCouponDiscount> itemsCouponsAndDiscounts = promotionServiceClient.getItemDiscountMap(itemIds);
444
 
445
		Map<Long, ItemCouponDiscount> couponsAndDiscounts = new HashMap<Long, ItemCouponDiscount>();
446
 
447
		for (ItemCouponDiscount itemCouponDiscount: itemsCouponsAndDiscounts) {
448
			couponsAndDiscounts.put(itemCouponDiscount.getItemId(), itemCouponDiscount);
449
		}
4384 varun.gupt 450
		Utils.info("Entity IDs: " + entityIdItemMap.keySet());
4188 varun.gupt 451
 
452
		for(Long entityId: entityIdItemMap.keySet()) {
453
			List<Item> items = entityIdItemMap.get(entityId);
454
			Item firstItem = items.get(0);
4384 varun.gupt 455
 
456
			Utils.info("First Item: " + firstItem);
457
 
4382 varun.gupt 458
			if(!isMobile(firstItem) && !isLaptop(firstItem)){
4188 varun.gupt 459
				continue;
460
			}
461
 
462
			productXMLSnippets.add(this.xmlIndentation[1] + "<products>");	
463
 
464
			productXMLSnippets.add(this.xmlIndentation[2] + "<ProductSKU>" + entityId + "</ProductSKU>");
465
 
466
			String title = getProductTitle(firstItem);
467
			productXMLSnippets.add(this.xmlIndentation[2] + "<ProductName>" + title + "</ProductName>");
468
 
469
			String url = getProductURL(entityId, firstItem);
470
 
471
			String imageUrl = "http://static" + ((entityId+1)%3) + ".saholic.com" + File.separator + "images" + File.separator + entityId + File.separator + "icon.jpg";    
472
 
473
			productXMLSnippets.add(this.xmlIndentation[2] + "<ProductURL>" + url + "</ProductURL>");
474
 
475
			productXMLSnippets.add(this.xmlIndentation[2] + "<ProductImageURL>" + imageUrl + "</ProductImageURL>");
476
 
477
			productXMLSnippets.add(this.xmlIndentation[2] + "<ProductMRP>" + firstItem.getMrp() + "</ProductMRP>");
478
 
479
			double minPrice = getMinPrice(items);
480
			productXMLSnippets.add(this.xmlIndentation[2] + "<ProductSellingPrice>" + (int)minPrice  + "</ProductSellingPrice>");
481
 
482
			productXMLSnippets.add(this.xmlIndentation[2] + "<ProductDiscount>" + (int)((firstItem.getMrp()-minPrice)/firstItem.getMrp()*100) + "</ProductDiscount>");
483
 
484
			long itemId = firstItem.getId();
485
 
486
			if(couponsAndDiscounts.containsKey(itemId))	{
487
 
488
				ItemCouponDiscount itemCouponDiscount = couponsAndDiscounts.get(itemId);
489
 
490
				productXMLSnippets.add(this.xmlIndentation[2] + "<ProductCoupons>");
491
				productXMLSnippets.add(this.xmlIndentation[3] + "<Coupon>");
492
				productXMLSnippets.add(this.xmlIndentation[4] + "<CouponCode>" + itemCouponDiscount.getCouponCode() + "</CouponCode>");
493
				productXMLSnippets.add(this.xmlIndentation[4] + "<PriceAfterCoupon>" + (int)(minPrice - itemCouponDiscount.getDiscount()) + "</PriceAfterCoupon>");
494
				productXMLSnippets.add(this.xmlIndentation[3] + "</Coupon>");
495
				productXMLSnippets.add(this.xmlIndentation[2] + "</ProductCoupons>");
496
 
497
			} else	{
498
				productXMLSnippets.add(this.xmlIndentation[2] + "<ProductCoupons />");
499
			}
500
 
501
			String description = "";
502
			Entity entity = CreationUtils.getEntity(entityId);
503
			if(entity!=null){
504
				if(entity.getSlide(130001) !=null){
4202 varun.gupt 505
					description = StringEscapeUtils.escapeXml(entity.getSlide(130001).getFreeformContent().getFreeformText());
4188 varun.gupt 506
				}
507
			}
508
 
509
			productXMLSnippets.add(this.xmlIndentation[2] + "<ProductDescription>" + description + "</ProductDescription>");
510
 
511
			productXMLSnippets.add(this.xmlIndentation[1] + "</products>");	
512
		}
513
 
514
		productXMLSnippets.add("</saholic.com>");
515
 
516
		String productDataXML = StringUtils.join(productXMLSnippets, "\n");
517
 
518
		Utils.info(productDataXML);
519
 
520
		// Write it to file
521
		String productXMLFilename = Utils.EXPORT_PARTNERS_CONTENT_PATH + "advertismentapi.xml";
522
		DBUtils.store(productDataXML, productXMLFilename);
523
	}
5229 varun.gupt 524
 
525
	public static void main(String[] args) throws Exception {
526
		CatalogClient cl = new CatalogClient();
527
		in.shop2020.model.v1.catalog.InventoryService.Client client = cl.getClient();
528
 
529
		List<Item> items = cl.getClient().getAllItemsByStatus(status.ACTIVE);
530
		items.addAll(cl.getClient().getAllItemsByStatus(status.PAUSED));
531
//		items.addAll(cl.getClient().getAllItemsByStatus(status.PAUSED_BY_RISK));
532
 
533
		Map<Long, List<Item>> entityIdItemMap1 = new HashMap<Long, List<Item>>();
534
		ProductListGenerator pl = new ProductListGenerator(entityIdItemMap1);
535
		pl.populateEntityIdItemMap(items);
5350 varun.gupt 536
		pl.generateProductsListXML();
5229 varun.gupt 537
	}
4143 varun.gupt 538
}