Subversion Repositories SmartDukaan

Rev

Rev 6476 | Blame | Last modification | View Log | RSS feed

package in.shop2020.serving.controllers;

import in.shop2020.serving.cache.SnippetCacheWrapper;
import in.shop2020.serving.cache.EhcacheWrapper.CacheKeys;
import in.shop2020.thrift.clients.CatalogClient;

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

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Result;

/**
 * @author Varun Gupta
 */
@SuppressWarnings("serial")
@Result(name = "index", location = "clearance-sale-index.vm")
public class ClearanceSaleController extends BaseController {

        private static Logger log = Logger.getLogger(ClearanceSaleController.class);
        private static List<Long> entityIds = new ArrayList<Long>();
        private static List<Long> sonyEntityIds = Arrays.asList(1004874L, 1002111L, 1003428L, 1003376L, 1004882L, 1004204L, 1003426L, 1005156L, 1004429L, 1004842L);
        private static List<Long> googleEntityIds = Arrays.asList(  1004202L, 1001674L, 1004207L, 1003235L, 1002294L, 1004874L,1004874L, 1003428L,         //Mobiles - Tablets
                                                                                                                        1004751L, 1004755L, 1004790L, 1004795L, 1005435L, //Cameras
                                                                                                                                1005067L, 1005081L, 1004252L, 1005137L, 1005128L, 1005118L,  //Laptops
                                                                                                                                1005024L, 1005251L);                                                                            //Accessories
        
                        //1005330L, 1005366);
        private List<String> snippets = new ArrayList<String>();
        private List<String> sonySnippets = new ArrayList<String>();
        private List<String> googleSnippets = new ArrayList<String>();
        
        static {                
                try {
                        CatalogClient catalogClientService = new CatalogClient();
                        in.shop2020.model.v1.catalog.CatalogService.Client client = catalogClientService.getClient();
                        log.info("Getting clearance sale products snippets.");
                        entityIds = client.getClearanceSaleCatalogIds();
                } catch (Exception e) {
                        log.error("Unable to get clearance sale products from inventory service", e);
                }
        }

        @Actions({
                @Action("/clearance-sale"),
                @Action("/sony"),
                @Action("/google-great-online-shopping-festival")
        })
        public String index()   {
                return "index";
        }
        
        public void addEntityId(Long entityId, List<String> snippets)   {

            String snippet = (String) SnippetCacheWrapper.getSnippet(CacheKeys.CATEGORY_SNIPPET_CACHE_KEY, entityId+"", sourceId);
            
            if (snippet != null)        {
                snippets.add(snippet);
            }
        }
        
        public List<String> getSnippets()       {
                if(request.getRequestURI().contains("google-great-online-shopping-festival")){
                        for(long entityId: googleEntityIds){
                                addEntityId(entityId, googleSnippets);
                        }
                        return googleSnippets;
                }else if(request.getRequestURI().contains("sony")){
                        for(long entityId: sonyEntityIds){
                                addEntityId(entityId, sonySnippets);
                        }
                        return sonySnippets;
                }else{
                        for(long entityId: entityIds){
                                addEntityId(entityId, snippets);
                        }
                        return snippets;
                }
        }
        public String getPageTitle(){
                if(request.getRequestURI().contains("google-great-online-shopping-festival")){
                        return "Google Great Online Shopping Festival";
                }else if(request.getRequestURI().contains("sony")){
                        return "Sony Phones at Best Price";
                } else{
                        return "Spice and Micromax Phones at Best Price | Clearance Sale";              
                }
        }
}