| 4267 |
anupam.sin |
1 |
package in.shop2020.crm.util;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.crm.ActivityType;
|
|
|
4 |
import in.shop2020.crm.TicketCategory;
|
|
|
5 |
import in.shop2020.crm.TicketPriority;
|
|
|
6 |
import in.shop2020.crm.TicketStatus;
|
|
|
7 |
import in.shop2020.crm.domain.Activity;
|
|
|
8 |
import in.shop2020.crm.domain.SearchFilter;
|
|
|
9 |
import in.shop2020.crm.domain.Ticket;
|
|
|
10 |
import in.shop2020.crm.handler.ActivityHandler;
|
|
|
11 |
import in.shop2020.crm.handler.TicketHandler;
|
|
|
12 |
import in.shop2020.model.v1.order.ExtraTransactionProcessingType;
|
|
|
13 |
import in.shop2020.model.v1.order.TransactionService.Client;
|
|
|
14 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
|
|
15 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
16 |
|
|
|
17 |
import java.util.ArrayList;
|
|
|
18 |
import java.util.List;
|
|
|
19 |
|
|
|
20 |
import org.apache.commons.logging.Log;
|
|
|
21 |
import org.apache.commons.logging.LogFactory;
|
|
|
22 |
import org.apache.thrift.TException;
|
|
|
23 |
import org.apache.thrift.transport.TTransportException;
|
|
|
24 |
import org.springframework.context.ApplicationContext;
|
|
|
25 |
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
|
|
26 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
public class FlaggedPaymentProcessorTask {
|
|
|
30 |
private static Log log = LogFactory.getLog(DelayedOrderProcessorTask.class);
|
|
|
31 |
private static final long ADMIN_AGENT_ID = 1;
|
| 6667 |
amar.kumar |
32 |
private static final long FLAGGED_PAYMENTS_DEFAULT_ASSIGNEE_ID = 34;
|
| 4267 |
anupam.sin |
33 |
|
|
|
34 |
private TicketHandler ticketHandler;
|
|
|
35 |
private ActivityHandler activityHandler;
|
|
|
36 |
|
|
|
37 |
public FlaggedPaymentProcessorTask()
|
|
|
38 |
{
|
|
|
39 |
ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
|
|
|
40 |
ticketHandler = context.getBean(TicketHandler.class);
|
|
|
41 |
activityHandler = context.getBean(ActivityHandler.class);
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
/* (non-Javadoc)
|
|
|
45 |
* @see java.lang.Runnable#run()
|
|
|
46 |
*/
|
|
|
47 |
/**
|
|
|
48 |
* @param args
|
|
|
49 |
*/
|
|
|
50 |
public static void main(String[] args) {
|
|
|
51 |
try {
|
|
|
52 |
FlaggedPaymentProcessorTask newTask = new FlaggedPaymentProcessorTask();
|
|
|
53 |
Client client = new TransactionClient().getClient();
|
|
|
54 |
List<Long> transactionIds = client.getTransactionsRequiringExtraProcessing(ExtraTransactionProcessingType.PAYMENT_FLAGGED);
|
|
|
55 |
if (transactionIds != null && !transactionIds.isEmpty()) {
|
|
|
56 |
log.info("Fetched " + transactionIds.size() + " transactions");
|
|
|
57 |
for (Long transactionId : transactionIds) {
|
| 4274 |
mandeep.dh |
58 |
client = new TransactionClient().getClient();
|
|
|
59 |
newTask.processFlaggedPayment(client.getTransaction(transactionId).getCustomer_id());
|
|
|
60 |
client = new TransactionClient().getClient();
|
|
|
61 |
client.markTransactionAsProcessed(transactionId, ExtraTransactionProcessingType.PAYMENT_FLAGGED);
|
| 4267 |
anupam.sin |
62 |
}
|
|
|
63 |
}
|
|
|
64 |
else {
|
|
|
65 |
log.info("No transactions to process");
|
|
|
66 |
}
|
|
|
67 |
} catch (TTransportException e) {
|
|
|
68 |
log.error("Could not create TransactionService client", e);
|
|
|
69 |
} catch (TException e) {
|
|
|
70 |
log.error("Could not fetch transactions for processing", e);
|
|
|
71 |
} catch (TransactionServiceException e) {
|
|
|
72 |
log.error("Could not lookup transaction", e);
|
|
|
73 |
}
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
private void processFlaggedPayment(Long customerId) {
|
|
|
77 |
log.info("Processing flagged payment for customerId: " + customerId);
|
|
|
78 |
SearchFilter searchFilter = new SearchFilter();
|
|
|
79 |
searchFilter.setTicketStatuses(new ArrayList<TicketStatus>());
|
|
|
80 |
searchFilter.getTicketStatuses().add(TicketStatus.OPEN);
|
|
|
81 |
searchFilter.getTicketStatuses().add(TicketStatus.REOPEN);
|
|
|
82 |
searchFilter.setTicketCategory(TicketCategory.PAYMENT_FLAGGED);
|
|
|
83 |
searchFilter.setCustomerId(customerId);
|
|
|
84 |
|
|
|
85 |
// No need to create a ticket if there exists one for the customer!
|
|
|
86 |
if (ticketHandler.getTickets(searchFilter).isEmpty()) {
|
|
|
87 |
Ticket ticket = new Ticket();
|
|
|
88 |
ticket.setCategory(TicketCategory.PAYMENT_FLAGGED);
|
|
|
89 |
ticket.setCreatorId(ADMIN_AGENT_ID);
|
|
|
90 |
ticket.setCustomerId(customerId);
|
|
|
91 |
ticket.setDescription("Payment is Flagged");
|
|
|
92 |
ticket.setPriority(TicketPriority.HIGH);
|
|
|
93 |
ticket.setStatus(TicketStatus.OPEN);
|
|
|
94 |
ticket.setAssigneeId(FLAGGED_PAYMENTS_DEFAULT_ASSIGNEE_ID);
|
|
|
95 |
|
|
|
96 |
Activity activity = new Activity();
|
|
|
97 |
activity.setCreatorId(ticket.getCreatorId());
|
|
|
98 |
activity.setCustomerId(ticket.getCustomerId());
|
|
|
99 |
activity.setDescription("Creating ticket");
|
|
|
100 |
activity.setTicketCategory(ticket.getCategory());
|
|
|
101 |
activity.setTicketDescription(ticket.getDescription());
|
|
|
102 |
activity.setTicketPriority(ticket.getPriority());
|
|
|
103 |
activity.setTicketStatus(ticket.getStatus());
|
|
|
104 |
activity.setType(ActivityType.OTHER);
|
|
|
105 |
activity.setTicketAssigneeId(ticket.getAssigneeId());
|
|
|
106 |
|
|
|
107 |
createTicket(ticket, activity);
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
@Transactional
|
|
|
112 |
private void createTicket(Ticket ticket, Activity activity) {
|
|
|
113 |
ticketHandler.insertTicket(ticket);
|
|
|
114 |
activity.setTicketId(ticket.getId());
|
|
|
115 |
activityHandler.insertActivity(activity);
|
|
|
116 |
}
|
|
|
117 |
}
|