Subversion Repositories SmartDukaan

Rev

Rev 6376 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package in.shop2020.support.controllers;

import java.util.HashMap;
import java.util.Map;

import in.shop2020.model.v1.order.TransactionService.Client;
import in.shop2020.thrift.clients.TransactionClient;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.util.ServletContextAware;
import org.apache.thrift.TException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 
 * @author Rajveer
 * 
 */
public class RechargeAvailabilityController implements ServletResponseAware, ServletRequestAware, ServletContextAware {
    
    private static Logger logger = LoggerFactory.getLogger(RechargeAvailabilityController.class);
    
        private String id;
        
        private HttpServletRequest request;
        private HttpServletResponse response;
        private HttpSession session;
        private ServletContext context;
        
    private String errorMsg = "";
    private static Map<Long, String> circles = new HashMap<Long, String>();
    
    static{
        circles.put(1L, "Andhra Pradesh");
        circles.put(2L, "Assam");
        circles.put(3L, "Bihar and Jharkhand");
        circles.put(4L, "Chennai");
        circles.put(5L, "Delhi");
        circles.put(6L, "Gujarat");
        circles.put(7L, "Himachal Pradesh");
        circles.put(8L, "J&k");
        circles.put(9L, "Haryana");
        circles.put(10L, "Karnataka");
        circles.put(11L, "Kerala");
        circles.put(12L, "Kolkata");
        circles.put(13L, "Maharashtra");
        circles.put(14L, "Madhya Pradesh and Chattis.");
        circles.put(15L, "Mumbai");
        circles.put(16L, "North-east");
        circles.put(17L, "Orrisa");
        circles.put(18L, "Punjab");
        circles.put(19L, "Rajsthan");
        circles.put(20L, "TamilNadu");
        circles.put(21L, "UP(E)");
        circles.put(22L, "UP(W) & Uttarakhand");
        circles.put(23L, "West Bengal");        
    }
    
    
        public String index(){
                if(getSessionUserName()==null)
                        return "authfail";
                else
                        return "authsuccess";
        }

        
        public String show() throws TException{
                long operatorId = Long.parseLong(getId());
                long circleId = Long.parseLong(request.getParameter("circleId"));
                boolean isAvailable;
                isAvailable = Boolean.parseBoolean(request.getParameter("isAvailable"));
                TransactionClient tc = new TransactionClient();
                Client tClient = tc.getClient();
                if(circleId==0){
                        for(Long cid: circles.keySet()){
                                tClient.updateAvailabilityStatus(operatorId, cid, isAvailable);
                        }
                }else{
                        tClient.updateAvailabilityStatus(operatorId, circleId, isAvailable);
                }
                return "authsuccess";
        }

        
        // Handler for POST /recharge-availability
        public String create(){
                String username = request.getParameter("username");
                String password = request.getParameter("password");
                if(StringUtils.isEmpty(username) && StringUtils.isEmpty(username)){
                        return "authfail";
                }
                if(!(username.equals("sdeck") && password.equals("sdeck@7436"))){
                        return "authfail";
                }
                session.setAttribute("username", username);
                return "authsuccess";
        }
        
        
        @Override
        public void setServletResponse(HttpServletResponse response) {
                this.response  = response;
        }

        @Override
        public void setServletRequest(HttpServletRequest request) {
                this.request = request;
                this.session = request.getSession();
        }

        public String getId(){
                return id;
        }
        
        public void setId(String id){
                this.id = id;
        }
        
        public String getSessionUserName(){
                return (String) session.getAttribute("username");
        }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public Map<Long, String> getOperators(){
        return RechargeOrdersController.getProviderMap();
    }
    
    public Map<Long, String> getCircles(){
        return circles;
    }
    
        @Override
        public void setServletContext(ServletContext context) {
                this.context = context;
                
        }
}