Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
7506 amit.gupta 1
package in.shop2020.util;
2
 
3
import in.shop2020.metamodel.core.Entity;
4
import in.shop2020.metamodel.util.CreationUtils;
5
import in.shop2020.model.v1.catalog.CatalogService.Client;
6
import in.shop2020.model.v1.catalog.Item;
7
import in.shop2020.model.v1.catalog.status;
8
import in.shop2020.thrift.clients.CatalogClient;
9
import in.shop2020.ui.util.CatalogUploderToGAE;
10
 
11
import java.util.ArrayList;
12
import java.util.HashMap;
13
import java.util.HashSet;
14
import java.util.List;
15
import java.util.Map;
16
 
17
import org.apache.commons.logging.Log;
18
import org.apache.commons.logging.LogFactory;
19
 
20
public class WeeklyContentCreation {
21
 
22
	private static Log log = LogFactory.getLog(ContentGenerationUtility.class);
23
 
24
	private static List<Item> items = null;
25
	private static Map<Long,List<Item>> entityIdItemMap = new HashMap<Long, List<Item>>();
26
	private static List<Long> allValidEntityIds = null;
27
	private static List<Entity> allValidEntities = null;
28
 
29
	public static void main(String[] args) throws Exception {
30
		//Boolean.parseBoolean("true");
31
		Client client = new CatalogClient().getClient();
32
 
33
		items = client.getAllItemsByStatus(status.ACTIVE);
34
		items.addAll(client.getAllItemsByStatus(status.PAUSED));
35
		items.addAll(client.getAllItemsByStatus(status.COMING_SOON));
36
 
37
		populateEntityIdItemMap();
38
		Map<Long, Entity> allEntities = CreationUtils.getEntities();
39
		allValidEntities = new ArrayList<Entity>();
40
		allValidEntityIds = new ArrayList<Long>(entityIdItemMap.keySet());
41
 
42
		for(Long entityId : entityIdItemMap.keySet()) {
43
			if(allEntities.containsKey(entityId)){
44
				allValidEntities.add(allEntities.get(entityId));
45
			}
46
		}
47
 
48
 
49
		// Upload catalog to Google App Engine.
7662 amit.gupta 50
		log.info("Uploading Catalog to Google app engine");
7506 amit.gupta 51
		CatalogUploderToGAE catalogUploaderToGAE = new CatalogUploderToGAE();
52
		catalogUploaderToGAE.uploadItems(items);
53
 
54
		// FIXME Avoiding the finding of accesories, as list of categories for
55
		// which we need to find accessories is hardocoded in code.
56
		// We need to make that configurable. Also creating ticket to improve
57
		// it.
58
		try {
59
			log.info("Finding accessories");
60
			AccessoriesFinder af = new AccessoriesFinder(new HashSet<Long>(
61
					allValidEntityIds));
62
			Map<Long, Map<Long, List<Long>>> relatedAccessories = af
63
					.findAccessories();
64
			CreationUtils.storeRelatedAccessories(relatedAccessories);
65
		} catch (Exception e) {
66
			log.error("Error while generating accessories" + e);
67
		}
68
 
69
        // Generate synonyms list. This will be used in PriceComparisonTool to
70
        // resolve the product names.
71
        log.info("Generating synonyms");
72
        SynonymExporter sx = new SynonymExporter();
73
        sx.storeSynonyms(allValidEntities);
74
 
75
        //Generation for website SEO      
76
        log.info("Generating HTML for Site Index");
77
        ProductIndexGenerator indexGenerator = new ProductIndexGenerator(allValidEntities);
78
        indexGenerator.generate();
79
 
80
        log.info("Generating HTML for Site for Product Documents");
81
        ProductDocumentsGenerator asGenerator = new ProductDocumentsGenerator(allValidEntities);
82
        asGenerator.generate();
83
 
84
        log.info("Generating HTML for Accessories Compatibility Index");	
85
        CompatibleAccessoriesIndexGenerator generator = new CompatibleAccessoriesIndexGenerator(allValidEntities);
86
        generator.generate();
87
 
88
        log.info("Generating HTML for Most Frequently searched keywords");
89
        MostFrequentlySearchedKeywords mfsk = new MostFrequentlySearchedKeywords();
90
        mfsk.generate();
91
 
92
        log.info("Generating HTML for Most Compared Index");
93
        MostComparedIndexGenerator mostCompGenerator = new MostComparedIndexGenerator(allValidEntityIds);
94
        mostCompGenerator.generate();
95
 
96
        log.info("Generating XML for Mobile Site XML feed");
97
        MobileSiteDataXMLGenerator mSiteXMLGenerator = new MobileSiteDataXMLGenerator(allValidEntities);
98
        mSiteXMLGenerator.generate();
99
	}
100
 
101
 
102
    private static void populateEntityIdItemMap() {
103
        Utils.info("Processing " + items.size() + " items");
104
        for (Item item : items) {
105
            Utils.info(item.getId() + " Item is adding");
106
            List<Item> itemList = entityIdItemMap.get(item.getCatalogItemId());
107
            if (itemList == null) {
108
                itemList = new ArrayList<Item>();
109
            } 
110
            itemList.add(item);
111
            entityIdItemMap.put(item.getCatalogItemId(), itemList);
112
        }
113
    }
114
}