Subversion Repositories SmartDukaan

Rev

Rev 5460 | 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.List;

import org.apache.log4j.Logger;

/**
 * @author Varun Gupta
 */
@SuppressWarnings("serial")
public class ClearanceSaleController extends BaseController {

        private static Logger log = Logger.getLogger(ClearanceSaleController.class);
        private List<Long> entityIds = new ArrayList<Long>();
        private List<String> snippets = new ArrayList<String>();
        
        CatalogClient catalogClientService = null;
        
        public ClearanceSaleController() {
                super();
                try {
                        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);
                }
        }
        
        public String index()   {
                for(long entityId: entityIds){
                        addEntityId(entityId);
                }
                return "index";
        }
        
        public void addEntityId(Long entityId)  {

            String snippet = (String) SnippetCacheWrapper.getSnippet(CacheKeys.CATEGORY_SNIPPET_CACHE_KEY, entityId+"", sourceId);
            
            if (snippet != null)        {
                snippets.add(snippet);
            }
        }
        
        public List<String> getSnippets()       {
                return snippets;
        }
}