Subversion Repositories SmartDukaan

Rev

Rev 1731 | Rev 1886 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1597 ankur.sing 1
package in.shop2020.support.controllers;
2
 
3
import in.shop2020.model.v1.user.UserType;
1611 ankur.sing 4
import in.shop2020.thrift.clients.HelperServiceClient;
1630 ankur.sing 5
import in.shop2020.thrift.clients.PaymentServiceClient;
1597 ankur.sing 6
import in.shop2020.thrift.clients.TransactionServiceClient;
7
import in.shop2020.thrift.clients.UserContextServiceClient;
1611 ankur.sing 8
import in.shop2020.utils.StatisticsUser;
1597 ankur.sing 9
 
1731 ankur.sing 10
import java.util.List;
11
 
1611 ankur.sing 12
import javax.servlet.ServletContext;
1597 ankur.sing 13
import javax.servlet.http.HttpServletRequest;
1611 ankur.sing 14
import javax.servlet.http.HttpSession;
1597 ankur.sing 15
 
16
import org.apache.struts2.interceptor.ServletRequestAware;
1611 ankur.sing 17
import org.apache.struts2.util.ServletContextAware;
1597 ankur.sing 18
 
1884 chandransh 19
public class StatisticsController implements ServletRequestAware, ServletContextAware{
1597 ankur.sing 20
 
1611 ankur.sing 21
	private ServletContext context;
1597 ankur.sing 22
	private HttpServletRequest request;
1611 ankur.sing 23
	private HttpSession session;
1597 ankur.sing 24
 
25
	private String errorMsg = "";
26
	private long noOfRegisterUsers;
27
	private long noOfOrders;
1630 ankur.sing 28
	private long noOfCustomers;
29
	private double maxOrderAmount;
30
	private double minOrderAmount;
31
	private double maxPaymentAmount;
32
	private double minPaymentAmount;
1731 ankur.sing 33
	private List<Double> paymentAmountRange;
34
	private List<Double> orderAmountRange;
1630 ankur.sing 35
 
1597 ankur.sing 36
	public StatisticsController(){
37
 
38
	}
39
 
40
	@Override
41
	public void setServletRequest(HttpServletRequest req) {
42
		this.request = req;
1611 ankur.sing 43
		this.session = req.getSession();
1597 ankur.sing 44
	}
45
 
46
	public String index()	{
1611 ankur.sing 47
		if(getSessionUserName()==null) {
48
			return "authfail";
49
		}
50
		else {
51
			getStats();
52
			return "authsuccess";
53
		}
54
	}
55
 
56
 
57
	private void getStats() {
1597 ankur.sing 58
		UserContextServiceClient usc;
59
		TransactionServiceClient tsc;
1630 ankur.sing 60
		PaymentServiceClient psc;
1597 ankur.sing 61
		try {
62
			usc = new UserContextServiceClient();
63
			in.shop2020.model.v1.user.UserContextService.Client uclient = usc.getClient();
64
			noOfRegisterUsers = uclient.getUserCount(UserType.USER);
65
 
66
			tsc = new TransactionServiceClient();
67
			in.shop2020.model.v1.order.TransactionService.Client tClient = tsc.getClient();
68
			noOfOrders = tClient.getValidOrderCount();
1630 ankur.sing 69
			noOfCustomers = tClient.getNoOfCustomersWithSuccessfulTransaction();
1731 ankur.sing 70
			orderAmountRange = tClient.getValidOrdersAmountRange();
71
			minOrderAmount = orderAmountRange.get(0);
72
			maxOrderAmount = orderAmountRange.get(1);
1630 ankur.sing 73
 
74
			psc = new PaymentServiceClient();
75
			in.shop2020.payments.PaymentService.Client pClient = psc.getClient();
1731 ankur.sing 76
			paymentAmountRange = pClient.getSuccessfulPaymentsAmountRange();
77
			minPaymentAmount = paymentAmountRange.get(0);
78
			maxPaymentAmount = paymentAmountRange.get(1);
1597 ankur.sing 79
		} catch (Exception e) {
80
			e.printStackTrace();
81
		}
82
	}
83
 
1611 ankur.sing 84
	// Handler for POST /statistics
85
	public String create(){
86
		String username = request.getParameter("username");
87
		String password = request.getParameter("password");
88
		try{
89
			HelperServiceClient helperServiceClient = new HelperServiceClient();
90
			in.shop2020.utils.HelperService.Client client = helperServiceClient.getClient();
91
			StatisticsUser user = client.authenticateStatisticsUser(username, password);
92
			session.setAttribute("username", user.getUsername());
93
		}catch(Exception e){
94
			e.printStackTrace();
95
			return "authfail";
96
		}
97
		getStats();
98
		return "authsuccess";
99
	}
100
 
101
 
1597 ankur.sing 102
	public String show(){
103
		return null;
104
	}
105
 
106
	// Handles the POST request (Form Submission)
107
 
108
	public String getErrorMsg() {
109
		return errorMsg;
110
	}
111
 
112
	public long getNoOfRegisterUsers() {
113
		return noOfRegisterUsers;
114
	}
115
 
116
	public long getNoOfOrders() {
117
		return noOfOrders;
118
	}
119
 
1630 ankur.sing 120
	public long getNoOfCustomers() {
121
		return noOfCustomers;
122
	}
123
 
124
	public double getMaxOrderAmount() {
125
		return maxOrderAmount;
126
	}
127
 
128
	public double getMinOrderAmount() {
129
		return minOrderAmount;
130
	}
131
 
132
	public double getMaxPaymentAmount() {
133
		return maxPaymentAmount;
134
	}
135
 
136
	public double getMinPaymentAmount() {
137
		return minPaymentAmount;
138
	}
139
 
1611 ankur.sing 140
	public String getSessionUserName(){
141
		return (String) session.getAttribute("username");
142
	}
143
 
144
	public String getServletContextPath(){
145
		return context.getContextPath();
146
	}
147
 
148
	@Override
149
	public void setServletContext(ServletContext context) {
150
		this.context = context;
151
 
152
	}
1597 ankur.sing 153
}
154