Subversion Repositories SmartDukaan

Rev

Rev 5113 | Rev 5347 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5113 Rev 5229
Line 23... Line 23...
23
 
23
 
24
import org.apache.commons.lang.StringEscapeUtils;
24
import org.apache.commons.lang.StringEscapeUtils;
25
import org.apache.commons.lang.StringUtils;
25
import org.apache.commons.lang.StringUtils;
26
import org.json.JSONObject;
26
import org.json.JSONObject;
27
 
27
 
28
 
-
 
29
/**
28
/**
30
 * Command line utility to generate xml file for partners
29
 * Command line utility to generate xml file for partners
31
 * 
30
 * 
32
 * @author rajveer
31
 * @author rajveer
33
 *
32
 *
Line 107... Line 106...
107
		in.shop2020.metamodel.definitions.Category parentCategory = defContainer.getCategory(item.getCategory()).getParentCategory();
106
		in.shop2020.metamodel.definitions.Category parentCategory = defContainer.getCategory(item.getCategory()).getParentCategory();
108
		return parentCategory.getID() == Utils.MOBILE_PHONES_CATAGORY;
107
		return parentCategory.getID() == Utils.MOBILE_PHONES_CATAGORY;
109
	}
108
	}
110
	
109
	
111
	/**
110
	/**
-
 
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
	/**
112
	 * Checks whether a product is laptop or not
119
	 * Checks whether a product is laptop or not
113
	 */
120
	 */
114
	private boolean isLaptop(Item item) {
121
	private boolean isLaptop(Item item) {
115
		in.shop2020.metamodel.definitions.Category parentCategory = defContainer.getCategory(item.getCategory()).getParentCategory();
122
		in.shop2020.metamodel.definitions.Category parentCategory = defContainer.getCategory(item.getCategory()).getParentCategory();
116
		return parentCategory.getID() == Utils.LAPTOPS_CATEGORY;
123
		return parentCategory.getID() == Utils.LAPTOPS_CATEGORY;
Line 145... Line 152...
145
					+ e);
152
					+ e);
146
		}
153
		}
147
		for(Long entityId: entityIdItemMap.keySet()){
154
		for(Long entityId: entityIdItemMap.keySet()){
148
			List<Item> items = entityIdItemMap.get(entityId);
155
			List<Item> items = entityIdItemMap.get(entityId);
149
			Item firstItem = items.get(0);
156
			Item firstItem = items.get(0);
-
 
157
			
150
			if(!isMobile(firstItem)){
158
			if(!isMobile(firstItem) && !isTablet(firstItem))	{
151
				continue;
159
				continue;
152
			}
160
			}
153
			
161
			
154
			irDataXMLSnippets.add(this.xmlIndentation[1] + "<products>");	
162
			irDataXMLSnippets.add(this.xmlIndentation[1] + "<products>");	
155
			
163
			
Line 255... Line 263...
255
		
263
		
256
		// Write it to file
264
		// Write it to file
257
		String productXMLFilename = Utils.EXPORT_JAVASCRIPT_CONTENT_PATH + "saholicmobilephones.js";
265
		String productXMLFilename = Utils.EXPORT_JAVASCRIPT_CONTENT_PATH + "saholicmobilephones.js";
258
		DBUtils.store(productsJavascript.toString(), productXMLFilename);
266
		DBUtils.store(productsJavascript.toString(), productXMLFilename);
259
	}
267
	}
260
	
-
 
261
	public static void main(String[] args) throws Exception {
-
 
262
		CatalogClient cl = new CatalogClient();
-
 
263
		in.shop2020.model.v1.catalog.InventoryService.Client client = cl.getClient();
-
 
264
		
-
 
265
		List<Item> items = cl.getClient().getAllItemsByStatus(status.ACTIVE);
-
 
266
		items.addAll(cl.getClient().getAllItemsByStatus(status.PAUSED));
-
 
267
		items.addAll(cl.getClient().getAllItemsByStatus(status.PAUSED_BY_RISK));
-
 
268
 
-
 
269
		Map<Long, List<Item>> entityIdItemMap1 = new HashMap<Long, List<Item>>();
-
 
270
		ProductListGenerator pl = new ProductListGenerator(entityIdItemMap1);
-
 
271
		pl.populateEntityIdItemMap(items);
-
 
272
		pl.generateProductsListXML();
-
 
273
		//pl.generateProductXMLForDisplayAds();
-
 
274
	}
-
 
275
 
268
 
276
    private void populateEntityIdItemMap(List<Item> items){
269
    private void populateEntityIdItemMap(List<Item> items){
277
        Date toDate = new Date();
270
        Date toDate = new Date();
278
        for(Item item: items){
271
        for(Item item: items){
279
            //TODO Can be removed as we are checking in calling function
272
            //TODO Can be removed as we are checking in calling function
Line 307... Line 300...
307
        }
300
        }
308
        for(Long entityId: removeEntities){
301
        for(Long entityId: removeEntities){
309
            entityIdItemMap.remove(entityId);
302
            entityIdItemMap.remove(entityId);
310
        }
303
        }
311
    }
304
    }
-
 
305
    
-
 
306
    /**
-
 
307
     * Generate XML feed for mobile site
-
 
308
     * @throws Exception
-
 
309
     */
-
 
310
    public void generateXMLFeedForMobileSite() throws Exception	{
-
 
311
    	List<String> productXMLSnippets = new ArrayList<String>();
-
 
312
		productXMLSnippets.add("<Products>");
-
 
313
		List<Long> itemIds = new ArrayList<Long>();
-
 
314
		
-
 
315
		for(Long entityId: entityIdItemMap.keySet()){
-
 
316
			List<Item> items = entityIdItemMap.get(entityId);
-
 
317
			Item firstItem = items.get(0);
-
 
318
			Utils.info("first Item: " + firstItem);
-
 
319
			
-
 
320
			if(isMobile(firstItem) || isLaptop(firstItem)) {
-
 
321
				itemIds.add(firstItem.getId());
-
 
322
			}
-
 
323
		}
-
 
324
 
-
 
325
		List<String> descriptions = new ArrayList<String>();
-
 
326
		descriptions.add("8MP camera, Super AMOLED Plus display, Android Gingerbread");
-
 
327
		descriptions.add("Android OS v2.2 Froyo, 800MHz processor, 3.5\" capacitive display");
-
 
328
		descriptions.add("Dual-SIM, Wi-Fi, Bluetooth, Social networking &amp; IM");
-
 
329
		descriptions.add("Android Gingerbread, Facebook button, 5MP camera");
-
 
330
		descriptions.add("Android Gingerbread, 1GHz processor, 3.7\" Gorilla Glass display");
-
 
331
		descriptions.add("2GB RAM, 500GB HDD, Intel Core 2 Duo T6570 processor, DOS");
-
 
332
		descriptions.add("4GB RAM, 500GB HDD, Intel Core i5 2410M processor, Windows 7 Basic");
-
 
333
		descriptions.add("3.2\" touchscreen, 2MP camera, IM &amp; social networking");
-
 
334
		
-
 
335
		for(Long entityId: entityIdItemMap.keySet()) {
-
 
336
			List<Item> items = entityIdItemMap.get(entityId);
-
 
337
			Item firstItem = items.get(0);
-
 
338
			
-
 
339
			if(!isMobile(firstItem) && !isLaptop(firstItem)){
-
 
340
				continue;
-
 
341
			}
312
 
342
 
-
 
343
			String url = getProductURL(entityId, firstItem);
-
 
344
			String imageUrl = "http://www.saholic.com/images/website" + File.separator + entityId + File.separator + "thumbnail.jpg";
-
 
345
			String description = descriptions.get((int) (8 * Math.random()));
-
 
346
			double minPrice = getMinPrice(items);
-
 
347
			
-
 
348
			String productType = "";
-
 
349
			
-
 
350
			if (firstItem.getCategory() == 10001 || firstItem.getCategory() == 10002 || firstItem.getCategory() == 10003 || firstItem.getCategory() == 10004 || firstItem.getCategory() == 10005)	{
-
 
351
				productType = "Mobile Phone";
-
 
352
			
-
 
353
			} else if (firstItem.getCategory() == 10010)	{
-
 
354
				productType = "Tablet";
-
 
355
				
-
 
356
			} else if (firstItem.getCategory() == 10050)	{
-
 
357
				productType = "Laptop";
-
 
358
			}
-
 
359
			
-
 
360
			productXMLSnippets.add(this.xmlIndentation[1] + "<Product>");	
-
 
361
			
-
 
362
			productXMLSnippets.add(this.xmlIndentation[2] + "<ID>" + entityId + "</ID>");
-
 
363
			productXMLSnippets.add(this.xmlIndentation[2] + "<Type>" + productType + "</Type>");
-
 
364
			productXMLSnippets.add(this.xmlIndentation[2] + "<Brand>" + firstItem.getBrand() + "</Brand>");
-
 
365
			productXMLSnippets.add(this.xmlIndentation[2] + "<ModelName>" + firstItem.getModelName() + "</ModelName>");
-
 
366
			productXMLSnippets.add(this.xmlIndentation[2] + "<ModelNumber>" + firstItem.getModelNumber() + "</ModelNumber>");
-
 
367
			productXMLSnippets.add(this.xmlIndentation[2] + "<URL>" + url + "</URL>");
-
 
368
			productXMLSnippets.add(this.xmlIndentation[2] + "<ImageURL>" + imageUrl + "</ImageURL>");
-
 
369
			productXMLSnippets.add(this.xmlIndentation[2] + "<ShortDesc>" + description + "</ShortDesc>");
-
 
370
			productXMLSnippets.add(this.xmlIndentation[2] + "<MRP>" + firstItem.getMrp() + "</MRP>");
-
 
371
			productXMLSnippets.add(this.xmlIndentation[2] + "<SellingPrice>" + (int)minPrice  + "</SellingPrice>");
-
 
372
			
-
 
373
			productXMLSnippets.add(this.xmlIndentation[1] + "</Product>");
-
 
374
		}
-
 
375
		
-
 
376
		productXMLSnippets.add("</Products>");
-
 
377
		
-
 
378
		String productDataXML = StringUtils.join(productXMLSnippets, "\n");
-
 
379
		
-
 
380
		Utils.info(productDataXML);
-
 
381
		
-
 
382
		// Write it to file
-
 
383
		String productXMLFilename = Utils.EXPORT_PARTNERS_CONTENT_PATH + "msitedata.xml";
-
 
384
		DBUtils.store(productDataXML, productXMLFilename);
-
 
385
    }
313
 
386
 
314
	/**
387
	/**
315
	 * Generate the xml list of all the active phones and store in a file
388
	 * Generate the xml list of all the active phones and store in a file
316
	 * @throws Exception
389
	 * @throws Exception
317
	 */
390
	 */
Line 415... Line 488...
415
		
488
		
416
		// Write it to file
489
		// Write it to file
417
		String productXMLFilename = Utils.EXPORT_PARTNERS_CONTENT_PATH + "advertismentapi.xml";
490
		String productXMLFilename = Utils.EXPORT_PARTNERS_CONTENT_PATH + "advertismentapi.xml";
418
		DBUtils.store(productDataXML, productXMLFilename);
491
		DBUtils.store(productDataXML, productXMLFilename);
419
	}
492
	}
-
 
493
	
-
 
494
	public static void main(String[] args) throws Exception {
-
 
495
		CatalogClient cl = new CatalogClient();
-
 
496
		in.shop2020.model.v1.catalog.InventoryService.Client client = cl.getClient();
-
 
497
		
-
 
498
		List<Item> items = cl.getClient().getAllItemsByStatus(status.ACTIVE);
-
 
499
		items.addAll(cl.getClient().getAllItemsByStatus(status.PAUSED));
-
 
500
//		items.addAll(cl.getClient().getAllItemsByStatus(status.PAUSED_BY_RISK));
-
 
501
 
-
 
502
		Map<Long, List<Item>> entityIdItemMap1 = new HashMap<Long, List<Item>>();
-
 
503
		ProductListGenerator pl = new ProductListGenerator(entityIdItemMap1);
-
 
504
		pl.populateEntityIdItemMap(items);
-
 
505
		pl.generateXMLFeedForMobileSite();
-
 
506
	}
420
}
507
}
421
508