Subversion Repositories SmartDukaan

Rev

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

Rev 11526 Rev 11535
Line 61... Line 61...
61
    public CartController() throws Exception{
61
    public CartController() throws Exception{
62
        super();
62
        super();
63
        userClient = new UserClient().getClient();
63
        userClient = new UserClient().getClient();
64
    }
64
    }
65
    
65
    
-
 
66
    public UserContextService.Client getClient() throws Exception{
-
 
67
    	if (userClient.isAlive()) {
-
 
68
    		userClient = new UserClient().getClient();
-
 
69
    	}
-
 
70
    	return userClient;
-
 
71
    }
66
    public String index() {
72
    public String index() {
67
        if(id != -1){
73
        if(id != -1){
68
            try {
74
            try {
69
            	log.info("Before cart response--------");
75
            	log.info("Before cart response--------");
70
                List<String> cartResponse  = userClient.validateCart(id, -1);
76
                List<String> cartResponse  = getClient().validateCart(id, -1);
71
                log.info("After cart response--------");
77
                log.info("After cart response--------");
72
                if (!"".equals(cartResponse.get(0))) {
78
                if (!"".equals(cartResponse.get(0))) {
73
                    errorMsg = cartResponse.get(0);
79
                    errorMsg = cartResponse.get(0);
74
                }
80
                }
75
                if(StringUtils.isNotEmpty(cartResponse.get(1))) {
81
                if(StringUtils.isNotEmpty(cartResponse.get(1))) {
76
                    addActionMessage(cartResponse.get(1));
82
                    addActionMessage(cartResponse.get(1));
77
                }
83
                }
78
                log.info("Cart Change/EMI Message rcvd from the service is:" + errorMsg);
84
                log.info("Cart Change/EMI Message rcvd from the service is:" + errorMsg);
79
                
85
                
80
                Cart cart = userClient.getCurrentCart(userinfo.getUserId());
86
                Cart cart = getClient().getCurrentCart(userinfo.getUserId());
81
                String pincode = "110001";
87
                String pincode = "110001";
82
                if(!cart.isSetAddressId()) {
88
                if(!cart.isSetAddressId()) {
83
                    try {
89
                    try {
84
                        pincode = userClient.getDefaultPincode(userinfo.getUserId());
90
                        pincode = getClient().getDefaultPincode(userinfo.getUserId());
85
                    } catch(Exception e) {
91
                    } catch(Exception e) {
86
                        log.error("Unable to get default pincode for userId : " + userinfo.getUserId(), e);
92
                        log.error("Unable to get default pincode for userId : " + userinfo.getUserId(), e);
87
                    }
93
                    }
88
                } else {
94
                } else {
89
                    try {
95
                    try {
90
                        pincode = userClient.getAddressById(cart.getAddressId()).getPin();
96
                        pincode = getClient().getAddressById(cart.getAddressId()).getPin();
91
                    } catch(Exception e) {
97
                    } catch(Exception e) {
92
                        log.error("Unable to get address for addressId : " + cart.getAddressId(), e);
98
                        log.error("Unable to get address for addressId : " + cart.getAddressId(), e);
93
                    }   
99
                    }   
94
                }
100
                }
95
                Boolean needInuranceInfo = false;
101
                Boolean needInuranceInfo = false;
96
                for(Line line : cart.getLines()) {
102
                for(Line line : cart.getLines()) {
97
                	log.info("Insurer is set: " + String.valueOf(line.getInsurer()>0));
103
                	log.info("Insurer is set: " + String.valueOf(line.getInsurer()>0));
98
                	if(line.getInsurer()>0){
104
                	if(line.getInsurer()>0){
99
                		long defaultAddressId = userClient.getDefaultAddressId(userinfo.getUserId());
105
                		long defaultAddressId = getClient().getDefaultAddressId(userinfo.getUserId());
100
                		log.info(defaultAddressId);
106
                		log.info(defaultAddressId);
101
                		needInuranceInfo = !userClient.isInsuranceDetailPresent(defaultAddressId);
107
                		needInuranceInfo = !getClient().isInsuranceDetailPresent(defaultAddressId);
102
                		log.info("Need insurance: " + needInuranceInfo);
108
                		log.info("Need insurance: " + needInuranceInfo);
103
                		break;
109
                		break;
104
                	}
110
                	}
105
                }
111
                }
106
                
112
                
Line 120... Line 126...
120
    public String create() {
126
    public String create() {
121
    	RedirectPojo rp = new RedirectPojo();
127
    	RedirectPojo rp = new RedirectPojo();
122
    	rp.setRedirectUrl("");
128
    	rp.setRedirectUrl("");
123
        try {
129
        try {
124
        	//Try adding to cart
130
        	//Try adding to cart
125
            cartMsg = userClient.addItemToCart(id, itemId, 1, -1);
131
            cartMsg = getClient().addItemToCart(id, itemId, 1, -1);
-
 
132
            log.info("Cart message while adding item to cart - " + cartMsg);
126
            //If could not add to cart try to add notification reminder if email exists.
133
            //If could not add to cart try to add notification reminder if email exists.
127
            if (!("".equals(cartMsg))) {
134
            if (!("".equals(cartMsg))) {
128
            	String emailId = this.request.getParameter("email");
135
            	String emailId = this.request.getParameter("email");
129
            	log.info("QuesyString" + this.request.getParameterMap().toString());
136
            	log.info("QuesyString" + this.request.getParameterMap().toString());
130
    			if(emailId==null || emailId.equals("")){
137
    			if(emailId==null || emailId.equals("")){
Line 161... Line 168...
161
 
168
 
162
    // DELETE /entity
169
    // DELETE /entity
163
    public String destroy() {
170
    public String destroy() {
164
        if(id > 0)  {
171
        if(id > 0)  {
165
            try {
172
            try {
166
                userClient.deleteItemFromCart(id, itemId);
173
                getClient().deleteItemFromCart(id, itemId);
167
                return index();
174
                return index();
168
            } catch (ShoppingCartException e) {
175
            } catch (ShoppingCartException e) {
169
                log.error("Unable to delete item from cart: ", e);
176
                log.error("Unable to delete item from cart: ", e);
170
                errorMsg = "Unable to delete item. Please try again.";
177
                errorMsg = "Unable to delete item. Please try again.";
171
            } catch (TException e) {
178
            } catch (TException e) {
Line 192... Line 199...
192
        return index();
199
        return index();
193
    }
200
    }
194
    
201
    
195
    private boolean updateItemQuantityInCart(long cartId, long itemId, long quantity){
202
    private boolean updateItemQuantityInCart(long cartId, long itemId, long quantity){
196
        try {
203
        try {
197
            userClient.addItemToCart(cartId, itemId, quantity, -1);
204
            getClient().addItemToCart(cartId, itemId, quantity, -1);
198
            return true;
205
            return true;
199
        } catch (ShoppingCartException e) {
206
        } catch (ShoppingCartException e) {
200
            log.error("Unable to update the item quantity in the cart: ", e);
207
            log.error("Unable to update the item quantity in the cart: ", e);
201
            errorMsg = "Unable to change quantity. Please try again.";
208
            errorMsg = "Unable to change quantity. Please try again.";
202
        } catch (TException e) {
209
        } catch (TException e) {
Line 210... Line 217...
210
    }
217
    }
211
           
218
           
212
    public String insureItem() {
219
    public String insureItem() {
213
        insuranceResult = "";
220
        insuranceResult = "";
214
        try {
221
        try {
215
            if(userClient.insureItem(itemId, id, toInsure, insuranceType)) {
222
            if(getClient().insureItem(itemId, id, toInsure, insuranceType)) {
216
                setInsuranceResult("SUCCESS");
223
                setInsuranceResult("SUCCESS");
217
            } else {
224
            } else {
218
                setInsuranceResult("FAILURE");
225
                setInsuranceResult("FAILURE");
219
            }
226
            }
220
        } catch (Exception e) {
227
        } catch (Exception e) {
Line 245... Line 252...
245
                
252
                
246
                promotionClient.applyCoupon(couponCode, id);
253
                promotionClient.applyCoupon(couponCode, id);
247
                
254
                
248
            }
255
            }
249
            else if (action.equals("removecoupon"))    {
256
            else if (action.equals("removecoupon"))    {
250
                userClient.removeCoupon(id);
257
                getClient().removeCoupon(id);
251
            }
258
            }
252
        } catch (PromotionException e) {
259
        } catch (PromotionException e) {
253
            log.info("Invalid coupon: " + e.getMessage());
260
            log.info("Invalid coupon: " + e.getMessage());
254
            errorMsg = "Invalid coupon : " + e.getMessage();
261
            errorMsg = "Invalid coupon : " + e.getMessage();
255
        } catch (Exception e) {
262
        } catch (Exception e) {
Line 268... Line 275...
268
            addressId = Long.parseLong(request.getParameter("addressId"));
275
            addressId = Long.parseLong(request.getParameter("addressId"));
269
        }
276
        }
270
         
277
         
271
        try {
278
        try {
272
            if(request.getParameter("addressType").equalsIgnoreCase("store")) {
279
            if(request.getParameter("addressType").equalsIgnoreCase("store")) {
273
                userClient.addStoreToCart(id, addressId);
280
                getClient().addStoreToCart(id, addressId);
274
            } else if (request.getParameter("addressType").equalsIgnoreCase("home")){
281
            } else if (request.getParameter("addressType").equalsIgnoreCase("home")){
275
                userClient.addAddressToCart(id, addressId);
282
                getClient().addAddressToCart(id, addressId);
276
            } else {
283
            } else {
277
                errorMsg = "Invalid addressType. It can only be set to home or store.";
284
                errorMsg = "Invalid addressType. It can only be set to home or store.";
278
            }
285
            }
279
        } catch(Exception e) {
286
        } catch(Exception e) {
280
            log.error("Unable to change address", e);
287
            log.error("Unable to change address", e);