| 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());
|
| 6373 |
rajveer |
78 |
long circleId = Long.parseLong(request.getParameter("circleId"));
|
| 6371 |
rajveer |
79 |
boolean isAvailable;
|
|
|
80 |
isAvailable = Boolean.parseBoolean(request.getParameter("isAvailable"));
|
|
|
81 |
TransactionClient tc = new TransactionClient();
|
|
|
82 |
Client tClient = tc.getClient();
|
| 6372 |
rajveer |
83 |
if(circleId==0){
|
|
|
84 |
for(Long cid: circles.keySet()){
|
|
|
85 |
tClient.updateAvailabilityStatus(operatorId, cid, isAvailable);
|
|
|
86 |
}
|
|
|
87 |
}else{
|
|
|
88 |
tClient.updateAvailabilityStatus(operatorId, circleId, isAvailable);
|
|
|
89 |
}
|
| 6371 |
rajveer |
90 |
return "authsuccess";
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
// Handler for POST /recharge-availability
|
|
|
95 |
public String create(){
|
|
|
96 |
String username = request.getParameter("username");
|
|
|
97 |
String password = request.getParameter("password");
|
|
|
98 |
if(StringUtils.isEmpty(username) && StringUtils.isEmpty(username)){
|
|
|
99 |
return "authfail";
|
|
|
100 |
}
|
| 6376 |
rajveer |
101 |
if(!(username.equals("sdeck") && password.equals("sdeck@7436"))){
|
| 6371 |
rajveer |
102 |
return "authfail";
|
|
|
103 |
}
|
| 6377 |
rajveer |
104 |
session.setAttribute("username", username);
|
| 6371 |
rajveer |
105 |
return "authsuccess";
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
@Override
|
|
|
110 |
public void setServletResponse(HttpServletResponse response) {
|
|
|
111 |
this.response = response;
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
@Override
|
|
|
115 |
public void setServletRequest(HttpServletRequest request) {
|
|
|
116 |
this.request = request;
|
|
|
117 |
this.session = request.getSession();
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
public String getId(){
|
|
|
121 |
return id;
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
public void setId(String id){
|
|
|
125 |
this.id = id;
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
public String getSessionUserName(){
|
|
|
129 |
return (String) session.getAttribute("username");
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
public String getErrorMsg() {
|
|
|
133 |
return errorMsg;
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
public void setErrorMsg(String errorMsg) {
|
|
|
137 |
this.errorMsg = errorMsg;
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
public Map<Long, String> getOperators(){
|
|
|
141 |
return RechargeOrdersController.getProviderMap();
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
public Map<Long, String> getCircles(){
|
|
|
145 |
return circles;
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
@Override
|
|
|
149 |
public void setServletContext(ServletContext context) {
|
|
|
150 |
this.context = context;
|
|
|
151 |
|
|
|
152 |
}
|
|
|
153 |
}
|