Subversion Repositories SmartDukaan

Rev

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

Rev 9709 Rev 9713
Line 4... Line 4...
4
import in.shop2020.mobileapi.serving.utils.PojoPopulator;
4
import in.shop2020.mobileapi.serving.utils.PojoPopulator;
5
import in.shop2020.mobileapi.serving.utils.SnippetType;
5
import in.shop2020.mobileapi.serving.utils.SnippetType;
6
import in.shop2020.model.v1.catalog.CatalogService.Client;
6
import in.shop2020.model.v1.catalog.CatalogService.Client;
7
import in.shop2020.model.v1.catalog.Item;
7
import in.shop2020.model.v1.catalog.Item;
8
import in.shop2020.model.v1.user.Cart;
8
import in.shop2020.model.v1.user.Cart;
-
 
9
import in.shop2020.model.v1.user.PromotionException;
-
 
10
import in.shop2020.model.v1.user.PromotionService;
9
import in.shop2020.model.v1.user.ShoppingCartException;
11
import in.shop2020.model.v1.user.ShoppingCartException;
10
import in.shop2020.model.v1.user.UserContextService;
12
import in.shop2020.model.v1.user.UserContextService;
11
import in.shop2020.thrift.clients.CatalogClient;
13
import in.shop2020.thrift.clients.CatalogClient;
-
 
14
import in.shop2020.thrift.clients.PromotionClient;
12
import in.shop2020.thrift.clients.UserClient;
15
import in.shop2020.thrift.clients.UserClient;
13
 
16
 
14
import java.util.List;
17
import java.util.List;
15
import java.util.Map;
18
import java.util.Map;
16
 
19
 
Line 57... Line 60...
57
    public String index()  {
60
    public String index()  {
58
        if(id != -1){
61
        if(id != -1){
59
            try {
62
            try {
60
                UserContextService.Client userClient = (new UserClient()).getClient();
63
                UserContextService.Client userClient = (new UserClient()).getClient();
61
                List<String> cartResponse  = userClient.validateCart(id, -1);
64
                List<String> cartResponse  = userClient.validateCart(id, -1);
-
 
65
                if (!"".equals(cartResponse.get(0))) {
62
                errorMsg = cartResponse.get(0);
66
                    errorMsg = cartResponse.get(0);
-
 
67
                }
63
                if(StringUtils.isNotEmpty(cartResponse.get(1))) {
68
                if(StringUtils.isNotEmpty(cartResponse.get(1))) {
64
                    addActionMessage(cartResponse.get(1));
69
                    addActionMessage(cartResponse.get(1));
65
                }
70
                }
66
                log.info("Cart Change/EMI Message rcvd from the service is:" + errorMsg);
71
                log.info("Cart Change/EMI Message rcvd from the service is:" + errorMsg);
67
                
72
                
Line 86... Line 91...
86
            if (!("".equals(cartMsg))) {
91
            if (!("".equals(cartMsg))) {
87
                return "outofstock";
92
                return "outofstock";
88
            }
93
            }
89
        } catch (TException e) {
94
        } catch (TException e) {
90
            log.error("Unable to create or add to cart because of: ", e);
95
            log.error("Unable to create or add to cart because of: ", e);
-
 
96
            errorMsg = "Unable to add to cart. Please try again.";
91
        } catch (Exception e) {
97
        } catch (Exception e) {
92
            log.error("Unable to create or add to cart because of: ", e);
98
            log.error("Unable to create or add to cart because of: ", e);
-
 
99
            errorMsg = "Unable to add to cart. Please try again.";
93
        }
100
        }
94
        
101
        
95
    return index();
102
    return index();
96
    }       
103
    }       
97
 
104
 
Line 105... Line 112...
105
 
112
 
106
                userClient.deleteItemFromCart(id, itemId);
113
                userClient.deleteItemFromCart(id, itemId);
107
                return index();
114
                return index();
108
            } catch (ShoppingCartException e) {
115
            } catch (ShoppingCartException e) {
109
                log.error("Unable to delete item from cart: ", e);
116
                log.error("Unable to delete item from cart: ", e);
-
 
117
                errorMsg = "Unable to delete item. Please try again.";
110
            } catch (TException e) {
118
            } catch (TException e) {
111
                log.error("Unable to delete item from cart: ", e);
119
                log.error("Unable to delete item from cart: ", e);
-
 
120
                errorMsg = "Unable to delete item. Please try again.";
112
            } catch (Exception e) {
121
            } catch (Exception e) {
113
                log.error("Unable to delete item from cart: ", e);
122
                log.error("Unable to delete item from cart: ", e);
-
 
123
                errorMsg = "Unable to delete item. Please try again.";
114
            }
124
            }
115
        }
125
        }
116
        return index();
126
        return index();
117
    }
127
    }
118
    
128
    
119
    //PUT
129
    //PUT
120
    public String update() {
130
    public String update() {
121
        if(quantity <= 0)   {
131
        if(quantity <= 0)   {
122
            log.info("Not valid item quantity. Unable to change item quantity.");
132
            log.info("Not valid item quantity. Unable to change item quantity.");
-
 
133
            errorMsg = "Invalid item quantity";
123
        } else  {
134
        } else  {
124
            if(updateItemQuantityInCart(id, itemId, quantity))    {
135
            if(updateItemQuantityInCart(id, itemId, quantity))    {
125
                return index();
136
                return index();
126
            }
137
            }
127
        }
138
        }
Line 135... Line 146...
135
 
146
 
136
            userClient.addItemToCart(cartId, itemId, quantity, -1);
147
            userClient.addItemToCart(cartId, itemId, quantity, -1);
137
            return true;
148
            return true;
138
        } catch (ShoppingCartException e) {
149
        } catch (ShoppingCartException e) {
139
            log.error("Unable to update the item quantity in the cart: ", e);
150
            log.error("Unable to update the item quantity in the cart: ", e);
-
 
151
            errorMsg = "Unable to change quantity. Please try again.";
140
        } catch (TException e) {
152
        } catch (TException e) {
141
            log.error("Unable to update the item quantity in the cart: ", e);
153
            log.error("Unable to update the item quantity in the cart: ", e);
-
 
154
            errorMsg = "Unable to change quantity. Please try again.";
142
        } catch (Exception e) {
155
        } catch (Exception e) {
143
            log.error("Unable to update the item quantity in the cart: ", e);
156
            log.error("Unable to update the item quantity in the cart: ", e);
-
 
157
            errorMsg = "Unable to change quantity. Please try again.";
144
        }
158
        }
145
        return false;
159
        return false;
146
    }
160
    }
147
           
161
           
148
    public String insureItem() {
162
    public String insureItem() {
Line 158... Line 172...
158
            log.error("Unable to insure item : " + itemId + " for cart : " + id, e);
172
            log.error("Unable to insure item : " + itemId + " for cart : " + id, e);
159
            setInsuranceResult("FAILURE");
173
            setInsuranceResult("FAILURE");
160
        }
174
        }
161
        return "insurance-result";
175
        return "insurance-result";
162
    }
176
    }
-
 
177
    
-
 
178
    public String edit()  {
-
 
179
        String action = request.getParameter("action");
-
 
180
        UserClient userServiceClient = null;
-
 
181
        PromotionClient promotionServiceClient = null;
-
 
182
        try {
-
 
183
            if(action == null || action.isEmpty())  {
-
 
184
                errorMsg = "Invalid Request Action";
-
 
185
                return index();
-
 
186
            }
-
 
187
            String couponCode = request.getParameter("coupon_code");
-
 
188
            
-
 
189
            if (action.equalsIgnoreCase("applycoupon"))   {
-
 
190
                if (couponCode == null || couponCode.isEmpty()) {
-
 
191
                    errorMsg = "Coupon Code field cannot be left empty";
-
 
192
                    return index();
-
 
193
                }
-
 
194
                
-
 
195
                promotionServiceClient = new PromotionClient();
-
 
196
                PromotionService.Client promotionClient = promotionServiceClient.getClient();
-
 
197
                
-
 
198
                promotionClient.applyCoupon(couponCode, id);
-
 
199
                
-
 
200
            }
-
 
201
            else if (action.equals("removecoupon"))    {
-
 
202
                userServiceClient = new UserClient();
-
 
203
                UserContextService.Client userClient = userServiceClient.getClient();
-
 
204
                userClient.removeCoupon(id);
-
 
205
            }
-
 
206
        } catch (PromotionException e) {
-
 
207
            log.info("Invalid coupon: " + e.getMessage());
-
 
208
            errorMsg = "Invalid coupon : " + e.getMessage();
-
 
209
        } catch (Exception e) {
-
 
210
            log.error("Unable to apply or remove coupon", e);
-
 
211
            errorMsg = "Unable to apply or remove coupon";
-
 
212
        }
-
 
213
        return index();
-
 
214
    }
163
 
215
 
164
    public long getItemId(){
216
    public long getItemId(){
165
        return this.itemId;
217
        return this.itemId;
166
    }
218
    }
167
    
219