Subversion Repositories SmartDukaan

Rev

Rev 7068 | Rev 7096 | 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.DenominationType;
4
import in.shop2020.model.v1.order.DeviceNumberInfo;
5
import in.shop2020.model.v1.order.RechargeDenomination;
6
import in.shop2020.model.v1.order.RechargePlan;
7
import in.shop2020.model.v1.order.RechargeType;
8
import in.shop2020.thrift.clients.TransactionClient;
9
 
7073 anupam.sin 10
import java.util.HashMap;
7068 anupam.sin 11
import java.util.List;
12
import java.util.Map;
13
 
14
import org.apache.log4j.Logger;
15
import org.apache.struts2.convention.annotation.Action;
16
 
17
public class HomeController extends BaseController {
18
 
19
    /**
20
     * 
21
     */
7073 anupam.sin 22
    private String deviceType = null; //Default is Mobile , 2 is for DTH
7068 anupam.sin 23
    private String deviceNumber = "";
24
    private String form = "";
25
    private String error = "";
26
    private String operatorId;
27
    private String operatorName;
28
    private String serviceName;
29
    private String denominationType;
30
    private String circleCode;
31
    private List<RechargeDenomination> rechargeDenominations = null;
32
    private static final long serialVersionUID = 2079308723099307749L;
33
 
34
    private static Logger log = Logger.getLogger(Class.class);
35
    private static Map<Long, String> mobileProvidersMap;
36
    private static Map<Long, String> dthProvidersMap;
37
    private static Map<Long, List<RechargePlan>> operatorPlanMap;
7073 anupam.sin 38
    private static String errorMsg = "";
7068 anupam.sin 39
 
40
 
41
    static {
7073 anupam.sin 42
        TransactionClient tcl;
43
        try {
44
            operatorPlanMap = new HashMap<Long, List<RechargePlan>>();
45
            tcl = new TransactionClient();
46
            mobileProvidersMap = tcl.getClient().getServiceProviders(RechargeType.MOBILE, true);
47
            setDthProvidersMap(tcl.getClient().getServiceProviders(RechargeType.DTH, true));
48
            for (Long operatorId : mobileProvidersMap.keySet()) {
49
                List<RechargePlan> plans = tcl.getClient().getPlansForOperator(operatorId);
50
                if (!plans.isEmpty()) {
51
                    operatorPlanMap.put(operatorId, plans);
52
                }
53
            }
54
        } catch(Exception e) {
55
            setErrorMsg("There seems to be some problem. Please try again.");
56
        }
7068 anupam.sin 57
    }
58
 
59
 
60
    @Action("/")
61
    public String index() {
62
        System.out.println("Index method");
63
 
64
//        uri = request.getRequestURI();
65
//        uri = uri.replace("/", "");
66
//        log.info("Uri: " + uri);
67
//        Map<String, String> valueMap = Utils.getOperatorByUri(uri);
68
//        operatorId  = valueMap.get("Id");
69
//        operatorName = valueMap.get("Name"); 
70
//        serviceName  = valueMap.get("ServiceName");
7073 anupam.sin 71
//        if(deviceType == null){
72
//            deviceType  = valueMap.get("deviceType");
7068 anupam.sin 73
//        }
7073 anupam.sin 74
 
7068 anupam.sin 75
        return "index";
76
    }
77
 
78
    public String create() {
79
        return index();
80
    }
81
 
82
//    public Map<Long, String> getProviderMap() {
7073 anupam.sin 83
//        if(deviceType.equals("1"))
7068 anupam.sin 84
//            providers = Utils.getMobileProvidersMap();
85
//        else
86
//            providers = Utils.getDthProvidersMap();
87
//        return providers;
88
//    }
89
//    
90
    public String getServiceProvider() {
91
        return "service-provider";
92
    }
93
 
94
    public String getProvider(){
95
        TransactionClient tcl;
96
        try {
97
            tcl = new TransactionClient();
7073 anupam.sin 98
            DeviceNumberInfo deviceInfo =  tcl.getClient().getServiceProviderForDevice(RechargeType.findByValue(Integer.parseInt(this.deviceType)), deviceNumber);
7068 anupam.sin 99
            return deviceInfo.getOperatorId() + ":" + deviceInfo.getCircleCode();
100
        } catch (Exception e) {
7073 anupam.sin 101
            log.error("Unable to get service provider for Device number " + deviceNumber + " and rechargeType : " +  deviceType, e);
7068 anupam.sin 102
            return ":";
103
        }
104
    }
105
 
106
    public String getAllDenominations() {
107
        TransactionClient tcl;
108
        try {
109
            tcl = new TransactionClient();
110
            rechargeDenominations =  tcl.getClient().getRechargeDenominations(Long.parseLong(operatorId), circleCode, DenominationType.findByValue(Integer.parseInt(denominationType)));
111
            if(rechargeDenominations == null || rechargeDenominations.isEmpty()) {
112
                setError("This information is unavailable for now.<br>You can recharge with the amount you normally use or you can try later.");
113
            }
114
        } catch (Exception e) {
115
            log.error("Unable to get rechargeDenominations for operatorId " + operatorId + " and circleCode : " +  circleCode + " and DenominationType : " + denominationType, e);
116
            setError("This information is unavailable for now.<br>You can recharge with the amount you normally use or you can try later.");
117
        }
118
        return "recharge-denomination";
119
    }
120
 
121
//    public String getPlanMapInJson() {
122
//        Gson gson = new Gson();
123
//            return (gson.toJson(Utils.getOperatorPlanMap()));
124
//    }
125
 
7073 anupam.sin 126
    public void setDeviceType(String incomingdeviceType) {
127
        deviceType = incomingdeviceType;
7068 anupam.sin 128
    }
129
 
130
    public void setDeviceNumber(String deviceNumber){
131
        this.deviceNumber = deviceNumber;
132
    }
133
 
7073 anupam.sin 134
    public String getDeviceType() {
135
        return deviceType;
7068 anupam.sin 136
    }
137
 
138
    public String getForm() {
139
        return form;
140
    }
141
 
142
    public void setForm(String form) {
143
        this.form = form;
144
    }
145
 
146
    public String getError() {
147
        return error;
148
    }
149
 
150
    public void setError(String error) {
151
        this.error = error;
152
    }
153
 
154
    public String getPageName() {
155
        return operatorName  + " online recharge";
156
    }
157
 
158
    public String getPageTitle() {
159
        return operatorName  + " online recharge";
160
    }
161
 
162
    public String getPageMetaDesc() {
163
        return "Recharge your " + this.operatorName +  " " + this.serviceName +  " online for all cities using Credit/Debit card & net banking. Fast, Secure and Hassle Free Recharge";
164
    }
165
 
166
    public String getPageMetaKeywords() {
167
        return "mobile, recharge";
168
    }
169
 
170
    public long getOperatorId(){
171
        return Long.parseLong(this.operatorId);
172
    }
173
 
174
    public String getDenominationType() {
175
        return denominationType;
176
    }
177
 
178
    public void setDenominationType(String denominationType) {
179
        this.denominationType = denominationType;
180
    }
181
 
182
    public String getCircleCode() {
183
        return circleCode;
184
    }
185
 
186
    public void setCircleCode(String circleCode) {
187
        this.circleCode = circleCode;
188
    }
189
 
190
    public List<RechargeDenomination> getRechargeDenominations() {
191
        return rechargeDenominations;
192
    }
193
 
194
    public void setRechargeDenominations(
195
            List<RechargeDenomination> rechargeDenominations) {
196
        this.rechargeDenominations = rechargeDenominations;
197
    }
198
 
199
    public void setOperatorId(String operatorId) {
200
        this.operatorId = operatorId;
201
    }
202
 
203
    public static void setErrorMsg(String errorMsg) {
204
        HomeController.errorMsg = errorMsg;
205
    }
206
 
207
    public static String getErrorMsg() {
208
        return errorMsg;
209
    }
210
 
211
    public static void setDthProvidersMap(Map<Long, String> dthProvidersMap) {
212
        HomeController.dthProvidersMap = dthProvidersMap;
213
    }
214
 
215
    public static Map<Long, String> getDthProvidersMap() {
216
        return dthProvidersMap;
217
    }
218
 
219
    public static void setMobileProvidersMap(Map<Long, String> mobileProvidersMap) {
220
        HomeController.mobileProvidersMap = mobileProvidersMap;
221
    }
222
 
223
    public static Map<Long, String> getMobileProvidersMap() {
224
        return mobileProvidersMap;
225
    }
226
}