Subversion Repositories SmartDukaan

Rev

Rev 6199 | Rev 6201 | 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 Map<Long, String> providers;
6103 amit.gupta 23
    private String error = "";
6050 anupam.sin 24
 
25
    private static final long serialVersionUID = 2079308723099307749L;
26
 
27
    private static Logger log = Logger.getLogger(Class.class);
28
 
6057 anupam.sin 29
 
6050 anupam.sin 30
    public String index() {
6103 amit.gupta 31
    	if(error.equals("ServiceDown")){
6174 rajveer 32
    		error = "Oops! There seems to be a problem. Please try after some time";
6103 amit.gupta 33
    	}else{
34
    		error = "";
35
    	}
6050 anupam.sin 36
        return "index";
37
    }
38
 
39
    public String create() {
40
        if(form.equals("serviceSelect")) {
41
            return index();
42
        }
43
        return "hello";
44
    }
6057 anupam.sin 45
 
46
    public Map<Long, String> getProviderMap() {
47
        TransactionClient tc;
48
        try {
6178 anupam.sin 49
            if(serviceType.equals("1"))
50
                providers = Utils.getMobileProvidersMap();
51
            else
52
                providers = Utils.getDthProvidersMap();
6057 anupam.sin 53
            setProviderKeys(providers.keySet());
54
        } catch (Exception e) {
55
            log.error("Cannot get providers", e);
56
        }
57
        return providers;
58
    }
6100 anupam.sin 59
 
6103 amit.gupta 60
    public String getServiceProvider() {
61
    	return "service-provider";
6100 anupam.sin 62
    }
6103 amit.gupta 63
 
64
    public String getProvider(){
65
    	TransactionClient tcl;
66
    	try {
67
    		tcl = new TransactionClient();
68
    		return tcl.getClient().getServiceProviderForDevice(RechargeType.findByValue(Integer.parseInt(this.serviceType)), deviceNumber) + "";
69
    	} catch (Exception e) {
70
    		log.error("Unable to get service provider for Device number " + deviceNumber + " and rechargeType : " +  serviceType, e);
71
    	}
72
    	return 0 + "";
73
    }
6178 anupam.sin 74
 
75
    public String getPlanMapInJson() {
76
        Gson gson = new Gson();
77
            return (gson.toJson(Utils.getOperatorPlanMap()));
78
    }
6050 anupam.sin 79
 
6057 anupam.sin 80
    public void setServiceType(String incomingServiceType) {
81
        serviceType = incomingServiceType;
82
    }
6103 amit.gupta 83
 
84
    public void setDeviceNumber(String deviceNumber){
85
    	this.deviceNumber = deviceNumber;
86
    }
6057 anupam.sin 87
 
6050 anupam.sin 88
    public String getServiceType() {
89
        return serviceType;
90
    }
91
 
92
    public String getForm() {
93
        return form;
94
    }
95
 
96
    public void setForm(String form) {
97
        this.form = form;
98
    }
6103 amit.gupta 99
 
100
	public String getError() {
101
		return error;
102
	}
103
 
104
	public void setError(String error) {
105
		this.error = error;
106
	}
107
 
6050 anupam.sin 108
}