Subversion Repositories SmartDukaan

Rev

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