| 3019 |
rajveer |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
| 8274 |
amit.gupta |
3 |
import in.shop2020.model.v1.catalog.BrandInfo;
|
|
|
4 |
import in.shop2020.model.v1.catalog.CatalogService.Client;
|
|
|
5 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
|
|
6 |
import in.shop2020.model.v1.order.Order;
|
|
|
7 |
import in.shop2020.model.v1.order.OrderStatus;
|
|
|
8 |
import in.shop2020.model.v1.order.TransactionService;
|
|
|
9 |
import in.shop2020.serving.utils.FormattingUtils;
|
|
|
10 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
11 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
12 |
|
| 6915 |
anupam.sin |
13 |
import java.nio.ByteBuffer;
|
| 3019 |
rajveer |
14 |
import java.text.SimpleDateFormat;
|
|
|
15 |
import java.util.ArrayList;
|
| 3022 |
rajveer |
16 |
import java.util.Arrays;
|
| 3019 |
rajveer |
17 |
import java.util.Calendar;
|
|
|
18 |
import java.util.Collections;
|
|
|
19 |
import java.util.Date;
|
|
|
20 |
import java.util.HashMap;
|
|
|
21 |
import java.util.List;
|
|
|
22 |
import java.util.Map;
|
|
|
23 |
|
| 6915 |
anupam.sin |
24 |
import javax.servlet.ServletOutputStream;
|
|
|
25 |
|
| 5945 |
mandeep.dh |
26 |
import in.shop2020.model.v1.catalog.CatalogService.Client;
|
|
|
27 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
| 3019 |
rajveer |
28 |
import in.shop2020.model.v1.order.Order;
|
|
|
29 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 6915 |
anupam.sin |
30 |
import in.shop2020.model.v1.order.TransactionService;
|
| 3019 |
rajveer |
31 |
import in.shop2020.serving.utils.FormattingUtils;
|
| 3126 |
rajveer |
32 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
33 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 3019 |
rajveer |
34 |
|
|
|
35 |
import org.apache.log4j.Logger;
|
|
|
36 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
37 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
|
|
38 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
39 |
import org.apache.struts2.convention.annotation.Results;
|
| 3950 |
rajveer |
40 |
import org.apache.thrift.TException;
|
| 3019 |
rajveer |
41 |
|
| 3561 |
rajveer |
42 |
|
| 3019 |
rajveer |
43 |
/**
|
|
|
44 |
* @author rajveer
|
|
|
45 |
*
|
|
|
46 |
*/
|
|
|
47 |
|
|
|
48 |
@InterceptorRefs({
|
|
|
49 |
@InterceptorRef("myDefault"),
|
|
|
50 |
@InterceptorRef("login")
|
|
|
51 |
})
|
|
|
52 |
|
|
|
53 |
@Results({
|
|
|
54 |
@Result(name="redirect", type="redirectAction",
|
|
|
55 |
params = {"actionName" , "login"})
|
|
|
56 |
})
|
|
|
57 |
public class MyPurchasesController extends BaseController {
|
|
|
58 |
|
|
|
59 |
private static final long serialVersionUID = 1L;
|
|
|
60 |
private static Logger logger = Logger.getLogger(Class.class);
|
| 3022 |
rajveer |
61 |
private static final List<OrderStatus> statuses = Arrays.asList(new OrderStatus[] {OrderStatus.DELIVERY_SUCCESS});
|
|
|
62 |
|
| 3019 |
rajveer |
63 |
private FormattingUtils formattingUtils = new FormattingUtils();
|
|
|
64 |
|
|
|
65 |
Map<Long, String> providerNames = new HashMap<Long, String>();
|
|
|
66 |
List<Order> orders = null;
|
| 8274 |
amit.gupta |
67 |
Map<String, BrandInfo> brandInfo = null;
|
| 3019 |
rajveer |
68 |
List<String> orderDate = new ArrayList<String>();
|
| 6915 |
anupam.sin |
69 |
|
|
|
70 |
private String orderId;
|
| 3019 |
rajveer |
71 |
|
| 3126 |
rajveer |
72 |
CatalogClient csc = null;
|
| 3019 |
rajveer |
73 |
Client client = null;
|
|
|
74 |
public MyPurchasesController() {
|
|
|
75 |
super();
|
|
|
76 |
try {
|
| 3126 |
rajveer |
77 |
csc = new CatalogClient();
|
| 3019 |
rajveer |
78 |
client = csc.getClient();
|
|
|
79 |
} catch (Exception e) {
|
|
|
80 |
logger.error("Unable to get catalog service client", e);
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
public String index(){
|
| 3126 |
rajveer |
85 |
TransactionClient transactionServiceClient = null;
|
| 3019 |
rajveer |
86 |
in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
|
|
|
87 |
try{
|
| 3126 |
rajveer |
88 |
transactionServiceClient = new TransactionClient();
|
| 3019 |
rajveer |
89 |
orderClient = transactionServiceClient.getClient();
|
| 3022 |
rajveer |
90 |
orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0, (new Date()).getTime(), statuses);
|
| 8274 |
amit.gupta |
91 |
brandInfo = client.getBrandInfo();
|
| 3019 |
rajveer |
92 |
Collections.reverse(orders);
|
|
|
93 |
} catch (Exception e) {
|
|
|
94 |
logger.error("Not able to get order information from service.");
|
|
|
95 |
}
|
|
|
96 |
return "index";
|
|
|
97 |
}
|
| 6915 |
anupam.sin |
98 |
|
|
|
99 |
public String downloadPolicyDoc() {
|
|
|
100 |
ByteBuffer buffer = null;
|
|
|
101 |
try {
|
|
|
102 |
if (orderId == null || orderId.isEmpty()) {
|
|
|
103 |
logger.error("Order Id is null or empty");
|
|
|
104 |
return "index";
|
|
|
105 |
}
|
|
|
106 |
TransactionClient transactionServiceClient = new TransactionClient();
|
|
|
107 |
TransactionService.Client orderClient = transactionServiceClient.getClient();
|
|
|
108 |
buffer = orderClient.getDocument(1, Long.parseLong(orderId));
|
|
|
109 |
if(!buffer.hasArray()) {
|
|
|
110 |
logger.error("The policy doc is not backed by an accessible byte buffer");
|
|
|
111 |
}
|
|
|
112 |
} catch (Exception e) {
|
|
|
113 |
System.out.println(e.getMessage());
|
|
|
114 |
}
|
|
|
115 |
response.setHeader("Content-disposition", "inline; filename=" + orderId + "-policy.pdf");
|
|
|
116 |
|
|
|
117 |
ServletOutputStream sos;
|
|
|
118 |
try {
|
|
|
119 |
sos = response.getOutputStream();
|
|
|
120 |
sos.write(buffer.array());
|
|
|
121 |
sos.flush();
|
|
|
122 |
} catch (Exception e) {
|
|
|
123 |
System.out.println("Unable to stream the manifest file");
|
|
|
124 |
}
|
|
|
125 |
return "index";
|
|
|
126 |
}
|
| 3019 |
rajveer |
127 |
|
| 7077 |
rajveer |
128 |
public String downloadInvoice() {
|
|
|
129 |
ByteBuffer buffer = null;
|
|
|
130 |
try {
|
|
|
131 |
if (orderId == null || orderId.isEmpty()) {
|
|
|
132 |
logger.error("Order Id is null or empty");
|
|
|
133 |
return "index";
|
|
|
134 |
}
|
|
|
135 |
TransactionClient transactionServiceClient = new TransactionClient();
|
|
|
136 |
TransactionService.Client orderClient = transactionServiceClient.getClient();
|
| 7081 |
rajveer |
137 |
buffer = orderClient.retrieveInvoice(Long.parseLong(orderId), userinfo.getUserId());
|
| 7077 |
rajveer |
138 |
if(!buffer.hasArray()) {
|
|
|
139 |
logger.error("The invoice does not found");
|
|
|
140 |
}
|
|
|
141 |
} catch (Exception e) {
|
|
|
142 |
System.out.println(e.getMessage());
|
|
|
143 |
}
|
|
|
144 |
response.setHeader("Content-disposition", "inline; filename=invoice-" + orderId + ".pdf");
|
|
|
145 |
|
|
|
146 |
ServletOutputStream sos;
|
|
|
147 |
try {
|
|
|
148 |
sos = response.getOutputStream();
|
|
|
149 |
sos.write(buffer.array());
|
|
|
150 |
sos.flush();
|
|
|
151 |
} catch (Exception e) {
|
|
|
152 |
System.out.println("Unable to stream the invoice file");
|
|
|
153 |
}
|
|
|
154 |
return "index";
|
|
|
155 |
}
|
|
|
156 |
|
| 3019 |
rajveer |
157 |
public String formatPrice(double price) {
|
|
|
158 |
return formattingUtils.formatPrice(price);
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
public List<Order> getOrders() {
|
|
|
162 |
return orders;
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
public List<String> getOrderDate() {
|
|
|
166 |
return orderDate;
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
public String formatDate(long timestamp){
|
|
|
170 |
Date date = new Date(timestamp);
|
|
|
171 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy");
|
|
|
172 |
return dateformat.format(date);
|
|
|
173 |
}
|
|
|
174 |
|
| 3950 |
rajveer |
175 |
public long getCatalogId(long itemId){
|
|
|
176 |
long catalogId = 0;
|
|
|
177 |
try {
|
|
|
178 |
catalogId = csc.getClient().getItem(itemId).getCatalogItemId();
|
| 5945 |
mandeep.dh |
179 |
} catch (CatalogServiceException e) {
|
| 3950 |
rajveer |
180 |
logger.error("Unable to get item information." + e);
|
|
|
181 |
} catch (TException e) {
|
|
|
182 |
logger.error("Unable to get item information." + e);
|
|
|
183 |
}
|
|
|
184 |
return catalogId;
|
|
|
185 |
}
|
|
|
186 |
|
| 3019 |
rajveer |
187 |
public String getWarrantyDate(long timestamp, String brand){
|
|
|
188 |
Calendar cd = Calendar.getInstance();
|
|
|
189 |
cd.setTimeInMillis(timestamp);
|
|
|
190 |
int addition = 12;
|
| 4275 |
varun.gupt |
191 |
if(brand.equalsIgnoreCase("blackberry")) {
|
| 3019 |
rajveer |
192 |
addition = 18;
|
|
|
193 |
}
|
|
|
194 |
cd.add(Calendar.MONTH, addition);
|
|
|
195 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy");
|
|
|
196 |
return dateformat.format(cd.getTime());
|
|
|
197 |
}
|
| 6903 |
anupam.sin |
198 |
|
|
|
199 |
public String getInsuranceExpiryDate(long timestamp, long insurer){
|
|
|
200 |
if(insurer == 0) {
|
|
|
201 |
return "N/A";
|
|
|
202 |
}
|
|
|
203 |
Calendar cd = Calendar.getInstance();
|
|
|
204 |
cd.setTimeInMillis(timestamp);
|
|
|
205 |
int addition = 12;
|
|
|
206 |
cd.add(Calendar.MONTH, addition);
|
|
|
207 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy");
|
|
|
208 |
return dateformat.format(cd.getTime());
|
|
|
209 |
}
|
| 6915 |
anupam.sin |
210 |
|
|
|
211 |
public String getOrderId() {
|
|
|
212 |
return orderId;
|
|
|
213 |
}
|
|
|
214 |
|
|
|
215 |
public void setOrderId(String orderId) {
|
|
|
216 |
this.orderId = orderId;
|
|
|
217 |
}
|
| 8274 |
amit.gupta |
218 |
|
|
|
219 |
public String getSupportUrl(String brand){
|
|
|
220 |
if (brandInfo.get(brand) != null){
|
|
|
221 |
return brandInfo.get(brand).getServiceCenterLocatorUrl();
|
|
|
222 |
}else {
|
|
|
223 |
return null;
|
|
|
224 |
}
|
|
|
225 |
}
|
| 3019 |
rajveer |
226 |
}
|