Subversion Repositories SmartDukaan

Rev

Rev 7117 | Rev 7207 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7068 anupam.sin 1
package in.shop2020.recharge.controllers;
2
 
3
import in.shop2020.model.v1.order.DeviceNumberInfo;
7125 amit.gupta 4
import in.shop2020.model.v1.order.FRC;
7113 rajveer 5
import in.shop2020.model.v1.order.HotspotStore;
7068 anupam.sin 6
import in.shop2020.model.v1.order.RechargeDenomination;
7
import in.shop2020.model.v1.order.RechargePlan;
8
import in.shop2020.model.v1.order.RechargeType;
9
import in.shop2020.thrift.clients.TransactionClient;
10
 
7073 anupam.sin 11
import java.util.HashMap;
7068 anupam.sin 12
import java.util.List;
13
import java.util.Map;
14
 
15
import org.apache.log4j.Logger;
7096 anupam.sin 16
import org.apache.struts2.convention.annotation.Result;
17
import org.apache.struts2.convention.annotation.Results;
7068 anupam.sin 18
 
7096 anupam.sin 19
import com.google.gson.Gson;
20
 
21
@Results({
22
    @Result(name = "redirect", location = "${redirectUrl}", type = "redirect")
23
})
24
 
7068 anupam.sin 25
public class HomeController extends BaseController {
26
 
27
    /**
28
     * 
29
     */
7073 anupam.sin 30
    private String deviceType = null; //Default is Mobile , 2 is for DTH
7068 anupam.sin 31
    private String deviceNumber = "";
32
    private String form = "";
33
    private String error = "";
34
    private String operatorId;
35
    private String operatorName;
36
    private String serviceName;
37
    private String denominationType;
7096 anupam.sin 38
    private String circlecode;
7068 anupam.sin 39
    private List<RechargeDenomination> rechargeDenominations = null;
40
    private static final long serialVersionUID = 2079308723099307749L;
41
 
7096 anupam.sin 42
    private Long storeId;
7068 anupam.sin 43
    private static Logger log = Logger.getLogger(Class.class);
44
    private static Map<Long, String> mobileProvidersMap;
45
    private static Map<Long, String> dthProvidersMap;
46
    private static Map<Long, List<RechargePlan>> operatorPlanMap;
7117 rajveer 47
    public static Map<Long, HotspotStore> hotspotStores = new HashMap<Long, HotspotStore>();
7096 anupam.sin 48
    private String errorMsg = "";
49
    private String redirectUrl;
7068 anupam.sin 50
 
51
 
52
    static {
7073 anupam.sin 53
        TransactionClient tcl;
54
        try {
55
            operatorPlanMap = new HashMap<Long, List<RechargePlan>>();
56
            tcl = new TransactionClient();
57
            mobileProvidersMap = tcl.getClient().getServiceProviders(RechargeType.MOBILE, true);
58
            setDthProvidersMap(tcl.getClient().getServiceProviders(RechargeType.DTH, true));
59
            for (Long operatorId : mobileProvidersMap.keySet()) {
60
                List<RechargePlan> plans = tcl.getClient().getPlansForOperator(operatorId);
61
                if (!plans.isEmpty()) {
62
                    operatorPlanMap.put(operatorId, plans);
63
                }
64
            }
65
        } catch(Exception e) {
7096 anupam.sin 66
            ;
7073 anupam.sin 67
        }
7068 anupam.sin 68
    }
69
 
7096 anupam.sin 70
    public String getPlanMapInJson() {
71
        Gson gson = new Gson();
72
            return (gson.toJson(operatorPlanMap));
73
    }
7068 anupam.sin 74
 
75
    public String index() {
76
 
7096 anupam.sin 77
        String loginStatus = (String) request.getSession().getAttribute("LOGGED_IN");
78
        if(loginStatus != null && loginStatus.equals("TRUE")){
7115 rajveer 79
        	storeId = Long.parseLong((String) request.getSession().getAttribute("STORE_ID"));
7113 rajveer 80
        	if(!hotspotStores.containsKey(storeId)){
7114 rajveer 81
        		try{
82
        			HotspotStore hotSpotStore = (new TransactionClient()).getClient().getHotspotStore(storeId, "");
83
        			hotspotStores.put(storeId, hotSpotStore);
84
        		} catch (Exception e) {
85
                    log.error("Unable to get store", e);
86
                }
7113 rajveer 87
        	}
7096 anupam.sin 88
            return "index";
89
        }
90
        return "authfail";
7068 anupam.sin 91
    }
92
 
93
    public String create() {
94
        return index();
95
    }
96
 
97
//    public Map<Long, String> getProviderMap() {
7073 anupam.sin 98
//        if(deviceType.equals("1"))
7068 anupam.sin 99
//            providers = Utils.getMobileProvidersMap();
100
//        else
101
//            providers = Utils.getDthProvidersMap();
102
//        return providers;
103
//    }
104
//    
105
    public String getServiceProvider() {
106
        return "service-provider";
107
    }
7125 amit.gupta 108
 
109
    public String getFRC() {
110
    	return "frc-result";
111
    }
7068 anupam.sin 112
 
7125 amit.gupta 113
    public String getFRCJSONString(){
114
    	long circleId = Long.parseLong((String)(request.getSession().getAttribute("CIRCLE_ID")));
115
    	TransactionClient tcl;
116
        try {
117
            tcl = new TransactionClient();
118
            List<FRC> frcList =  tcl.getClient().getFRCs(circleId, Long.parseLong(operatorId));
119
            return new Gson().toJson(frcList);
120
        } catch (Exception e) {
121
            log.error("Unable to get service provider for Device number " + deviceNumber + " and rechargeType : " +  deviceType, e);
122
            return "";
123
        }
124
    }
125
 
7068 anupam.sin 126
    public String getProvider(){
127
        TransactionClient tcl;
128
        try {
129
            tcl = new TransactionClient();
7073 anupam.sin 130
            DeviceNumberInfo deviceInfo =  tcl.getClient().getServiceProviderForDevice(RechargeType.findByValue(Integer.parseInt(this.deviceType)), deviceNumber);
7068 anupam.sin 131
            return deviceInfo.getOperatorId() + ":" + deviceInfo.getCircleCode();
132
        } catch (Exception e) {
7073 anupam.sin 133
            log.error("Unable to get service provider for Device number " + deviceNumber + " and rechargeType : " +  deviceType, e);
7068 anupam.sin 134
            return ":";
135
        }
136
    }
137
 
7073 anupam.sin 138
    public void setDeviceType(String incomingdeviceType) {
139
        deviceType = incomingdeviceType;
7068 anupam.sin 140
    }
141
 
142
    public void setDeviceNumber(String deviceNumber){
143
        this.deviceNumber = deviceNumber;
144
    }
145
 
7073 anupam.sin 146
    public String getDeviceType() {
147
        return deviceType;
7068 anupam.sin 148
    }
149
 
150
    public String getForm() {
151
        return form;
152
    }
153
 
154
    public void setForm(String form) {
155
        this.form = form;
156
    }
157
 
158
    public String getError() {
159
        return error;
160
    }
161
 
162
    public void setError(String error) {
163
        this.error = error;
164
    }
165
 
166
    public String getPageName() {
167
        return operatorName  + " online recharge";
168
    }
169
 
170
    public String getPageTitle() {
171
        return operatorName  + " online recharge";
172
    }
173
 
174
    public String getPageMetaDesc() {
175
        return "Recharge your " + this.operatorName +  " " + this.serviceName +  " online for all cities using Credit/Debit card & net banking. Fast, Secure and Hassle Free Recharge";
176
    }
177
 
178
    public String getPageMetaKeywords() {
179
        return "mobile, recharge";
180
    }
181
 
182
    public long getOperatorId(){
183
        return Long.parseLong(this.operatorId);
184
    }
185
 
186
    public String getDenominationType() {
187
        return denominationType;
188
    }
189
 
190
    public void setDenominationType(String denominationType) {
191
        this.denominationType = denominationType;
192
    }
193
 
7096 anupam.sin 194
    public String getCirclecode() {
195
        return circlecode;
7068 anupam.sin 196
    }
197
 
7096 anupam.sin 198
    public void setCircleCode(String circlecode) {
199
        this.circlecode = circlecode;
7068 anupam.sin 200
    }
201
 
202
    public List<RechargeDenomination> getRechargeDenominations() {
203
        return rechargeDenominations;
204
    }
205
 
206
    public void setRechargeDenominations(
207
            List<RechargeDenomination> rechargeDenominations) {
208
        this.rechargeDenominations = rechargeDenominations;
209
    }
210
 
211
    public void setOperatorId(String operatorId) {
212
        this.operatorId = operatorId;
213
    }
214
 
7096 anupam.sin 215
    public void setErrorMsg(String errorMsg) {
216
        this.errorMsg = errorMsg;
7068 anupam.sin 217
    }
218
 
7096 anupam.sin 219
    public String getErrorMsg() {
7068 anupam.sin 220
        return errorMsg;
221
    }
222
 
223
    public static void setDthProvidersMap(Map<Long, String> dthProvidersMap) {
224
        HomeController.dthProvidersMap = dthProvidersMap;
225
    }
226
 
227
    public static Map<Long, String> getDthProvidersMap() {
228
        return dthProvidersMap;
229
    }
230
 
231
    public static void setMobileProvidersMap(Map<Long, String> mobileProvidersMap) {
232
        HomeController.mobileProvidersMap = mobileProvidersMap;
233
    }
234
 
235
    public static Map<Long, String> getMobileProvidersMap() {
236
        return mobileProvidersMap;
237
    }
7096 anupam.sin 238
 
239
    public Long getStoreId() {
240
        return storeId;
241
    }
242
 
243
    public void setStoreId(Long storeId) {
244
        this.storeId = storeId;
245
    }
246
 
7125 amit.gupta 247
    public String getStoreCircleCode() {
248
    	return (String)(request.getSession().getAttribute("STORE_CIRCLE_CODE"));
249
    }
250
 
7096 anupam.sin 251
    public String getRedirectUrl() {
252
        return redirectUrl;
253
    }
254
 
255
    public void setRedirectUrl(String redirectUrl) {
256
        this.redirectUrl = redirectUrl;
257
    }
7113 rajveer 258
 
259
    public String getStoreCode(){
260
    	return hotspotStores.get(storeId).getHotspotId();	
261
    }
262
 
263
    public String getCollectedAmount(){
264
    	return hotspotStores.get(storeId).getCollectedAmount()+"";
265
    }
266
 
7068 anupam.sin 267
}