Subversion Repositories SmartDukaan

Rev

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

Rev 1466 Rev 1614
Line 7... Line 7...
7
import in.shop2020.model.v1.user.UserContextService;
7
import in.shop2020.model.v1.user.UserContextService;
8
import in.shop2020.serving.controllers.BaseController;
8
import in.shop2020.serving.controllers.BaseController;
9
import in.shop2020.thrift.clients.UserContextServiceClient;
9
import in.shop2020.thrift.clients.UserContextServiceClient;
10
 
10
 
11
import org.apache.log4j.Logger;
11
import org.apache.log4j.Logger;
-
 
12
import org.apache.struts2.convention.annotation.Action;
-
 
13
import org.apache.struts2.convention.annotation.InterceptorRef;
-
 
14
import org.apache.struts2.convention.annotation.InterceptorRefs;
12
import org.apache.struts2.convention.annotation.Result;
15
import org.apache.struts2.convention.annotation.Result;
-
 
16
import org.apache.struts2.convention.annotation.Results;
13
import org.apache.struts2.interceptor.ParameterAware;
17
import org.apache.struts2.interceptor.ParameterAware;
14
import org.apache.thrift.TException;
18
import org.apache.thrift.TException;
15
 
19
 
-
 
20
 
-
 
21
@Results({
16
@Result(name="redirect", type="redirectAction", 
22
	@Result(name="redirect", type="redirectAction", 
17
   		params = {"actionName" , "cart"})
23
	   		params = {"actionName" , "cart"}),
-
 
24
	@Result(name="failure", location="cart-failure.vm"),
-
 
25
	@Result(name="success", location="cart-success.vm")
-
 
26
})
-
 
27
 
-
 
28
 
18
public class CartController extends BaseController implements ParameterAware{
29
public class CartController extends BaseController implements ParameterAware{
19
	
30
	
20
	private static final long serialVersionUID = 1L;
31
	private static final long serialVersionUID = 1L;
21
	private static Logger log = Logger.getLogger(Class.class);	
32
	private static Logger log = Logger.getLogger(Class.class);	
22
	Map<String, String[]> reqparams = null;
33
	Map<String, String[]> reqparams = null;
Line 27... Line 38...
27
	public CartController(){
38
	public CartController(){
28
		super();
39
		super();
29
	}
40
	}
30
	
41
	
31
	 // GET /cart
42
	 // GET /cart
-
 
43
 
-
 
44
	@Action(value="cart",interceptorRefs={@InterceptorRef("myDefault")})
32
	 public String index() {
45
	 public String index() {
33
    	try {
46
    	try {
34
			UserContextService.Client userClient = (new UserContextServiceClient()).getClient();
47
			UserContextService.Client userClient = (new UserContextServiceClient()).getClient();
35
			errorMsg = userClient.validateCart(userinfo.getCartId());
48
			errorMsg = userClient.validateCart(userinfo.getCartId());
36
		} catch (Exception e) {
49
		} catch (Exception e) {
Line 43... Line 56...
43
		htmlSnippets.put("CART_HEADER", pageLoader.getCartHeaderHtml());
56
		htmlSnippets.put("CART_HEADER", pageLoader.getCartHeaderHtml());
44
		htmlSnippets.put("CART_DETAILS", pageLoader.getCartDetailsHtml(userinfo.getUserId(), userinfo.getCartId(), errorMsg));
57
		htmlSnippets.put("CART_DETAILS", pageLoader.getCartDetailsHtml(userinfo.getUserId(), userinfo.getCartId(), errorMsg));
45
    	return "index";
58
    	return "index";
46
	 }
59
	 }
47
 
60
 
-
 
61
	
-
 
62
 
48
	// POST /entity
63
	// POST /entity
-
 
64
 
-
 
65
	@Action(value="addtocart",interceptorRefs={@InterceptorRef("createuser"),@InterceptorRef("myDefault")})
49
	public String create() {
66
	public String create() {
50
		log.info("CartController.create");
67
		log.info("CartController.create");
51
 
68
 
52
		printParams();
69
		printParams();
53
 
70
 
54
		long userId = userinfo.getUserId();
71
		long userId = userinfo.getUserId();
55
		long cartId = userinfo.getCartId();
72
		long cartId = userinfo.getCartId();
56
 
73
 
-
 
74
		log.info("user id is " + userId);
-
 
75
		log.info("cart id is " + cartId);
-
 
76
		
57
		log.info("item id is " + this.reqparams.get("productid"));
77
		log.info("item id is " + this.reqparams.get("productid"));
-
 
78
		
-
 
79
		if (this.reqparams.get("historyitems") != null) {
-
 
80
			String historyItems = this.reqparams.get("productid")[0];
-
 
81
			updateHistory(historyItems);
-
 
82
		}
58
 
83
		
59
		String itemIds = "";
84
		String itemIds = "";
60
		if (this.reqparams.get("productid") != null) {
85
		if (this.reqparams.get("productid") != null) {
61
			itemIds = this.reqparams.get("productid")[0];
86
			itemIds = this.reqparams.get("productid")[0];
62
		}else{
87
		}else{
63
			return "failure";
88
			return "failure";
Line 87... Line 112...
87
		}
112
		}
88
 
113
 
89
		return "success";
114
		return "success";
90
	}		
115
	}		
91
 
116
 
-
 
117
	private void updateHistory(String historyItems) {
-
 
118
		UserContextServiceClient userServiceClient;
-
 
119
		try {
-
 
120
			userServiceClient = new UserContextServiceClient();
-
 
121
			UserContextService.Client userClient = userServiceClient.getClient();
-
 
122
			StringTokenizer tokenizer = new StringTokenizer(historyItems, "_");
-
 
123
		
-
 
124
			while (tokenizer.hasMoreTokens()) {
-
 
125
				long itemId = Long.parseLong(tokenizer.nextToken());
-
 
126
				userClient.updateBrowseHistory(userinfo.getUserId(), itemId);
-
 
127
			}	
-
 
128
		} catch (Exception e) {
-
 
129
			e.printStackTrace();
-
 
130
		}
-
 
131
 
-
 
132
			
-
 
133
	}
-
 
134
 
92
		// DELETE /entity
135
		// DELETE /entity
93
		public String destroy() {
136
		public String destroy() {
94
	    	log.info("CartController.destroy");
137
	    	log.info("CartController.destroy");
95
	    	printParams();
138
	    	printParams();
96
	    	log.info("item id is " + this.request.getParameter("productid"));
139
	    	log.info("item id is " + this.request.getParameter("productid"));