| Line 3... |
Line 3... |
| 3 |
*/
|
3 |
*/
|
| 4 |
package in.shop2020.serving.controllers;
|
4 |
package in.shop2020.serving.controllers;
|
| 5 |
|
5 |
|
| 6 |
import in.shop2020.model.v1.catalog.InventoryServiceException;
|
6 |
import in.shop2020.model.v1.catalog.InventoryServiceException;
|
| 7 |
import in.shop2020.serving.cache.EhcacheWrapper;
|
7 |
import in.shop2020.serving.cache.EhcacheWrapper;
|
| 8 |
import in.shop2020.serving.utils.FileUtils;
|
8 |
import in.shop2020.serving.services.ContentServingService;
|
| 9 |
import in.shop2020.serving.utils.Utils;
|
9 |
import in.shop2020.serving.utils.SnippetType;
|
| 10 |
import in.shop2020.thrift.clients.CatalogClient;
|
10 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 11 |
|
11 |
|
| 12 |
import java.io.File;
|
- |
|
| 13 |
import java.io.IOException;
|
- |
|
| 14 |
import java.util.ArrayList;
|
12 |
import java.util.ArrayList;
|
| 15 |
import java.util.List;
|
13 |
import java.util.List;
|
| 16 |
|
14 |
|
| 17 |
import net.sf.ehcache.CacheManager;
|
15 |
import net.sf.ehcache.CacheManager;
|
| 18 |
|
16 |
|
| Line 74... |
Line 72... |
| 74 |
// GET /show
|
72 |
// GET /show
|
| 75 |
@SuppressWarnings("unchecked")
|
73 |
@SuppressWarnings("unchecked")
|
| 76 |
public HttpHeaders show() {
|
74 |
public HttpHeaders show() {
|
| 77 |
EhcacheWrapper<String, Object> showcasePageSnippetsCache = new EhcacheWrapper<String, Object>(
|
75 |
EhcacheWrapper<String, Object> showcasePageSnippetsCache = new EhcacheWrapper<String, Object>(
|
| 78 |
EhcacheWrapper.SHOWCASE_PAGE_SNIPPET_CACHE_NAME, CacheManager.create());
|
76 |
EhcacheWrapper.SHOWCASE_PAGE_SNIPPET_CACHE_NAME, CacheManager.create());
|
| - |
|
77 |
if(sourceId == -1){
|
| 79 |
this.snippets = (List<String>)showcasePageSnippetsCache.get(SHOWCASE_BEST_DEALS_CACHE_KEY + beginIndex);
|
78 |
this.snippets = (List<String>)showcasePageSnippetsCache.get(SHOWCASE_BEST_DEALS_CACHE_KEY + beginIndex);
|
| 80 |
this.totalItems = (Long)showcasePageSnippetsCache.get(SHOWCASE_BEST_DEALS_COUNT_CACHE_KEY);
|
79 |
this.totalItems = (Long)showcasePageSnippetsCache.get(SHOWCASE_BEST_DEALS_COUNT_CACHE_KEY);
|
| 81 |
if(this.snippets != null && !this.snippets.isEmpty() && this.totalItems > 0) {
|
80 |
if(this.snippets != null && !this.snippets.isEmpty() && this.totalItems > 0) {
|
| 82 |
log.info("Using Cache.");
|
81 |
log.info("Using Cache.");
|
| 83 |
return new DefaultHttpHeaders("show");
|
82 |
return new DefaultHttpHeaders("show");
|
| - |
|
83 |
}
|
| 84 |
}
|
84 |
}
|
| 85 |
log.info("Getting best deals from snippets.");
|
85 |
log.info("Getting best deals from snippets.");
|
| 86 |
in.shop2020.model.v1.catalog.InventoryService.Client client = catalogClientService.getClient();
|
86 |
in.shop2020.model.v1.catalog.InventoryService.Client client = catalogClientService.getClient();
|
| 87 |
try {
|
87 |
try {
|
| 88 |
this.setTotalItems(client.getBestDealsCount());
|
88 |
this.setTotalItems(client.getBestDealsCount());
|
| - |
|
89 |
if(sourceId == -1){
|
| 89 |
showcasePageSnippetsCache.put(SHOWCASE_BEST_DEALS_COUNT_CACHE_KEY, this.totalItems);
|
90 |
showcasePageSnippetsCache.put(SHOWCASE_BEST_DEALS_COUNT_CACHE_KEY, this.totalItems);
|
| - |
|
91 |
}
|
| 90 |
this.items = client.getBestDealsCatalogIds(beginIndex, windowSize, null, -1);
|
92 |
this.items = client.getBestDealsCatalogIds(beginIndex, windowSize, null, -1);
|
| 91 |
setSnippets();
|
93 |
setSnippets();
|
| - |
|
94 |
if(sourceId == -1){
|
| 92 |
showcasePageSnippetsCache.put(SHOWCASE_BEST_DEALS_CACHE_KEY + beginIndex, this.snippets);
|
95 |
showcasePageSnippetsCache.put(SHOWCASE_BEST_DEALS_CACHE_KEY + beginIndex, this.snippets);
|
| - |
|
96 |
}
|
| 93 |
} catch (InventoryServiceException e) {
|
97 |
} catch (InventoryServiceException e) {
|
| 94 |
log.error("Unable to get best deals from inventory service.", e);
|
98 |
log.error("Unable to get best deals from inventory service.", e);
|
| 95 |
} catch (TException e) {
|
99 |
} catch (TException e) {
|
| 96 |
log.error("Unable to get best deals from inventory service.", e);
|
100 |
log.error("Unable to get best deals from inventory service.", e);
|
| 97 |
}
|
101 |
}
|
| Line 100... |
Line 104... |
| 100 |
|
104 |
|
| 101 |
private void setSnippets(){
|
105 |
private void setSnippets(){
|
| 102 |
this.snippets = new ArrayList<String>();
|
106 |
this.snippets = new ArrayList<String>();
|
| 103 |
if(items != null){
|
107 |
if(items != null){
|
| 104 |
for(long item: items){
|
108 |
for(long item: items){
|
| 105 |
try {
|
- |
|
| 106 |
snippets.add(FileUtils.read(Utils.EXPORT_ENTITIES_PATH + item + File.separator +"CategorySnippet.html"));
|
109 |
snippets.add(ContentServingService.getSnippet(SnippetType.CATEGORY_SNIPPET, item+"", sourceId));
|
| 107 |
} catch (IOException ioex) {
|
- |
|
| 108 |
log.error("Error while getting the snippet for: " + item, ioex);
|
- |
|
| 109 |
}
|
- |
|
| 110 |
}
|
110 |
}
|
| 111 |
}
|
111 |
}
|
| 112 |
}
|
112 |
}
|
| 113 |
|
113 |
|
| 114 |
public List<String> getSnippets() {
|
114 |
public List<String> getSnippets() {
|