| Line 15... |
Line 15... |
| 15 |
import in.shop2020.model.v1.order.Order;
|
15 |
import in.shop2020.model.v1.order.Order;
|
| 16 |
import in.shop2020.model.v1.order.OrderStatus;
|
16 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 17 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
17 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 18 |
import in.shop2020.model.v1.user.User;
|
18 |
import in.shop2020.model.v1.user.User;
|
| 19 |
import in.shop2020.model.v1.user.UserContextException;
|
19 |
import in.shop2020.model.v1.user.UserContextException;
|
| - |
|
20 |
import in.shop2020.payments.Payment;
|
| - |
|
21 |
import in.shop2020.payments.PaymentException;
|
| - |
|
22 |
import in.shop2020.payments.PaymentStatus;
|
| 20 |
import in.shop2020.serving.auth.CRMAuthorizingRealm;
|
23 |
import in.shop2020.serving.auth.CRMAuthorizingRealm;
|
| 21 |
import in.shop2020.thrift.clients.CRMClient;
|
24 |
import in.shop2020.thrift.clients.CRMClient;
|
| 22 |
import in.shop2020.thrift.clients.HelperClient;
|
25 |
import in.shop2020.thrift.clients.HelperClient;
|
| - |
|
26 |
import in.shop2020.thrift.clients.PaymentClient;
|
| 23 |
import in.shop2020.thrift.clients.TransactionClient;
|
27 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 24 |
import in.shop2020.thrift.clients.UserClient;
|
28 |
import in.shop2020.thrift.clients.UserClient;
|
| 25 |
import in.shop2020.util.CRMConstants;
|
29 |
import in.shop2020.util.CRMConstants;
|
| 26 |
import in.shop2020.utils.HelperService.Client;
|
30 |
import in.shop2020.utils.HelperService.Client;
|
| 27 |
import in.shop2020.utils.HelperServiceException;
|
31 |
import in.shop2020.utils.HelperServiceException;
|
| 28 |
import in.shop2020.utils.ModelUtils;
|
32 |
import in.shop2020.utils.ModelUtils;
|
| 29 |
|
33 |
|
| 30 |
import java.text.ParseException;
|
34 |
import java.text.ParseException;
|
| 31 |
import java.util.ArrayList;
|
35 |
import java.util.ArrayList;
|
| - |
|
36 |
import java.util.Calendar;
|
| 32 |
import java.util.Collections;
|
37 |
import java.util.Collections;
|
| 33 |
import java.util.Date;
|
38 |
import java.util.Date;
|
| 34 |
import java.util.List;
|
39 |
import java.util.List;
|
| 35 |
|
40 |
|
| 36 |
import org.apache.shiro.SecurityUtils;
|
41 |
import org.apache.shiro.SecurityUtils;
|
| Line 125... |
Line 130... |
| 125 |
if (order.isCod()) {
|
130 |
if (order.isCod()) {
|
| 126 |
orders.add(order);
|
131 |
orders.add(order);
|
| 127 |
}
|
132 |
}
|
| 128 |
}
|
133 |
}
|
| 129 |
}
|
134 |
}
|
| - |
|
135 |
|
| - |
|
136 |
if (TicketCategory.FAILED_PAYMENTS.equals(ticket.getCategory())) {
|
| - |
|
137 |
log.info("Fetching orders for " + ticket.getCustomerId());
|
| - |
|
138 |
orders = new ArrayList<Order>();
|
| - |
|
139 |
in.shop2020.payments.PaymentService.Client paymentClient = new PaymentClient().getClient();
|
| - |
|
140 |
|
| - |
|
141 |
long failedTransactionId = -1;
|
| - |
|
142 |
long lastfailedTransactionTimestamp = -1;
|
| - |
|
143 |
for (Payment payment : paymentClient.getPaymentsForUser(ticket.getCustomerId(), 0, getTomorrow().getTime(), PaymentStatus.FAILED, 0)) {
|
| - |
|
144 |
if (payment.getErrorTimestamp() > lastfailedTransactionTimestamp) {
|
| - |
|
145 |
failedTransactionId = payment.getMerchantTxnId();
|
| - |
|
146 |
}
|
| - |
|
147 |
}
|
| - |
|
148 |
|
| - |
|
149 |
transactionServiceClient = new TransactionClient().getClient();
|
| - |
|
150 |
orders.addAll(transactionServiceClient.getOrdersForTransaction(failedTransactionId, ticket.getCustomerId()));
|
| - |
|
151 |
}
|
| 130 |
} catch (TException e) {
|
152 |
} catch (TException e) {
|
| 131 |
log.error("Error loading edit page", e);
|
153 |
log.error("Error loading edit page", e);
|
| 132 |
return EXCEPTION;
|
- |
|
| 133 |
} catch (NumberFormatException e) {
|
154 |
} catch (NumberFormatException e) {
|
| 134 |
log.error("Error parsing orderId", e);
|
155 |
log.error("Error parsing orderId", e);
|
| 135 |
return EXCEPTION;
|
- |
|
| 136 |
} catch (TransactionServiceException e) {
|
156 |
} catch (TransactionServiceException e) {
|
| 137 |
log.error("Error fetching orders for " + ticket.getCustomerId(), e);
|
157 |
log.error("Error fetching orders for " + ticket.getCustomerId(), e);
|
| 138 |
return EXCEPTION;
|
158 |
} catch (PaymentException e) {
|
| - |
|
159 |
log.error("Error fetching payments for " + ticket.getCustomerId(), e);
|
| 139 |
}
|
160 |
}
|
| 140 |
|
161 |
|
| 141 |
return EDIT;
|
162 |
return EDIT;
|
| 142 |
}
|
163 |
}
|
| 143 |
|
164 |
|
| 144 |
private String createSubjectString(Ticket ticket) {
|
165 |
private String createSubjectString(Ticket ticket) {
|
| 145 |
return CRMConstants.CRM_SUBJECT_PREFIX_FOR_TICKET_ID + ticket.getId()
|
166 |
return CRMConstants.CRM_SUBJECT_PREFIX_FOR_TICKET_ID + ticket.getId()
|
| 146 |
+ " " + ticket.getCategory().name();
|
167 |
+ " " + ticket.getCategory().name();
|
| 147 |
}
|
168 |
}
|
| 148 |
|
169 |
|
| - |
|
170 |
private Date getTomorrow() {
|
| - |
|
171 |
Calendar calendar = Calendar.getInstance();
|
| - |
|
172 |
calendar.setTime(new Date());
|
| - |
|
173 |
calendar.add(Calendar.DAY_OF_MONTH, 1);
|
| - |
|
174 |
return calendar.getTime();
|
| - |
|
175 |
}
|
| - |
|
176 |
|
| 149 |
public String create() {
|
177 |
public String create() {
|
| 150 |
try {
|
178 |
try {
|
| 151 |
long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId)
|
179 |
long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId)
|
| 152 |
.getId();
|
180 |
.getId();
|
| 153 |
Ticket ticket = new Ticket();
|
181 |
Ticket ticket = new Ticket();
|
| Line 336... |
Line 364... |
| 336 |
Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);
|
364 |
Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);
|
| 337 |
ticket.setDescription(description);
|
365 |
ticket.setDescription(description);
|
| 338 |
ticket.setPriority(TicketPriority.valueOf(priority));
|
366 |
ticket.setPriority(TicketPriority.valueOf(priority));
|
| 339 |
|
367 |
|
| 340 |
// Update when a ticket is closed!
|
368 |
// Update when a ticket is closed!
|
| 341 |
if (TicketStatus.CLOSED.name().equals(status)) {
|
369 |
if (TicketStatus.CLOSED.name().equals(status) || TicketCategory.COD_VERIFICATION.equals(ticket.getCategory())) {
|
| 342 |
if (TicketCategory.COD_VERIFICATION.equals(ticket.getCategory())
|
370 |
if (TicketCategory.COD_VERIFICATION.equals(ticket.getCategory())
|
| 343 |
&& pendingCODOrders(ticket.getCustomerId())) {
|
371 |
&& pendingCODOrders(ticket.getCustomerId())) {
|
| 344 |
addActionMessage("Cod orders pending for verification. Ticket can not be closed and its category cannot be changed.");
|
372 |
addActionMessage("Cod orders pending for verification. Ticket can not be closed and its category cannot be changed.");
|
| 345 |
} else {
|
373 |
} else {
|
| 346 |
ticket.setCategory(TicketCategory.valueOf(category));
|
374 |
ticket.setCategory(TicketCategory.valueOf(category));
|
| Line 348... |
Line 376... |
| 348 |
ticket.setCloseDate(new Date().getTime());
|
376 |
ticket.setCloseDate(new Date().getTime());
|
| 349 |
}
|
377 |
}
|
| 350 |
}
|
378 |
}
|
| 351 |
else {
|
379 |
else {
|
| 352 |
ticket.setCategory(TicketCategory.valueOf(category));
|
380 |
ticket.setCategory(TicketCategory.valueOf(category));
|
| 353 |
ticket.setStatus(TicketStatus.valueOf(status));
|
381 |
ticket.setStatus(TicketStatus.valueOf(status));
|
| 354 |
}
|
382 |
}
|
| 355 |
|
383 |
|
| 356 |
if (activityDescription == null || activityDescription.isEmpty()) {
|
384 |
if (activityDescription == null || activityDescription.isEmpty()) {
|
| 357 |
activityDescription = "Updating ticket fields";
|
385 |
activityDescription = "Updating ticket fields";
|
| 358 |
}
|
386 |
}
|
| Line 465... |
Line 493... |
| 465 |
public String updateOrderStatus() throws NumberFormatException,
|
493 |
public String updateOrderStatus() throws NumberFormatException,
|
| 466 |
TransactionServiceException, TException {
|
494 |
TransactionServiceException, TException {
|
| 467 |
long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId)
|
495 |
long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId)
|
| 468 |
.getId();
|
496 |
.getId();
|
| 469 |
|
497 |
|
| - |
|
498 |
OrderStatus orderStatusEnum = OrderStatus.valueOf(orderStatus);
|
| 470 |
transactionServiceClient = new TransactionClient().getClient();
|
499 |
transactionServiceClient = new TransactionClient().getClient();
|
| - |
|
500 |
|
| - |
|
501 |
if (OrderStatus.SUBMITTED_FOR_PROCESSING.equals(orderStatusEnum)) {
|
| 471 |
transactionServiceClient.changeOrderStatus(Long.parseLong(orderId),
|
502 |
transactionServiceClient.verifyOrder(Long.parseLong(orderId));
|
| - |
|
503 |
}
|
| 472 |
OrderStatus.valueOf(orderStatus),
|
504 |
else if (OrderStatus.CANCELED.equals(orderStatusEnum)) {
|
| 473 |
OrderStatus.valueOf(orderStatus).getDescription());
|
505 |
transactionServiceClient.refundOrder(Long.parseLong(orderId), currentAgentEmailId, "COD - Cancelled");
|
| - |
|
506 |
}
|
| - |
|
507 |
else {
|
| - |
|
508 |
throw new UnsupportedOperationException("Cannot update status of orderId: " + orderId + " to: " + orderStatus);
|
| - |
|
509 |
}
|
| 474 |
|
510 |
|
| 475 |
SearchFilter searchFilter = new SearchFilter();
|
511 |
SearchFilter searchFilter = new SearchFilter();
|
| 476 |
searchFilter.setTicketId(Long.parseLong(id));
|
512 |
searchFilter.setTicketId(Long.parseLong(id));
|
| 477 |
crmServiceClient = new CRMClient().getClient();
|
513 |
crmServiceClient = new CRMClient().getClient();
|
| 478 |
Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);
|
514 |
Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);
|