Subversion Repositories SmartDukaan

Rev

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

Rev 3561 Rev 5529
Line 13... Line 13...
13
import java.util.List;
13
import java.util.List;
14
 
14
 
15
import net.sf.ehcache.CacheManager;
15
import net.sf.ehcache.CacheManager;
16
 
16
 
17
import org.apache.log4j.Logger;
17
import org.apache.log4j.Logger;
-
 
18
import org.apache.struts2.convention.annotation.Result;
-
 
19
import org.apache.struts2.convention.annotation.Results;
18
import org.apache.struts2.rest.DefaultHttpHeaders;
20
import org.apache.struts2.rest.DefaultHttpHeaders;
19
import org.apache.struts2.rest.HttpHeaders;
21
import org.apache.struts2.rest.HttpHeaders;
20
import org.apache.thrift.TException;
22
import org.apache.thrift.TException;
21
 
23
 
22
/**
24
/**
23
 * get best sellers items from the catalog service
25
 * get best sellers items from the catalog service
24
 * @author rajveer
26
 * @author rajveer
25
 *	
27
 *	
26
 */
28
 */
-
 
29
@Results({
-
 
30
    @Result(name = "redirect", location = "${redirectUrl}", type = "redirect", params={"statusCode", "301"})
-
 
31
})
27
public class BestSellersController extends BaseController {
32
public class BestSellersController extends BaseController {
28
	
33
	
29
	private static final long serialVersionUID = 3380274695464543863L;
34
	private static final long serialVersionUID = 3380274695464543863L;
30
	
35
	
31
	private static Logger log = Logger.getLogger(Class.class);	
36
	private static Logger log = Logger.getLogger(Class.class);	
Line 37... Line 42...
37
	private long beginIndex = 0;
42
	private long beginIndex = 0;
38
	
43
	
39
	private Long totalItems = 0l;
44
	private Long totalItems = 0l;
40
	
45
	
41
	private String id;
46
	private String id;
-
 
47
	private String redirectUrl;
42
	
48
	
43
	List<Long> items = null;
49
	List<Long> items = null;
44
    
50
    
45
    private List<String> snippets = null;
51
    private List<String> snippets = null;
46
	
52
	
Line 70... Line 76...
70
    }
76
    }
71
 
77
 
72
    // GET /show
78
    // GET /show
73
    @SuppressWarnings("unchecked")
79
    @SuppressWarnings("unchecked")
74
    public HttpHeaders show() {
80
    public HttpHeaders show() {
-
 
81
    	if(getCurrentPage() > 1) {
-
 
82
    		log.info("Redirecting");
-
 
83
    		this.redirectUrl = "/best-sellers/1";
-
 
84
    		return new DefaultHttpHeaders("redirect");
-
 
85
    	}    	
75
        EhcacheWrapper<String, Object> showcasePageSnippetsCache = new EhcacheWrapper<String, Object>(
86
        EhcacheWrapper<String, Object> showcasePageSnippetsCache = new EhcacheWrapper<String, Object>(
76
                EhcacheWrapper.SHOWCASE_PAGE_SNIPPET_CACHE_NAME, CacheManager.create());
87
                EhcacheWrapper.SHOWCASE_PAGE_SNIPPET_CACHE_NAME, CacheManager.create());
77
        if(sourceId == -1){
88
        if(sourceId == -1){
78
        	this.snippets = (List<String>)showcasePageSnippetsCache.get(SHOWCASE_BEST_SELLERS_CACHE_KEY + beginIndex);
89
        	this.snippets = (List<String>)showcasePageSnippetsCache.get(SHOWCASE_BEST_SELLERS_CACHE_KEY + beginIndex);
79
        	this.totalItems = (Long)showcasePageSnippetsCache.get(SHOWCASE_BEST_SELLERS_COUNT_CACHE_KEY);
90
        	this.totalItems = (Long)showcasePageSnippetsCache.get(SHOWCASE_BEST_SELLERS_COUNT_CACHE_KEY);
Line 83... Line 94...
83
        	}
94
        	}
84
        }
95
        }
85
        log.info("Getting best sellers from snippets.");
96
        log.info("Getting best sellers from snippets.");
86
    	in.shop2020.model.v1.catalog.InventoryService.Client client = catalogClientService.getClient();
97
    	in.shop2020.model.v1.catalog.InventoryService.Client client = catalogClientService.getClient();
87
    	try {
98
    	try {
-
 
99
 
88
			this.setTotalItems(client.getBestSellersCount());
100
    		long count = client.getBestSellersCount();
-
 
101
			this.setTotalItems(count > 20 ? 20 : count);
89
			if(sourceId == -1){
102
			if(sourceId == -1){
90
				showcasePageSnippetsCache.put(SHOWCASE_BEST_SELLERS_COUNT_CACHE_KEY, this.totalItems);
103
				showcasePageSnippetsCache.put(SHOWCASE_BEST_SELLERS_COUNT_CACHE_KEY, this.totalItems);
91
			}
104
			}
92
			this.items = client.getBestSellersCatalogIds(beginIndex, windowSize, null, -1);
105
			this.items = client.getBestSellersCatalogIds(beginIndex, windowSize, null, -1);
93
			setSnippets(items);
106
			setSnippets(items);
Line 143... Line 156...
143
	}
156
	}
144
 
157
 
145
	public long getCurrentPage() {
158
	public long getCurrentPage() {
146
		return Long.parseLong(getId());
159
		return Long.parseLong(getId());
147
	}
160
	}
-
 
161
	
-
 
162
	public String getRedirectUrl(){
-
 
163
		return this.redirectUrl;
-
 
164
	}
148
}
165
}