Subversion Repositories SmartDukaan

Rev

Rev 7068 | Rev 7096 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7068 Rev 7073
Line 5... Line 5...
5
import in.shop2020.model.v1.order.RechargeDenomination;
5
import in.shop2020.model.v1.order.RechargeDenomination;
6
import in.shop2020.model.v1.order.RechargePlan;
6
import in.shop2020.model.v1.order.RechargePlan;
7
import in.shop2020.model.v1.order.RechargeType;
7
import in.shop2020.model.v1.order.RechargeType;
8
import in.shop2020.thrift.clients.TransactionClient;
8
import in.shop2020.thrift.clients.TransactionClient;
9
 
9
 
-
 
10
import java.util.HashMap;
10
import java.util.List;
11
import java.util.List;
11
import java.util.Map;
12
import java.util.Map;
12
 
13
 
13
import org.apache.log4j.Logger;
14
import org.apache.log4j.Logger;
14
import org.apache.struts2.convention.annotation.Action;
15
import org.apache.struts2.convention.annotation.Action;
Line 16... Line 17...
16
public class HomeController extends BaseController {
17
public class HomeController extends BaseController {
17
    
18
    
18
    /**
19
    /**
19
     * 
20
     * 
20
     */
21
     */
21
    private String serviceType = null; //Default is Mobile , 2 is for DTH
22
    private String deviceType = null; //Default is Mobile , 2 is for DTH
22
    private String deviceNumber = "";
23
    private String deviceNumber = "";
23
    private String form = "";
24
    private String form = "";
24
    private String error = "";
25
    private String error = "";
25
    private String operatorId;
26
    private String operatorId;
26
    private String operatorName;
27
    private String operatorName;
Line 32... Line 33...
32
 
33
 
33
    private static Logger log = Logger.getLogger(Class.class);
34
    private static Logger log = Logger.getLogger(Class.class);
34
    private static Map<Long, String> mobileProvidersMap;
35
    private static Map<Long, String> mobileProvidersMap;
35
    private static Map<Long, String> dthProvidersMap;
36
    private static Map<Long, String> dthProvidersMap;
36
    private static Map<Long, List<RechargePlan>> operatorPlanMap;
37
    private static Map<Long, List<RechargePlan>> operatorPlanMap;
37
    private static String errorMsg;
38
    private static String errorMsg = "";
38
    
39
    
39
    
40
    
40
    static {
41
    static {
-
 
42
        TransactionClient tcl;
-
 
43
        try {
-
 
44
            operatorPlanMap = new HashMap<Long, List<RechargePlan>>();
41
        System.out.println("Static Method");
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
        }
42
    }
57
    }
43
    
58
    
44
    
59
    
45
    @Action("/")
60
    @Action("/")
46
    public String index() {
61
    public String index() {
Line 51... Line 66...
51
//        log.info("Uri: " + uri);
66
//        log.info("Uri: " + uri);
52
//        Map<String, String> valueMap = Utils.getOperatorByUri(uri);
67
//        Map<String, String> valueMap = Utils.getOperatorByUri(uri);
53
//        operatorId  = valueMap.get("Id");
68
//        operatorId  = valueMap.get("Id");
54
//        operatorName = valueMap.get("Name"); 
69
//        operatorName = valueMap.get("Name"); 
55
//        serviceName  = valueMap.get("ServiceName");
70
//        serviceName  = valueMap.get("ServiceName");
56
//        if(serviceType == null){
71
//        if(deviceType == null){
57
//            serviceType  = valueMap.get("ServiceType");
72
//            deviceType  = valueMap.get("deviceType");
58
//        }
73
//        }
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
        }
74
        
73
        return "index";
75
        return "index";
74
    }
76
    }
75
    
77
    
76
    public String create() {
78
    public String create() {
77
        return index();
79
        return index();
78
    }
80
    }
79
    
81
    
80
//    public Map<Long, String> getProviderMap() {
82
//    public Map<Long, String> getProviderMap() {
81
//        if(serviceType.equals("1"))
83
//        if(deviceType.equals("1"))
82
//            providers = Utils.getMobileProvidersMap();
84
//            providers = Utils.getMobileProvidersMap();
83
//        else
85
//        else
84
//            providers = Utils.getDthProvidersMap();
86
//            providers = Utils.getDthProvidersMap();
85
//        return providers;
87
//        return providers;
86
//    }
88
//    }
Line 91... Line 93...
91
    
93
    
92
    public String getProvider(){
94
    public String getProvider(){
93
        TransactionClient tcl;
95
        TransactionClient tcl;
94
        try {
96
        try {
95
            tcl = new TransactionClient();
97
            tcl = new TransactionClient();
96
            DeviceNumberInfo deviceInfo =  tcl.getClient().getServiceProviderForDevice(RechargeType.findByValue(Integer.parseInt(this.serviceType)), deviceNumber);
98
            DeviceNumberInfo deviceInfo =  tcl.getClient().getServiceProviderForDevice(RechargeType.findByValue(Integer.parseInt(this.deviceType)), deviceNumber);
97
            return deviceInfo.getOperatorId() + ":" + deviceInfo.getCircleCode();
99
            return deviceInfo.getOperatorId() + ":" + deviceInfo.getCircleCode();
98
        } catch (Exception e) {
100
        } catch (Exception e) {
99
            log.error("Unable to get service provider for Device number " + deviceNumber + " and rechargeType : " +  serviceType, e);
101
            log.error("Unable to get service provider for Device number " + deviceNumber + " and rechargeType : " +  deviceType, e);
100
            return ":";
102
            return ":";
101
        }
103
        }
102
    }
104
    }
103
    
105
    
104
    public String getAllDenominations() {
106
    public String getAllDenominations() {
Line 119... Line 121...
119
//    public String getPlanMapInJson() {
121
//    public String getPlanMapInJson() {
120
//        Gson gson = new Gson();
122
//        Gson gson = new Gson();
121
//            return (gson.toJson(Utils.getOperatorPlanMap()));
123
//            return (gson.toJson(Utils.getOperatorPlanMap()));
122
//    }
124
//    }
123
 
125
 
124
    public void setServiceType(String incomingServiceType) {
126
    public void setDeviceType(String incomingdeviceType) {
125
        serviceType = incomingServiceType;
127
        deviceType = incomingdeviceType;
126
    }
128
    }
127
    
129
    
128
    public void setDeviceNumber(String deviceNumber){
130
    public void setDeviceNumber(String deviceNumber){
129
        this.deviceNumber = deviceNumber;
131
        this.deviceNumber = deviceNumber;
130
    }
132
    }
131
 
133
 
132
    public String getServiceType() {
134
    public String getDeviceType() {
133
        return serviceType;
135
        return deviceType;
134
    }
136
    }
135
 
137
 
136
    public String getForm() {
138
    public String getForm() {
137
        return form;
139
        return form;
138
    }
140
    }