Subversion Repositories SmartDukaan

Rev

Rev 6100 | Rev 6124 | 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;
4
import in.shop2020.thrift.clients.TransactionClient;
5
 
6050 anupam.sin 6
import java.util.Map;
6057 anupam.sin 7
import java.util.Set;
6050 anupam.sin 8
 
9
import org.apache.log4j.Logger;
6100 anupam.sin 10
import org.apache.thrift.transport.TTransportException;
6050 anupam.sin 11
 
12
public class RechargeController extends BaseController {
13
 
14
    /**
15
     * 
16
     */
6057 anupam.sin 17
    private String serviceType = "1";
6103 amit.gupta 18
    private String deviceNumber = "";
6050 anupam.sin 19
    private String form = "";
6057 anupam.sin 20
    private Set<Long> providerKeys;
21
    private Map<Long, String> providers;
6103 amit.gupta 22
    private String error = "";
6050 anupam.sin 23
 
24
    private static final long serialVersionUID = 2079308723099307749L;
25
 
26
    private static Logger log = Logger.getLogger(Class.class);
27
 
6057 anupam.sin 28
 
29
/*    static{
30
        TransactionClient tc;
31
        try {
32
            tc = new TransactionClient();
33
            providers = tc.getClient().getServiceProviders(RechargeType.valueOf(serviceType));
34
        } catch (Exception e) {
35
            log.error("Cannot get providers");
36
        }
37
        setProviderKeys(providers.keySet());
38
    }*/
39
 
6050 anupam.sin 40
    public String index() {
6103 amit.gupta 41
    	if(error.equals("ServiceDown")){
42
    		error = "Recharge service is down. Please try after some time";
43
    	}else{
44
    		error = "";
45
    	}
6050 anupam.sin 46
        return "index";
47
    }
48
 
49
    public String create() {
50
        if(form.equals("serviceSelect")) {
51
            return index();
52
        }
53
        return "hello";
54
    }
6057 anupam.sin 55
 
56
    public Map<Long, String> getProviderMap() {
57
        System.out.println("2");
58
        TransactionClient tc;
59
        try {
60
            tc = new TransactionClient();
61
            System.out.println("3");
62
            providers = tc.getClient().getServiceProviders(RechargeType.findByValue(Integer.parseInt(serviceType)));
63
            System.out.println("4");
64
            setProviderKeys(providers.keySet());
65
            System.out.println("5");
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
    }
6050 anupam.sin 86
 
6057 anupam.sin 87
    private void setProviderKeys(Set<Long> keySet) {
88
        this.providerKeys = keySet;
6050 anupam.sin 89
    }
6057 anupam.sin 90
 
91
    public Set<Long> getProviderKeys() {
92
        System.out.println("6");
93
        return providerKeys;
94
    }
6050 anupam.sin 95
 
6057 anupam.sin 96
    public void setServiceType(String incomingServiceType) {
97
        serviceType = incomingServiceType;
98
    }
6103 amit.gupta 99
 
100
    public void setDeviceNumber(String deviceNumber){
101
    	this.deviceNumber = deviceNumber;
102
    }
6057 anupam.sin 103
 
6050 anupam.sin 104
    public String getServiceType() {
105
        return serviceType;
106
    }
107
 
108
    public String getForm() {
109
        return form;
110
    }
111
 
112
    public void setForm(String form) {
113
        this.form = form;
114
    }
6103 amit.gupta 115
 
116
	public String getError() {
117
		return error;
118
	}
119
 
120
	public void setError(String error) {
121
		this.error = error;
122
	}
123
 
6050 anupam.sin 124
}