Subversion Repositories SmartDukaan

Rev

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

package in.shop2020.mobileapi.serving.utils;

import in.shop2020.metamodel.util.ContentPojo;
import in.shop2020.storage.mongo.StorageManager;
import in.shop2020.metamodel.util.ProductPojo;
import in.shop2020.mobileapi.serving.controllers.CategoryController;
import in.shop2020.mobileapi.serving.pojos.MenuPojo;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.google.gson.Gson;

public class PojoPopulator {
        
        public static Gson gson = new Gson();
        private static Logger log = Logger.getLogger(PojoPopulator.class);

    public static List<MenuPojo> getCurrentMenu() {
        List<MenuPojo> finalList = new ArrayList<MenuPojo>();
        List<MenuPojo> children = new ArrayList<MenuPojo>();
        List<MenuPojo> children1 = new ArrayList<MenuPojo>();
        List<MenuPojo> children2 = new ArrayList<MenuPojo>();
        List<MenuPojo> children3 = new ArrayList<MenuPojo>();
        List<MenuPojo> children4 = new ArrayList<MenuPojo>();
        List<MenuPojo> children5 = new ArrayList<MenuPojo>();

        //  Mobile Menu start
        children.clear();
        children.add(getMenuPojoObject("Android Phones", "android", "", null));
        children.add(getMenuPojoObject("Business Phones", "business", "", null));
        children.add(getMenuPojoObject("Windows Phones", "windows", "", null));
        children.add(getMenuPojoObject("Samsung Phones", "samsung", "", null));
        finalList.add(getMenuPojoObject("Mobiles", "all-mobiles/10006", "images/menu/mobile.PNG", children));
        //  Mobile Menu end
        
        //  Tablet Menu start
        children1.add(getMenuPojoObject("With call facility", "tablets-with-calling", "", null));
        children1.add(getMenuPojoObject("Without call facility", "tablets-without-calling", "", null));
        children1.add(getMenuPojoObject("Apple", "apple-tablets", "", null));
        children1.add(getMenuPojoObject("Samsung", "samsung-tablets", "", null));
        children1.add(getMenuPojoObject("Spice", "spice-tablets", "", null));
        finalList.add(getMenuPojoObject("Tablets", "all-tablets/10010", "images/menu/tablet.PNG", children1));
        //  Tablet Menu end
        
        //  Laptop Menu start
        children2.add(getMenuPojoObject("Windows Laptop", "windows-laptop", "", null));
        children2.add(getMenuPojoObject("Apple Macbook", "mac-laptops", "", null));
        children2.add(getMenuPojoObject("Linux/DOS Laptops", "cheap-laptops", "", null));
        finalList.add(getMenuPojoObject("Laptops", "all-laptops/10050", "images/menu/laptop.PNG", children2));
        //  Laptop Menu end
        
        //  Accessories Menu start
        children3.add(getMenuPojoObject("Carrying case", "carrying-case/10018", "", null));
        children3.add(getMenuPojoObject("Headphones", "headphones/10082", "", null));
        children3.add(getMenuPojoObject("Headsets", "headset/10015", "", null));
        children3.add(getMenuPojoObject("Chargers", "charger/10016", "", null));
        children3.add(getMenuPojoObject("Music Players", "portable-music-players/12001", "", null));
        children3.add(getMenuPojoObject("Headsets", "headset/10015", "", null));
        finalList.add(getMenuPojoObject("Accessories", "all-mobile-accessories/10011", "images/menu/accessories.PNG", children3));
        /*
            <a class="link-menu-secondary menu-secondary-brand" href="/battery/10014">Battery</a>
            <a class="link-menu-secondary menu-secondary-brand" href="/memory-card/10013">Memory Card</a>
            <a class="link-menu-secondary menu-secondary-brand" href="/bluetooth-headset/10012">Bluetooth Headset</a>
            <a class="link-menu-secondary menu-secondary-brand" href="/pen-drive/10017">Pen Drive</a>
            <a class="link-menu-secondary menu-secondary-brand" href="/speaker/10026">Speaker</a>
            <a class="link-menu-secondary menu-secondary-brand" href="/laptop-bags/10085">Laptop Bags</a>
            <a class="link-menu-secondary menu-secondary-brand" href="/mouse/10081">Mouse</a>
            <a class="link-menu-secondary menu-secondary-brand" href="/laptop-batteries/10077">Laptop Batteries</a>
            <a class="link-menu-secondary menu-secondary-brand" href="/data-cards/10083">Data Cards</a>
            <a class="link-menu-secondary menu-secondary-brand" href="/external-hard-disks/10073">External Hard disk</a>
            <a class="link-menu-secondary menu-secondary-brand" href="/mouse-pads/10084">Mouse Pads</a>
        */
        //  Accessories Menu end
        
        //  Camera Menu start
        children4.add(getMenuPojoObject("DSLR Camera", "dslr-camera/11003", "", null));
        children4.add(getMenuPojoObject("Compact Camera", "compact-camera/11002", "", null));
        finalList.add(getMenuPojoObject("Cameras", "all-cameras/11001", "images/menu/camera.PNG", children4));
        //  Camera Menu end
        
        //  Recharge Menu start
        children5.add(getMenuPojoObject("My Wallet", "my-wallet", "", null));
        children5.add(getMenuPojoObject("My Recharges", "my-recharges", "", null));
        children5.add(getMenuPojoObject("Learn More", "recharge-faq", "", null));
        finalList.add(getMenuPojoObject("Recharge", "recharge", "//static.saholic.com/images/tabletMenuIcon.png", children5));
        //  Recharge Menu end
        
        return finalList;
    }
    
    private static MenuPojo getMenuPojoObject(String name, String url, String iconUrl, List<MenuPojo> children) {
        MenuPojo menuObject = new MenuPojo();
        menuObject.setName(name);
        menuObject.setUrl(url);
        menuObject.setIcon_url(iconUrl);
        menuObject.setChildren(children);
        return menuObject;
    }
    
        
        public static ProductPojo getShortContent(long entityId) {
                ContentPojo cp = StorageManager.getById(StorageManager.views.siteContent, entityId, ContentPojo.class);
                ProductPojo pp = null;
                if(cp!=null){
                        try {
                        pp = new ProductPojo();
                        pp.setOfferText(cp.getOfferText());
                        pp.setDescription(StringUtils.join(cp.getKeySpecs().subList(0, 3),", "));
                        pp.setImageUrl(cp.getThumbnailImageUrl());
                        pp.setUrl(cp.getUrl());
                        
                        pp.setMrp(cp.getItems().get(0).getMrp());
                        pp.setPrice(cp.getItems().get(0).getSellingPrice());
                        pp.setTitle(cp.getTitle());
                        } catch (Exception e) {
                                log.error("Error in entity : " + entityId);
                                pp = null;
                        }
                }
                return pp;
        }
    
}