Subversion Repositories SmartDukaan

Rev

Rev 6372 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6371 rajveer 1
package in.shop2020.support.controllers;
2
 
3
import java.util.HashMap;
4
import java.util.Map;
5
 
6
import in.shop2020.model.v1.order.TransactionService.Client;
7
import in.shop2020.thrift.clients.TransactionClient;
8
 
9
import javax.servlet.ServletContext;
10
import javax.servlet.http.HttpServletRequest;
11
import javax.servlet.http.HttpServletResponse;
12
import javax.servlet.http.HttpSession;
13
 
14
import org.apache.commons.lang.StringUtils;
15
import org.apache.struts2.interceptor.ServletRequestAware;
16
import org.apache.struts2.interceptor.ServletResponseAware;
17
import org.apache.struts2.util.ServletContextAware;
18
import org.apache.thrift.TException;
19
import org.slf4j.Logger;
20
import org.slf4j.LoggerFactory;
21
 
22
/**
23
 * 
24
 * @author Rajveer
25
 * 
26
 */
27
public class RechargeAvailabilityController implements ServletResponseAware, ServletRequestAware, ServletContextAware {
28
 
29
    private static Logger logger = LoggerFactory.getLogger(RechargeAvailabilityController.class);
30
 
31
	private String id;
32
 
33
	private HttpServletRequest request;
34
	private HttpServletResponse response;
35
	private HttpSession session;
36
	private ServletContext context;
37
 
38
    private String errorMsg = "";
39
    private static Map<Long, String> circles = new HashMap<Long, String>();
40
 
41
    static{
42
    	circles.put(1L, "Andhra Pradesh");
43
    	circles.put(2L, "Assam");
44
    	circles.put(3L, "Bihar and Jharkhand");
45
    	circles.put(4L, "Chennai");
46
    	circles.put(5L, "Delhi");
47
    	circles.put(6L, "Gujarat");
48
    	circles.put(7L, "Himachal Pradesh");
49
    	circles.put(8L, "J&k");
50
    	circles.put(9L, "Haryana");
51
    	circles.put(10L, "Karnataka");
52
    	circles.put(11L, "Kerala");
53
    	circles.put(12L, "Kolkata");
54
    	circles.put(13L, "Maharashtra");
55
    	circles.put(14L, "Madhya Pradesh and Chattis.");
56
    	circles.put(15L, "Mumbai");
57
    	circles.put(16L, "North-east");
58
    	circles.put(17L, "Orrisa");
59
    	circles.put(18L, "Punjab");
60
    	circles.put(19L, "Rajsthan");
61
    	circles.put(20L, "TamilNadu");
62
    	circles.put(21L, "UP(E)");
63
    	circles.put(22L, "UP(W) & Uttarakhand");
64
    	circles.put(23L, "West Bengal");	
65
    }
66
 
67
 
68
	public String index(){
69
		if(getSessionUserName()==null)
70
			return "authfail";
71
		else
72
			return "authsuccess";
73
	}
74
 
75
 
76
	public String show() throws TException{
77
		long operatorId = Long.parseLong(getId());
78
		long circleId = ((Long)session.getAttribute("circleId")).longValue();
79
		boolean isAvailable;
80
		isAvailable = Boolean.parseBoolean(request.getParameter("isAvailable"));
81
		TransactionClient tc = new TransactionClient();
82
		Client tClient = tc.getClient();
83
		tClient.updateAvailabilityStatus(operatorId, circleId, isAvailable);
84
		return "authsuccess";
85
	}
86
 
87
 
88
	// Handler for POST /recharge-availability
89
	public String create(){
90
		String username = request.getParameter("username");
91
		String password = request.getParameter("password");
92
		if(StringUtils.isEmpty(username) && StringUtils.isEmpty(username)){
93
			return "authfail";
94
		}
95
		if(!(username.equals("sdeck") && password.equals("saholic"))){
96
			return "authfail";
97
		}
98
		return "authsuccess";
99
	}
100
 
101
 
102
	@Override
103
	public void setServletResponse(HttpServletResponse response) {
104
		this.response  = response;
105
	}
106
 
107
	@Override
108
	public void setServletRequest(HttpServletRequest request) {
109
		this.request = request;
110
		this.session = request.getSession();
111
	}
112
 
113
	public String getId(){
114
		return id;
115
	}
116
 
117
	public void setId(String id){
118
		this.id = id;
119
	}
120
 
121
	public String getSessionUserName(){
122
		return (String) session.getAttribute("username");
123
	}
124
 
125
    public String getErrorMsg() {
126
        return errorMsg;
127
    }
128
 
129
    public void setErrorMsg(String errorMsg) {
130
        this.errorMsg = errorMsg;
131
    }
132
 
133
    public Map<Long, String> getOperators(){
134
    	return RechargeOrdersController.getProviderMap();
135
    }
136
 
137
    public Map<Long, String> getCircles(){
138
    	return circles;
139
    }
140
 
141
	@Override
142
	public void setServletContext(ServletContext context) {
143
		this.context = context;
144
 
145
	}
146
}