Subversion Repositories SmartDukaan

Rev

Rev 4191 | Rev 5484 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4191 Rev 5142
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
 *
33
 *
32
 * This class processes all the orders whose delivery has been delayed due
34
 * This class processes all the orders whose delivery has been delayed due
33
 * to one or the other issue (delayReason field). We create a ticket per customer
35
 * to one or the other issue (delayReason field). We create a ticket per customer
34
 * in such cases and Outbound team intimates them regarding the delay.
36
 * in such cases and Outbound team intimates them regarding the delay.
35
 */
37
 */
36
public class DelayedOrderProcessorTask implements Runnable {
38
public class DelayedOrderProcessorTask {
37
    private static Log log = LogFactory.getLog(DelayedOrderProcessorTask.class);
39
    private static Log log = LogFactory.getLog(DelayedOrderProcessorTask.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 DelayedOrderProcessorTask(TicketHandler ticketHandler,
46
    public DelayedOrderProcessorTask()
45
            ActivityHandler activityHandler)
-
 
46
    {
47
    {
-
 
48
        ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
47
        this.ticketHandler = ticketHandler;
49
        ticketHandler              = context.getBean(TicketHandler.class);
48
        this.activityHandler = activityHandler;
50
        activityHandler            = context.getBean(ActivityHandler.class);
49
    }
51
    }
50
 
52
 
51
    /* (non-Javadoc)
-
 
52
     * @see java.lang.Runnable#run()
-
 
53
     */
-
 
54
    public void run() {
53
    public static void main(String[] args) {
55
        try {
54
        try {
-
 
55
            DelayedOrderProcessorTask newTask = new DelayedOrderProcessorTask();
56
            Client client = new TransactionClient().getClient();
56
            Client client = new TransactionClient().getClient();
57
            List<Long> transactionIds = client.getTransactionsRequiringExtraProcessing(ExtraTransactionProcessingType.DELAYED_DELIVERY);
57
            List<Long> transactionIds = client.getTransactionsRequiringExtraProcessing(ExtraTransactionProcessingType.DELAYED_DELIVERY);
58
            if (transactionIds != null && !transactionIds.isEmpty()) {
58
            if (transactionIds != null && !transactionIds.isEmpty()) {
59
                log.info("Fetched " + transactionIds.size() + " transactions");
59
                log.info("Fetched " + transactionIds.size() + " transactions");
60
                for (Long transactionId : transactionIds) {
60
                for (Long transactionId : transactionIds) {
61
                    processDelayedOrder(client.getTransaction(transactionId).getCustomer_id());
61
                    newTask.processDelayedOrder(client.getTransaction(transactionId).getCustomer_id());
62
                    client.markTransactionAsProcessed(transactionId, ExtraTransactionProcessingType.DELAYED_DELIVERY);
62
                    client.markTransactionAsProcessed(transactionId, ExtraTransactionProcessingType.DELAYED_DELIVERY);
63
                }
63
                }
64
            }
64
            }
65
            else {
65
            else {
66
                log.info("No transactions to process");
66
                log.info("No transactions to process");