Subversion Repositories SmartDukaan

Rev

Rev 6174 | Rev 6199 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6050 anupam.sin 1
package in.shop2020.serving.controllers;
2
 
6066 amit.gupta 3
import in.shop2020.model.v1.order.RechargeType;
6178 anupam.sin 4
import in.shop2020.serving.utils.Utils;
6066 amit.gupta 5
import in.shop2020.thrift.clients.TransactionClient;
6
 
6050 anupam.sin 7
import java.util.Map;
6057 anupam.sin 8
import java.util.Set;
6050 anupam.sin 9
 
10
import org.apache.log4j.Logger;
11
 
6178 anupam.sin 12
import com.google.gson.Gson;
13
 
6050 anupam.sin 14
public class RechargeController extends BaseController {
15
 
16
    /**
17
     * 
18
     */
6178 anupam.sin 19
    private String serviceType = "1"; //Default is Mobile , 2 is for DTH
6103 amit.gupta 20
    private String deviceNumber = "";
6050 anupam.sin 21
    private String form = "";
6057 anupam.sin 22
    private Set<Long> providerKeys;
23
    private Map<Long, String> providers;
6103 amit.gupta 24
    private String error = "";
6050 anupam.sin 25
 
26
    private static final long serialVersionUID = 2079308723099307749L;
27
 
28
    private static Logger log = Logger.getLogger(Class.class);
29
 
6057 anupam.sin 30
 
31
/*    static{
32
        TransactionClient tc;
33
        try {
34
            tc = new TransactionClient();
35
            providers = tc.getClient().getServiceProviders(RechargeType.valueOf(serviceType));
36
        } catch (Exception e) {
37
            log.error("Cannot get providers");
38
        }
39
        setProviderKeys(providers.keySet());
40
    }*/
41
 
6050 anupam.sin 42
    public String index() {
6103 amit.gupta 43
    	if(error.equals("ServiceDown")){
6174 rajveer 44
    		error = "Oops! There seems to be a problem. Please try after some time";
6103 amit.gupta 45
    	}else{
46
    		error = "";
47
    	}
6050 anupam.sin 48
        return "index";
49
    }
50
 
51
    public String create() {
52
        if(form.equals("serviceSelect")) {
53
            return index();
54
        }
55
        return "hello";
56
    }
6057 anupam.sin 57
 
58
    public Map<Long, String> getProviderMap() {
59
        TransactionClient tc;
60
        try {
6178 anupam.sin 61
            if(serviceType.equals("1"))
62
                providers = Utils.getMobileProvidersMap();
63
            else
64
                providers = Utils.getDthProvidersMap();
6057 anupam.sin 65
            setProviderKeys(providers.keySet());
66
        } catch (Exception e) {
67
            log.error("Cannot get providers", e);
68
        }
69
        return providers;
70
    }
6100 anupam.sin 71
 
6103 amit.gupta 72
    public String getServiceProvider() {
73
    	return "service-provider";
6100 anupam.sin 74
    }
6103 amit.gupta 75
 
76
    public String getProvider(){
77
    	TransactionClient tcl;
78
    	try {
79
    		tcl = new TransactionClient();
80
    		return tcl.getClient().getServiceProviderForDevice(RechargeType.findByValue(Integer.parseInt(this.serviceType)), deviceNumber) + "";
81
    	} catch (Exception e) {
82
    		log.error("Unable to get service provider for Device number " + deviceNumber + " and rechargeType : " +  serviceType, e);
83
    	}
84
    	return 0 + "";
85
    }
6178 anupam.sin 86
 
87
    public String getPlanMapInJson() {
88
        Gson gson = new Gson();
89
            return (gson.toJson(Utils.getOperatorPlanMap()));
90
    }
6050 anupam.sin 91
 
6057 anupam.sin 92
    private void setProviderKeys(Set<Long> keySet) {
93
        this.providerKeys = keySet;
6050 anupam.sin 94
    }
6057 anupam.sin 95
 
96
    public Set<Long> getProviderKeys() {
97
        System.out.println("6");
98
        return providerKeys;
99
    }
6050 anupam.sin 100
 
6057 anupam.sin 101
    public void setServiceType(String incomingServiceType) {
102
        serviceType = incomingServiceType;
103
    }
6103 amit.gupta 104
 
105
    public void setDeviceNumber(String deviceNumber){
106
    	this.deviceNumber = deviceNumber;
107
    }
6057 anupam.sin 108
 
6050 anupam.sin 109
    public String getServiceType() {
110
        return serviceType;
111
    }
112
 
113
    public String getForm() {
114
        return form;
115
    }
116
 
117
    public void setForm(String form) {
118
        this.form = form;
119
    }
6103 amit.gupta 120
 
121
	public String getError() {
122
		return error;
123
	}
124
 
125
	public void setError(String error) {
126
		this.error = error;
127
	}
128
 
6050 anupam.sin 129
}