Subversion Repositories SmartDukaan

Rev

Rev 3266 | Rev 3656 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3266 Rev 3561
Line 2... Line 2...
2
 
2
 
3
import in.shop2020.datalogger.EventType;
3
import in.shop2020.datalogger.EventType;
4
import in.shop2020.model.v1.catalog.InventoryService.Client;
4
import in.shop2020.model.v1.catalog.InventoryService.Client;
5
import in.shop2020.model.v1.catalog.InventoryServiceException;
5
import in.shop2020.model.v1.catalog.InventoryServiceException;
6
import in.shop2020.serving.cache.EhcacheWrapper;
6
import in.shop2020.serving.cache.EhcacheWrapper;
7
import in.shop2020.serving.utils.FileUtils;
7
import in.shop2020.serving.services.ContentServingService;
8
import in.shop2020.serving.utils.Utils;
8
import in.shop2020.serving.utils.SnippetType;
9
import in.shop2020.thrift.clients.CatalogClient;
9
import in.shop2020.thrift.clients.CatalogClient;
10
import in.shop2020.utils.DataLogger;
10
import in.shop2020.utils.DataLogger;
11
 
11
 
12
import java.io.File;
-
 
13
import java.io.IOException;
12
import java.io.IOException;
14
import java.util.ArrayList;
13
import java.util.ArrayList;
15
import java.util.Arrays;
14
import java.util.Arrays;
16
import java.util.List;
15
import java.util.List;
17
 
16
 
Line 95... Line 94...
95
	 * into memory.
94
	 * into memory.
96
	 */
95
	 */
97
    private void setSnippets() {
96
    private void setSnippets() {
98
        EhcacheWrapper<String, List<String>> homeSnippetCache = new EhcacheWrapper<String, List<String>>(
97
        EhcacheWrapper<String, List<String>> homeSnippetCache = new EhcacheWrapper<String, List<String>>(
99
                EhcacheWrapper.HOME_PAGE_SNIPPET_CACHE_NAME, CacheManager.create());
98
                EhcacheWrapper.HOME_PAGE_SNIPPET_CACHE_NAME, CacheManager.create());
-
 
99
        if(sourceId == -1){
100
        bestDealSnippets = homeSnippetCache.get(BEST_DEALS_CACHE_KEY);
100
        	bestDealSnippets = homeSnippetCache.get(BEST_DEALS_CACHE_KEY);
101
        bestSellerSnippets = homeSnippetCache.get(BEST_SELLERS_CACHE_KEY);
101
        	bestSellerSnippets = homeSnippetCache.get(BEST_SELLERS_CACHE_KEY);
102
        latestArrivalSnippets = homeSnippetCache.get(LATEST_ARRIVALS_CACHE_KEY);
102
        	latestArrivalSnippets = homeSnippetCache.get(LATEST_ARRIVALS_CACHE_KEY);
103
        
103
        
104
        if (bestDealSnippets != null && bestSellerSnippets != null && latestArrivalSnippets != null) {
104
	        if (bestDealSnippets != null && bestSellerSnippets != null && latestArrivalSnippets != null) {
105
            return;
105
	            return;
-
 
106
	        }
106
        }
107
        }
-
 
108
        
107
        List<Long> bestDealCatalogIds = null;
109
        List<Long> bestDealCatalogIds = null;
108
        List<Long> bestSellerCatalogIds = null;
110
        List<Long> bestSellerCatalogIds = null;
109
        List<Long> latestArrivalCatalogIds = null;
111
        List<Long> latestArrivalCatalogIds = null;
110
        
112
        
111
        int bestSellerCount = 4;
113
        int bestSellerCount = 4;
Line 140... Line 142...
140
        }
142
        }
141
        
143
        
142
        bestDealSnippets = getSnippets(bestDealCatalogIds);
144
        bestDealSnippets = getSnippets(bestDealCatalogIds);
143
        bestSellerSnippets = getSnippets(bestSellerCatalogIds.subList(0, bestSellerCount));
145
        bestSellerSnippets = getSnippets(bestSellerCatalogIds.subList(0, bestSellerCount));
144
        latestArrivalSnippets = getSnippets(latestArrivalCatalogIds.subList(0, latestArrivalCount));
146
        latestArrivalSnippets = getSnippets(latestArrivalCatalogIds.subList(0, latestArrivalCount));
-
 
147
        if(sourceId == -1){
145
        if (!bestDealSnippets.isEmpty() && !bestSellerSnippets.isEmpty() && !latestArrivalSnippets.isEmpty()) {
148
	        if (!bestDealSnippets.isEmpty() && !bestSellerSnippets.isEmpty() && !latestArrivalSnippets.isEmpty()) {
146
            homeSnippetCache.put(BEST_DEALS_CACHE_KEY, bestDealSnippets);
149
	            homeSnippetCache.put(BEST_DEALS_CACHE_KEY, bestDealSnippets);
147
            homeSnippetCache.put(BEST_SELLERS_CACHE_KEY, bestSellerSnippets);
150
	            homeSnippetCache.put(BEST_SELLERS_CACHE_KEY, bestSellerSnippets);
148
            homeSnippetCache.put(LATEST_ARRIVALS_CACHE_KEY, latestArrivalSnippets);
151
	            homeSnippetCache.put(LATEST_ARRIVALS_CACHE_KEY, latestArrivalSnippets);
-
 
152
	        }
149
        }
153
        }
150
    }
154
    }
151
	
155
	
152
    /**
156
    /**
153
     * Returns a list of snippets to be used on the home page corresponding to
157
     * Returns a list of snippets to be used on the home page corresponding to
Line 162... Line 166...
162
    private List<String> getSnippets(List<Long> catalogIds) {
166
    private List<String> getSnippets(List<Long> catalogIds) {
163
        List<String> snippets = new ArrayList<String>();
167
        List<String> snippets = new ArrayList<String>();
164
        if(catalogIds == null)
168
        if(catalogIds == null)
165
            return snippets;
169
            return snippets;
166
        for(Long item: catalogIds){
170
        for(Long item: catalogIds){
167
            try{
-
 
168
                snippets.add(FileUtils.read( Utils.EXPORT_ENTITIES_PATH + item + File.separator +"HomeSnippet.html"));
171
        	snippets.add(ContentServingService.getSnippet(SnippetType.HOME_SNIPPET, item+"", sourceId));
169
            }catch(IOException ioex){
-
 
170
                logger.error("Unable to get home page snippet for " + item, ioex);
-
 
171
            }
-
 
172
        }
172
        }
173
        return snippets;
173
        return snippets;
174
    }
174
    }
175
}
175
}
176
 
176