Subversion Repositories SmartDukaan

Rev

Rev 7096 | Rev 7114 | 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;
7113 rajveer 50
    private 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")){
7113 rajveer 82
        	storeId = Long.parseLong((String) request.getSession().getAttribute("storeid"));
83
        	if(!hotspotStores.containsKey(storeId)){
84
        		HotspotStore hotSpotStore = (new TransactionClient()).getClient().getHotspotStore(storeId, "");
85
        		hotspotStores.put(storeId, hotSpotStore);
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
    }
107
 
108
    public String getProvider(){
109
        TransactionClient tcl;
110
        try {
111
            tcl = new TransactionClient();
7073 anupam.sin 112
            DeviceNumberInfo deviceInfo =  tcl.getClient().getServiceProviderForDevice(RechargeType.findByValue(Integer.parseInt(this.deviceType)), deviceNumber);
7068 anupam.sin 113
            return deviceInfo.getOperatorId() + ":" + deviceInfo.getCircleCode();
114
        } catch (Exception e) {
7073 anupam.sin 115
            log.error("Unable to get service provider for Device number " + deviceNumber + " and rechargeType : " +  deviceType, e);
7068 anupam.sin 116
            return ":";
117
        }
118
    }
119
 
7073 anupam.sin 120
    public void setDeviceType(String incomingdeviceType) {
121
        deviceType = incomingdeviceType;
7068 anupam.sin 122
    }
123
 
124
    public void setDeviceNumber(String deviceNumber){
125
        this.deviceNumber = deviceNumber;
126
    }
127
 
7073 anupam.sin 128
    public String getDeviceType() {
129
        return deviceType;
7068 anupam.sin 130
    }
131
 
132
    public String getForm() {
133
        return form;
134
    }
135
 
136
    public void setForm(String form) {
137
        this.form = form;
138
    }
139
 
140
    public String getError() {
141
        return error;
142
    }
143
 
144
    public void setError(String error) {
145
        this.error = error;
146
    }
147
 
148
    public String getPageName() {
149
        return operatorName  + " online recharge";
150
    }
151
 
152
    public String getPageTitle() {
153
        return operatorName  + " online recharge";
154
    }
155
 
156
    public String getPageMetaDesc() {
157
        return "Recharge your " + this.operatorName +  " " + this.serviceName +  " online for all cities using Credit/Debit card & net banking. Fast, Secure and Hassle Free Recharge";
158
    }
159
 
160
    public String getPageMetaKeywords() {
161
        return "mobile, recharge";
162
    }
163
 
164
    public long getOperatorId(){
165
        return Long.parseLong(this.operatorId);
166
    }
167
 
168
    public String getDenominationType() {
169
        return denominationType;
170
    }
171
 
172
    public void setDenominationType(String denominationType) {
173
        this.denominationType = denominationType;
174
    }
175
 
7096 anupam.sin 176
    public String getCirclecode() {
177
        return circlecode;
7068 anupam.sin 178
    }
179
 
7096 anupam.sin 180
    public void setCircleCode(String circlecode) {
181
        this.circlecode = circlecode;
7068 anupam.sin 182
    }
183
 
184
    public List<RechargeDenomination> getRechargeDenominations() {
185
        return rechargeDenominations;
186
    }
187
 
188
    public void setRechargeDenominations(
189
            List<RechargeDenomination> rechargeDenominations) {
190
        this.rechargeDenominations = rechargeDenominations;
191
    }
192
 
193
    public void setOperatorId(String operatorId) {
194
        this.operatorId = operatorId;
195
    }
196
 
7096 anupam.sin 197
    public void setErrorMsg(String errorMsg) {
198
        this.errorMsg = errorMsg;
7068 anupam.sin 199
    }
200
 
7096 anupam.sin 201
    public String getErrorMsg() {
7068 anupam.sin 202
        return errorMsg;
203
    }
204
 
205
    public static void setDthProvidersMap(Map<Long, String> dthProvidersMap) {
206
        HomeController.dthProvidersMap = dthProvidersMap;
207
    }
208
 
209
    public static Map<Long, String> getDthProvidersMap() {
210
        return dthProvidersMap;
211
    }
212
 
213
    public static void setMobileProvidersMap(Map<Long, String> mobileProvidersMap) {
214
        HomeController.mobileProvidersMap = mobileProvidersMap;
215
    }
216
 
217
    public static Map<Long, String> getMobileProvidersMap() {
218
        return mobileProvidersMap;
219
    }
7096 anupam.sin 220
 
221
    public Long getStoreId() {
222
        return storeId;
223
    }
224
 
225
    public void setStoreId(Long storeId) {
226
        this.storeId = storeId;
227
    }
228
 
229
    public String getRedirectUrl() {
230
        return redirectUrl;
231
    }
232
 
233
    public void setRedirectUrl(String redirectUrl) {
234
        this.redirectUrl = redirectUrl;
235
    }
7113 rajveer 236
 
237
    public String getStoreCode(){
238
    	return hotspotStores.get(storeId).getHotspotId();	
239
    }
240
 
241
    public String getCollectedAmount(){
242
    	return hotspotStores.get(storeId).getCollectedAmount()+"";
243
    }
244
 
7068 anupam.sin 245
}