Subversion Repositories SmartDukaan

Rev

Rev 2895 | Rev 3121 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2895 chandransh 1
package in.shop2020.serving.controllers;
2
 
3
import in.shop2020.model.v1.order.Order;
4
import in.shop2020.model.v1.order.OrderStatus;
5
import in.shop2020.serving.utils.FormattingUtils;
6
import in.shop2020.thrift.clients.TransactionServiceClient;
7
 
8
import java.text.SimpleDateFormat;
3014 chandransh 9
import java.util.Arrays;
2895 chandransh 10
import java.util.Collections;
11
import java.util.Date;
12
import java.util.List;
13
 
14
import org.apache.log4j.Logger;
15
import org.apache.struts2.convention.annotation.InterceptorRef;
16
import org.apache.struts2.convention.annotation.InterceptorRefs;
17
import org.apache.struts2.convention.annotation.Result;
18
import org.apache.struts2.convention.annotation.Results;
19
 
20
@SuppressWarnings("serial")
21
@InterceptorRefs({
22
    @InterceptorRef("myDefault"),
23
    @InterceptorRef("login")
24
})
25
 
26
@Results({
27
    @Result(name="redirect", type="redirectAction", 
28
            params = {"actionName" , "login"})
29
})
30
public class FailedOrdersController extends BaseController {
31
    private static Logger logger = Logger.getLogger(FailedOrdersController.class);
3014 chandransh 32
    private static final List<OrderStatus> statuses = Arrays.asList(new OrderStatus[] {OrderStatus.PAYMENT_FAILED});
33
 
2895 chandransh 34
    private FormattingUtils formattingUtils = new FormattingUtils();
3014 chandransh 35
    SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
2895 chandransh 36
    List<Order> orders = null;
37
 
38
    public String index(){
39
        logger.info("this.request=" + this.request);
40
 
41
        try {
42
            TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
43
            in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
3014 chandransh 44
 
45
            orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0, (new Date()).getTime(), statuses);
2895 chandransh 46
            //Reverse the list of order. Last come should be displayed first. 
47
            Collections.reverse(orders);            
48
        } catch (Exception e)   {
49
            logger.error("Unable to get the failed orders of the customer", e);
50
        }
51
 
52
        return "index";
53
    }
54
 
55
    public String formatPrice(double price)    {
56
        return formattingUtils.formatPrice(price);
57
    }
58
 
59
    public List<Order> getOrders()  {
60
        return orders;
61
    }
62
 
63
    public String getOrderCreationDate(Order order){        
64
        Date orderedOn = new Date(order.getCreated_timestamp());
65
        return dateformat.format(orderedOn);
66
    }
67
}