Subversion Repositories SmartDukaan

Rev

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

Rev 10554 Rev 10724
Line 1... Line 1...
1
	package in.shop2020.mobileapi.serving.controllers;
1
	package in.shop2020.mobileapi.serving.controllers;
2
 
2
 
3
import in.shop2020.mobileapi.serving.pojos.NotificationPojo;
3
import in.shop2020.mobileapi.serving.pojos.NotificationPojo;
-
 
4
import in.shop2020.mobileapi.serving.pojos.RedirectPojo;
4
import in.shop2020.mobileapi.serving.services.ContentServingService;
5
import in.shop2020.mobileapi.serving.services.ContentServingService;
5
import in.shop2020.mobileapi.serving.utils.PojoPopulator;
6
import in.shop2020.mobileapi.serving.utils.PojoPopulator;
6
import in.shop2020.mobileapi.serving.utils.SnippetType;
7
import in.shop2020.mobileapi.serving.utils.SnippetType;
7
import in.shop2020.model.v1.catalog.CatalogService.Client;
8
import in.shop2020.model.v1.catalog.CatalogService.Client;
8
import in.shop2020.model.v1.catalog.Item;
9
import in.shop2020.model.v1.catalog.Item;
Line 111... Line 112...
111
        }
112
        }
112
        return "index";
113
        return "index";
113
    }
114
    }
114
 
115
 
115
    public String create() {
116
    public String create() {
-
 
117
    	RedirectPojo rp = new RedirectPojo();
-
 
118
    	rp.setRedirectUrl("");
116
        try {
119
        try {
117
        	NotificationPojo np = new NotificationPojo();
120
        	//NotificationPojo np = new NotificationPojo();
118
            UserClient userServiceClient = new UserClient();
121
            UserClient userServiceClient = new UserClient();
119
            UserContextService.Client userClient = userServiceClient.getClient();
122
            UserContextService.Client userClient = userServiceClient.getClient();
120
            cartMsg = userClient.addItemToCart(id, itemId, 1, -1);
123
            cartMsg = userClient.addItemToCart(id, itemId, 1, -1);
121
            if (!("".equals(cartMsg))) {
124
            if (!("".equals(cartMsg))) {
122
            	String emailId = "";
125
            	String emailId = this.request.getParameter("emailId");
-
 
126
    			if(emailId==null || emailId.equals("")){
-
 
127
    				rp.setMessage("Item is currently out of stock");
-
 
128
    			} else {	
123
        		try {
129
        			try {
124
        			emailId = this.request.getParameter("emailId");
130
	        	        CatalogClient catalogClientService;
125
        			if(emailId!=null){
131
	        			catalogClientService = new CatalogClient();
126
        				np.setMessage("Could not add this item to cart");
132
	        			in.shop2020.model.v1.catalog.CatalogService.Client client = catalogClientService.getClient();
127
        				np.setStatus("oos");
133
	        			client.addProductNotification(itemId, emailId);
-
 
134
	        			log.debug("Got product notification for product: " + itemId + "  from user: " + emailId );
128
        				cartPojoJson = new Gson().toJson(np);
135
	        			rp.setMessage("You will be notified when product is avaliable");
129
        				return "index";
136
        			} catch (Exception e) {
130
        				
137
        				rp.setMessage("Error occurred while adding to notificiation");
-
 
138
        				log.error("Exception while adding product notification for item: " + itemId + " and email: " + emailId, e);
131
        			}
139
        			}
132
        			itemId = Long.parseLong(this.request.getParameter("itemId"));
-
 
133
 
-
 
134
        	        CatalogClient catalogClientService;
-
 
135
        			catalogClientService = new CatalogClient();
-
 
136
        			in.shop2020.model.v1.catalog.CatalogService.Client client = catalogClientService.getClient();
-
 
137
        			client.addProductNotification(itemId, emailId);
-
 
138
        		} catch (Exception e) {
140
        			
139
        			log.error("Exception while adding product notification for item: " + itemId + " and email: " + emailId, e);
-
 
140
        		}
141
        		}
141
        		log.debug("Got product notification for product: " + itemId + "  from user: " + emailId );
-
 
142
        		np.setMessage("You will be notified when product is avaliable");
-
 
143
        		np.setStatus("success");
142
            } else {
144
        		cartPojoJson = new Gson().toJson(np);
-
 
145
                return "index";
143
            	rp.setRedirectUrl("cart");
146
            }
144
            }
147
        } catch (TException e) {
145
        } catch (TException e) {
148
            log.error("Unable to create or add to cart because of: ", e);
146
            log.error("Unable to create or add to cart because of: ", e);
149
            errorMsg = "Unable to add to cart. Please try again.";
147
            errorMsg = "Unable to add to cart. Please try again.";
150
        } catch (Exception e) {
148
        } catch (Exception e) {
151
            log.error("Unable to create or add to cart because of: ", e);
149
            log.error("Unable to create or add to cart because of: ", e);
152
            errorMsg = "Unable to add to cart. Please try again.";
150
            errorMsg = "Unable to add to cart. Please try again.";
153
        }
151
        }
154
        
152
        cartPojoJson = new Gson().toJson(rp);
155
    return index();
153
        return "index";
156
    }       
154
    }       
157
 
155
 
158
 
156
 
159
    // DELETE /entity
157
    // DELETE /entity
160
    public String destroy() {
158
    public String destroy() {