Subversion Repositories SmartDukaan

Rev

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