| Line 1... |
Line 1... |
| 1 |
package in.shop2020.serving.controllers;
|
1 |
package in.shop2020.serving.controllers;
|
| 2 |
|
2 |
|
| - |
|
3 |
import in.shop2020.crm.Activity;
|
| - |
|
4 |
import in.shop2020.crm.ActivityType;
|
| 3 |
import in.shop2020.crm.SearchFilter;
|
5 |
import in.shop2020.crm.SearchFilter;
|
| 4 |
import in.shop2020.crm.Ticket;
|
6 |
import in.shop2020.crm.Ticket;
|
| 5 |
import in.shop2020.crm.TicketCategory;
|
7 |
import in.shop2020.crm.TicketCategory;
|
| - |
|
8 |
import in.shop2020.crm.TicketPriority;
|
| 6 |
import in.shop2020.crm.TicketStatus;
|
9 |
import in.shop2020.crm.TicketStatus;
|
| 7 |
import in.shop2020.model.v1.order.LineItem;
|
10 |
import in.shop2020.model.v1.order.LineItem;
|
| 8 |
import in.shop2020.model.v1.order.Order;
|
11 |
import in.shop2020.model.v1.order.Order;
|
| 9 |
import in.shop2020.model.v1.order.OrderStatus;
|
12 |
import in.shop2020.model.v1.order.OrderStatus;
|
| - |
|
13 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 10 |
import in.shop2020.model.v1.user.Address;
|
14 |
import in.shop2020.model.v1.user.Address;
|
| - |
|
15 |
import in.shop2020.model.v1.user.User;
|
| - |
|
16 |
import in.shop2020.model.v1.user.UserContextException;
|
| 11 |
import in.shop2020.payments.Attribute;
|
17 |
import in.shop2020.payments.Attribute;
|
| 12 |
import in.shop2020.payments.Constants;
|
18 |
import in.shop2020.payments.Constants;
|
| 13 |
import in.shop2020.payments.Payment;
|
19 |
import in.shop2020.payments.Payment;
|
| 14 |
import in.shop2020.payments.PaymentException;
|
20 |
import in.shop2020.payments.PaymentException;
|
| 15 |
import in.shop2020.payments.PaymentService.Client;
|
21 |
import in.shop2020.payments.PaymentService.Client;
|
| - |
|
22 |
import in.shop2020.serving.auth.CRMAuthorizingRealm;
|
| 16 |
import in.shop2020.serving.model.ShipmentUpdate;
|
23 |
import in.shop2020.serving.model.ShipmentUpdate;
|
| 17 |
import in.shop2020.serving.services.BlueDartTrackingService;
|
24 |
import in.shop2020.serving.services.BlueDartTrackingService;
|
| 18 |
import in.shop2020.thrift.clients.CRMClient;
|
25 |
import in.shop2020.thrift.clients.CRMClient;
|
| 19 |
import in.shop2020.thrift.clients.PaymentClient;
|
26 |
import in.shop2020.thrift.clients.PaymentClient;
|
| 20 |
import in.shop2020.thrift.clients.TransactionClient;
|
27 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 21 |
import in.shop2020.thrift.clients.UserClient;
|
28 |
import in.shop2020.thrift.clients.UserClient;
|
| 22 |
import in.shop2020.utils.ModelUtils;
|
29 |
import in.shop2020.utils.ModelUtils;
|
| 23 |
|
30 |
|
| 24 |
import java.util.ArrayList;
|
31 |
import java.util.ArrayList;
|
| 25 |
import java.util.Collections;
|
32 |
import java.util.Collections;
|
| - |
|
33 |
import java.util.HashSet;
|
| 26 |
import java.util.List;
|
34 |
import java.util.List;
|
| - |
|
35 |
import java.util.Set;
|
| 27 |
import java.util.concurrent.Callable;
|
36 |
import java.util.concurrent.Callable;
|
| 28 |
import java.util.concurrent.Executors;
|
37 |
import java.util.concurrent.Executors;
|
| 29 |
import java.util.concurrent.TimeUnit;
|
38 |
import java.util.concurrent.TimeUnit;
|
| 30 |
|
39 |
|
| - |
|
40 |
import net.htmlparser.jericho.Source;
|
| - |
|
41 |
|
| 31 |
import org.apache.log4j.Logger;
|
42 |
import org.apache.log4j.Logger;
|
| 32 |
import org.apache.thrift.TException;
|
43 |
import org.apache.thrift.TException;
|
| 33 |
import org.apache.thrift.transport.TTransportException;
|
44 |
import org.apache.thrift.transport.TTransportException;
|
| 34 |
|
45 |
|
| 35 |
/**
|
46 |
/**
|
| Line 45... |
Line 56... |
| 45 |
private Order order;
|
56 |
private Order order;
|
| 46 |
private List<Payment> payments;
|
57 |
private List<Payment> payments;
|
| 47 |
private List<ShipmentUpdate> shipmentUpdates = new ArrayList<ShipmentUpdate>();
|
58 |
private List<ShipmentUpdate> shipmentUpdates = new ArrayList<ShipmentUpdate>();
|
| 48 |
private Long codTicketId;
|
59 |
private Long codTicketId;
|
| 49 |
private List<Address> addresses;
|
60 |
private List<Address> addresses;
|
| - |
|
61 |
private Set<OrderStatus> setOfcancellableStates;
|
| - |
|
62 |
private String cancellationInitiator;
|
| - |
|
63 |
private String cancelReason;
|
| - |
|
64 |
private String body;
|
| 50 |
|
65 |
|
| 51 |
public UserOrderInfoController() {
|
66 |
public UserOrderInfoController() {
|
| 52 |
super();
|
67 |
super();
|
| - |
|
68 |
setOfcancellableStates = new HashSet<OrderStatus>();
|
| - |
|
69 |
setOfcancellableStates.add(OrderStatus.COD_VERIFICATION_PENDING);
|
| - |
|
70 |
setOfcancellableStates.add(OrderStatus.SUBMITTED_FOR_PROCESSING);
|
| - |
|
71 |
setOfcancellableStates.add(OrderStatus.INVENTORY_LOW);
|
| - |
|
72 |
setOfcancellableStates.add(OrderStatus.LOW_INV_PO_RAISED);
|
| - |
|
73 |
setOfcancellableStates.add(OrderStatus.LOW_INV_REVERSAL_IN_PROCESS);
|
| - |
|
74 |
setOfcancellableStates.add(OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT);
|
| - |
|
75 |
setOfcancellableStates.add(OrderStatus.ACCEPTED);
|
| - |
|
76 |
setOfcancellableStates.add(OrderStatus.BILLED);
|
| - |
|
77 |
setOfcancellableStates.add(OrderStatus.PAYMENT_FLAGGED);
|
| 53 |
}
|
78 |
}
|
| 54 |
|
79 |
|
| 55 |
public String index() throws Exception {
|
80 |
public String index() {
|
| 56 |
PaymentClient paymentServiceClient = new PaymentClient();
|
- |
|
| 57 |
TransactionClient transactionServiceClient = new TransactionClient();
|
- |
|
| 58 |
|
- |
|
| 59 |
try {
|
81 |
try {
|
| - |
|
82 |
PaymentClient paymentServiceClient = new PaymentClient();
|
| - |
|
83 |
TransactionClient transactionServiceClient = new TransactionClient();
|
| - |
|
84 |
|
| 60 |
order = transactionServiceClient.getClient().getOrder(orderId);
|
85 |
order = transactionServiceClient.getClient().getOrder(orderId);
|
| 61 |
} catch (Exception e) {
|
- |
|
| 62 |
addActionError("Invalid order id or no order selected.");
|
- |
|
| 63 |
return "index";
|
- |
|
| 64 |
}
|
- |
|
| 65 |
|
86 |
|
| 66 |
payments = paymentServiceClient.getClient()
|
87 |
payments = paymentServiceClient.getClient()
|
| 67 |
.getPaymentForTxnId(order.getTransactionId());
|
88 |
.getPaymentForTxnId(order.getTransactionId());
|
| 68 |
|
89 |
|
| 69 |
|
90 |
|
| - |
|
91 |
|
| 70 |
// Spawning a thread to capture shipment updates from Bluedart
|
92 |
// Spawning a thread to capture shipment updates from Bluedart
|
| 71 |
// This is done to ensure that response from Crm web app is sent
|
93 |
// This is done to ensure that response from Crm web app is sent
|
| 72 |
// within given time limits. Also, we wont be affected in the cases
|
94 |
// within given time limits. Also, we wont be affected in the cases
|
| 73 |
// where bluedart site is down or slow
|
95 |
// where bluedart site is down or slow
|
| 74 |
Executors.newSingleThreadExecutor().invokeAll(Collections.singletonList(new Callable<Boolean>() {
|
96 |
Executors.newSingleThreadExecutor().invokeAll(Collections.singletonList(new Callable<Boolean>() {
|
| 75 |
public Boolean call() throws Exception {
|
97 |
public Boolean call() throws Exception {
|
| 76 |
shipmentUpdates = blueDartTrackingService.getUpdates(order.getAirwaybill_no());
|
98 |
shipmentUpdates = blueDartTrackingService.getUpdates(order.getAirwaybill_no());
|
| 77 |
return true;
|
99 |
return true;
|
| - |
|
100 |
}
|
| - |
|
101 |
}), 5, TimeUnit.SECONDS);
|
| - |
|
102 |
|
| - |
|
103 |
if (order.isCod() && OrderStatus.COD_VERIFICATION_PENDING.equals(order.getStatus())) {
|
| - |
|
104 |
populateCODTicketId(order.getCustomer_id());
|
| 78 |
}
|
105 |
}
|
| 79 |
}), 5, TimeUnit.SECONDS);
|
- |
|
| 80 |
|
106 |
|
| - |
|
107 |
if (canEditOrderAddress()) {
|
| 81 |
if (order.isCod() && OrderStatus.COD_VERIFICATION_PENDING.equals(order.getStatus())) {
|
108 |
userContextServiceClient = new UserClient().getClient();
|
| 82 |
populateCODTicketId(order.getCustomer_id());
|
109 |
addresses = userContextServiceClient.getAllAddressesForUser(order.getCustomer_id());
|
| 83 |
}
|
110 |
}
|
| 84 |
|
111 |
|
| - |
|
112 |
} catch (TTransportException e) {
|
| - |
|
113 |
log.error("Unable to create thrift Client", e);
|
| - |
|
114 |
} catch (TransactionServiceException e) {
|
| - |
|
115 |
addActionError("Invalid order id or no order selected.");
|
| 85 |
if (canEditOrderAddress()) {
|
116 |
} catch (TException e) {
|
| 86 |
userContextServiceClient = new UserClient().getClient();
|
117 |
log.error("Unable to get thrift Client", e);
|
| - |
|
118 |
} catch (PaymentException e) {
|
| - |
|
119 |
log.error("Unable to get payments for transctionId : " + order.getTransactionId(), e);
|
| - |
|
120 |
} catch (InterruptedException e) {
|
| - |
|
121 |
log.error("Thread was interrupted", e);
|
| - |
|
122 |
} catch (UserContextException e) {
|
| 87 |
addresses = userContextServiceClient.getAllAddressesForUser(order.getCustomer_id());
|
123 |
log.error("Unable to get addresses for user : " + order.getCustomer_id(), e);
|
| 88 |
}
|
124 |
}
|
| 89 |
|
- |
|
| 90 |
return INDEX;
|
125 |
return INDEX;
|
| 91 |
}
|
126 |
}
|
| 92 |
|
127 |
|
| 93 |
private boolean canEditOrderAddress() {
|
128 |
private boolean canEditOrderAddress() {
|
| 94 |
return false;
|
129 |
return false;
|
| Line 110... |
Line 145... |
| 110 |
} catch (TException e) {
|
145 |
} catch (TException e) {
|
| 111 |
log.error("Error fetching tickets for customerId: " + customerId, e);
|
146 |
log.error("Error fetching tickets for customerId: " + customerId, e);
|
| 112 |
}
|
147 |
}
|
| 113 |
}
|
148 |
}
|
| 114 |
|
149 |
|
| - |
|
150 |
public String markOrderForCancellation() {
|
| - |
|
151 |
try{
|
| - |
|
152 |
TransactionClient transactionServiceClient = new TransactionClient();
|
| - |
|
153 |
log.info("URL = " + request.getRequestURI());
|
| - |
|
154 |
log.info("Initiator = " + request.getParameter("cancellationInitiator"));
|
| - |
|
155 |
log.info("orderId = " + request.getParameter("orderId"));
|
| - |
|
156 |
if (cancellationInitiator.equals("CUSTOMER")) {
|
| - |
|
157 |
order = transactionServiceClient.getClient().getOrder(orderId);
|
| - |
|
158 |
transactionServiceClient.getClient().markOrderCancellationRequestReceived(orderId);
|
| - |
|
159 |
long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId();
|
| - |
|
160 |
Ticket ticket = new Ticket();
|
| - |
|
161 |
String plainTextbody = "";
|
| - |
|
162 |
if(body!=null && !body.isEmpty()){
|
| - |
|
163 |
plainTextbody = new Source(body).getTextExtractor().toString();
|
| - |
|
164 |
}
|
| - |
|
165 |
ticket.setDescription("Creating ticket for Cancellation Request Received, Reason : " + cancelReason + " : " + plainTextbody);
|
| - |
|
166 |
ticket.setCreatorId(creatorId);
|
| - |
|
167 |
ticket.setStatus(TicketStatus.OPEN);
|
| - |
|
168 |
ticket.setPriority(TicketPriority.HIGH);
|
| - |
|
169 |
ticket.setCategory(TicketCategory.ORDER_CANCELLATION);
|
| - |
|
170 |
ticket.setOrderId(orderId);
|
| - |
|
171 |
|
| - |
|
172 |
Activity activity = new Activity();
|
| - |
|
173 |
activity.setDescription("Creating Ticket");
|
| - |
|
174 |
activity.setType(ActivityType.OTHER);
|
| - |
|
175 |
activity.setTicketPriority(TicketPriority.HIGH);
|
| - |
|
176 |
activity.setTicketStatus(TicketStatus.OPEN);
|
| - |
|
177 |
activity.setCreatorId(creatorId);
|
| - |
|
178 |
activity.setTicketDescription("Creating ticket for Cancellation Request Received, Reason : " + cancelReason + " : " + plainTextbody);
|
| - |
|
179 |
activity.setTicketCategory(TicketCategory.ORDER_CANCELLATION);
|
| - |
|
180 |
|
| - |
|
181 |
ticket.setCustomerId(order.getCustomer_id());
|
| - |
|
182 |
activity.setCustomerId(order.getCustomer_id());
|
| - |
|
183 |
ticket.setCustomerName(order.getCustomer_name());
|
| - |
|
184 |
activity.setCustomerName(order.getCustomer_name());
|
| - |
|
185 |
ticket.setCustomerEmailId(order.getCustomer_email());
|
| - |
|
186 |
activity.setCustomerEmailId(order.getCustomer_email());
|
| - |
|
187 |
ticket.setCustomerMobileNumber(order.getCustomer_mobilenumber());
|
| - |
|
188 |
activity.setCustomerMobileNumber(order.getCustomer_mobilenumber());
|
| - |
|
189 |
ticket.setAssigneeId(1);
|
| - |
|
190 |
activity.setTicketAssigneeId(1);
|
| - |
|
191 |
|
| - |
|
192 |
crmServiceClient = new CRMClient().getClient();
|
| - |
|
193 |
crmServiceClient.insertTicket(ticket, activity);
|
| - |
|
194 |
}
|
| - |
|
195 |
else if (cancellationInitiator.equals("INTERNAL")) {
|
| - |
|
196 |
String plainTextbody = "";
|
| - |
|
197 |
if(body!=null && !body.isEmpty()){
|
| - |
|
198 |
plainTextbody = new Source(body).getTextExtractor().toString();
|
| - |
|
199 |
}
|
| - |
|
200 |
transactionServiceClient.getClient().refundOrder(orderId, currentAgentEmailId, cancelReason + " : " + plainTextbody);
|
| - |
|
201 |
long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId();
|
| - |
|
202 |
Ticket ticket = new Ticket();
|
| - |
|
203 |
ticket.setDescription("Creating ticket for Order Cancellation due to Low inventory");
|
| - |
|
204 |
ticket.setCreatorId(creatorId);
|
| - |
|
205 |
ticket.setStatus(TicketStatus.CLOSED);
|
| - |
|
206 |
ticket.setPriority(TicketPriority.MEDIUM);
|
| - |
|
207 |
ticket.setCategory(TicketCategory.ORDER_CANCELLATION);
|
| - |
|
208 |
ticket.setOrderId(orderId);
|
| - |
|
209 |
|
| - |
|
210 |
Activity activity = new Activity();
|
| - |
|
211 |
activity.setDescription("Creating Ticket");
|
| - |
|
212 |
activity.setType(ActivityType.OTHER);
|
| - |
|
213 |
activity.setTicketPriority(TicketPriority.MEDIUM);
|
| - |
|
214 |
activity.setTicketStatus(TicketStatus.CLOSED);
|
| - |
|
215 |
activity.setCreatorId(creatorId);
|
| - |
|
216 |
activity.setTicketCategory(TicketCategory.ORDER_CANCELLATION);
|
| - |
|
217 |
activity.setTicketDescription("Creating ticket for Order Cancellation due to Low inventory");
|
| - |
|
218 |
|
| - |
|
219 |
ticket.setCustomerId(order.getCustomer_id());
|
| - |
|
220 |
activity.setCustomerId(order.getCustomer_id());
|
| - |
|
221 |
ticket.setCustomerName(order.getCustomer_name());
|
| - |
|
222 |
activity.setCustomerName(order.getCustomer_name());
|
| - |
|
223 |
ticket.setCustomerEmailId(order.getCustomer_email());
|
| - |
|
224 |
activity.setCustomerEmailId(order.getCustomer_email());
|
| - |
|
225 |
ticket.setCustomerMobileNumber(order.getCustomer_mobilenumber());
|
| - |
|
226 |
activity.setCustomerMobileNumber(order.getCustomer_mobilenumber());
|
| - |
|
227 |
ticket.setAssigneeId(1);
|
| - |
|
228 |
activity.setTicketAssigneeId(1);
|
| - |
|
229 |
|
| - |
|
230 |
crmServiceClient = new CRMClient().getClient();
|
| - |
|
231 |
crmServiceClient.insertTicket(ticket, activity);
|
| - |
|
232 |
}
|
| - |
|
233 |
} catch(Exception e) {
|
| - |
|
234 |
log.error("Could not mark order for Cancellation, OrderId : " + orderId, e);
|
| - |
|
235 |
}
|
| - |
|
236 |
return index();
|
| - |
|
237 |
}
|
| - |
|
238 |
|
| - |
|
239 |
public boolean canOrderBeCancelled() {
|
| - |
|
240 |
if (setOfcancellableStates.contains(order.getStatus())) {
|
| - |
|
241 |
return true;
|
| - |
|
242 |
}
|
| - |
|
243 |
return false;
|
| - |
|
244 |
}
|
| - |
|
245 |
|
| 115 |
public String getPaymentGateway(Payment payment) {
|
246 |
public String getPaymentGateway(Payment payment) {
|
| 116 |
String gatewayName = "";
|
247 |
String gatewayName = "";
|
| 117 |
|
248 |
|
| 118 |
try {
|
249 |
try {
|
| 119 |
Client paymentServiceClient = new PaymentClient().getClient();
|
250 |
Client paymentServiceClient = new PaymentClient().getClient();
|
| Line 209... |
Line 340... |
| 209 |
status = "Completed";
|
340 |
status = "Completed";
|
| 210 |
}
|
341 |
}
|
| 211 |
|
342 |
|
| 212 |
return status;
|
343 |
return status;
|
| 213 |
}
|
344 |
}
|
| - |
|
345 |
|
| - |
|
346 |
public String getCancellationInitiator() {
|
| - |
|
347 |
return cancellationInitiator;
|
| - |
|
348 |
}
|
| - |
|
349 |
|
| - |
|
350 |
public void setCancellationInitiator(String cancellationInitiator) {
|
| - |
|
351 |
this.cancellationInitiator = cancellationInitiator;
|
| - |
|
352 |
}
|
| - |
|
353 |
|
| - |
|
354 |
public String getCancelReason() {
|
| - |
|
355 |
return cancelReason;
|
| - |
|
356 |
}
|
| - |
|
357 |
|
| - |
|
358 |
public void setCancelReason(String cancelReason) {
|
| - |
|
359 |
this.cancelReason = cancelReason;
|
| - |
|
360 |
}
|
| - |
|
361 |
|
| - |
|
362 |
public String getBody() {
|
| - |
|
363 |
return body;
|
| - |
|
364 |
}
|
| - |
|
365 |
|
| - |
|
366 |
public void setBody(String body) {
|
| - |
|
367 |
this.body = body;
|
| - |
|
368 |
}
|
| 214 |
}
|
369 |
}
|
| 215 |
|
370 |
|