Subversion Repositories SmartDukaan

Rev

Rev 3022 | Go to most recent revision | Details | 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;
5
import java.util.Calendar;
6
import java.util.Collections;
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.model.v1.catalog.InventoryService.Client;
13
import in.shop2020.model.v1.catalog.InventoryServiceException;
14
import in.shop2020.model.v1.order.Order;
15
import in.shop2020.model.v1.order.OrderStatus;
16
import in.shop2020.serving.utils.FormattingUtils;
17
import in.shop2020.thrift.clients.CatalogServiceClient;
18
import in.shop2020.thrift.clients.TransactionServiceClient;
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
import org.apache.thrift.TException;
26
 
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);
45
    private FormattingUtils formattingUtils = new FormattingUtils();
46
 
47
    Map<Long, String> providerNames = new HashMap<Long, String>();
48
    List<Order> orders = null;
49
    List<String> orderDate = new ArrayList<String>();
50
 
51
    CatalogServiceClient csc = null;
52
    Client client = null;
53
	public MyPurchasesController() {
54
		super();
55
		try {
56
			csc = new CatalogServiceClient();
57
			client = csc.getClient();
58
		} catch (Exception e) {
59
			logger.error("Unable to get catalog service client", e);
60
		}
61
	}
62
 
63
	public String index(){
64
        TransactionServiceClient transactionServiceClient = null;
65
        in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
66
        try{
67
            transactionServiceClient = new TransactionServiceClient();
68
            orderClient = transactionServiceClient.getClient();
69
            orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0, (new Date()).getTime(), OrderStatus.DELIVERY_SUCCESS);
70
            Collections.reverse(orders);
71
        } catch (Exception e)   {
72
        	logger.error("Not able to get order information from service.");
73
        }
74
		return "index";
75
    }
76
 
77
	public String formatPrice(double price)    {
78
        return formattingUtils.formatPrice(price);
79
    }
80
 
81
    public List<Order> getOrders()  {
82
        return orders;
83
    }
84
 
85
    public List<String> getOrderDate()  {
86
        return orderDate;
87
    }
88
 
89
    public String formatDate(long timestamp){
90
    	Date date = new Date(timestamp);
91
    	SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy");
92
    	return dateformat.format(date);
93
    }
94
 
95
	public String getWarrantyDate(long timestamp, String brand){
96
    	Calendar cd = Calendar.getInstance();
97
    	cd.setTimeInMillis(timestamp);
98
    	int addition = 12;
99
    	if(brand.equalsIgnoreCase(brand.trim())){
100
    		addition = 18;
101
    	}
102
    	cd.add(Calendar.MONTH, addition);
103
    	SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy");
104
    	return dateformat.format(cd.getTime());
105
    }
106
 
107
	public long getCatalogId(long itemId){
108
		if(client != null){
109
			try {
110
				return client.getItem(itemId).getCatalogItemId();
111
			} catch (InventoryServiceException e) {
112
				logger.error("Not able to get item information from service.", e);
113
			} catch (TException e) {
114
				logger.error("Not able to get item information from service.", e);
115
			}
116
		}
117
		return 0;
118
	}
119
}