| Line 22... |
Line 22... |
| 22 |
|
22 |
|
| 23 |
import org.apache.commons.logging.Log;
|
23 |
import org.apache.commons.logging.Log;
|
| 24 |
import org.apache.commons.logging.LogFactory;
|
24 |
import org.apache.commons.logging.LogFactory;
|
| 25 |
import org.apache.thrift.TException;
|
25 |
import org.apache.thrift.TException;
|
| 26 |
import org.apache.thrift.transport.TTransportException;
|
26 |
import org.apache.thrift.transport.TTransportException;
|
| - |
|
27 |
import org.springframework.context.ApplicationContext;
|
| - |
|
28 |
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
| 27 |
import org.springframework.transaction.annotation.Transactional;
|
29 |
import org.springframework.transaction.annotation.Transactional;
|
| 28 |
|
30 |
|
| 29 |
/**
|
31 |
/**
|
| 30 |
* @author mandeep
|
32 |
* @author mandeep
|
| 31 |
* Process all the payments failed for a customer while booking orders. A ticket per
|
33 |
* Process all the payments failed for a customer while booking orders. A ticket per
|
| 32 |
* customer is created and Outbound team tries to help customers to make a
|
34 |
* customer is created and Outbound team tries to help customers to make a
|
| 33 |
* successful payment.
|
35 |
* successful payment.
|
| 34 |
*/
|
36 |
*/
|
| 35 |
public class PaymentProcessorTask implements Runnable {
|
37 |
public class PaymentProcessorTask {
|
| 36 |
private static Log log = LogFactory
|
38 |
private static Log log = LogFactory
|
| 37 |
.getLog(PaymentProcessorTask.class);
|
39 |
.getLog(PaymentProcessorTask.class);
|
| 38 |
private static final long ADMIN_AGENT_ID = 1;
|
40 |
private static final long ADMIN_AGENT_ID = 1;
|
| 39 |
private static final long OUTBOUND_DEFAULT_ASSIGNEE_ID = 12;
|
41 |
private static final long OUTBOUND_DEFAULT_ASSIGNEE_ID = 12;
|
| 40 |
|
42 |
|
| 41 |
private TicketHandler ticketHandler;
|
43 |
private TicketHandler ticketHandler;
|
| 42 |
private ActivityHandler activityHandler;
|
44 |
private ActivityHandler activityHandler;
|
| 43 |
|
45 |
|
| 44 |
public PaymentProcessorTask(TicketHandler ticketHandler,
|
46 |
public PaymentProcessorTask() {
|
| 45 |
ActivityHandler activityHandler) {
|
47 |
ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
|
| 46 |
this.ticketHandler = ticketHandler;
|
48 |
ticketHandler = context.getBean(TicketHandler.class);
|
| 47 |
this.activityHandler = activityHandler;
|
49 |
activityHandler = context.getBean(ActivityHandler.class);
|
| 48 |
}
|
50 |
}
|
| 49 |
|
51 |
|
| 50 |
/*
|
52 |
/*
|
| 51 |
* (non-Javadoc)
|
53 |
* (non-Javadoc)
|
| 52 |
*
|
54 |
*
|
| 53 |
* @see java.lang.Runnable#run()
|
55 |
* @see java.lang.Runnable#run()
|
| 54 |
*/
|
56 |
*/
|
| 55 |
public void run() {
|
57 |
public static void main(String[] args) {
|
| 56 |
try {
|
58 |
try {
|
| - |
|
59 |
PaymentProcessorTask newTask = new PaymentProcessorTask();
|
| 57 |
Client client = new PaymentClient().getClient();
|
60 |
Client client = new PaymentClient().getClient();
|
| 58 |
List<Long> paymentIds = client
|
61 |
List<Long> paymentIds = client
|
| 59 |
.getPaymentsRequiringExtraProcessing(ExtraPaymentProcessingType.FAILED_PAYMENTS);
|
62 |
.getPaymentsRequiringExtraProcessing(ExtraPaymentProcessingType.FAILED_PAYMENTS);
|
| 60 |
if (paymentIds != null && !paymentIds.isEmpty()) {
|
63 |
if (paymentIds != null && !paymentIds.isEmpty()) {
|
| 61 |
log.info("Fetched " + paymentIds.size() + " payments");
|
64 |
log.info("Fetched " + paymentIds.size() + " payments");
|
| 62 |
for (Long paymentId : paymentIds) {
|
65 |
for (Long paymentId : paymentIds) {
|
| 63 |
processPaymentFailure(client.getPayment(paymentId).getUserId());
|
66 |
newTask.processPaymentFailure(client.getPayment(paymentId).getUserId());
|
| 64 |
client = new PaymentClient().getClient();
|
67 |
client = new PaymentClient().getClient();
|
| 65 |
client.markPaymentAsProcessed(paymentId, ExtraPaymentProcessingType.FAILED_PAYMENTS);
|
68 |
client.markPaymentAsProcessed(paymentId, ExtraPaymentProcessingType.FAILED_PAYMENTS);
|
| 66 |
}
|
69 |
}
|
| 67 |
} else {
|
70 |
} else {
|
| 68 |
log.info("No payments to process");
|
71 |
log.info("No payments to process");
|