Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

/**
 * 
 */
package in.shop2020.serving.controllers;


import in.shop2020.model.v1.widgets.WidgetService.Client;
import in.shop2020.serving.pages.PageContentKeys;
import in.shop2020.serving.pages.PageEnum;
import in.shop2020.serving.pages.PageManager;
import in.shop2020.thrift.clients.WidgetServiceClient;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

import javax.servlet.ServletContext;

import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.rest.DefaultHttpHeaders;
import org.apache.struts2.rest.HttpHeaders;
import org.apache.struts2.util.ServletContextAware;

import com.opensymphony.xwork2.ModelDriven;

/**
 * 
 * @author rajveer
 *
 */
@Results({
        @Result(name="success", location="/home-index")
})
public class HomeController extends BaseController 
        implements  ModelDriven<Object>, ServletContextAware  {
                  
        private PageManager pageManager = null;
        
        /**
         * 
         */
        private static Log log = LogFactory.getLog(HomeController.class);
        
        /**
         * 
         */
        @SuppressWarnings("unused")
        private ServletContext servletContext = null;
        
        /**
         * 
         */
        private String id;
        
        private Map<String,String> htmlSnippets;
        
        
        public HomeController(){
                super();
                pageManager = PageManager.getPageManager();
        }


    public HttpHeaders index() throws SecurityException, IOException {
        log.info("id=" + id);
        Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
        
        params.put(PageContentKeys.USER_ID, new Long(userinfo.getUserId()).toString());
        params.put(PageContentKeys.CART_ID, new Long(userinfo.getCartId()).toString());
        params.put(PageContentKeys.SESSION_ID, new Long(userinfo.getSessionId()).toString());
        params.put(PageContentKeys.USER_NAME, userinfo.getNameOfUser());
        params.put(PageContentKeys.ITEM_COUNT, new Long(userinfo.getTotalItems()).toString());
        
        htmlSnippets = pageManager.getPageContents(PageEnum.HOME_PAGE, params);
        
        return new DefaultHttpHeaders("index");
    }
    
    /**
     * 
     * @param id
     */
    public void setId(String id) {
        StringTokenizer tokenizer = new StringTokenizer(id,"-");
        while(tokenizer.hasMoreTokens()){
                this.id = tokenizer.nextToken();
        }
    }

        /* (non-Javadoc)
         * @see com.opensymphony.xwork2.ModelDriven#getModel()
         */
        @Override
        public Object getModel() {
                System.out.println(" getModer  is called");
                return htmlSnippets;
                //return this.id;
        }
        
        /**
         * 
         */
        @Override
        public void setServletContext(ServletContext servletContext) {
                this.servletContext = servletContext;
        }
        
        public Map<String,String> getHtmlSnippets(){
                System.out.println(" getHtmlSnippets  is called");
                return htmlSnippets;
        }
        
        public String getHeaderSnippet(){
                return htmlSnippets.get("HEADER");
        }

        public String getSlideGuideSnippet(){
                return htmlSnippets.get("SLIDE_GUIDE");
        }

        public String getMainMenuSnippet(){
                return htmlSnippets.get("MAIN_MENU");
        }
        
        public String getSearchBarSnippet(){
                return htmlSnippets.get("SEARCH_BAR");
        }
                

        public String getMainBannerSnippet(){
                return htmlSnippets.get("MAIN_BANNER");
        }
        
        public String getBestDealsSnippet(){
                return htmlSnippets.get("BEST_DEALS"); 
        }
        
        public String getLatestArrivalsSnippet(){
                return htmlSnippets.get("LATEST_ARRIVALS");
        }
        
        public String getBestSellersSnippet(){
                return htmlSnippets.get("BEST_SELLERS");
        }
        
        public String getCustomerServiceSnippet(){
                return htmlSnippets.get("CUSTOMER_SERVICE");
        }
        
        public String getMyResearchSnippet(){
                return htmlSnippets.get("MY_RESEARCH");
        }
        

        public String getRecommendationsSnippet(){
                return htmlSnippets.get("RECOMMENDATIONS");
        }

        public String getBrowseHistorySnippet(){
                return htmlSnippets.get("BROWSE_HISTORY");
        }
                        
        public String getFooterSnippet(){
                return htmlSnippets.get("FOOTER");
        }

        public String getJsFileSnippet(){
                return htmlSnippets.get("JS_FILES");
        }
        
        public String getCssFileSnippet(){
                return htmlSnippets.get("CSS_FILES");
        }
        
}