Subversion Repositories SmartDukaan

Rev

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

Rev 7506 Rev 7662
Line 76... Line 76...
76
    private Date 				  timeStamp			  		  = null;
76
    private Date 				  timeStamp			  		  = null;
77
    private CommandLine           cmd                         = null;
77
    private CommandLine           cmd                         = null;
78
    private Map<Long, List<Item>> entityIdItemMap             = new LinkedHashMap<Long, List<Item>>();
78
    private Map<Long, List<Item>> entityIdItemMap             = new LinkedHashMap<Long, List<Item>>();
79
    private Long                  lastGenerationTime          = 0l;
79
    private Long                  lastGenerationTime          = 0l;
80
    private Map<Long, Entity>     entities;
80
    private Map<Long, Entity>     entities;
-
 
81
    private List<Long> removeEntities = new ArrayList<Long>();
81
    private List<Item>            items;
82
    private List<Item>            items;
82
    private List<Source>          sources;
83
    private List<Source>          sources;
83
    private CatalogClient         csc;
84
    private CatalogClient         csc;
84
    private Client                client;
85
    private Client                client;
85
    private List<Item>			  alertItems;	
86
    private List<Item>			  alertItems;	
Line 286... Line 287...
286
            log.info("Before removing old resources.");
287
            log.info("Before removing old resources.");
287
            removeOldResources();
288
            removeOldResources();
288
 
289
 
289
        }
290
        }
290
 
291
 
291
        // this still needs to be evolved. Must not be used.
-
 
292
        if (GENERATION_TYPE.equals(GENERATION_TYPE_INCREMENTAL)) {
292
/*        if (GENERATION_TYPE.equals(GENERATION_TYPE_INCREMENTAL)) {
293
        }
293
        }
294
 
294
*/
295
        // Populate the entityIdIemMap
-
 
296
        populateEntityIdItemMap();
295
        populateEntityIdItemMap();
297
        // Generate partners and json objects for phones only
296
        // Generate partners and json objects for phones only
298
        if (!GENERATION_TYPE.equals(GENERATION_TYPE_ONE)) {
297
        if (!GENERATION_TYPE.equals(GENERATION_TYPE_ONE)) {
299
        	try	{
298
        	try	{
300
	        	ProductListGenerator generator = new ProductListGenerator(entityIdItemMap);
299
	        	ProductListGenerator generator = new ProductListGenerator(entityIdItemMap);
Line 340... Line 339...
340
            boolean domainOnce = true;
339
            boolean domainOnce = true;
341
            boolean sourceOnce = true;
340
            boolean sourceOnce = true;
342
            for(String domainPath : DOMAINPATHS){
341
            for(String domainPath : DOMAINPATHS){
343
            	String domainName = domainPath;
342
            	String domainName = domainPath;
344
            	String pathName = domainPath.split("\\.")[0].split(":")[0];
343
            	String pathName = domainPath.split("\\.")[0].split(":")[0];
345
            	//Special check for store.
-
 
346
            	minPrice = priceInserter.insertPriceInHtml(items, entityId,
344
            	if(!removeEntities.contains(entityId)){
347
            			domainName, Utils.EXPORT_PATH + "html/entities-" +  pathName + "/", null);
345
            		priceInserter.insertPriceInHtml(items, entityId, domainName, Utils.EXPORT_PATH + "html/entities-" +  pathName + "/", null);
-
 
346
            	}
348
            	if(domainOnce){
347
            	if(domainOnce){
-
 
348
            		minPrice = getMinPrice(items, entityId, null);
349
            		priceString.append("<field name=\"F_50002\">" + minPrice + "</field>");
349
            		priceString.append("<field name=\"F_50002\">" + minPrice + "</field>");
350
            		availabilityString.append("<field name=\"F_50028\">" + availability + "</field>");
350
            		availabilityString.append("<field name=\"F_50028\">" + availability + "</field>");
351
            		if(entityTags.containsKey(entityId)) {
351
            		if(entityTags.containsKey(entityId)) {
352
            			List<String> tags = entityTags.get(entityId);
352
            			List<String> tags = entityTags.get(entityId);
353
            			for(String tag: tags){
353
            			for(String tag: tags){
Line 361... Line 361...
361
            		}
361
            		}
362
            		domainOnce = false;
362
            		domainOnce = false;
363
            	}
363
            	}
364
            	if(sources != null){
364
            	if(sources != null){
365
            		for (Source source : sources) {
365
            		for (Source source : sources) {
366
                        minPrice = priceInserter.insertPriceInHtml(items, entityId,
-
 
367
                                domainName, Utils.EXPORT_PATH + "html/entities-" + pathName + "/",
366
						priceInserter.insertPriceInHtml(items, entityId,domainName, Utils.EXPORT_PATH + "html/entities-" + pathName + "/",source);
368
                                source);
-
 
369
                        if(sourceOnce){
367
                        if(sourceOnce){
-
 
368
                        	minPrice = getMinPrice(items, entityId, source);
370
                        	priceString.append("<field name=\"F_50002_"
369
                        	priceString.append("<field name=\"F_50002_"
371
                                + source.getId() + "\">" + minPrice + "</field>");
370
                                + source.getId() + "\">" + minPrice + "</field>");
372
                        }
371
                        }
373
            		}
372
            		}
374
            		sourceOnce = false;
373
            		sourceOnce = false;
Line 458... Line 457...
458
            if (isValidEntity(entities.get(entityID))) {
457
            if (isValidEntity(entities.get(entityID))) {
459
                validEntities.add(entities.get(entityID));
458
                validEntities.add(entities.get(entityID));
460
                validEntityIds.add(entityID);
459
                validEntityIds.add(entityID);
461
            }
460
            }
462
        }
461
        }
-
 
462
        
-
 
463
        log.info("Generating synonyms");
-
 
464
        SynonymExporter sx = new SynonymExporter();
-
 
465
        sx.storeSynonyms(validEntities);
463
 
466
 
464
        // Calculate comparison scores
467
        // Calculate comparison scores
465
        log.info("Calculating comparison scores");
468
        log.info("Calculating comparison scores");
466
        NewCMP cmp = new NewCMP(validEntities);
469
        NewCMP cmp = new NewCMP(validEntities);
467
        Map<Long, Map<Long, Double>> slideScoresByEntity = cmp.getSlideScores();
470
        Map<Long, Map<Long, Double>> slideScoresByEntity = cmp.getSlideScores();
Line 505... Line 508...
505
        }
508
        }
506
 
509
 
507
        for (Map.Entry<Long, List<Item>> entry : entityIdItemMap.entrySet()) {
510
        for (Map.Entry<Long, List<Item>> entry : entityIdItemMap.entrySet()) {
508
            List<Item> items = entry.getValue();
511
            List<Item> items = entry.getValue();
509
            for (Item item : items) {
512
            for (Item item : items) {
510
                if ( (item.getItemStatus() == status.CONTENT_COMPLETE && validEntityIds.contains(item.getCatalogItemId())) 
513
                if (item.getItemStatus() == status.CONTENT_COMPLETE 
511
                		|| item.getItemStatus() == status.COMING_SOON) {
514
                		|| item.getItemStatus() == status.COMING_SOON) {
512
                	if(item.getStartDate() <= new Date().getTime() + ONE_DAY){
515
                	if(item.getStartDate() <= new Date().getTime() + ONE_DAY){
513
                		item.setItemStatus(status.ACTIVE);
516
                		item.setItemStatus(status.ACTIVE);
514
                		item.setStatus_description("This item is active");
517
                		item.setStatus_description("This item is active");
515
                	} else {
518
                	} else {
Line 623... Line 626...
623
        }
626
        }
624
 
627
 
625
        Utils.info("Processing " + entityIdItemMap.size() + " entities");
628
        Utils.info("Processing " + entityIdItemMap.size() + " entities");
626
        // Remove all items which have not been updated since last content
629
        // Remove all items which have not been updated since last content
627
        // generation.
630
        // generation.
628
        List<Long> removeEntities = new ArrayList<Long>();
631
        if (!(UPDATE_TYPE_CONTENT.equals(UPDATE_TYPE) || lastGenerationTime == 0)) {
629
        for (Long entityId : entityIdItemMap.keySet()) {
632
	        for (Long entityId : entityIdItemMap.keySet()) {
630
            boolean isValidEntity = false;
633
	            boolean isValidEntity = false;
631
            // If any one of the items has been updated before current
634
	            // If any one of the items has been updated before current
632
            // timestamp, than we generate content for whole entity
635
	            // timestamp, than we generate content for pricing
633
            for (Item item : entityIdItemMap.get(entityId)) {
636
	            for (Item item : entityIdItemMap.get(entityId)) {
634
                if (item.getUpdatedOn() > lastGenerationTime || item.getItemStatus()==status.COMING_SOON) {
637
	                if (item.getUpdatedOn() > lastGenerationTime) {
635
                    isValidEntity = true;
638
	                    isValidEntity = true;
636
                }
639
	                }
637
            }
640
	            }
638
            if (!isValidEntity) {
641
	            if (!isValidEntity) {
639
                removeEntities.add(entityId);
642
	                removeEntities.add(entityId);
640
            }
643
	            }
641
        }
644
	        }
642
 
-
 
643
        for (Long entityId : removeEntities) {
-
 
644
            entityIdItemMap.remove(entityId);
-
 
645
        }
645
        }
646
 
646
 
647
        Utils.info("Final valid entities to be processed: " + entityIdItemMap.size());
647
        Utils.info("Final valid entities to be processed: " + entityIdItemMap.size());
648
    }
648
    }
649
 
649
 
Line 702... Line 702...
702
			DBUtils.store(gson.toJson(finalsynonyms), autosuggestFilename);
702
			DBUtils.store(gson.toJson(finalsynonyms), autosuggestFilename);
703
		} catch (Exception e) {
703
		} catch (Exception e) {
704
			e.printStackTrace();
704
			e.printStackTrace();
705
		}
705
		}
706
    }
706
    }
-
 
707
 
-
 
708
	public double getMinPrice(List<Item> items, long catalogId, Source source) {
-
 
709
		Item minPriceItem = null;
-
 
710
		for (Item item : items) {
-
 
711
			if (minPriceItem == null
-
 
712
					|| minPriceItem.getSellingPrice() > item.getSellingPrice()) {
-
 
713
				minPriceItem = item;
-
 
714
			}
-
 
715
		}
-
 
716
		return minPriceItem.getSellingPrice();
-
 
717
	}
707
}
718
}