| 6154 |
rajveer |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
| 6194 |
rajveer |
3 |
import in.shop2020.model.v1.order.RechargeOrderStatus;
|
|
|
4 |
import in.shop2020.model.v1.order.RechargeStatistics;
|
| 6161 |
rajveer |
5 |
import in.shop2020.model.v1.order.RechargeType;
|
| 6154 |
rajveer |
6 |
import in.shop2020.support.utils.ReportsUtils;
|
|
|
7 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
8 |
|
|
|
9 |
import java.text.DateFormat;
|
|
|
10 |
import java.text.SimpleDateFormat;
|
|
|
11 |
import java.util.Calendar;
|
| 6161 |
rajveer |
12 |
import java.util.Map;
|
|
|
13 |
import java.util.Map.Entry;
|
| 6154 |
rajveer |
14 |
|
|
|
15 |
import javax.servlet.ServletContext;
|
|
|
16 |
import javax.servlet.http.HttpServletRequest;
|
|
|
17 |
import javax.servlet.http.HttpSession;
|
|
|
18 |
|
|
|
19 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
20 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
|
|
21 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
22 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
23 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
24 |
import org.apache.struts2.util.ServletContextAware;
|
|
|
25 |
import org.slf4j.Logger;
|
|
|
26 |
import org.slf4j.LoggerFactory;
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
@InterceptorRefs({
|
|
|
30 |
@InterceptorRef("defaultStack"),
|
|
|
31 |
@InterceptorRef("login")
|
|
|
32 |
})
|
|
|
33 |
|
|
|
34 |
@Results({
|
|
|
35 |
@Result(name="authfail", type="redirectAction", params = {"actionName" , "reports"})
|
|
|
36 |
})
|
|
|
37 |
public class RechargeOrdersController implements ServletRequestAware, ServletContextAware {
|
|
|
38 |
|
|
|
39 |
private static Logger logger = LoggerFactory.getLogger(RechargeOrdersController.class);
|
|
|
40 |
|
|
|
41 |
private HttpServletRequest request;
|
|
|
42 |
private HttpSession session;
|
|
|
43 |
private ServletContext context;
|
|
|
44 |
|
| 6194 |
rajveer |
45 |
private RechargeStatistics stats;
|
| 6154 |
rajveer |
46 |
|
| 6161 |
rajveer |
47 |
private static Map<Long, String> providers;
|
|
|
48 |
|
| 6154 |
rajveer |
49 |
private TransactionClient tsc;
|
|
|
50 |
private in.shop2020.model.v1.order.TransactionService.Client tClient;
|
|
|
51 |
|
|
|
52 |
private final DateFormat formatter = new SimpleDateFormat("EEE, dd-MMM-yyyy hh:mm a");
|
|
|
53 |
|
|
|
54 |
public RechargeOrdersController(){
|
|
|
55 |
try {
|
|
|
56 |
tsc = new TransactionClient();
|
|
|
57 |
tClient = tsc.getClient();
|
|
|
58 |
} catch (Exception e) {
|
|
|
59 |
logger.error("Error connecting to one of the user, order or payment service", e);
|
|
|
60 |
}
|
|
|
61 |
}
|
|
|
62 |
|
| 6161 |
rajveer |
63 |
static{
|
|
|
64 |
TransactionClient tc;
|
|
|
65 |
try {
|
|
|
66 |
tc = new TransactionClient();
|
|
|
67 |
providers = tc.getClient().getServiceProviders(RechargeType.MOBILE);
|
|
|
68 |
for(Entry<Long, String> providerEntry: tc.getClient().getServiceProviders(RechargeType.DTH).entrySet()){
|
|
|
69 |
providers.put(providerEntry.getKey(), providerEntry.getValue());
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
} catch (Exception e) {
|
|
|
73 |
logger.error("Cannot get providers", e);
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
|
| 6154 |
rajveer |
77 |
public String index() {
|
|
|
78 |
if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getServletPath())) {
|
|
|
79 |
return "authfail";
|
|
|
80 |
}
|
| 6194 |
rajveer |
81 |
try {
|
|
|
82 |
stats = tClient.getRechargeStatistics();
|
| 6154 |
rajveer |
83 |
} catch (Exception e){
|
|
|
84 |
logger.error("Error while getting order statistics", e);
|
|
|
85 |
}
|
| 6194 |
rajveer |
86 |
return "authsuccess";
|
|
|
87 |
|
| 6154 |
rajveer |
88 |
}
|
|
|
89 |
|
| 6194 |
rajveer |
90 |
public RechargeStatistics getStats() {
|
|
|
91 |
return stats;
|
| 6154 |
rajveer |
92 |
}
|
| 6161 |
rajveer |
93 |
|
|
|
94 |
public String getOperator(long operatorId) {
|
|
|
95 |
return providers.get(operatorId);
|
|
|
96 |
}
|
|
|
97 |
|
| 6196 |
rajveer |
98 |
public String getStatusDescription(long status) {
|
|
|
99 |
return RechargeOrderStatus.findByValue((int)status).toString();
|
| 6194 |
rajveer |
100 |
}
|
|
|
101 |
|
| 6154 |
rajveer |
102 |
public String getDateTime(long milliseconds) {
|
|
|
103 |
Calendar cal = Calendar.getInstance();
|
|
|
104 |
cal.setTimeInMillis(milliseconds);
|
|
|
105 |
return formatter.format(cal.getTime());
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
@Override
|
|
|
109 |
public void setServletRequest(HttpServletRequest req) {
|
|
|
110 |
this.request = req;
|
|
|
111 |
this.session = req.getSession();
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
@Override
|
|
|
115 |
public void setServletContext(ServletContext context) {
|
|
|
116 |
this.context = context;
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
public String getServletContextPath() {
|
|
|
120 |
return context.getContextPath();
|
|
|
121 |
}
|
| 6161 |
rajveer |
122 |
|
|
|
123 |
public Map<Long, String> getProviderMap() {
|
|
|
124 |
return providers;
|
|
|
125 |
}
|
| 6154 |
rajveer |
126 |
}
|
|
|
127 |
|