Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
405 rajveer 1
package in.shop2020.serving.controllers;
2
 
2191 varun.gupt 3
import java.text.SimpleDateFormat;
4
import java.util.ArrayList;
3014 chandransh 5
import java.util.Arrays;
2355 rajveer 6
import java.util.Collections;
2191 varun.gupt 7
import java.util.Date;
8
import java.util.HashMap;
9
import java.util.List;
10
import java.util.Map;
11
 
12
import in.shop2020.logistics.Provider;
13
import in.shop2020.model.v1.order.Order;
3014 chandransh 14
import in.shop2020.model.v1.order.OrderStatus;
2191 varun.gupt 15
import in.shop2020.serving.utils.FormattingUtils;
16
import in.shop2020.thrift.clients.LogisticsServiceClient;
17
import in.shop2020.thrift.clients.TransactionServiceClient;
18
 
832 rajveer 19
import org.apache.log4j.Logger;
781 vikas 20
import org.apache.struts2.convention.annotation.InterceptorRef;
21
import org.apache.struts2.convention.annotation.InterceptorRefs;
413 rajveer 22
import org.apache.struts2.convention.annotation.Result;
23
import org.apache.struts2.convention.annotation.Results;
405 rajveer 24
 
25
/**
413 rajveer 26
 * @author rajveer
405 rajveer 27
 *
28
 */
413 rajveer 29
 
3014 chandransh 30
@SuppressWarnings("serial")
781 vikas 31
@InterceptorRefs({
822 vikas 32
    @InterceptorRef("myDefault"),
33
    @InterceptorRef("login")
781 vikas 34
})
35
 
637 rajveer 36
@Results({
37
    @Result(name="redirect", type="redirectAction", 
38
    		params = {"actionName" , "login"})
39
})
650 rajveer 40
public class MyaccountController extends BaseController {
405 rajveer 41
 
2897 chandransh 42
	private static Logger logger = Logger.getLogger(Class.class);
3014 chandransh 43
	private static final List<OrderStatus> statuses = Arrays.asList(new OrderStatus[] {});
2191 varun.gupt 44
    private FormattingUtils formattingUtils = new FormattingUtils();
650 rajveer 45
 
2191 varun.gupt 46
    Map<Long, String> providerNames = new HashMap<Long, String>();
47
    List<Order> orders = null;
48
    List<String> orderDate = new ArrayList<String>();
405 rajveer 49
 
50
	public MyaccountController() {
51
		super();
52
	}
650 rajveer 53
 
54
	public String index(){
2897 chandransh 55
    	logger.info("this.request=" + this.request);
650 rajveer 56
 
2191 varun.gupt 57
        try {
58
            TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
59
            in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
3014 chandransh 60
            orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0, (new Date()).getTime(), statuses);
2355 rajveer 61
            //Reverse the list of order. Last come first displayed 
62
            Collections.reverse(orders);
2191 varun.gupt 63
            LogisticsServiceClient logisticsServiceClient = new LogisticsServiceClient();
64
            in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
65
            List<Provider> providers = logisticsClient.getAllProviders();
66
 
67
            for(Provider provider: providers)
68
                providerNames.put(provider.getId(), provider.getName());
69
 
70
        } catch (Exception e)   {
2897 chandransh 71
            logger.error("Error while getting the orders for the user", e);
2191 varun.gupt 72
        }
73
        SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
74
 
75
        if(orders != null && !orders.isEmpty()){
76
            for(Order order: orders)    {
77
                Date orderedOn = new Date(order.getCreated_timestamp());
78
                orderDate.add(dateformat.format(orderedOn));
79
            }
80
        }
650 rajveer 81
		return "index";
405 rajveer 82
    }
83
 
2191 varun.gupt 84
	public String formatPrice(double price)    {
85
        return formattingUtils.formatPrice(price);
86
    }
507 rajveer 87
 
2191 varun.gupt 88
    public Map<Long, String> getProviderNames() {
89
        return providerNames;
90
    }
91
 
92
    public List<Order> getOrders()  {
93
        return orders;
94
    }
95
 
96
    public List<String> getOrderDate()  {
97
        return orderDate;
98
    }
99
}