Subversion Repositories SmartDukaan

Rev

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

package in.shop2020.util;

import in.shop2020.metamodel.core.Entity;
import in.shop2020.metamodel.util.CreationUtils;
import in.shop2020.model.v1.catalog.CatalogService.Client;
import in.shop2020.model.v1.catalog.Item;
import in.shop2020.model.v1.catalog.status;
import in.shop2020.thrift.clients.CatalogClient;
import in.shop2020.ui.util.CatalogUploderToGAE;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class WeeklyContentCreation {

        private static Log log = LogFactory.getLog(ContentGenerationUtility.class);
        
        private static List<Item> items = null;
        private static Map<Long,List<Item>> entityIdItemMap = new HashMap<Long, List<Item>>();
        private static List<Long> allValidEntityIds = null;
        private static List<Entity> allValidEntities = null;

        public static void main(String[] args) throws Exception {
                //Boolean.parseBoolean("true");
                Client client = new CatalogClient().getClient();
                                
                items = client.getAllItemsByStatus(status.ACTIVE);
                items.addAll(client.getAllItemsByStatus(status.PAUSED));
                items.addAll(client.getAllItemsByStatus(status.COMING_SOON));
                
                populateEntityIdItemMap();
                Map<Long, Entity> allEntities = CreationUtils.getEntities();
                allValidEntities = new ArrayList<Entity>();
                allValidEntityIds = new ArrayList<Long>(entityIdItemMap.keySet());
                
                for(Long entityId : entityIdItemMap.keySet()) {
                        if(allEntities.containsKey(entityId)){
                                allValidEntities.add(allEntities.get(entityId));
                        }
                }
                try {
                //Temporarily added
                AmazonSCDataGenerator asg = new AmazonSCDataGenerator(allValidEntities, "ALL");
                asg.generateSCProdData();
                }catch(Exception e){
                        System.out.println("Could not generate Amazon feed.");
                        e.printStackTrace();
                }
                
                // Upload catalog to Google App Engine.
                log.info("Uploading Catalog to Google app engine");
                CatalogUploderToGAE catalogUploaderToGAE = new CatalogUploderToGAE();
                catalogUploaderToGAE.uploadItems(items);

                // FIXME Avoiding the finding of accesories, as list of categories for
                // which we need to find accessories is hardocoded in code.
                // We need to make that configurable. Also creating ticket to improve
                // it.
                try {
                        log.info("Finding accessories");
                        AccessoriesFinder af = new AccessoriesFinder(new HashSet<Long>(
                                        allValidEntityIds));
                        Map<Long, Map<Long, List<Long>>> relatedAccessories = af
                                        .findAccessories();
                        CreationUtils.storeRelatedAccessories(relatedAccessories);
                } catch (Exception e) {
                        log.error("Error while generating accessories" + e);
                }
                
        // Generate synonyms list. This will be used in PriceComparisonTool to
        // resolve the product names.
        log.info("Generating synonyms");
        SynonymExporter sx = new SynonymExporter();
        sx.storeSynonyms(allValidEntities);
        
        //Generation for website SEO      
        log.info("Generating HTML for Site Index");
        ProductIndexGenerator indexGenerator = new ProductIndexGenerator(allValidEntities);
        indexGenerator.generate();

        log.info("Generating HTML for Site for Product Documents");
        ProductDocumentsGenerator asGenerator = new ProductDocumentsGenerator(allValidEntities);
        asGenerator.generate();
        
        log.info("Generating HTML for Accessories Compatibility Index");        
        CompatibleAccessoriesIndexGenerator generator = new CompatibleAccessoriesIndexGenerator(allValidEntities);
        generator.generate();

        log.info("Generating HTML for Most Frequently searched keywords");
        MostFrequentlySearchedKeywords mfsk = new MostFrequentlySearchedKeywords();
        mfsk.generate();
        
        log.info("Generating HTML for Most Compared Index");
        MostComparedIndexGenerator mostCompGenerator = new MostComparedIndexGenerator(allValidEntityIds);
        mostCompGenerator.generate();

        log.info("Generating XML for Mobile Site XML feed");
        MobileSiteDataXMLGenerator mSiteXMLGenerator = new MobileSiteDataXMLGenerator(allValidEntities);
        mSiteXMLGenerator.generate();
        }

    
    private static void populateEntityIdItemMap() {
        Utils.info("Processing " + items.size() + " items");
        for (Item item : items) {
            Utils.info(item.getId() + " Item is adding");
            List<Item> itemList = entityIdItemMap.get(item.getCatalogItemId());
            if (itemList == null) {
                itemList = new ArrayList<Item>();
            } 
            itemList.add(item);
            entityIdItemMap.put(item.getCatalogItemId(), itemList);
        }
    }
}