Subversion Repositories SmartDukaan

Rev

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

Rev 1703 Rev 1957
Line 4... Line 4...
4
import java.util.StringTokenizer;
4
import java.util.StringTokenizer;
5
 
5
 
6
import in.shop2020.model.v1.user.ShoppingCartException;
6
import in.shop2020.model.v1.user.ShoppingCartException;
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.serving.utils.DataLogger;
-
 
10
import in.shop2020.serving.utils.DataLogger.Event;
9
import in.shop2020.thrift.clients.UserContextServiceClient;
11
import in.shop2020.thrift.clients.UserContextServiceClient;
10
 
12
 
-
 
13
import org.apache.commons.lang.StringUtils;
11
import org.apache.log4j.Logger;
14
import org.apache.log4j.Logger;
12
import org.apache.struts2.convention.annotation.Action;
15
import org.apache.struts2.convention.annotation.Action;
13
import org.apache.struts2.convention.annotation.InterceptorRef;
16
import org.apache.struts2.convention.annotation.InterceptorRef;
14
import org.apache.struts2.convention.annotation.InterceptorRefs;
17
import org.apache.struts2.convention.annotation.InterceptorRefs;
15
import org.apache.struts2.convention.annotation.Result;
18
import org.apache.struts2.convention.annotation.Result;
Line 27... Line 30...
27
 
30
 
28
 
31
 
29
public class CartController extends BaseController implements ParameterAware{
32
public class CartController extends BaseController implements ParameterAware{
30
	
33
	
31
	private static final long serialVersionUID = 1L;
34
	private static final long serialVersionUID = 1L;
32
	private static Logger log = Logger.getLogger(Class.class);	
35
	private static Logger log = Logger.getLogger(Class.class);
-
 
36
	private static Logger dataLog = DataLogger.getLogger();
33
	Map<String, String[]> reqparams = null;
37
	Map<String, String[]> reqparams = null;
34
	
38
	
35
	
39
	
36
	private String errorMsg = "";
40
	private String errorMsg = "";
37
	
41
	
Line 81... Line 85...
81
			itemIds = this.reqparams.get("productid")[0];
85
			itemIds = this.reqparams.get("productid")[0];
82
		}else{
86
		}else{
83
			return "failure";
87
			return "failure";
84
		}
88
		}
85
		
89
		
86
 
-
 
87
		StringTokenizer tokenizer = new StringTokenizer(itemIds, "_");
90
		StringTokenizer tokenizer = new StringTokenizer(itemIds, "_");
88
		while (tokenizer.hasMoreTokens()) {
91
		while (tokenizer.hasMoreTokens()) {
89
			long itemId = Long.parseLong(tokenizer.nextToken());
92
			long itemId = Long.parseLong(tokenizer.nextToken());
90
 
93
 
91
			try {
94
			try {
Line 103... Line 106...
103
			} catch (Exception e) {
106
			} catch (Exception e) {
104
				e.printStackTrace();
107
				e.printStackTrace();
105
			}
108
			}
106
 
109
 
107
		}
110
		}
108
 
-
 
-
 
111
		dataLog.info(StringUtils.join(new String[] { Event.ADD_TO_CART.name(),
-
 
112
                userinfo.getEmail(), Long.toString(cartId), itemIds }, ", "));
109
		return "success";
113
		return "success";
110
	}		
114
	}		
111
 
115
 
112
 
116
 
113
		// DELETE /entity
117
		// DELETE /entity
Line 118... Line 122...
118
			String itemIdString = this.request.getParameter("productid");
122
			String itemIdString = this.request.getParameter("productid");
119
			long itemId = Long.parseLong(itemIdString);
123
			long itemId = Long.parseLong(itemIdString);
120
			if(userinfo.getCartId() == -1){
124
			if(userinfo.getCartId() == -1){
121
				log.info("Cart does not exist. Nothing to delete.");
125
				log.info("Cart does not exist. Nothing to delete.");
122
			}else{
126
			}else{
123
				if(deleteItemFromCart(userinfo.getCartId(), itemId, userinfo.getUserId(), userinfo.isSessionId())){
127
				if(deleteItemFromCart(userinfo.getCartId(), itemId, userinfo.getUserId(), userinfo.isSessionId()))
-
 
128
				{
124
					userinfo.setTotalItems(getNumberOfItemsInCart(userinfo.getCartId()));
129
					userinfo.setTotalItems(getNumberOfItemsInCart(userinfo.getCartId()));
-
 
130
                    dataLog.info(StringUtils.join(new String[] {
-
 
131
                            Event.DELETE_FROM_CART.name(), userinfo.getEmail(),
-
 
132
                            Long.toString(userinfo.getCartId()), itemIdString },
-
 
133
                            ", "));
125
					return "redirect";	
134
					return "redirect";	
126
				}
135
				}
127
			}
136
			}
128
			return "redirect";
137
			return "redirect";
129
		}
138
		}
Line 141... Line 150...
141
			long quantity = Long.parseLong(quantityString);
150
			long quantity = Long.parseLong(quantityString);
142
			if(quantity <= 0){
151
			if(quantity <= 0){
143
				log.info("Not valid item quantity. Unable to change item quantity.");
152
				log.info("Not valid item quantity. Unable to change item quantity.");
144
			}else{
153
			}else{
145
				if(updateItemQuantityInCart(userinfo.getCartId(), itemId, quantity)){
154
				if(updateItemQuantityInCart(userinfo.getCartId(), itemId, quantity)){
-
 
155
				    dataLog.info(StringUtils.join(new String[] {
-
 
156
                            Event.UPDATE_CART_QUANTITY.name(), userinfo.getEmail(),
-
 
157
                            Long.toString(userinfo.getCartId()), Long.toString(itemId), Long.toString(quantity) },
-
 
158
                            ", "));
146
					return "redirect";	
159
					return "redirect";	
147
				}
160
				}
148
			}
161
			}
-
 
162
			dataLog.info(StringUtils.join(new String[] {
-
 
163
                    Event.UPDATE_CART_QUANTITY_FAILED.name(), userinfo.getEmail(),
-
 
164
                    Long.toString(userinfo.getCartId()), Long.toString(itemId), Long.toString(quantity) },
-
 
165
                    ", "));
149
			addActionError("Unable to update the quantity");
166
			addActionError("Unable to update the quantity");
150
			return "redirect";
167
			return "redirect";
151
		}
168
		}
152
		
169
		
153
		
170