| Line 5... |
Line 5... |
| 5 |
import in.shop2020.model.v1.order.Transaction;
|
5 |
import in.shop2020.model.v1.order.Transaction;
|
| 6 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
6 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 7 |
import in.shop2020.model.v1.user.Address;
|
7 |
import in.shop2020.model.v1.user.Address;
|
| 8 |
import in.shop2020.model.v1.user.User;
|
8 |
import in.shop2020.model.v1.user.User;
|
| 9 |
import in.shop2020.model.v1.user.UserCommunication;
|
9 |
import in.shop2020.model.v1.user.UserCommunication;
|
| - |
|
10 |
import in.shop2020.model.v1.user.UserCommunicationException;
|
| - |
|
11 |
import in.shop2020.model.v1.user.UserContextException;
|
| 10 |
import in.shop2020.model.v1.user.UserContextService.Client;
|
12 |
import in.shop2020.model.v1.user.UserContextService.Client;
|
| 11 |
import in.shop2020.payments.Payment;
|
13 |
import in.shop2020.payments.Payment;
|
| - |
|
14 |
import in.shop2020.payments.PaymentException;
|
| 12 |
import in.shop2020.support.utils.ReportsUtils;
|
15 |
import in.shop2020.support.utils.ReportsUtils;
|
| 13 |
import in.shop2020.thrift.clients.PaymentServiceClient;
|
16 |
import in.shop2020.thrift.clients.PaymentServiceClient;
|
| 14 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
17 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
| 15 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
18 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
| 16 |
|
19 |
|
| Line 41... |
Line 44... |
| 41 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
44 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
| 42 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
45 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
| 43 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
46 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
| 44 |
import org.apache.struts2.interceptor.ServletResponseAware;
|
47 |
import org.apache.struts2.interceptor.ServletResponseAware;
|
| 45 |
import org.apache.struts2.util.ServletContextAware;
|
48 |
import org.apache.struts2.util.ServletContextAware;
|
| - |
|
49 |
import org.apache.thrift.TException;
|
| - |
|
50 |
import org.slf4j.Logger;
|
| - |
|
51 |
import org.slf4j.LoggerFactory;
|
| 46 |
|
52 |
|
| 47 |
@InterceptorRefs({
|
53 |
@InterceptorRefs({
|
| 48 |
@InterceptorRef("defaultStack"),
|
54 |
@InterceptorRef("defaultStack"),
|
| 49 |
@InterceptorRef("login")
|
55 |
@InterceptorRef("login")
|
| 50 |
})
|
56 |
})
|
| 51 |
|
57 |
|
| 52 |
public class UserOrdersController implements ServletRequestAware, ServletResponseAware, ServletContextAware {
|
58 |
public class UserOrdersController implements ServletRequestAware, ServletResponseAware, ServletContextAware {
|
| 53 |
|
59 |
|
| - |
|
60 |
private static Logger logger = LoggerFactory.getLogger(UserOrdersController.class);
|
| - |
|
61 |
|
| 54 |
private HttpServletRequest request;
|
62 |
private HttpServletRequest request;
|
| 55 |
private HttpSession session;
|
63 |
private HttpSession session;
|
| 56 |
private HttpServletResponse response;
|
64 |
private HttpServletResponse response;
|
| 57 |
private ServletContext context;
|
65 |
private ServletContext context;
|
| 58 |
|
66 |
|
| Line 88... |
Line 96... |
| 88 |
user = userClient.getUserByEmail(email);
|
96 |
user = userClient.getUserByEmail(email);
|
| 89 |
if(user.getUserId() == -1){
|
97 |
if(user.getUserId() == -1){
|
| 90 |
errorMsg = "No user for this id.";
|
98 |
errorMsg = "No user for this id.";
|
| 91 |
return "report";
|
99 |
return "report";
|
| 92 |
}
|
100 |
}
|
| 93 |
}
|
- |
|
| 94 |
else {
|
101 |
} else {
|
| 95 |
try {
|
102 |
try {
|
| 96 |
user = userClient.getUserById(transactionClient.getOrder(Long.parseLong(orderid)).getCustomer_id());
|
103 |
user = userClient.getUserById(transactionClient.getOrder(Long.parseLong(orderid)).getCustomer_id());
|
| 97 |
} catch (NumberFormatException e) {
|
104 |
} catch (NumberFormatException e) {
|
| - |
|
105 |
logger.error("Error parsing order id", e);
|
| 98 |
errorMsg = "Order Id should be a number.";
|
106 |
errorMsg = "Order Id should be a number.";
|
| 99 |
return "report";
|
107 |
return "report";
|
| 100 |
}
|
108 |
}
|
| 101 |
}
|
109 |
}
|
| 102 |
|
110 |
|
| Line 133... |
Line 141... |
| 133 |
sos = response.getOutputStream();
|
141 |
sos = response.getOutputStream();
|
| 134 |
baos.writeTo(sos);
|
142 |
baos.writeTo(sos);
|
| 135 |
sos.flush();
|
143 |
sos.flush();
|
| 136 |
} catch (IOException e) {
|
144 |
} catch (IOException e) {
|
| 137 |
errorMsg = "Failed to write to response.";
|
145 |
errorMsg = "Failed to write to response.";
|
| 138 |
e.printStackTrace();
|
146 |
logger.error("Error streaming the user orders report", e);
|
| 139 |
}
|
147 |
}
|
| 140 |
|
148 |
|
| 141 |
} catch (ParseException e) {
|
149 |
} catch (ParseException e) {
|
| 142 |
errorMsg = e.getMessage();
|
150 |
errorMsg = e.getMessage();
|
| 143 |
e.printStackTrace();
|
151 |
logger.error("Unexpected parse exception", e);
|
| 144 |
} catch (TransactionServiceException e) {
|
152 |
} catch (TransactionServiceException e) {
|
| 145 |
errorMsg = e.getMessage();
|
153 |
errorMsg = e.getMessage();
|
| - |
|
154 |
logger.error("Error retrieving info from transaction service", e);
|
| - |
|
155 |
} catch (UserContextException e) {
|
| 146 |
e.printStackTrace();
|
156 |
errorMsg = e.getMessage();
|
| - |
|
157 |
logger.error("Error retrieving info from user service", e);
|
| - |
|
158 |
} catch (PaymentException e) {
|
| - |
|
159 |
errorMsg = e.getMessage();
|
| - |
|
160 |
logger.error("Error retrieving info from payment service", e);
|
| - |
|
161 |
} catch (UserCommunicationException e) {
|
| - |
|
162 |
errorMsg = e.getMessage();
|
| - |
|
163 |
logger.error("Error retrieving user communication from user service", e);
|
| 147 |
} catch (Exception e) {
|
164 |
} catch (TException e) {
|
| 148 |
errorMsg = e.getMessage();
|
165 |
errorMsg = e.getMessage();
|
| - |
|
166 |
logger.error("Error retrieving info from user, payment or transaction service", e);
|
| 149 |
e.printStackTrace();
|
167 |
} catch (Exception e) {
|
| - |
|
168 |
errorMsg = "Error establishing connection to one of the services";
|
| - |
|
169 |
logger.error("Error establishing connection from user, payment or transaction service", e);
|
| 150 |
}
|
170 |
}
|
| 151 |
return "report";
|
171 |
return "report";
|
| 152 |
}
|
172 |
}
|
| 153 |
|
173 |
|
| 154 |
// Prepares the XLS worksheet object and fills in the data with proper formatting
|
174 |
// Prepares the XLS worksheet object and fills in the data with proper formatting
|
| 155 |
private ByteArrayOutputStream getSpreadSheetData(User user,
|
175 |
private ByteArrayOutputStream getSpreadSheetData(User user,
|
| Line 177... |
Line 197... |
| 177 |
// Write the workbook to the output stream
|
197 |
// Write the workbook to the output stream
|
| 178 |
try {
|
198 |
try {
|
| 179 |
wb.write(baosXLS);
|
199 |
wb.write(baosXLS);
|
| 180 |
baosXLS.close();
|
200 |
baosXLS.close();
|
| 181 |
} catch (IOException e) {
|
201 |
} catch (IOException e) {
|
| 182 |
e.printStackTrace();
|
202 |
logger.error("Error streaming user order report", e);
|
| 183 |
}
|
203 |
}
|
| 184 |
return baosXLS;
|
204 |
return baosXLS;
|
| 185 |
}
|
205 |
}
|
| 186 |
|
206 |
|
| 187 |
private void createTransactionSheet(List<Transaction> transactions, Map<Long, Payment> txnIdToPaymentMap, Workbook wb, CellStyle style, CellStyle dateCellStyle) {
|
207 |
private void createTransactionSheet(List<Transaction> transactions, Map<Long, Payment> txnIdToPaymentMap, Workbook wb, CellStyle style, CellStyle dateCellStyle) {
|