Subversion Repositories SmartDukaan

Rev

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