Subversion Repositories SmartDukaan

Rev

Rev 7073 | Go to most recent revision | Details | 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
 
10
import java.util.List;
11
import java.util.Map;
12
 
13
import org.apache.log4j.Logger;
14
import org.apache.struts2.convention.annotation.Action;
15
 
16
public class HomeController extends BaseController {
17
 
18
    /**
19
     * 
20
     */
21
    private String serviceType = null; //Default is Mobile , 2 is for DTH
22
    private String deviceNumber = "";
23
    private String form = "";
24
    private String error = "";
25
    private String operatorId;
26
    private String operatorName;
27
    private String serviceName;
28
    private String denominationType;
29
    private String circleCode;
30
    private List<RechargeDenomination> rechargeDenominations = null;
31
    private static final long serialVersionUID = 2079308723099307749L;
32
 
33
    private static Logger log = Logger.getLogger(Class.class);
34
    private static Map<Long, String> mobileProvidersMap;
35
    private static Map<Long, String> dthProvidersMap;
36
    private static Map<Long, List<RechargePlan>> operatorPlanMap;
37
    private static String errorMsg;
38
 
39
 
40
    static {
41
        System.out.println("Static Method");
42
    }
43
 
44
 
45
    @Action("/")
46
    public String index() {
47
        System.out.println("Index method");
48
 
49
//        uri = request.getRequestURI();
50
//        uri = uri.replace("/", "");
51
//        log.info("Uri: " + uri);
52
//        Map<String, String> valueMap = Utils.getOperatorByUri(uri);
53
//        operatorId  = valueMap.get("Id");
54
//        operatorName = valueMap.get("Name"); 
55
//        serviceName  = valueMap.get("ServiceName");
56
//        if(serviceType == null){
57
//            serviceType  = valueMap.get("ServiceType");
58
//        }
59
        TransactionClient tcl;
60
        try {
61
            tcl = new TransactionClient();
62
            mobileProvidersMap = tcl.getClient().getServiceProviders(RechargeType.MOBILE, true);
63
            setDthProvidersMap(tcl.getClient().getServiceProviders(RechargeType.DTH, true));
64
            for (Long operatorId : mobileProvidersMap.keySet()) {
65
                List<RechargePlan> plans = tcl.getClient().getPlansForOperator(operatorId);
66
                if (!plans.isEmpty()) {
67
                    operatorPlanMap.put(operatorId, plans);
68
                }
69
            }
70
        } catch(Exception e) {
71
            setErrorMsg("There seems to be some problem. Please try again.");
72
        }
73
        return "index";
74
    }
75
 
76
    public String create() {
77
        return index();
78
    }
79
 
80
//    public Map<Long, String> getProviderMap() {
81
//        if(serviceType.equals("1"))
82
//            providers = Utils.getMobileProvidersMap();
83
//        else
84
//            providers = Utils.getDthProvidersMap();
85
//        return providers;
86
//    }
87
//    
88
    public String getServiceProvider() {
89
        return "service-provider";
90
    }
91
 
92
    public String getProvider(){
93
        TransactionClient tcl;
94
        try {
95
            tcl = new TransactionClient();
96
            DeviceNumberInfo deviceInfo =  tcl.getClient().getServiceProviderForDevice(RechargeType.findByValue(Integer.parseInt(this.serviceType)), deviceNumber);
97
            return deviceInfo.getOperatorId() + ":" + deviceInfo.getCircleCode();
98
        } catch (Exception e) {
99
            log.error("Unable to get service provider for Device number " + deviceNumber + " and rechargeType : " +  serviceType, e);
100
            return ":";
101
        }
102
    }
103
 
104
    public String getAllDenominations() {
105
        TransactionClient tcl;
106
        try {
107
            tcl = new TransactionClient();
108
            rechargeDenominations =  tcl.getClient().getRechargeDenominations(Long.parseLong(operatorId), circleCode, DenominationType.findByValue(Integer.parseInt(denominationType)));
109
            if(rechargeDenominations == null || rechargeDenominations.isEmpty()) {
110
                setError("This information is unavailable for now.<br>You can recharge with the amount you normally use or you can try later.");
111
            }
112
        } catch (Exception e) {
113
            log.error("Unable to get rechargeDenominations for operatorId " + operatorId + " and circleCode : " +  circleCode + " and DenominationType : " + denominationType, e);
114
            setError("This information is unavailable for now.<br>You can recharge with the amount you normally use or you can try later.");
115
        }
116
        return "recharge-denomination";
117
    }
118
 
119
//    public String getPlanMapInJson() {
120
//        Gson gson = new Gson();
121
//            return (gson.toJson(Utils.getOperatorPlanMap()));
122
//    }
123
 
124
    public void setServiceType(String incomingServiceType) {
125
        serviceType = incomingServiceType;
126
    }
127
 
128
    public void setDeviceNumber(String deviceNumber){
129
        this.deviceNumber = deviceNumber;
130
    }
131
 
132
    public String getServiceType() {
133
        return serviceType;
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
 
180
    public String getCircleCode() {
181
        return circleCode;
182
    }
183
 
184
    public void setCircleCode(String circleCode) {
185
        this.circleCode = circleCode;
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
 
201
    public static void setErrorMsg(String errorMsg) {
202
        HomeController.errorMsg = errorMsg;
203
    }
204
 
205
    public static String getErrorMsg() {
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
    }
224
}