Subversion Repositories SmartDukaan

Rev

Rev 7662 | Rev 8131 | 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
		}
7708 amit.gupta 47
		try {
48
		//Temporarily added
49
		AmazonSCDataGenerator asg = new AmazonSCDataGenerator(allValidEntities, "ALL");
50
		asg.generateSCProdData();
51
		}catch(Exception e){
52
			System.out.println("Could not generate Amazon feed.");
53
		}
7506 amit.gupta 54
 
55
		// Upload catalog to Google App Engine.
7662 amit.gupta 56
		log.info("Uploading Catalog to Google app engine");
7506 amit.gupta 57
		CatalogUploderToGAE catalogUploaderToGAE = new CatalogUploderToGAE();
58
		catalogUploaderToGAE.uploadItems(items);
59
 
60
		// FIXME Avoiding the finding of accesories, as list of categories for
61
		// which we need to find accessories is hardocoded in code.
62
		// We need to make that configurable. Also creating ticket to improve
63
		// it.
64
		try {
65
			log.info("Finding accessories");
66
			AccessoriesFinder af = new AccessoriesFinder(new HashSet<Long>(
67
					allValidEntityIds));
68
			Map<Long, Map<Long, List<Long>>> relatedAccessories = af
69
					.findAccessories();
70
			CreationUtils.storeRelatedAccessories(relatedAccessories);
71
		} catch (Exception e) {
72
			log.error("Error while generating accessories" + e);
73
		}
74
 
75
        // Generate synonyms list. This will be used in PriceComparisonTool to
76
        // resolve the product names.
77
        log.info("Generating synonyms");
78
        SynonymExporter sx = new SynonymExporter();
79
        sx.storeSynonyms(allValidEntities);
80
 
81
        //Generation for website SEO      
82
        log.info("Generating HTML for Site Index");
83
        ProductIndexGenerator indexGenerator = new ProductIndexGenerator(allValidEntities);
84
        indexGenerator.generate();
85
 
86
        log.info("Generating HTML for Site for Product Documents");
87
        ProductDocumentsGenerator asGenerator = new ProductDocumentsGenerator(allValidEntities);
88
        asGenerator.generate();
89
 
90
        log.info("Generating HTML for Accessories Compatibility Index");	
91
        CompatibleAccessoriesIndexGenerator generator = new CompatibleAccessoriesIndexGenerator(allValidEntities);
92
        generator.generate();
93
 
94
        log.info("Generating HTML for Most Frequently searched keywords");
95
        MostFrequentlySearchedKeywords mfsk = new MostFrequentlySearchedKeywords();
96
        mfsk.generate();
97
 
98
        log.info("Generating HTML for Most Compared Index");
99
        MostComparedIndexGenerator mostCompGenerator = new MostComparedIndexGenerator(allValidEntityIds);
100
        mostCompGenerator.generate();
101
 
102
        log.info("Generating XML for Mobile Site XML feed");
103
        MobileSiteDataXMLGenerator mSiteXMLGenerator = new MobileSiteDataXMLGenerator(allValidEntities);
104
        mSiteXMLGenerator.generate();
105
	}
106
 
107
 
108
    private static void populateEntityIdItemMap() {
109
        Utils.info("Processing " + items.size() + " items");
110
        for (Item item : items) {
111
            Utils.info(item.getId() + " Item is adding");
112
            List<Item> itemList = entityIdItemMap.get(item.getCatalogItemId());
113
            if (itemList == null) {
114
                itemList = new ArrayList<Item>();
115
            } 
116
            itemList.add(item);
117
            entityIdItemMap.put(item.getCatalogItemId(), itemList);
118
        }
119
    }
120
}