Subversion Repositories SmartDukaan

Rev

Rev 649 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 649 Rev 650
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
-
 
3
import java.util.Map;
-
 
4
import java.util.StringTokenizer;
-
 
5
 
3
import in.shop2020.model.v1.user.ShoppingCartException;
6
import in.shop2020.model.v1.user.ShoppingCartException;
4
import in.shop2020.model.v1.user.UserContextService;
7
import in.shop2020.model.v1.user.UserContextService;
5
import in.shop2020.serving.controllers.BaseController;
8
import in.shop2020.serving.controllers.BaseController;
6
import in.shop2020.serving.pages.PageContentKeys;
-
 
7
import in.shop2020.serving.pages.PageEnum;
-
 
8
import in.shop2020.serving.pages.PageManager;
-
 
9
import in.shop2020.serving.utils.Utils;
9
import in.shop2020.serving.utils.Utils;
10
import in.shop2020.thrift.clients.UserContextServiceClient;
10
import in.shop2020.thrift.clients.UserContextServiceClient;
11
 
11
 
12
import java.util.*;
-
 
13
 
-
 
14
import org.apache.juli.logging.Log;
12
import org.apache.juli.logging.Log;
15
import org.apache.juli.logging.LogFactory;
13
import org.apache.juli.logging.LogFactory;
16
import org.apache.struts2.interceptor.ParameterAware;
14
import org.apache.struts2.interceptor.ParameterAware;
17
import org.apache.struts2.rest.DefaultHttpHeaders;
-
 
18
import org.apache.struts2.rest.HttpHeaders;
-
 
19
import org.apache.thrift.TException;
15
import org.apache.thrift.TException;
20
 
16
 
21
public class CartController extends BaseController implements ParameterAware{
17
public class CartController extends BaseController implements ParameterAware{
22
	
18
	
23
	private static final long serialVersionUID = 1L;
19
	private static final long serialVersionUID = 1L;
24
	private static Log log = LogFactory.getLog(CartController.class);
20
	private static Log log = LogFactory.getLog(CartController.class);
25
	Map<String, String[]> reqparams = null;
21
	Map<String, String[]> reqparams = null;
26
	
22
	
27
	private Map<String,String> htmlSnippets;
-
 
-
 
23
	
28
	private String errorMsg = "";
24
	private String errorMsg = "";
29
	
25
	
30
	public CartController(){
26
	public CartController(){
31
		super();
27
		super();
32
	}
28
	}
33
	
29
	
34
	 // GET /cart
30
	 // GET /cart
35
	 public HttpHeaders index() {
31
	 public String index() {
36
    	long userId = userinfo.getUserId();
-
 
37
    	try {
32
    	try {
38
			UserContextService.Client userClient = (new UserContextServiceClient()).getClient();
33
			UserContextService.Client userClient = (new UserContextServiceClient()).getClient();
39
			if(!userClient.validateCart(userinfo.getCartId()))
34
			if(!userClient.validateCart(userinfo.getCartId()))
40
				errorMsg = "Your cart has been updated.";
35
				errorMsg = "Your cart has been updated.";
41
		} catch (Exception e) {
36
		} catch (Exception e) {
42
			// This exception can be ignored for showing the cart. Not so
37
			// This exception can be ignored for showing the cart. Not so
43
			// innocent when this occurs at the time of checkout or when the
38
			// innocent when this occurs at the time of checkout or when the
44
			// user is proceeding to pay.
39
			// user is proceeding to pay.
45
			e.printStackTrace();
40
			e.printStackTrace();
46
		}
41
		}
47
		Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
-
 
48
		
-
 
49
		params.put(PageContentKeys.CUSTOMER_ID, userId+"");
-
 
50
		params.put(PageContentKeys.IS_LOGGED_IN, userinfo.isLoggedIn()+"");
-
 
51
		params.put(PageContentKeys.CART_ID, userinfo.getCartId()+"");		
-
 
52
		params.put(PageContentKeys.ITEM_COUNT, userinfo.getTotalItems()+"");
-
 
53
		params.put(PageContentKeys.USER_NAME, userinfo.getNameOfUser());
-
 
54
		params.put(PageContentKeys.ERROR_MSG, errorMsg);
-
 
55
		htmlSnippets = PageManager.getPageManager().getPageContents(PageEnum.SHOPPING_CART_PAGE, params);
-
 
56
		
42
		
57
    	return new DefaultHttpHeaders("index").disableCaching();
43
		htmlSnippets.put("CART_HEADER", pageLoader.getCartHeaderHtml());
-
 
44
		htmlSnippets.put("CART_DETAILS", pageLoader.getCartDetailsHtml(userinfo.getCartId(), errorMsg));
-
 
45
    	return "index";
58
	 }
46
	 }
59
 
47
 
60
	// POST /entity
48
	// POST /entity
61
	public String create() {
49
	public String create() {
62
		log.info("CartController.create");
50
		log.info("CartController.create");
Line 149... Line 137...
149
    		log.info("param first is " + reqparams.get(param)[0]);
137
    		log.info("param first is " + reqparams.get(param)[0]);
150
    	}
138
    	}
151
    	log.info(this.reqparams);
139
    	log.info(this.reqparams);
152
    }
140
    }
153
 
141
 
154
	@Override
-
 
155
	public void setParameters(Map<String, String[]> reqmap) {
-
 
156
		log.info("setParameters:" + reqmap);
-
 
157
		
-
 
158
		this.reqparams = reqmap;
-
 
159
	}
-
 
160
 
-
 
161
    public String getHeaderSnippet(){
-
 
162
		return htmlSnippets.get("HEADER");
-
 
163
	}
-
 
164
	
-
 
165
	public String getMainMenuSnippet(){
-
 
166
		return htmlSnippets.get("MAIN_MENU");
-
 
167
	}
-
 
168
	
-
 
169
	public String getSearchBarSnippet(){
-
 
170
		return htmlSnippets.get("SEARCH_BAR");
-
 
171
	}
-
 
172
			
-
 
173
	
-
 
174
	public String getCustomerServiceSnippet(){
-
 
175
		return htmlSnippets.get("CUSTOMER_SERVICE");
-
 
176
	}
-
 
177
	
-
 
178
	public String getCartHeaderSnippet(){
142
	public String getCartHeaderSnippet(){
179
		return htmlSnippets.get("CART_HEADER");
143
		return htmlSnippets.get("CART_HEADER");
180
	}
144
	}
181
	
145
	
182
	public String getCartDetailsSnippet(){
146
	public String getCartDetailsSnippet(){
183
		return htmlSnippets.get("CART_DETAILS");
147
		return htmlSnippets.get("CART_DETAILS");
184
	}
148
	}
185
	
149
	
186
	public String getMyResearchSnippet(){
-
 
187
		return htmlSnippets.get("MY_RESEARCH");
-
 
188
	}
-
 
189
				
-
 
190
	public String getFooterSnippet(){
-
 
191
		return htmlSnippets.get("FOOTER");
-
 
192
	}
-
 
193
	
-
 
194
	public String getJsFileSnippet(){
-
 
195
		return htmlSnippets.get("JS_FILES");
-
 
196
	}
-
 
197
	
-
 
198
	public String getCssFileSnippet(){
-
 
199
		return htmlSnippets.get("CSS_FILES");
-
 
200
	}
-
 
201
	
-
 
202
	public long getNumberOfItems(){
150
	public long getNumberOfItems(){
203
		return userinfo.getTotalItems();
151
		return userinfo.getTotalItems();
204
	}
152
	}
-
 
153
 
-
 
154
	@Override
-
 
155
	public void setParameters(Map<String, String[]> parameters) {
-
 
156
		this.reqparams = parameters;	
-
 
157
	}
205
}
158
}