| 6154 |
rajveer |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.model.v1.order.RechargeOrder;
|
|
|
4 |
import in.shop2020.support.utils.ReportsUtils;
|
|
|
5 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
6 |
|
|
|
7 |
import java.text.DateFormat;
|
|
|
8 |
import java.text.SimpleDateFormat;
|
|
|
9 |
import java.util.Calendar;
|
|
|
10 |
import java.util.List;
|
|
|
11 |
|
|
|
12 |
import javax.servlet.ServletContext;
|
|
|
13 |
import javax.servlet.http.HttpServletRequest;
|
|
|
14 |
import javax.servlet.http.HttpSession;
|
|
|
15 |
|
|
|
16 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
17 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
|
|
18 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
19 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
20 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
21 |
import org.apache.struts2.util.ServletContextAware;
|
|
|
22 |
import org.slf4j.Logger;
|
|
|
23 |
import org.slf4j.LoggerFactory;
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
@InterceptorRefs({
|
|
|
27 |
@InterceptorRef("defaultStack"),
|
|
|
28 |
@InterceptorRef("login")
|
|
|
29 |
})
|
|
|
30 |
|
|
|
31 |
@Results({
|
|
|
32 |
@Result(name="authfail", type="redirectAction", params = {"actionName" , "reports"})
|
|
|
33 |
})
|
|
|
34 |
public class RechargeOrdersController implements ServletRequestAware, ServletContextAware {
|
|
|
35 |
|
|
|
36 |
private static Logger logger = LoggerFactory.getLogger(RechargeOrdersController.class);
|
|
|
37 |
|
|
|
38 |
private HttpServletRequest request;
|
|
|
39 |
private HttpSession session;
|
|
|
40 |
private ServletContext context;
|
|
|
41 |
|
|
|
42 |
private List<RechargeOrder> allOrders;
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
private TransactionClient tsc;
|
|
|
46 |
private in.shop2020.model.v1.order.TransactionService.Client tClient;
|
|
|
47 |
|
|
|
48 |
private final DateFormat formatter = new SimpleDateFormat("EEE, dd-MMM-yyyy hh:mm a");
|
|
|
49 |
|
|
|
50 |
public RechargeOrdersController(){
|
|
|
51 |
try {
|
|
|
52 |
tsc = new TransactionClient();
|
|
|
53 |
tClient = tsc.getClient();
|
|
|
54 |
} catch (Exception e) {
|
|
|
55 |
logger.error("Error connecting to one of the user, order or payment service", e);
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
public String index() {
|
|
|
60 |
if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getServletPath())) {
|
|
|
61 |
return "authfail";
|
|
|
62 |
}
|
|
|
63 |
getStats();
|
|
|
64 |
return "authsuccess";
|
|
|
65 |
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
private void getStats() {
|
|
|
69 |
try {
|
|
|
70 |
allOrders = tClient.getRechargeOrdersForStatus(-1);
|
|
|
71 |
} catch (Exception e){
|
|
|
72 |
logger.error("Error while getting order statistics", e);
|
|
|
73 |
}
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
public List<RechargeOrder> getValidOrders() {
|
|
|
77 |
return allOrders;
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
public String getDateTime(long milliseconds) {
|
|
|
81 |
Calendar cal = Calendar.getInstance();
|
|
|
82 |
cal.setTimeInMillis(milliseconds);
|
|
|
83 |
return formatter.format(cal.getTime());
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
@Override
|
|
|
87 |
public void setServletRequest(HttpServletRequest req) {
|
|
|
88 |
this.request = req;
|
|
|
89 |
this.session = req.getSession();
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
@Override
|
|
|
93 |
public void setServletContext(ServletContext context) {
|
|
|
94 |
this.context = context;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
public String getServletContextPath() {
|
|
|
98 |
return context.getContextPath();
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
|