Subversion Repositories SmartDukaan

Rev

Rev 6289 | Rev 6336 | 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
 
6289 anupam.sin 3
import in.shop2020.model.v1.order.DenominationType;
4
import in.shop2020.model.v1.order.DeviceNumberInfo;
5
import in.shop2020.model.v1.order.RechargeDenomination;
6066 amit.gupta 6
import in.shop2020.model.v1.order.RechargeType;
6178 anupam.sin 7
import in.shop2020.serving.utils.Utils;
6066 amit.gupta 8
import in.shop2020.thrift.clients.TransactionClient;
9
 
6289 anupam.sin 10
import java.util.List;
6050 anupam.sin 11
import java.util.Map;
12
 
13
import org.apache.log4j.Logger;
14
 
6178 anupam.sin 15
import com.google.gson.Gson;
16
 
6050 anupam.sin 17
public class RechargeController extends BaseController {
18
 
19
    /**
20
     * 
21
     */
6204 rajveer 22
    private String serviceType = null; //Default is Mobile , 2 is for DTH
6103 amit.gupta 23
    private String deviceNumber = "";
6050 anupam.sin 24
    private String form = "";
6057 anupam.sin 25
    private Map<Long, String> providers;
6103 amit.gupta 26
    private String error = "";
6204 rajveer 27
    private String uri;
28
    private String operatorId;
29
    private String operatorName;
30
    private String serviceName;
6289 anupam.sin 31
    private String denominationType;
6307 anupam.sin 32
    private String circleCode;
6289 anupam.sin 33
    private List<RechargeDenomination> rechargeDenominations = null;
6050 anupam.sin 34
    private static final long serialVersionUID = 2079308723099307749L;
35
 
36
    private static Logger log = Logger.getLogger(Class.class);
37
 
6204 rajveer 38
 
6050 anupam.sin 39
    public String index() {
6204 rajveer 40
    	uri = request.getRequestURI();
41
		uri = uri.replace("/", "");
42
	    log.info("Uri: " + uri);
43
	    Map<String, String> valueMap = Utils.getOperatorByUri(uri);
44
	    operatorId  = valueMap.get("Id");
45
        operatorName = valueMap.get("Name"); 
46
        serviceName  = valueMap.get("ServiceName");
47
	    if(serviceType == null){
48
	        serviceType  = valueMap.get("ServiceType");
49
	    }
6270 rajveer 50
	    return "index";
6050 anupam.sin 51
    }
52
 
53
    public String create() {
54
        if(form.equals("serviceSelect")) {
55
            return index();
56
        }
6307 anupam.sin 57
        return "";
6050 anupam.sin 58
    }
6057 anupam.sin 59
 
60
    public Map<Long, String> getProviderMap() {
6201 rajveer 61
        if(serviceType.equals("1"))
62
            providers = Utils.getMobileProvidersMap();
63
        else
64
            providers = Utils.getDthProvidersMap();
6057 anupam.sin 65
        return providers;
66
    }
6100 anupam.sin 67
 
6103 amit.gupta 68
    public String getServiceProvider() {
69
    	return "service-provider";
6100 anupam.sin 70
    }
6103 amit.gupta 71
 
72
    public String getProvider(){
73
    	TransactionClient tcl;
74
    	try {
75
    		tcl = new TransactionClient();
6289 anupam.sin 76
    		DeviceNumberInfo deviceInfo =  tcl.getClient().getServiceProviderForDevice(RechargeType.findByValue(Integer.parseInt(this.serviceType)), deviceNumber);
77
    		return deviceInfo.getOperatorId() + ":" + deviceInfo.getCircleName();
6103 amit.gupta 78
    	} catch (Exception e) {
79
    		log.error("Unable to get service provider for Device number " + deviceNumber + " and rechargeType : " +  serviceType, e);
6289 anupam.sin 80
    	    return ":";
6103 amit.gupta 81
    	}
82
    }
6178 anupam.sin 83
 
6289 anupam.sin 84
    public String getAllDenominations() {
85
        TransactionClient tcl;
86
        try {
87
            tcl = new TransactionClient();
6307 anupam.sin 88
            rechargeDenominations =  tcl.getClient().getRechargeDenominations(Long.parseLong(operatorId), circleCode, DenominationType.findByValue(Integer.parseInt(denominationType)));
6289 anupam.sin 89
            if(rechargeDenominations == null || rechargeDenominations.isEmpty()) {
90
                setError("This information is unavailable for now.<br>You can recharge with the amount you normally use or you can try later.");
91
            }
92
        } catch (Exception e) {
6307 anupam.sin 93
            log.error("Unable to get rechargeDenominations for operatorId " + operatorId + " and circleCode : " +  circleCode + " and DenominationType : " + denominationType, e);
6289 anupam.sin 94
            setError("This information is unavailable for now.<br>You can recharge with the amount you normally use or you can try later.");
95
        }
96
        return "recharge-denomination";
97
    }
98
 
6178 anupam.sin 99
    public String getPlanMapInJson() {
100
        Gson gson = new Gson();
101
            return (gson.toJson(Utils.getOperatorPlanMap()));
102
    }
6050 anupam.sin 103
 
6057 anupam.sin 104
    public void setServiceType(String incomingServiceType) {
105
        serviceType = incomingServiceType;
106
    }
6103 amit.gupta 107
 
108
    public void setDeviceNumber(String deviceNumber){
109
    	this.deviceNumber = deviceNumber;
110
    }
6057 anupam.sin 111
 
6050 anupam.sin 112
    public String getServiceType() {
113
        return serviceType;
114
    }
115
 
116
    public String getForm() {
117
        return form;
118
    }
119
 
120
    public void setForm(String form) {
121
        this.form = form;
122
    }
6103 amit.gupta 123
 
124
	public String getError() {
125
		return error;
126
	}
127
 
128
	public void setError(String error) {
129
		this.error = error;
130
	}
131
 
6204 rajveer 132
	public String getPageName() {
133
    	return operatorName  + " online recharge";
134
    }
135
 
136
	public String getPageTitle() {
137
		return operatorName  + " online recharge";
138
    }
139
 
140
    public String getPageMetaDesc() {
141
    	return "Recharge your " + this.operatorName +  " " + this.serviceName +  " online for all cities using Credit/Debit card & net banking. Fast, Secure and Hassle Free Recharge";
142
    }
143
 
144
    public String getPageMetaKeywords() {
145
    	return "mobile, recharge";
146
    }
147
 
148
    public long getOperatorId(){
149
    	return Long.parseLong(this.operatorId);
150
    }
6289 anupam.sin 151
 
152
    public String getDenominationType() {
153
        return denominationType;
154
    }
155
 
156
    public void setDenominationType(String denominationType) {
157
        this.denominationType = denominationType;
158
    }
159
 
6307 anupam.sin 160
    public String getCircleCode() {
161
        return circleCode;
6289 anupam.sin 162
    }
163
 
6307 anupam.sin 164
    public void setCircleCode(String circleCode) {
165
        this.circleCode = circleCode;
6289 anupam.sin 166
    }
167
 
168
    public List<RechargeDenomination> getRechargeDenominations() {
169
        return rechargeDenominations;
170
    }
171
 
172
    public void setRechargeDenominations(
173
            List<RechargeDenomination> rechargeDenominations) {
174
        this.rechargeDenominations = rechargeDenominations;
175
    }
176
 
177
    public void setOperatorId(String operatorId) {
178
        this.operatorId = operatorId;
179
    }
6050 anupam.sin 180
}