| 569 |
rajveer |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
| 1297 |
varun.gupt |
3 |
import java.io.IOException;
|
| 1380 |
varun.gupt |
4 |
import java.lang.NumberFormatException;
|
| 569 |
rajveer |
5 |
import java.util.ArrayList;
|
| 1297 |
varun.gupt |
6 |
import java.util.Date;
|
| 569 |
rajveer |
7 |
import java.util.List;
|
|
|
8 |
|
| 1297 |
varun.gupt |
9 |
import in.shop2020.model.v1.order.LineItem;
|
|
|
10 |
import in.shop2020.model.v1.order.Order;
|
| 1380 |
varun.gupt |
11 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 1170 |
varun.gupt |
12 |
import in.shop2020.model.v1.user.UserContextException;
|
|
|
13 |
import in.shop2020.model.v1.user.UserContextService;
|
| 569 |
rajveer |
14 |
import in.shop2020.serving.controllers.BaseController;
|
|
|
15 |
import in.shop2020.thrift.clients.HelperServiceClient;
|
| 1297 |
varun.gupt |
16 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
| 1170 |
varun.gupt |
17 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
|
|
18 |
import in.shop2020.serving.utils.UserMessage;
|
| 569 |
rajveer |
19 |
|
| 832 |
rajveer |
20 |
import org.apache.log4j.Logger;
|
| 569 |
rajveer |
21 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
|
|
22 |
import org.apache.struts2.rest.HttpHeaders;
|
| 1297 |
varun.gupt |
23 |
import org.apache.velocity.VelocityContext;
|
| 569 |
rajveer |
24 |
|
| 1309 |
varun.gupt |
25 |
/**
|
|
|
26 |
* @author Varun Gupta
|
|
|
27 |
*/
|
|
|
28 |
|
| 980 |
vikas |
29 |
public class ContactUsController extends BaseController{
|
| 1297 |
varun.gupt |
30 |
|
|
|
31 |
private String id;
|
| 569 |
rajveer |
32 |
private static final long serialVersionUID = 1L;
|
| 832 |
rajveer |
33 |
private static Logger log = Logger.getLogger(Class.class);
|
| 1297 |
varun.gupt |
34 |
List<Order> orders = null;
|
|
|
35 |
List<LineItem> products = null;
|
| 1380 |
varun.gupt |
36 |
List<Long> order_ids = null;
|
| 1297 |
varun.gupt |
37 |
|
| 1170 |
varun.gupt |
38 |
public ContactUsController(){
|
| 1297 |
varun.gupt |
39 |
super();
|
| 1170 |
varun.gupt |
40 |
}
|
| 1297 |
varun.gupt |
41 |
|
| 1170 |
varun.gupt |
42 |
// GET /Show Form
|
| 1297 |
varun.gupt |
43 |
public String index() {
|
|
|
44 |
try {
|
|
|
45 |
TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
|
|
|
46 |
in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
|
|
|
47 |
orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0, (new Date()).getTime(), null);
|
| 1481 |
varun.gupt |
48 |
}
|
|
|
49 |
catch(Exception e) {
|
| 1297 |
varun.gupt |
50 |
e.printStackTrace();
|
|
|
51 |
}
|
|
|
52 |
return "index";
|
| 1170 |
varun.gupt |
53 |
}
|
|
|
54 |
|
| 1297 |
varun.gupt |
55 |
public String show() throws SecurityException, IOException {
|
|
|
56 |
try {
|
|
|
57 |
TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
|
|
|
58 |
in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
|
| 1380 |
varun.gupt |
59 |
|
|
|
60 |
if (id.equals("to_return")) {
|
|
|
61 |
order_ids = orderClient.getReturnableOrdersForCustomer(userinfo.getUserId(), 0);
|
|
|
62 |
}
|
|
|
63 |
else if (id.equals("to_cancel")) {
|
|
|
64 |
order_ids = orderClient.getCancellableOrdersForCustomer(userinfo.getUserId(), 0);
|
|
|
65 |
}
|
|
|
66 |
else if (id.equals("all_orders")) {
|
|
|
67 |
orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0, (new Date()).getTime(), null);
|
|
|
68 |
}
|
|
|
69 |
else {
|
|
|
70 |
long orderId = Integer.parseInt(id);
|
|
|
71 |
products = orderClient.getLineItemsForOrder(orderId);
|
|
|
72 |
}
|
| 1297 |
varun.gupt |
73 |
}
|
| 1380 |
varun.gupt |
74 |
catch (NumberFormatException e) {
|
|
|
75 |
e.printStackTrace();
|
|
|
76 |
}
|
| 1297 |
varun.gupt |
77 |
catch (Exception e) {
|
|
|
78 |
e.printStackTrace();
|
|
|
79 |
}
|
|
|
80 |
return "ajax";
|
|
|
81 |
}
|
|
|
82 |
|
| 1170 |
varun.gupt |
83 |
// POST /Save Communication
|
|
|
84 |
public String create() {
|
|
|
85 |
long communicationType = -1;
|
|
|
86 |
long orderId = -1;
|
|
|
87 |
|
|
|
88 |
try {
|
|
|
89 |
boolean u = userinfo.isLoggedIn();
|
|
|
90 |
long userId = u ? userinfo.getUserId() : 0;
|
|
|
91 |
String email = request.getParameter("email");
|
|
|
92 |
communicationType = Integer.parseInt(request.getParameter("communication_type"));
|
| 1600 |
varun.gupt |
93 |
|
|
|
94 |
if(request.getParameter("order_id") != null) {
|
|
|
95 |
orderId = Integer.parseInt(request.getParameter("order_id"));
|
|
|
96 |
}
|
| 1170 |
varun.gupt |
97 |
String awb = request.getParameter("awb");
|
|
|
98 |
String product = request.getParameter("product");
|
|
|
99 |
String subject = request.getParameter("subject");
|
|
|
100 |
String message = request.getParameter("message");
|
|
|
101 |
|
|
|
102 |
UserContextService.Client userClient = (new UserContextServiceClient()).getClient();
|
|
|
103 |
|
|
|
104 |
if(userClient.saveUserCommunication(userId, email, communicationType, orderId, awb, product, subject, message)) {
|
|
|
105 |
System.out.println("User Communication saved successfully!");
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
} catch(NumberFormatException e) {
|
|
|
109 |
e.printStackTrace();
|
|
|
110 |
} catch (UserContextException e) {
|
|
|
111 |
e.printStackTrace();
|
|
|
112 |
} catch (Exception e) {
|
|
|
113 |
e.printStackTrace();
|
|
|
114 |
} finally {
|
|
|
115 |
|
| 569 |
rajveer |
116 |
}
|
| 1380 |
varun.gupt |
117 |
return "success";
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
public String getId() {
|
|
|
121 |
return this.id;
|
|
|
122 |
}
|
|
|
123 |
|
| 1297 |
varun.gupt |
124 |
/**
|
|
|
125 |
* @param id
|
|
|
126 |
*/
|
|
|
127 |
public void setId(String id) {
|
|
|
128 |
this.id = id;
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
public String getSuccessMsg() {
|
|
|
132 |
return UserMessage.USER_COMMUNICATION_SUCCESS;
|
|
|
133 |
}
|
| 569 |
rajveer |
134 |
|
| 1380 |
varun.gupt |
135 |
private String getOrderIdSelector(List<Long> order_ids) {
|
| 1297 |
varun.gupt |
136 |
String html = "";
|
|
|
137 |
|
| 1380 |
varun.gupt |
138 |
if (order_ids == null || order_ids.size() == 0) {
|
| 1297 |
varun.gupt |
139 |
html += "<option value='-1'>No Orders Found</option>";
|
|
|
140 |
} else {
|
|
|
141 |
html += "<option value='-1'>Select Order ID</option>";
|
|
|
142 |
|
| 1380 |
varun.gupt |
143 |
for(long order_id: order_ids) {
|
|
|
144 |
html += "<option value='" + order_id + "'>" + order_id + "</option>";
|
| 1297 |
varun.gupt |
145 |
}
|
| 569 |
rajveer |
146 |
}
|
| 1297 |
varun.gupt |
147 |
return html;
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
public String getProductsForOrder() {
|
|
|
151 |
String html = "";
|
|
|
152 |
|
|
|
153 |
if(products == null || products.size() == 0) {
|
|
|
154 |
html += "<option value='-1'>No Products Found</option>";
|
|
|
155 |
} else {
|
|
|
156 |
for (LineItem product: products) {
|
|
|
157 |
html += "<option value='" + product.getId() + "'>";
|
|
|
158 |
|
|
|
159 |
if(product.getBrand() != null) html += product.getBrand() + " ";
|
|
|
160 |
if(product.getModel_name() != null) html += product.getModel_name() + " ";
|
|
|
161 |
if(product.getModel_number() != null) html += product.getModel_number();
|
|
|
162 |
|
|
|
163 |
html += "</option>";
|
|
|
164 |
}
|
|
|
165 |
}
|
|
|
166 |
return html;
|
|
|
167 |
}
|
| 1380 |
varun.gupt |
168 |
|
|
|
169 |
public String getIdsOfAllOrders() {
|
|
|
170 |
List<Long> order_ids = new ArrayList<Long>();
|
|
|
171 |
|
|
|
172 |
for(Order order: this.orders) {
|
|
|
173 |
order_ids.add(order.getId());
|
|
|
174 |
}
|
|
|
175 |
return getOrderIdSelector(order_ids);
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
public String getIdsOfReturnableOrders() {
|
|
|
179 |
return getOrderIdSelector(this.order_ids);
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
public String getIdsOfCancellableOrders() {
|
|
|
183 |
return getOrderIdSelector(this.order_ids);
|
|
|
184 |
}
|
| 569 |
rajveer |
185 |
}
|