| 569 |
rajveer |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
| 3272 |
mandeep.dh |
3 |
import in.shop2020.crm.TicketCategory;
|
| 1297 |
varun.gupt |
4 |
import in.shop2020.model.v1.order.LineItem;
|
|
|
5 |
import in.shop2020.model.v1.order.Order;
|
| 4277 |
anupam.sin |
6 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 3126 |
rajveer |
7 |
import in.shop2020.model.v1.user.UserCommunicationException;
|
| 3272 |
mandeep.dh |
8 |
import in.shop2020.model.v1.user.UserCommunicationType;
|
| 1170 |
varun.gupt |
9 |
import in.shop2020.model.v1.user.UserContextService;
|
| 3272 |
mandeep.dh |
10 |
import in.shop2020.serving.utils.UserMessage;
|
| 3126 |
rajveer |
11 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
12 |
import in.shop2020.thrift.clients.UserClient;
|
| 569 |
rajveer |
13 |
|
| 3272 |
mandeep.dh |
14 |
import java.io.IOException;
|
|
|
15 |
import java.util.ArrayList;
|
|
|
16 |
import java.util.Date;
|
|
|
17 |
import java.util.List;
|
|
|
18 |
|
| 6176 |
amit.gupta |
19 |
import org.apache.commons.lang.StringUtils;
|
| 832 |
rajveer |
20 |
import org.apache.log4j.Logger;
|
| 3126 |
rajveer |
21 |
import org.apache.thrift.TException;
|
|
|
22 |
import org.apache.thrift.transport.TTransportException;
|
| 569 |
rajveer |
23 |
|
| 1309 |
varun.gupt |
24 |
/**
|
|
|
25 |
* @author Varun Gupta
|
|
|
26 |
*/
|
|
|
27 |
|
| 2145 |
chandransh |
28 |
@SuppressWarnings("serial")
|
| 1876 |
varun.gupt |
29 |
public class ContactUsController extends BaseController {
|
| 1297 |
varun.gupt |
30 |
|
| 3272 |
mandeep.dh |
31 |
private String id;
|
| 1170 |
varun.gupt |
32 |
|
| 3272 |
mandeep.dh |
33 |
private static Logger log = Logger.getLogger(Class.class);
|
| 1380 |
varun.gupt |
34 |
|
| 3272 |
mandeep.dh |
35 |
private UserCommunicationType formType = null;
|
| 1170 |
varun.gupt |
36 |
|
| 3272 |
mandeep.dh |
37 |
List<Order> orders = null;
|
|
|
38 |
List<LineItem> products = null;
|
|
|
39 |
List<Long> order_ids = null;
|
|
|
40 |
|
| 1876 |
varun.gupt |
41 |
public ContactUsController() {
|
|
|
42 |
super();
|
|
|
43 |
}
|
| 1170 |
varun.gupt |
44 |
|
| 1876 |
varun.gupt |
45 |
// GET /Show Form
|
|
|
46 |
public String index() {
|
|
|
47 |
try {
|
| 3126 |
rajveer |
48 |
TransactionClient transactionServiceClient = new TransactionClient();
|
| 3272 |
mandeep.dh |
49 |
in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient
|
|
|
50 |
.getClient();
|
|
|
51 |
orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0,
|
|
|
52 |
(new Date()).getTime(), null);
|
| 1876 |
varun.gupt |
53 |
} catch (Exception e) {
|
| 2944 |
chandransh |
54 |
log.error("Unable to get the orders for the user becauase of: ", e);
|
| 1876 |
varun.gupt |
55 |
}
|
| 1170 |
varun.gupt |
56 |
|
| 1876 |
varun.gupt |
57 |
if (request.getParameter("type") != null) {
|
| 3272 |
mandeep.dh |
58 |
String requestedFormType = request.getParameter("type").toString()
|
|
|
59 |
.trim();
|
| 2148 |
chandransh |
60 |
log.debug("Contact us requested for: " + requestedFormType);
|
| 3272 |
mandeep.dh |
61 |
|
| 1876 |
varun.gupt |
62 |
if (requestedFormType.equals("return")) {
|
|
|
63 |
this.formType = UserCommunicationType.RETURN_FORM;
|
|
|
64 |
} else if (requestedFormType.equals("cancel")) {
|
|
|
65 |
this.formType = UserCommunicationType.ORDER_CANCELLATION;
|
|
|
66 |
} else if (requestedFormType.equals("delivery")) {
|
|
|
67 |
this.formType = UserCommunicationType.DELIVERY_PROBLEM;
|
|
|
68 |
}
|
|
|
69 |
}
|
|
|
70 |
return "index";
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
public String show() throws SecurityException, IOException {
|
|
|
74 |
try {
|
| 3126 |
rajveer |
75 |
TransactionClient transactionServiceClient = new TransactionClient();
|
| 3272 |
mandeep.dh |
76 |
in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient
|
|
|
77 |
.getClient();
|
| 1876 |
varun.gupt |
78 |
|
|
|
79 |
if (id.equals("to_return")) {
|
| 3272 |
mandeep.dh |
80 |
order_ids = orderClient.getReturnableOrdersForCustomer(
|
|
|
81 |
userinfo.getUserId(), 0);
|
| 1876 |
varun.gupt |
82 |
} else if (id.equals("to_cancel")) {
|
| 3272 |
mandeep.dh |
83 |
order_ids = orderClient.getCancellableOrdersForCustomer(
|
|
|
84 |
userinfo.getUserId(), 0);
|
| 1876 |
varun.gupt |
85 |
} else if (id.equals("all_orders")) {
|
| 3272 |
mandeep.dh |
86 |
orders = orderClient.getOrdersForCustomer(userinfo.getUserId(),
|
|
|
87 |
0, (new Date()).getTime(), null);
|
| 1876 |
varun.gupt |
88 |
} else {
|
|
|
89 |
long orderId = Integer.parseInt(id);
|
|
|
90 |
products = orderClient.getLineItemsForOrder(orderId);
|
|
|
91 |
}
|
|
|
92 |
} catch (NumberFormatException e) {
|
| 2944 |
chandransh |
93 |
log.error("Unable to get order id", e);
|
| 1876 |
varun.gupt |
94 |
} catch (Exception e) {
|
| 2944 |
chandransh |
95 |
log.error("Unable to get user order details: ", e);
|
| 1876 |
varun.gupt |
96 |
}
|
|
|
97 |
return "ajax";
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
// POST /Save Communication
|
|
|
101 |
public String create() {
|
| 3952 |
mandeep.dh |
102 |
// Default communication type OTHER
|
|
|
103 |
long communicationType = 8;
|
| 1876 |
varun.gupt |
104 |
long orderId = -1;
|
|
|
105 |
|
|
|
106 |
try {
|
| 3272 |
mandeep.dh |
107 |
boolean isUserLoggedIn = userinfo.isLoggedIn();
|
|
|
108 |
long userId = isUserLoggedIn ? userinfo.getUserId() : 0;
|
| 1876 |
varun.gupt |
109 |
String email = request.getParameter("email");
|
| 3272 |
mandeep.dh |
110 |
communicationType = Integer.parseInt(request
|
|
|
111 |
.getParameter("communication_type"));
|
| 1876 |
varun.gupt |
112 |
|
| 4377 |
mandeep.dh |
113 |
TicketCategory ticketCategory = TicketCategory.findByValue((int) communicationType);
|
| 4277 |
anupam.sin |
114 |
|
| 4377 |
mandeep.dh |
115 |
// Validating ticket category to avoid cases where someone tries to programmatically
|
|
|
116 |
// send requests to us with invalid communication types
|
|
|
117 |
if (ticketCategory != null) {
|
| 4378 |
mandeep.dh |
118 |
if (request.getParameter("order_id") != null) {
|
|
|
119 |
orderId = Integer.parseInt(request.getParameter("order_id"));
|
|
|
120 |
}
|
| 6176 |
amit.gupta |
121 |
if (StringUtils.isNotEmpty(request.getParameter("rechargeOrderNumber"))) {
|
|
|
122 |
//Valid recharge formats are:
|
|
|
123 |
//MOBR9999
|
|
|
124 |
//99999
|
|
|
125 |
String []strOrder = request.getParameter("rechargeOrderNumber").split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)");
|
|
|
126 |
if(strOrder.length==2) {
|
|
|
127 |
orderId = Integer.parseInt(strOrder[1]);
|
|
|
128 |
} else {
|
|
|
129 |
orderId = Integer.parseInt(strOrder[0]);
|
|
|
130 |
}
|
|
|
131 |
}
|
|
|
132 |
|
| 4378 |
mandeep.dh |
133 |
|
|
|
134 |
String awb = request.getParameter("awb");
|
| 6176 |
amit.gupta |
135 |
if(StringUtils.isEmpty(awb)){
|
|
|
136 |
awb = request.getParameter("deviceNumber");
|
|
|
137 |
}
|
| 4378 |
mandeep.dh |
138 |
String product = request.getParameter("product");
|
|
|
139 |
String subject = request.getParameter("subject");
|
|
|
140 |
String message = request.getParameter("message");
|
|
|
141 |
|
|
|
142 |
UserContextService.Client userClient = (new UserClient()).getClient();
|
| 11943 |
kshitij.so |
143 |
if (communicationType == 21){
|
|
|
144 |
product = subject;
|
|
|
145 |
subject = "Bulk Order enquiry requested for " + subject;
|
|
|
146 |
message = message +"Product Name : "+product+"\n";
|
|
|
147 |
message = message+"Contact Number : "+request.getParameter("contactNumber")+"\n";
|
|
|
148 |
message = message+"Quantity : "+request.getParameter("quantity")+"\n";
|
|
|
149 |
message = message+"User Email: "+email;
|
|
|
150 |
awb = request.getParameter("contactNumber");
|
|
|
151 |
}
|
| 4378 |
mandeep.dh |
152 |
|
|
|
153 |
if (userClient.saveUserCommunication(userId, email,
|
|
|
154 |
communicationType, orderId, awb, product, subject, message)) {
|
|
|
155 |
log.info("User Communication saved successfully!");
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
/*
|
|
|
159 |
* We need to change status for the given order to
|
|
|
160 |
* CANCELLATION_REQUEST_RECIEVED
|
|
|
161 |
*/
|
|
|
162 |
if(communicationType == 2) {
|
|
|
163 |
in.shop2020.model.v1.order.TransactionService.Client transactionClient =
|
|
|
164 |
(new TransactionClient()).getClient();
|
|
|
165 |
transactionClient.markOrderCancellationRequestReceived(orderId);
|
|
|
166 |
}
|
| 3272 |
mandeep.dh |
167 |
}
|
| 1876 |
varun.gupt |
168 |
} catch (NumberFormatException e) {
|
| 2944 |
chandransh |
169 |
log.error("Unable to get communication type or order id: ", e);
|
| 3126 |
rajveer |
170 |
} catch (TTransportException e) {
|
| 3272 |
mandeep.dh |
171 |
log.error("Unable to initialize client: ", e);
|
|
|
172 |
} catch (UserCommunicationException e) {
|
| 3126 |
rajveer |
173 |
log.error("Unable to get communication type or order id: ", e);
|
| 3272 |
mandeep.dh |
174 |
} catch (TException e) {
|
|
|
175 |
log.error("Thrift exception: ", e);
|
| 4277 |
anupam.sin |
176 |
} catch (TransactionServiceException e) {
|
|
|
177 |
log.error("Unable to mark cancellation request recieved", e);
|
| 3272 |
mandeep.dh |
178 |
}
|
| 1876 |
varun.gupt |
179 |
return "success";
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
public String getId() {
|
|
|
183 |
return this.id;
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
/**
|
| 1297 |
varun.gupt |
187 |
* @param id
|
|
|
188 |
*/
|
|
|
189 |
public void setId(String id) {
|
| 1876 |
varun.gupt |
190 |
this.id = id;
|
| 1297 |
varun.gupt |
191 |
}
|
| 569 |
rajveer |
192 |
|
| 1876 |
varun.gupt |
193 |
public UserCommunicationType getFormType() {
|
|
|
194 |
return this.formType;
|
|
|
195 |
}
|
| 1297 |
varun.gupt |
196 |
|
| 1876 |
varun.gupt |
197 |
public String getSuccessMsg() {
|
|
|
198 |
return UserMessage.USER_COMMUNICATION_SUCCESS;
|
|
|
199 |
}
|
|
|
200 |
|
|
|
201 |
private String getOrderIdSelector(List<Long> order_ids) {
|
| 2944 |
chandransh |
202 |
StringBuilder html = new StringBuilder();
|
| 1876 |
varun.gupt |
203 |
|
|
|
204 |
if (order_ids == null || order_ids.size() == 0) {
|
| 2944 |
chandransh |
205 |
html.append("<option value='-1'>No Orders Found</option>");
|
| 1876 |
varun.gupt |
206 |
} else {
|
| 2944 |
chandransh |
207 |
html.append("<option value='-1'>Select Order ID</option>");
|
| 1876 |
varun.gupt |
208 |
|
|
|
209 |
for (long order_id : order_ids) {
|
| 3272 |
mandeep.dh |
210 |
html.append("<option value='" + order_id + "'>" + order_id
|
|
|
211 |
+ "</option>");
|
| 1876 |
varun.gupt |
212 |
}
|
|
|
213 |
}
|
| 2944 |
chandransh |
214 |
return html.toString();
|
| 1876 |
varun.gupt |
215 |
}
|
|
|
216 |
|
|
|
217 |
public String getProductsForOrder() {
|
| 2944 |
chandransh |
218 |
StringBuilder html = new StringBuilder();
|
| 1876 |
varun.gupt |
219 |
|
|
|
220 |
if (products == null || products.size() == 0) {
|
| 2944 |
chandransh |
221 |
html.append("<option value='-1'>No Products Found</option>");
|
| 1876 |
varun.gupt |
222 |
} else {
|
|
|
223 |
for (LineItem product : products) {
|
| 2944 |
chandransh |
224 |
html.append("<option value='" + product.getId() + "'>");
|
| 1876 |
varun.gupt |
225 |
|
|
|
226 |
if (product.getBrand() != null)
|
| 2944 |
chandransh |
227 |
html.append(product.getBrand() + " ");
|
| 1876 |
varun.gupt |
228 |
if (product.getModel_name() != null)
|
| 2944 |
chandransh |
229 |
html.append(product.getModel_name() + " ");
|
| 1876 |
varun.gupt |
230 |
if (product.getModel_number() != null)
|
| 2944 |
chandransh |
231 |
html.append(product.getModel_number());
|
| 1876 |
varun.gupt |
232 |
|
| 2944 |
chandransh |
233 |
html.append("</option>");
|
| 1876 |
varun.gupt |
234 |
}
|
|
|
235 |
}
|
| 2944 |
chandransh |
236 |
return html.toString();
|
| 1876 |
varun.gupt |
237 |
}
|
|
|
238 |
|
|
|
239 |
public String getIdsOfAllOrders() {
|
|
|
240 |
List<Long> order_ids = new ArrayList<Long>();
|
|
|
241 |
|
|
|
242 |
for (Order order : this.orders) {
|
|
|
243 |
order_ids.add(order.getId());
|
|
|
244 |
}
|
|
|
245 |
return getOrderIdSelector(order_ids);
|
|
|
246 |
}
|
|
|
247 |
|
|
|
248 |
public String getIdsOfReturnableOrders() {
|
|
|
249 |
return getOrderIdSelector(this.order_ids);
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
public String getIdsOfCancellableOrders() {
|
|
|
253 |
return getOrderIdSelector(this.order_ids);
|
|
|
254 |
}
|
| 569 |
rajveer |
255 |
}
|