Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
3019 rajveer 1
package in.shop2020.serving.controllers;
2
 
3
import java.text.SimpleDateFormat;
4
import java.util.ArrayList;
3022 rajveer 5
import java.util.Arrays;
3019 rajveer 6
import java.util.Calendar;
7
import java.util.Collections;
8
import java.util.Date;
9
import java.util.HashMap;
10
import java.util.List;
11
import java.util.Map;
12
 
13
import in.shop2020.model.v1.catalog.InventoryService.Client;
14
import in.shop2020.model.v1.order.Order;
15
import in.shop2020.model.v1.order.OrderStatus;
16
import in.shop2020.serving.utils.FormattingUtils;
3126 rajveer 17
import in.shop2020.thrift.clients.CatalogClient;
18
import in.shop2020.thrift.clients.TransactionClient;
3019 rajveer 19
 
20
import org.apache.log4j.Logger;
21
import org.apache.struts2.convention.annotation.InterceptorRef;
22
import org.apache.struts2.convention.annotation.InterceptorRefs;
23
import org.apache.struts2.convention.annotation.Result;
24
import org.apache.struts2.convention.annotation.Results;
25
 
3561 rajveer 26
 
3019 rajveer 27
/**
28
 * @author rajveer
29
 *
30
 */
31
 
32
@InterceptorRefs({
33
    @InterceptorRef("myDefault"),
34
    @InterceptorRef("login")
35
})
36
 
37
@Results({
38
    @Result(name="redirect", type="redirectAction", 
39
    		params = {"actionName" , "login"})
40
})
41
public class MyPurchasesController extends BaseController {
42
 
43
	private static final long serialVersionUID = 1L;
44
	private static Logger logger = Logger.getLogger(Class.class);
3022 rajveer 45
	private static final List<OrderStatus> statuses = Arrays.asList(new OrderStatus[] {OrderStatus.DELIVERY_SUCCESS});
46
 
3019 rajveer 47
    private FormattingUtils formattingUtils = new FormattingUtils();
48
 
49
    Map<Long, String> providerNames = new HashMap<Long, String>();
50
    List<Order> orders = null;
51
    List<String> orderDate = new ArrayList<String>();
52
 
3126 rajveer 53
    CatalogClient csc = null;
3019 rajveer 54
    Client client = null;
55
	public MyPurchasesController() {
56
		super();
57
		try {
3126 rajveer 58
			csc = new CatalogClient();
3019 rajveer 59
			client = csc.getClient();
60
		} catch (Exception e) {
61
			logger.error("Unable to get catalog service client", e);
62
		}
63
	}
64
 
65
	public String index(){
3126 rajveer 66
        TransactionClient transactionServiceClient = null;
3019 rajveer 67
        in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
68
        try{
3126 rajveer 69
            transactionServiceClient = new TransactionClient();
3019 rajveer 70
            orderClient = transactionServiceClient.getClient();
3022 rajveer 71
            orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0, (new Date()).getTime(), statuses);
3019 rajveer 72
            Collections.reverse(orders);
73
        } catch (Exception e)   {
74
        	logger.error("Not able to get order information from service.");
75
        }
76
		return "index";
77
    }
78
 
79
	public String formatPrice(double price)    {
80
        return formattingUtils.formatPrice(price);
81
    }
82
 
83
    public List<Order> getOrders()  {
84
        return orders;
85
    }
86
 
87
    public List<String> getOrderDate()  {
88
        return orderDate;
89
    }
90
 
91
    public String formatDate(long timestamp){
92
    	Date date = new Date(timestamp);
93
    	SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy");
94
    	return dateformat.format(date);
95
    }
96
 
97
	public String getWarrantyDate(long timestamp, String brand){
98
    	Calendar cd = Calendar.getInstance();
99
    	cd.setTimeInMillis(timestamp);
100
    	int addition = 12;
101
    	if(brand.equalsIgnoreCase(brand.trim())){
102
    		addition = 18;
103
    	}
104
    	cd.add(Calendar.MONTH, addition);
105
    	SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy");
106
    	return dateformat.format(cd.getTime());
107
    }
108
}