Subversion Repositories SmartDukaan

Rev

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