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 deals items from the catalog service
25
 * get best deals 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
})
-
 
32
 
27
public class BestDealsController extends BaseController {
33
public class BestDealsController extends BaseController {
28
	
34
	
29
	private static final long serialVersionUID = -6862524269260661024L;
35
	private static final long serialVersionUID = -6862524269260661024L;
30
	
36
	
31
	private static Logger log = Logger.getLogger(Class.class);
37
	private static Logger log = Logger.getLogger(Class.class);
Line 37... Line 43...
37
	private long beginIndex = 0;
43
	private long beginIndex = 0;
38
	
44
	
39
	private Long totalItems = 0l;
45
	private Long totalItems = 0l;
40
	
46
	
41
	private String id;
47
	private String id;
-
 
48
 
-
 
49
	private String redirectUrl;
42
	
50
	
43
	List<Long> items = null;
51
	List<Long> items = null;
44
	
52
	
45
	private List<String> snippets = null;
53
	private List<String> snippets = null;
46
	
54
	
Line 70... Line 78...
70
    }
78
    }
71
 
79
 
72
    // GET /show
80
    // GET /show
73
    @SuppressWarnings("unchecked")
81
    @SuppressWarnings("unchecked")
74
    public HttpHeaders show() {
82
    public HttpHeaders show() {
-
 
83
    	if(getCurrentPage() > 1){
-
 
84
    		log.info("Redirecting.");
-
 
85
    		redirectUrl = "/best-deals/1";
-
 
86
            return new DefaultHttpHeaders("redirect");
-
 
87
    	}
75
        EhcacheWrapper<String, Object> showcasePageSnippetsCache = new EhcacheWrapper<String, Object>(
88
        EhcacheWrapper<String, Object> showcasePageSnippetsCache = new EhcacheWrapper<String, Object>(
76
                EhcacheWrapper.SHOWCASE_PAGE_SNIPPET_CACHE_NAME, CacheManager.create());
89
                EhcacheWrapper.SHOWCASE_PAGE_SNIPPET_CACHE_NAME, CacheManager.create());
77
        if(sourceId == -1){
90
        if(sourceId == -1){
78
	        this.snippets = (List<String>)showcasePageSnippetsCache.get(SHOWCASE_BEST_DEALS_CACHE_KEY + beginIndex);
91
	        this.snippets = (List<String>)showcasePageSnippetsCache.get(SHOWCASE_BEST_DEALS_CACHE_KEY + beginIndex);
79
	        this.totalItems = (Long)showcasePageSnippetsCache.get(SHOWCASE_BEST_DEALS_COUNT_CACHE_KEY);
92
	        this.totalItems = (Long)showcasePageSnippetsCache.get(SHOWCASE_BEST_DEALS_COUNT_CACHE_KEY);
Line 83... Line 96...
83
	        }
96
	        }
84
        }
97
        }
85
        log.info("Getting best deals from snippets.");
98
        log.info("Getting best deals from snippets.");
86
    	in.shop2020.model.v1.catalog.InventoryService.Client client = catalogClientService.getClient();
99
    	in.shop2020.model.v1.catalog.InventoryService.Client client = catalogClientService.getClient();
87
    	try {
100
    	try {
-
 
101
    		long count = client.getBestDealsCount();
88
			this.setTotalItems(client.getBestDealsCount());
102
			this.setTotalItems(count > 20 ? 20 : count);
89
			if(sourceId == -1){
103
			if(sourceId == -1){
90
				showcasePageSnippetsCache.put(SHOWCASE_BEST_DEALS_COUNT_CACHE_KEY, this.totalItems);
104
				showcasePageSnippetsCache.put(SHOWCASE_BEST_DEALS_COUNT_CACHE_KEY, this.totalItems);
91
			}
105
			}
92
			this.items = client.getBestDealsCatalogIds(beginIndex, windowSize, null, -1);
106
			this.items = client.getBestDealsCatalogIds(beginIndex, windowSize, null, -1);
93
			setSnippets();
107
			setSnippets();
Line 143... Line 157...
143
	}
157
	}
144
 
158
 
145
	public long getCurrentPage() {
159
	public long getCurrentPage() {
146
		return Long.parseLong(getId());
160
		return Long.parseLong(getId());
147
	}
161
	}
-
 
162
	
-
 
163
	public String getRedirectUrl(){
-
 
164
		return redirectUrl;
-
 
165
    }
148
}
166
}