Subversion Repositories SmartDukaan

Rev

Rev 7125 | 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
 
7207 anupam.sin 42
 
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;
7096 anupam.sin 47
    private String errorMsg = "";
48
    private String redirectUrl;
7068 anupam.sin 49
 
50
 
51
    static {
7073 anupam.sin 52
        TransactionClient tcl;
53
        try {
54
            operatorPlanMap = new HashMap<Long, List<RechargePlan>>();
55
            tcl = new TransactionClient();
56
            mobileProvidersMap = tcl.getClient().getServiceProviders(RechargeType.MOBILE, true);
57
            setDthProvidersMap(tcl.getClient().getServiceProviders(RechargeType.DTH, true));
58
            for (Long operatorId : mobileProvidersMap.keySet()) {
59
                List<RechargePlan> plans = tcl.getClient().getPlansForOperator(operatorId);
60
                if (!plans.isEmpty()) {
61
                    operatorPlanMap.put(operatorId, plans);
62
                }
63
            }
64
        } catch(Exception e) {
7096 anupam.sin 65
            ;
7073 anupam.sin 66
        }
7068 anupam.sin 67
    }
68
 
7096 anupam.sin 69
    public String getPlanMapInJson() {
70
        Gson gson = new Gson();
71
            return (gson.toJson(operatorPlanMap));
72
    }
7068 anupam.sin 73
 
74
    public String index() {
75
 
7096 anupam.sin 76
        String loginStatus = (String) request.getSession().getAttribute("LOGGED_IN");
77
        if(loginStatus != null && loginStatus.equals("TRUE")){
7115 rajveer 78
        	storeId = Long.parseLong((String) request.getSession().getAttribute("STORE_ID"));
7113 rajveer 79
        	if(!hotspotStores.containsKey(storeId)){
7114 rajveer 80
        		try{
81
        			HotspotStore hotSpotStore = (new TransactionClient()).getClient().getHotspotStore(storeId, "");
82
        			hotspotStores.put(storeId, hotSpotStore);
83
        		} catch (Exception e) {
84
                    log.error("Unable to get store", e);
85
                }
7113 rajveer 86
        	}
7096 anupam.sin 87
            return "index";
88
        }
89
        return "authfail";
7068 anupam.sin 90
    }
91
 
92
    public String create() {
93
        return index();
94
    }
95
 
96
//    public Map<Long, String> getProviderMap() {
7073 anupam.sin 97
//        if(deviceType.equals("1"))
7068 anupam.sin 98
//            providers = Utils.getMobileProvidersMap();
99
//        else
100
//            providers = Utils.getDthProvidersMap();
101
//        return providers;
102
//    }
103
//    
104
    public String getServiceProvider() {
105
        return "service-provider";
106
    }
7125 amit.gupta 107
 
108
    public String getFRC() {
109
    	return "frc-result";
110
    }
7068 anupam.sin 111
 
7125 amit.gupta 112
    public String getFRCJSONString(){
113
    	long circleId = Long.parseLong((String)(request.getSession().getAttribute("CIRCLE_ID")));
114
    	TransactionClient tcl;
115
        try {
116
            tcl = new TransactionClient();
117
            List<FRC> frcList =  tcl.getClient().getFRCs(circleId, Long.parseLong(operatorId));
118
            return new Gson().toJson(frcList);
119
        } catch (Exception e) {
120
            log.error("Unable to get service provider for Device number " + deviceNumber + " and rechargeType : " +  deviceType, e);
121
            return "";
122
        }
123
    }
124
 
7068 anupam.sin 125
    public String getProvider(){
126
        TransactionClient tcl;
127
        try {
128
            tcl = new TransactionClient();
7073 anupam.sin 129
            DeviceNumberInfo deviceInfo =  tcl.getClient().getServiceProviderForDevice(RechargeType.findByValue(Integer.parseInt(this.deviceType)), deviceNumber);
7068 anupam.sin 130
            return deviceInfo.getOperatorId() + ":" + deviceInfo.getCircleCode();
131
        } catch (Exception e) {
7073 anupam.sin 132
            log.error("Unable to get service provider for Device number " + deviceNumber + " and rechargeType : " +  deviceType, e);
7068 anupam.sin 133
            return ":";
134
        }
135
    }
136
 
7073 anupam.sin 137
    public void setDeviceType(String incomingdeviceType) {
138
        deviceType = incomingdeviceType;
7068 anupam.sin 139
    }
140
 
141
    public void setDeviceNumber(String deviceNumber){
142
        this.deviceNumber = deviceNumber;
143
    }
144
 
7073 anupam.sin 145
    public String getDeviceType() {
146
        return deviceType;
7068 anupam.sin 147
    }
148
 
149
    public String getForm() {
150
        return form;
151
    }
152
 
153
    public void setForm(String form) {
154
        this.form = form;
155
    }
156
 
157
    public String getError() {
158
        return error;
159
    }
160
 
161
    public void setError(String error) {
162
        this.error = error;
163
    }
164
 
165
    public String getPageName() {
166
        return operatorName  + " online recharge";
167
    }
168
 
169
    public String getPageTitle() {
170
        return operatorName  + " online recharge";
171
    }
172
 
173
    public String getPageMetaDesc() {
174
        return "Recharge your " + this.operatorName +  " " + this.serviceName +  " online for all cities using Credit/Debit card & net banking. Fast, Secure and Hassle Free Recharge";
175
    }
176
 
177
    public String getPageMetaKeywords() {
178
        return "mobile, recharge";
179
    }
180
 
181
    public long getOperatorId(){
182
        return Long.parseLong(this.operatorId);
183
    }
184
 
185
    public String getDenominationType() {
186
        return denominationType;
187
    }
188
 
189
    public void setDenominationType(String denominationType) {
190
        this.denominationType = denominationType;
191
    }
192
 
7096 anupam.sin 193
    public String getCirclecode() {
194
        return circlecode;
7068 anupam.sin 195
    }
196
 
7096 anupam.sin 197
    public void setCircleCode(String circlecode) {
198
        this.circlecode = circlecode;
7068 anupam.sin 199
    }
200
 
201
    public List<RechargeDenomination> getRechargeDenominations() {
202
        return rechargeDenominations;
203
    }
204
 
205
    public void setRechargeDenominations(
206
            List<RechargeDenomination> rechargeDenominations) {
207
        this.rechargeDenominations = rechargeDenominations;
208
    }
209
 
210
    public void setOperatorId(String operatorId) {
211
        this.operatorId = operatorId;
212
    }
213
 
7096 anupam.sin 214
    public void setErrorMsg(String errorMsg) {
215
        this.errorMsg = errorMsg;
7068 anupam.sin 216
    }
217
 
7096 anupam.sin 218
    public String getErrorMsg() {
7068 anupam.sin 219
        return errorMsg;
220
    }
221
 
222
    public static void setDthProvidersMap(Map<Long, String> dthProvidersMap) {
223
        HomeController.dthProvidersMap = dthProvidersMap;
224
    }
225
 
226
    public static Map<Long, String> getDthProvidersMap() {
227
        return dthProvidersMap;
228
    }
229
 
230
    public static void setMobileProvidersMap(Map<Long, String> mobileProvidersMap) {
231
        HomeController.mobileProvidersMap = mobileProvidersMap;
232
    }
233
 
234
    public static Map<Long, String> getMobileProvidersMap() {
235
        return mobileProvidersMap;
236
    }
7096 anupam.sin 237
 
7125 amit.gupta 238
    public String getStoreCircleCode() {
239
    	return (String)(request.getSession().getAttribute("STORE_CIRCLE_CODE"));
240
    }
241
 
7096 anupam.sin 242
    public String getRedirectUrl() {
243
        return redirectUrl;
244
    }
245
 
246
    public void setRedirectUrl(String redirectUrl) {
247
        this.redirectUrl = redirectUrl;
248
    }
7068 anupam.sin 249
}