Subversion Repositories SmartDukaan

Rev

Rev 1044 | Rev 2355 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1044 Rev 2224
Line 1... Line 1...
1
/**
1
/**
2
 * 
2
 * 
3
 */
3
 */
4
package in.shop2020.serving.controllers;
4
package in.shop2020.serving.controllers;
5
 
5
 
-
 
6
import in.shop2020.logistics.Provider;
-
 
7
import in.shop2020.model.v1.order.Order;
-
 
8
import in.shop2020.model.v1.order.OrderStatus;
-
 
9
import in.shop2020.serving.utils.FormattingUtils;
-
 
10
import in.shop2020.thrift.clients.LogisticsServiceClient;
-
 
11
import in.shop2020.thrift.clients.TransactionServiceClient;
-
 
12
 
6
import java.io.UnsupportedEncodingException;
13
import java.io.UnsupportedEncodingException;
-
 
14
import java.text.SimpleDateFormat;
-
 
15
import java.util.ArrayList;
-
 
16
import java.util.Date;
-
 
17
import java.util.HashMap;
-
 
18
import java.util.List;
-
 
19
import java.util.Map;
7
 
20
 
8
import org.apache.log4j.Logger;
21
import org.apache.log4j.Logger;
9
import org.apache.struts2.convention.annotation.InterceptorRef;
22
import org.apache.struts2.convention.annotation.InterceptorRef;
10
import org.apache.struts2.convention.annotation.InterceptorRefs;
23
import org.apache.struts2.convention.annotation.InterceptorRefs;
11
import org.apache.struts2.convention.annotation.Result;
24
import org.apache.struts2.convention.annotation.Result;
Line 26... Line 39...
26
    		params = {"actionName" , "login"})
39
    		params = {"actionName" , "login"})
27
})
40
})
28
public class CompletedOrdersController extends BaseController {
41
public class CompletedOrdersController extends BaseController {
29
 
42
 
30
	private static final long serialVersionUID = 1L;
43
	private static final long serialVersionUID = 1L;
31
	private static Logger log = Logger.getLogger(Class.class);	
44
	private static Logger log = Logger.getLogger(Class.class);
-
 
45
    private FormattingUtils formattingUtils = new FormattingUtils();
-
 
46
    
-
 
47
    private List<Order> orders = null;
-
 
48
    private List<String> orderDate = new ArrayList<String>();
-
 
49
    private Map<Long, String> providerNames = new HashMap<Long, String>();	
32
	
50
	
33
	public CompletedOrdersController() {
51
	public CompletedOrdersController() {
34
		super();
52
		super();
35
	}
53
	}
36
	
54
	
37
    // GET /completed-orders
55
    // GET /completed-orders
38
    public String index() throws UnsupportedEncodingException {
56
    public String index() throws UnsupportedEncodingException {
39
    	log.info("this.request=" + this.request);
57
    	log.info("this.request=" + this.request);
40
    	
58
    	
-
 
59
        TransactionServiceClient transactionServiceClient = null;
-
 
60
        in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
-
 
61
        
-
 
62
        try{
-
 
63
            transactionServiceClient = new TransactionServiceClient();
-
 
64
            orderClient = transactionServiceClient.getClient();
-
 
65
            orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0, (new Date()).getTime(), OrderStatus.DELIVERY_SUCCESS);
-
 
66
 
-
 
67
            LogisticsServiceClient logisticsServiceClient = new LogisticsServiceClient();
-
 
68
            in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
-
 
69
            List<Provider> providers = logisticsClient.getAllProviders();
-
 
70
            for(Provider provider: providers)
41
		htmlSnippets.put("MYACCOUNT_HEADER", pageLoader.getMyaccountHeaderHtml());
71
                providerNames.put(provider.getId(), provider.getName());
-
 
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){
42
		htmlSnippets.put("MYACCOUNT_DETAILS", pageLoader.getCompletedOrdersHtml(userinfo.getUserId()));
77
                    Date orderedOn = new Date(order.getCreated_timestamp());
-
 
78
                    orderDate.add(dateformat.format(orderedOn));
-
 
79
                }
-
 
80
            }
-
 
81
        } catch (Exception e)   {
-
 
82
            
-
 
83
        }
43
		return "index";
84
		return "index";
44
    	
-
 
45
    }
85
    }
46
    
86
    
47
    public String getMyaccountHeaderSnippet(){
87
    public List<Order> getOrders()   {
48
		return htmlSnippets.get("MYACCOUNT_HEADER");
88
		return this.orders;
49
	}
89
	}
50
	
90
	
51
	public String getMyaccountDetailsSnippet(){
91
	public List<String> getOrderDate() {
-
 
92
	    return this.orderDate;
-
 
93
	}
-
 
94
    
-
 
95
	public Map<Long, String> getProviderNames()   {
52
		return htmlSnippets.get("MYACCOUNT_DETAILS");
96
	    return this.providerNames;
53
	}
97
	}
54
 
98
 
-
 
99
    public String formatPrice(double price)    {
-
 
100
        return formattingUtils.formatPrice(price);
-
 
101
    }
55
}
102
}
56
103