Subversion Repositories SmartDukaan

Rev

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

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