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