Subversion Repositories SmartDukaan

Rev

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

Rev 5058 Rev 5084
Line 37... Line 37...
37
import org.apache.commons.cli.ParseException;
37
import org.apache.commons.cli.ParseException;
38
import org.apache.commons.cli.PosixParser;
38
import org.apache.commons.cli.PosixParser;
39
import org.apache.commons.logging.Log;
39
import org.apache.commons.logging.Log;
40
import org.apache.commons.logging.LogFactory;
40
import org.apache.commons.logging.LogFactory;
41
 
41
 
-
 
42
import com.google.gson.Gson;
-
 
43
 
42
public class ContentGenerationUtility {
44
public class ContentGenerationUtility {
43
    private static final String   UPDATE_TYPE_CATALOG         = "CATALOG";
45
    private static final String   UPDATE_TYPE_CATALOG         = "CATALOG";
44
 
46
 
45
    private static final String   UPDATE_TYPE_CONTENT         = "CONTENT";
47
    private static final String   UPDATE_TYPE_CONTENT         = "CONTENT";
46
 
48
 
Line 308... Line 310...
308
            priceInserter.insertPriceInSolrData(entityId,
310
            priceInserter.insertPriceInSolrData(entityId,
309
                    priceString.toString());
311
                    priceString.toString());
310
        }
312
        }
311
 
313
 
312
        priceInserter.copySolrSchemaFiles();
314
        priceInserter.copySolrSchemaFiles();
313
        
315
        synonymTitlesExporter();
314
        // Generate partners and json objects for phones only
316
        // Generate partners and json objects for phones only
315
        if (!GENERATION_TYPE.equals(GENERATION_TYPE_ONE)) {
317
        if (!GENERATION_TYPE.equals(GENERATION_TYPE_ONE)) {
316
            ProductListGenerator generator = new ProductListGenerator(entityIdItemMap);
318
            ProductListGenerator generator = new ProductListGenerator(entityIdItemMap);
317
            generator.generateProductsListXML();
319
            generator.generateProductsListXML();
318
            generator.generateProductListJavascript();
320
            generator.generateProductListJavascript();
Line 423... Line 425...
423
        }
425
        }
424
 
426
 
425
        // Generate synonyms list. This will be used in PriceComparisonTool to
427
        // Generate synonyms list. This will be used in PriceComparisonTool to
426
        // resolve the product names.
428
        // resolve the product names.
427
        log.info("Generating synonyms");
429
        log.info("Generating synonyms");
428
        SynonymExporter sx = new SynonymExporter(validEntities);
430
        SynonymExporter sx = new SynonymExporter();
429
        sx.storeSynonyms();
431
        sx.storeSynonyms(validEntities);
430
        
432
        
431
        // Generate HTML for Site Index
433
        // Generate HTML for Site Index
432
        log.info("Generating HTML for Site Index");
434
        log.info("Generating HTML for Site Index");
433
        ProductIndexGenerator indexGenerator = new ProductIndexGenerator(validEntities);
435
        ProductIndexGenerator indexGenerator = new ProductIndexGenerator(validEntities);
434
        indexGenerator.generate();
436
        indexGenerator.generate();
Line 538... Line 540...
538
            entityIdItemMap.remove(entityId);
540
            entityIdItemMap.remove(entityId);
539
        }
541
        }
540
 
542
 
541
        Utils.info("Final valid entities to be processed: " + entityIdItemMap.size());
543
        Utils.info("Final valid entities to be processed: " + entityIdItemMap.size());
542
    }
544
    }
-
 
545
 
-
 
546
    private void synonymTitlesExporter() {
-
 
547
    	SynonymExporter sx = new SynonymExporter();
-
 
548
        Map<Long, Map<String,List<String>>> synonyms = sx.getSynonyms();
-
 
549
        Map<Long, List<String>> finalsynonyms = new HashMap<Long, List<String>>();
-
 
550
    	for (Map.Entry<Long, List<Item>> entry : entityIdItemMap.entrySet()) {
-
 
551
            long entityId = entry.getKey();
-
 
552
	    	try{
-
 
553
	            String brand = "";
-
 
554
	            List<String> modelNameSynonyms =  new ArrayList<String>();
-
 
555
	            List<String> modelNumberSynonyms =  new ArrayList<String>();
-
 
556
	            List<String> titles = new ArrayList<String>();
-
 
557
	            Map<String,List<String>> synonymMap = synonyms.get(entityId);
-
 
558
	            if(synonymMap != null && !synonymMap.isEmpty()){
-
 
559
	            	if(synonymMap.get("ORIGINAL_MODEL_NAME") != null && !synonymMap.get("ORIGINAL_MODEL_NAME").isEmpty()){
-
 
560
	            		modelNameSynonyms.addAll(synonymMap.get("ORIGINAL_MODEL_NAME"));
-
 
561
	            	}
-
 
562
	            	if(synonymMap.get("MODEL_NAME") != null && !synonymMap.get("MODEL_NAME").isEmpty()){
-
 
563
	            		modelNameSynonyms.addAll(synonymMap.get("MODEL_NAME"));
-
 
564
	            	}
-
 
565
	            	if(synonymMap.get("ORIGINAL_MODEL_NUMBER") != null && !synonymMap.get("ORIGINAL_MODEL_NUMBER").isEmpty()){
-
 
566
	            		modelNumberSynonyms.addAll(synonymMap.get("ORIGINAL_MODEL_NUMBER"));
-
 
567
	            	}
-
 
568
	            	if(synonymMap.get("MODEL_NUMBER") != null && !synonymMap.get("MODEL_NUMBER").isEmpty()){
-
 
569
	            		modelNumberSynonyms.addAll(synonymMap.get("MODEL_NUMBER"));
-
 
570
	            	}
-
 
571
	            	brand = ((synonymMap.get("ORIGINAL_BRAND") != null && !synonymMap.get("ORIGINAL_BRAND").isEmpty()) ? synonymMap.get("ORIGINAL_BRAND").get(0) : "");
-
 
572
	            }
-
 
573
	            for(String model_name: modelNameSynonyms){
-
 
574
	            	for(String model_number: modelNumberSynonyms){
-
 
575
	            		String title = brand + " " + model_name + " " + model_number;
-
 
576
	            		title = title.replaceAll("  ", " ");
-
 
577
	            		titles.add(title);
-
 
578
	            	}
-
 
579
	            }
-
 
580
	            finalsynonyms.put(entityId, titles);
-
 
581
	        } catch (Exception e) {
-
 
582
				e.printStackTrace();
-
 
583
			}
-
 
584
    	}
-
 
585
    	
-
 
586
    	String autosuggestFilename = Utils.EXPORT_JAVASCRIPT_CONTENT_PATH + "autosuggest.json";
-
 
587
        Gson gson = new Gson();
-
 
588
		try {
-
 
589
			DBUtils.store(gson.toJson(finalsynonyms), autosuggestFilename);
-
 
590
		} catch (Exception e) {
-
 
591
			e.printStackTrace();
-
 
592
		}
-
 
593
    }
543
}
594
}