Subversion Repositories SmartDukaan

Rev

Rev 6372 | Rev 6376 | Go to most recent revision | Details | Compare with Previous | 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());
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
		}
101
		if(!(username.equals("sdeck") && password.equals("saholic"))){
102
			return "authfail";
103
		}
104
		return "authsuccess";
105
	}
106
 
107
 
108
	@Override
109
	public void setServletResponse(HttpServletResponse response) {
110
		this.response  = response;
111
	}
112
 
113
	@Override
114
	public void setServletRequest(HttpServletRequest request) {
115
		this.request = request;
116
		this.session = request.getSession();
117
	}
118
 
119
	public String getId(){
120
		return id;
121
	}
122
 
123
	public void setId(String id){
124
		this.id = id;
125
	}
126
 
127
	public String getSessionUserName(){
128
		return (String) session.getAttribute("username");
129
	}
130
 
131
    public String getErrorMsg() {
132
        return errorMsg;
133
    }
134
 
135
    public void setErrorMsg(String errorMsg) {
136
        this.errorMsg = errorMsg;
137
    }
138
 
139
    public Map<Long, String> getOperators(){
140
    	return RechargeOrdersController.getProviderMap();
141
    }
142
 
143
    public Map<Long, String> getCircles(){
144
    	return circles;
145
    }
146
 
147
	@Override
148
	public void setServletContext(ServletContext context) {
149
		this.context = context;
150
 
151
	}
152
}