Subversion Repositories SmartDukaan

Rev

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

Rev 11680 Rev 11682
Line 70... Line 70...
70
		try {
70
		try {
71
			catalogClientService = new CatalogClient();
71
			catalogClientService = new CatalogClient();
72
		} catch (Exception e) {
72
		} catch (Exception e) {
73
			log.error("Unable to get catalog service client.", e);
73
			log.error("Unable to get catalog service client.", e);
74
		}
74
		}
75
		try {
-
 
76
			uc = new UserClient().getClient();
-
 
77
		} catch (TTransportException e) {
-
 
78
			log.error("Unable to get user service client.", e);	
-
 
79
		}
-
 
80
	}
75
	}
81
 
76
 
82
	// GET /index
77
	// GET /index
83
	public HttpHeaders index() throws Exception {
78
	public HttpHeaders index() throws Exception{
84
		if(isUserLoggedIn() && isPrivatedealUser()){
79
		if(isPrivatedealUser()){
85
			in.shop2020.model.v1.catalog.CatalogService.Client client = catalogClientService.getClient();
-
 
86
			this.items = client.getPrivateDealsCatalogIds(beginIndex, windowSize);
-
 
87
			setSnippets();
-
 
88
			return new DefaultHttpHeaders("index");
80
			redirectUrl = "/private-deals/1";
89
		}
-
 
90
		else{
81
		} else {
91
			redirectUrl = "/";
82
			redirectUrl = "/";
92
			return new DefaultHttpHeaders("redirect");
-
 
93
		}
83
		}
-
 
84
		return new DefaultHttpHeaders("redirect");
94
	}
85
	}
95
 
86
 
96
	// GET /show
87
	// GET /show
97
	@SuppressWarnings("unchecked")
88
	@SuppressWarnings("unchecked")
98
	public HttpHeaders show() {
89
	public HttpHeaders show() {
99
		try {
90
		try {
100
			if(isUserLoggedIn() && isPrivatedealUser()){
91
			if(isPrivatedealUser()){
101
 
92
 
102
				if(getCurrentPage() > 1){
-
 
103
					log.info("Redirecting.");
-
 
104
					redirectUrl = "/private-deals/1";
-
 
105
					return new DefaultHttpHeaders("redirect");
-
 
106
				}
-
 
107
				EhcacheWrapper<String, Object> showcasePageSnippetsCache = new EhcacheWrapper<String, Object>(
93
				EhcacheWrapper<String, Object> showcasePageSnippetsCache = new EhcacheWrapper<String, Object>(
108
						EhcacheWrapper.SHOWCASE_PAGE_SNIPPET_CACHE_NAME, CacheManager.create());
94
						EhcacheWrapper.SHOWCASE_PAGE_SNIPPET_CACHE_NAME, CacheManager.create());
109
				if(sourceId == -1){
95
				if(sourceId == -1){
110
					this.snippets = (List<String>)showcasePageSnippetsCache.get(SHOWCASE_PRIVATE_DEALS_CACHE_KEY + beginIndex);
96
					this.snippets = (List<String>)showcasePageSnippetsCache.get(SHOWCASE_PRIVATE_DEALS_CACHE_KEY + beginIndex);
111
					this.totalItems = (Long)showcasePageSnippetsCache.get(SHOWCASE_PRIVATE_DEALS_COUNT_CACHE_KEY);
97
					this.totalItems = (Long)showcasePageSnippetsCache.get(SHOWCASE_PRIVATE_DEALS_COUNT_CACHE_KEY);
-
 
98
					if(getCurrentPage() > getTotalPages()){
-
 
99
						log.info("Redirecting.");
-
 
100
						redirectUrl = "/private-deals/1";
-
 
101
						return new DefaultHttpHeaders("redirect");
-
 
102
					}
112
					if(this.snippets != null && !this.snippets.isEmpty() && this.totalItems > 0) {
103
					if(this.snippets != null && !this.snippets.isEmpty() && this.totalItems > 0) {
113
						log.info("Using Cache.");
104
						log.info("Using Cache.");
114
						return new DefaultHttpHeaders("show");
105
						return new DefaultHttpHeaders("show");
115
					}
106
					}
116
				}
107
				}
117
				log.info("Getting private deals from snippets.");
108
				log.info("Getting private deals from snippets.");
118
				in.shop2020.model.v1.catalog.CatalogService.Client client = catalogClientService.getClient();
109
				in.shop2020.model.v1.catalog.CatalogService.Client client = catalogClientService.getClient();
119
				try {
110
				try {
120
					int count = client.getPrivateDealsCount();
111
					int count = client.getPrivateDealsCount();
121
					this.setTotalItems(count > 20 ? 20 : count);
112
					this.setTotalItems(count);
-
 
113
					if(getCurrentPage() > getTotalPages()){
-
 
114
						log.info("Redirecting.");
-
 
115
						redirectUrl = "/private-deals/1";
-
 
116
						return new DefaultHttpHeaders("redirect");
-
 
117
					}
122
					if(sourceId == -1){
118
					if(sourceId == -1){
123
						showcasePageSnippetsCache.put(SHOWCASE_PRIVATE_DEALS_COUNT_CACHE_KEY, this.totalItems);
119
						showcasePageSnippetsCache.put(SHOWCASE_PRIVATE_DEALS_COUNT_CACHE_KEY, this.totalItems);
124
					}
120
					}
125
					this.items = client.getPrivateDealsCatalogIds(beginIndex, windowSize);
121
					this.items = client.getPrivateDealsCatalogIds(beginIndex, windowSize);
126
					setSnippets();
122
					setSnippets();
Line 202... Line 198...
202
	}
198
	}
203
	public boolean isUserLoggedIn()	{
199
	public boolean isUserLoggedIn()	{
204
		return userinfo.isLoggedIn();
200
		return userinfo.isLoggedIn();
205
	}
201
	}
206
	public boolean isPrivatedealUser() throws TTransportException, TException{
202
	public boolean isPrivatedealUser() throws TTransportException, TException{
207
		if(!uc.isAlive())
203
		try {
208
			uc = new UserClient().getClient();
204
			uc = new UserClient().getClient();
209
		return uc.isPrivateDealUser(super.getUserInfo().getUserId());
205
			return uc.isPrivateDealUser(super.getUserInfo().getUserId());
-
 
206
		} catch (TTransportException e) {
-
 
207
			log.error("Unable to get user service client.", e);	
-
 
208
		}
-
 
209
		return false;
210
	}
210
	}
211
}
211
}