| 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;
|
| 1170 |
varun.gupt |
11 |
import in.shop2020.model.v1.user.UserContextException;
|
|
|
12 |
import in.shop2020.model.v1.user.UserContextService;
|
| 1876 |
varun.gupt |
13 |
import in.shop2020.model.v1.user.UserCommunicationType;
|
| 569 |
rajveer |
14 |
import in.shop2020.serving.controllers.BaseController;
|
| 1297 |
varun.gupt |
15 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
| 1170 |
varun.gupt |
16 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
|
|
17 |
import in.shop2020.serving.utils.UserMessage;
|
| 569 |
rajveer |
18 |
|
| 832 |
rajveer |
19 |
import org.apache.log4j.Logger;
|
| 569 |
rajveer |
20 |
|
| 1309 |
varun.gupt |
21 |
/**
|
|
|
22 |
* @author Varun Gupta
|
|
|
23 |
*/
|
|
|
24 |
|
| 2145 |
chandransh |
25 |
@SuppressWarnings("serial")
|
| 1876 |
varun.gupt |
26 |
public class ContactUsController extends BaseController {
|
| 1297 |
varun.gupt |
27 |
|
| 1876 |
varun.gupt |
28 |
private String id;
|
| 2145 |
chandransh |
29 |
|
| 1876 |
varun.gupt |
30 |
private static Logger log = Logger.getLogger(Class.class);
|
| 1170 |
varun.gupt |
31 |
|
| 1876 |
varun.gupt |
32 |
private UserCommunicationType formType = null;
|
| 1380 |
varun.gupt |
33 |
|
| 1876 |
varun.gupt |
34 |
List<Order> orders = null;
|
|
|
35 |
List<LineItem> products = null;
|
|
|
36 |
List<Long> order_ids = null;
|
| 1170 |
varun.gupt |
37 |
|
| 1876 |
varun.gupt |
38 |
public ContactUsController() {
|
|
|
39 |
super();
|
|
|
40 |
}
|
| 1170 |
varun.gupt |
41 |
|
| 1876 |
varun.gupt |
42 |
// GET /Show Form
|
|
|
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);
|
|
|
48 |
} catch (Exception e) {
|
| 2944 |
chandransh |
49 |
log.error("Unable to get the orders for the user becauase of: ", e);
|
| 1876 |
varun.gupt |
50 |
}
|
| 1170 |
varun.gupt |
51 |
|
| 1876 |
varun.gupt |
52 |
if (request.getParameter("type") != null) {
|
|
|
53 |
String requestedFormType = request.getParameter("type").toString().trim();
|
| 2148 |
chandransh |
54 |
log.debug("Contact us requested for: " + requestedFormType);
|
|
|
55 |
|
| 1876 |
varun.gupt |
56 |
if (requestedFormType.equals("return")) {
|
|
|
57 |
this.formType = UserCommunicationType.RETURN_FORM;
|
|
|
58 |
} else if (requestedFormType.equals("cancel")) {
|
|
|
59 |
this.formType = UserCommunicationType.ORDER_CANCELLATION;
|
|
|
60 |
} else if (requestedFormType.equals("delivery")) {
|
|
|
61 |
this.formType = UserCommunicationType.DELIVERY_PROBLEM;
|
|
|
62 |
}
|
|
|
63 |
}
|
|
|
64 |
return "index";
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
public String show() throws SecurityException, IOException {
|
|
|
68 |
try {
|
|
|
69 |
TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
|
|
|
70 |
in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
|
|
|
71 |
|
|
|
72 |
if (id.equals("to_return")) {
|
|
|
73 |
order_ids = orderClient.getReturnableOrdersForCustomer(userinfo.getUserId(), 0);
|
|
|
74 |
} else if (id.equals("to_cancel")) {
|
|
|
75 |
order_ids = orderClient.getCancellableOrdersForCustomer(userinfo.getUserId(), 0);
|
|
|
76 |
} else if (id.equals("all_orders")) {
|
|
|
77 |
orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0, (new Date()).getTime(), null);
|
|
|
78 |
} else {
|
|
|
79 |
long orderId = Integer.parseInt(id);
|
|
|
80 |
products = orderClient.getLineItemsForOrder(orderId);
|
|
|
81 |
}
|
|
|
82 |
} catch (NumberFormatException e) {
|
| 2944 |
chandransh |
83 |
log.error("Unable to get order id", e);
|
| 1876 |
varun.gupt |
84 |
} catch (Exception e) {
|
| 2944 |
chandransh |
85 |
log.error("Unable to get user order details: ", e);
|
| 1876 |
varun.gupt |
86 |
}
|
|
|
87 |
return "ajax";
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
// POST /Save Communication
|
|
|
91 |
public String create() {
|
|
|
92 |
long communicationType = -1;
|
|
|
93 |
long orderId = -1;
|
|
|
94 |
|
|
|
95 |
try {
|
|
|
96 |
boolean u = userinfo.isLoggedIn();
|
|
|
97 |
long userId = u ? userinfo.getUserId() : 0;
|
|
|
98 |
String email = request.getParameter("email");
|
|
|
99 |
communicationType = Integer.parseInt(request.getParameter("communication_type"));
|
|
|
100 |
|
|
|
101 |
if (request.getParameter("order_id") != null) {
|
|
|
102 |
orderId = Integer.parseInt(request.getParameter("order_id"));
|
|
|
103 |
}
|
|
|
104 |
String awb = request.getParameter("awb");
|
|
|
105 |
String product = request.getParameter("product");
|
|
|
106 |
String subject = request.getParameter("subject");
|
|
|
107 |
String message = request.getParameter("message");
|
|
|
108 |
|
|
|
109 |
UserContextService.Client userClient = (new UserContextServiceClient()).getClient();
|
|
|
110 |
|
|
|
111 |
if (userClient.saveUserCommunication(userId, email, communicationType, orderId, awb, product, subject,
|
|
|
112 |
message)) {
|
| 2944 |
chandransh |
113 |
log.info("User Communication saved successfully!");
|
| 1876 |
varun.gupt |
114 |
}
|
|
|
115 |
|
|
|
116 |
} catch (NumberFormatException e) {
|
| 2944 |
chandransh |
117 |
log.error("Unable to get communication type or order id: ", e);
|
| 1876 |
varun.gupt |
118 |
} catch (UserContextException e) {
|
| 2944 |
chandransh |
119 |
log.error("Unable to save user communication: ", e);
|
| 1876 |
varun.gupt |
120 |
} catch (Exception e) {
|
| 2944 |
chandransh |
121 |
log.error("Unable to save user communication: ", e);
|
| 1876 |
varun.gupt |
122 |
} finally {
|
|
|
123 |
|
|
|
124 |
}
|
|
|
125 |
return "success";
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
public String getId() {
|
|
|
129 |
return this.id;
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
/**
|
| 1297 |
varun.gupt |
133 |
* @param id
|
|
|
134 |
*/
|
|
|
135 |
public void setId(String id) {
|
| 1876 |
varun.gupt |
136 |
this.id = id;
|
| 1297 |
varun.gupt |
137 |
}
|
| 569 |
rajveer |
138 |
|
| 1876 |
varun.gupt |
139 |
public UserCommunicationType getFormType() {
|
|
|
140 |
return this.formType;
|
|
|
141 |
}
|
| 1297 |
varun.gupt |
142 |
|
| 1876 |
varun.gupt |
143 |
public String getSuccessMsg() {
|
|
|
144 |
return UserMessage.USER_COMMUNICATION_SUCCESS;
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
private String getOrderIdSelector(List<Long> order_ids) {
|
| 2944 |
chandransh |
148 |
StringBuilder html = new StringBuilder();
|
| 1876 |
varun.gupt |
149 |
|
|
|
150 |
if (order_ids == null || order_ids.size() == 0) {
|
| 2944 |
chandransh |
151 |
html.append("<option value='-1'>No Orders Found</option>");
|
| 1876 |
varun.gupt |
152 |
} else {
|
| 2944 |
chandransh |
153 |
html.append("<option value='-1'>Select Order ID</option>");
|
| 1876 |
varun.gupt |
154 |
|
|
|
155 |
for (long order_id : order_ids) {
|
| 2944 |
chandransh |
156 |
html.append("<option value='" + order_id + "'>" + order_id + "</option>");
|
| 1876 |
varun.gupt |
157 |
}
|
|
|
158 |
}
|
| 2944 |
chandransh |
159 |
return html.toString();
|
| 1876 |
varun.gupt |
160 |
}
|
|
|
161 |
|
|
|
162 |
public String getProductsForOrder() {
|
| 2944 |
chandransh |
163 |
StringBuilder html = new StringBuilder();
|
| 1876 |
varun.gupt |
164 |
|
|
|
165 |
if (products == null || products.size() == 0) {
|
| 2944 |
chandransh |
166 |
html.append("<option value='-1'>No Products Found</option>");
|
| 1876 |
varun.gupt |
167 |
} else {
|
|
|
168 |
for (LineItem product : products) {
|
| 2944 |
chandransh |
169 |
html.append("<option value='" + product.getId() + "'>");
|
| 1876 |
varun.gupt |
170 |
|
|
|
171 |
if (product.getBrand() != null)
|
| 2944 |
chandransh |
172 |
html.append(product.getBrand() + " ");
|
| 1876 |
varun.gupt |
173 |
if (product.getModel_name() != null)
|
| 2944 |
chandransh |
174 |
html.append(product.getModel_name() + " ");
|
| 1876 |
varun.gupt |
175 |
if (product.getModel_number() != null)
|
| 2944 |
chandransh |
176 |
html.append(product.getModel_number());
|
| 1876 |
varun.gupt |
177 |
|
| 2944 |
chandransh |
178 |
html.append("</option>");
|
| 1876 |
varun.gupt |
179 |
}
|
|
|
180 |
}
|
| 2944 |
chandransh |
181 |
return html.toString();
|
| 1876 |
varun.gupt |
182 |
}
|
|
|
183 |
|
|
|
184 |
public String getIdsOfAllOrders() {
|
|
|
185 |
List<Long> order_ids = new ArrayList<Long>();
|
|
|
186 |
|
|
|
187 |
for (Order order : this.orders) {
|
|
|
188 |
order_ids.add(order.getId());
|
|
|
189 |
}
|
|
|
190 |
return getOrderIdSelector(order_ids);
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
public String getIdsOfReturnableOrders() {
|
|
|
194 |
return getOrderIdSelector(this.order_ids);
|
|
|
195 |
}
|
|
|
196 |
|
|
|
197 |
public String getIdsOfCancellableOrders() {
|
|
|
198 |
return getOrderIdSelector(this.order_ids);
|
|
|
199 |
}
|
| 569 |
rajveer |
200 |
}
|