| 507 |
rajveer |
1 |
package in.shop2020.serving.services;
|
|
|
2 |
|
|
|
3 |
import java.io.BufferedReader;
|
|
|
4 |
import java.io.File;
|
|
|
5 |
import java.io.FileInputStream;
|
|
|
6 |
import java.io.FileNotFoundException;
|
|
|
7 |
import java.io.IOException;
|
|
|
8 |
import java.io.InputStreamReader;
|
|
|
9 |
import java.io.StringWriter;
|
| 517 |
rajveer |
10 |
import java.text.SimpleDateFormat;
|
| 507 |
rajveer |
11 |
import java.util.ArrayList;
|
|
|
12 |
import java.util.Date;
|
|
|
13 |
import java.util.HashMap;
|
|
|
14 |
import java.util.List;
|
|
|
15 |
import java.util.Map;
|
|
|
16 |
import java.util.Properties;
|
|
|
17 |
|
|
|
18 |
import org.apache.thrift.TException;
|
|
|
19 |
import org.apache.velocity.Template;
|
|
|
20 |
import org.apache.velocity.VelocityContext;
|
|
|
21 |
import org.apache.velocity.app.Velocity;
|
|
|
22 |
import org.apache.velocity.exception.MethodInvocationException;
|
|
|
23 |
import org.apache.velocity.exception.ParseErrorException;
|
|
|
24 |
import org.apache.velocity.exception.ResourceNotFoundException;
|
|
|
25 |
|
|
|
26 |
|
| 745 |
chandransh |
27 |
import in.shop2020.logistics.Provider;
|
| 507 |
rajveer |
28 |
import in.shop2020.model.v1.catalog.InventoryServiceException;
|
|
|
29 |
import in.shop2020.model.v1.catalog.Item;
|
|
|
30 |
import in.shop2020.model.v1.catalog.InventoryService.Client;
|
|
|
31 |
import in.shop2020.model.v1.order.Order;
|
|
|
32 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 555 |
chandransh |
33 |
import in.shop2020.model.v1.user.Cart;
|
|
|
34 |
import in.shop2020.model.v1.user.Line;
|
| 507 |
rajveer |
35 |
import in.shop2020.model.v1.user.Address;
|
| 555 |
chandransh |
36 |
import in.shop2020.model.v1.user.User;
|
| 762 |
rajveer |
37 |
import in.shop2020.model.v1.user.UserContextException;
|
| 555 |
chandransh |
38 |
import in.shop2020.model.v1.user.Widget;
|
|
|
39 |
import in.shop2020.model.v1.user.WidgetItem;
|
|
|
40 |
import in.shop2020.model.v1.user.WidgetType;
|
| 507 |
rajveer |
41 |
import in.shop2020.serving.utils.*;
|
|
|
42 |
import in.shop2020.thrift.clients.CatalogServiceClient;
|
| 745 |
chandransh |
43 |
import in.shop2020.thrift.clients.LogisticsServiceClient;
|
| 507 |
rajveer |
44 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
|
|
45 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
public class PageLoaderHandler {
|
|
|
49 |
|
|
|
50 |
|
| 650 |
rajveer |
51 |
public String getMainBannerHtml() {
|
| 507 |
rajveer |
52 |
String htmlString = "";
|
|
|
53 |
VelocityContext context = new VelocityContext();
|
|
|
54 |
String templateFile = "templates/mainbanner.vm";
|
|
|
55 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
56 |
return htmlString;
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
|
| 650 |
rajveer |
60 |
public String getBestSellersHtml() {
|
| 507 |
rajveer |
61 |
String htmlString = "";
|
|
|
62 |
VelocityContext context = new VelocityContext();
|
|
|
63 |
String templateFile = "templates/bestsellers.vm";
|
|
|
64 |
|
|
|
65 |
CatalogServiceClient catalogServiceClient = null;
|
|
|
66 |
Client client = null;
|
|
|
67 |
|
|
|
68 |
try {
|
|
|
69 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
70 |
client = catalogServiceClient.getClient();
|
| 1923 |
rajveer |
71 |
List<Long> items = client.getBestSellersCatalogIds(1, 4, null, -1);
|
| 507 |
rajveer |
72 |
List<String> itemList = new ArrayList<String>();
|
|
|
73 |
for(Long item: items){
|
| 517 |
rajveer |
74 |
itemList.add(FileUtils.read( Utils.EXPORT_ENTITIES_PATH + item + File.separator +"HomeSnippet.html"));
|
| 507 |
rajveer |
75 |
}
|
|
|
76 |
context.put("itemList", itemList);
|
|
|
77 |
|
|
|
78 |
} catch(Exception e){
|
|
|
79 |
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
| 517 |
rajveer |
83 |
return htmlString;
|
|
|
84 |
}
|
| 507 |
rajveer |
85 |
|
|
|
86 |
|
| 650 |
rajveer |
87 |
public String getLatestArrivalsHtml() {
|
| 507 |
rajveer |
88 |
String htmlString = "";
|
|
|
89 |
VelocityContext context = new VelocityContext();
|
|
|
90 |
String templateFile = "templates/latestarrivals.vm";
|
|
|
91 |
|
|
|
92 |
CatalogServiceClient catalogServiceClient = null;
|
|
|
93 |
Client client = null;
|
|
|
94 |
|
|
|
95 |
try {
|
|
|
96 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
97 |
client = catalogServiceClient.getClient();
|
| 1923 |
rajveer |
98 |
List<Long> items = client.getLatestArrivalsCatalogIds(1, 4, null, 10003);
|
| 507 |
rajveer |
99 |
List<String> itemList = new ArrayList<String>();
|
|
|
100 |
for(Long item: items){
|
| 968 |
chandransh |
101 |
try{
|
|
|
102 |
itemList.add(FileUtils.read( Utils.EXPORT_ENTITIES_PATH + item + File.separator +"HomeSnippet.html"));
|
|
|
103 |
}catch(IOException ioex){
|
|
|
104 |
ioex.printStackTrace();
|
|
|
105 |
}
|
| 507 |
rajveer |
106 |
}
|
|
|
107 |
context.put("itemList", itemList);
|
|
|
108 |
|
|
|
109 |
} catch(Exception e){
|
| 968 |
chandransh |
110 |
e.printStackTrace();
|
| 507 |
rajveer |
111 |
}
|
|
|
112 |
|
|
|
113 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
114 |
return htmlString;
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
|
| 650 |
rajveer |
118 |
public String getBestDealsHtml() {
|
| 507 |
rajveer |
119 |
String htmlString = "";
|
|
|
120 |
VelocityContext context = new VelocityContext();
|
|
|
121 |
String templateFile = "templates/bestdeals.vm";
|
|
|
122 |
|
|
|
123 |
CatalogServiceClient catalogServiceClient = null;
|
|
|
124 |
Client client = null;
|
|
|
125 |
|
|
|
126 |
try {
|
|
|
127 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
128 |
client = catalogServiceClient.getClient();
|
| 1923 |
rajveer |
129 |
List<Long> items = client.getBestDealsCatalogIds(0,4, null, -1);
|
| 507 |
rajveer |
130 |
List<String> itemList = new ArrayList<String>();
|
|
|
131 |
for(Long item: items){
|
| 517 |
rajveer |
132 |
itemList.add(FileUtils.read( Utils.EXPORT_ENTITIES_PATH + item + File.separator +"HomeSnippet.html"));
|
| 507 |
rajveer |
133 |
}
|
|
|
134 |
context.put("itemList", itemList);
|
|
|
135 |
|
| 786 |
rajveer |
136 |
} catch (InventoryServiceException e) {
|
|
|
137 |
// TODO Auto-generated catch block
|
|
|
138 |
e.printStackTrace();
|
|
|
139 |
} catch (TException e) {
|
|
|
140 |
// TODO Auto-generated catch block
|
|
|
141 |
e.printStackTrace();
|
|
|
142 |
} catch (Exception e) {
|
|
|
143 |
// TODO Auto-generated catch block
|
|
|
144 |
e.printStackTrace();
|
| 1614 |
rajveer |
145 |
}
|
| 507 |
rajveer |
146 |
|
|
|
147 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
148 |
return htmlString;
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
|
| 517 |
rajveer |
152 |
public String getFooterHtml() {
|
| 507 |
rajveer |
153 |
String htmlString = "";
|
|
|
154 |
VelocityContext context = new VelocityContext();
|
|
|
155 |
String templateFile = "templates/footer.vm";
|
|
|
156 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
157 |
return htmlString;
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
|
| 1934 |
vikas |
161 |
public String getMyResearchHtml() {
|
|
|
162 |
String htmlString = "";
|
|
|
163 |
VelocityContext context = new VelocityContext();
|
|
|
164 |
String templateFile = "templates/myresearch.vm";
|
|
|
165 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
166 |
return htmlString;
|
| 507 |
rajveer |
167 |
}
|
|
|
168 |
|
| 1934 |
vikas |
169 |
public String getBrowseHistoryHtml() {
|
|
|
170 |
String htmlString = "";
|
|
|
171 |
VelocityContext context = new VelocityContext();
|
|
|
172 |
String templateFile = "templates/browsehistory.vm";
|
|
|
173 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
174 |
return htmlString;
|
| 507 |
rajveer |
175 |
}
|
|
|
176 |
|
| 517 |
rajveer |
177 |
public String getCustomerServiceHtml() {
|
| 507 |
rajveer |
178 |
String htmlString = "";
|
|
|
179 |
VelocityContext context = new VelocityContext();
|
|
|
180 |
String templateFile = "templates/customerservice.vm";
|
|
|
181 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
182 |
return htmlString;
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
|
| 620 |
rajveer |
186 |
public String getSlideGuideHtml(long productId) {
|
| 507 |
rajveer |
187 |
StringBuilder htmlString = new StringBuilder();
|
| 517 |
rajveer |
188 |
String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "SlideGuide.html";
|
| 507 |
rajveer |
189 |
File f = new File(filename);
|
|
|
190 |
|
|
|
191 |
|
|
|
192 |
FileInputStream fis = null;
|
|
|
193 |
try {
|
|
|
194 |
fis = new FileInputStream(f);
|
|
|
195 |
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
|
|
|
196 |
String line;
|
|
|
197 |
while((line = br.readLine()) != null){
|
|
|
198 |
htmlString.append(line+"\n");
|
|
|
199 |
}
|
|
|
200 |
} catch (FileNotFoundException e) {
|
|
|
201 |
// TODO Auto-generated catch block
|
|
|
202 |
e.printStackTrace();
|
|
|
203 |
} catch (IOException e) {
|
|
|
204 |
// TODO Auto-generated catch block
|
|
|
205 |
e.printStackTrace();
|
|
|
206 |
}
|
|
|
207 |
finally {
|
|
|
208 |
if(fis != null) {
|
|
|
209 |
try {
|
|
|
210 |
fis.close();
|
|
|
211 |
} catch (IOException e) {
|
|
|
212 |
// TODO Auto-generated catch block
|
|
|
213 |
e.printStackTrace();
|
|
|
214 |
}
|
|
|
215 |
}
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
return htmlString.toString();
|
|
|
219 |
}
|
|
|
220 |
|
| 517 |
rajveer |
221 |
public String getProductSummaryHtml(long productId) {
|
| 507 |
rajveer |
222 |
StringBuilder htmlString = new StringBuilder();
|
| 517 |
rajveer |
223 |
String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "ProductDetail.html";
|
| 507 |
rajveer |
224 |
File f = new File(filename);
|
|
|
225 |
|
|
|
226 |
|
|
|
227 |
FileInputStream fis = null;
|
|
|
228 |
try {
|
|
|
229 |
fis = new FileInputStream(f);
|
|
|
230 |
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
|
|
|
231 |
String line;
|
|
|
232 |
while((line = br.readLine()) != null){
|
|
|
233 |
htmlString.append(line+"\n");
|
|
|
234 |
}
|
|
|
235 |
} catch (FileNotFoundException e) {
|
|
|
236 |
// TODO Auto-generated catch block
|
|
|
237 |
e.printStackTrace();
|
|
|
238 |
} catch (IOException e) {
|
|
|
239 |
// TODO Auto-generated catch block
|
|
|
240 |
e.printStackTrace();
|
|
|
241 |
}
|
|
|
242 |
finally {
|
|
|
243 |
if(fis != null) {
|
|
|
244 |
try {
|
|
|
245 |
fis.close();
|
|
|
246 |
} catch (IOException e) {
|
|
|
247 |
// TODO Auto-generated catch block
|
|
|
248 |
e.printStackTrace();
|
|
|
249 |
}
|
|
|
250 |
}
|
|
|
251 |
}
|
|
|
252 |
|
|
|
253 |
return htmlString.toString();
|
|
|
254 |
}
|
|
|
255 |
|
| 974 |
vikas |
256 |
public String getPageTitleHtml(long productId) {
|
|
|
257 |
StringBuilder htmlString = new StringBuilder();
|
| 989 |
vikas |
258 |
String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "TitleSnippet.html";
|
| 974 |
vikas |
259 |
File f = new File(filename);
|
|
|
260 |
|
|
|
261 |
|
|
|
262 |
FileInputStream fis = null;
|
|
|
263 |
try {
|
|
|
264 |
fis = new FileInputStream(f);
|
|
|
265 |
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
|
|
|
266 |
String line;
|
|
|
267 |
while((line = br.readLine()) != null){
|
|
|
268 |
htmlString.append(line+"\n");
|
|
|
269 |
}
|
|
|
270 |
} catch (FileNotFoundException e) {
|
|
|
271 |
// TODO Auto-generated catch block
|
|
|
272 |
e.printStackTrace();
|
|
|
273 |
} catch (IOException e) {
|
|
|
274 |
// TODO Auto-generated catch block
|
|
|
275 |
e.printStackTrace();
|
|
|
276 |
}
|
|
|
277 |
finally {
|
|
|
278 |
if(fis != null) {
|
|
|
279 |
try {
|
|
|
280 |
fis.close();
|
|
|
281 |
} catch (IOException e) {
|
|
|
282 |
// TODO Auto-generated catch block
|
|
|
283 |
e.printStackTrace();
|
|
|
284 |
}
|
|
|
285 |
}
|
|
|
286 |
}
|
|
|
287 |
|
|
|
288 |
return htmlString.toString();
|
|
|
289 |
}
|
|
|
290 |
|
|
|
291 |
public String getPageMetaDescriptionHtml(long productId) {
|
|
|
292 |
StringBuilder htmlString = new StringBuilder();
|
| 989 |
vikas |
293 |
String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "MetaDescriptionSnippet.html";
|
| 974 |
vikas |
294 |
File f = new File(filename);
|
|
|
295 |
|
|
|
296 |
|
|
|
297 |
FileInputStream fis = null;
|
|
|
298 |
try {
|
|
|
299 |
fis = new FileInputStream(f);
|
|
|
300 |
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
|
|
|
301 |
String line;
|
|
|
302 |
while((line = br.readLine()) != null){
|
|
|
303 |
htmlString.append(line+"\n");
|
|
|
304 |
}
|
|
|
305 |
} catch (FileNotFoundException e) {
|
|
|
306 |
// TODO Auto-generated catch block
|
|
|
307 |
e.printStackTrace();
|
|
|
308 |
} catch (IOException e) {
|
|
|
309 |
// TODO Auto-generated catch block
|
|
|
310 |
e.printStackTrace();
|
|
|
311 |
}
|
|
|
312 |
finally {
|
|
|
313 |
if(fis != null) {
|
|
|
314 |
try {
|
|
|
315 |
fis.close();
|
|
|
316 |
} catch (IOException e) {
|
|
|
317 |
// TODO Auto-generated catch block
|
|
|
318 |
e.printStackTrace();
|
|
|
319 |
}
|
|
|
320 |
}
|
|
|
321 |
}
|
|
|
322 |
|
|
|
323 |
return htmlString.toString();
|
|
|
324 |
}
|
|
|
325 |
|
|
|
326 |
public String getPageMetaKeywordsHtml(long productId) {
|
|
|
327 |
StringBuilder htmlString = new StringBuilder();
|
| 989 |
vikas |
328 |
String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "MetaKeywordsSnippet.html";
|
| 974 |
vikas |
329 |
File f = new File(filename);
|
|
|
330 |
|
|
|
331 |
|
|
|
332 |
FileInputStream fis = null;
|
|
|
333 |
try {
|
|
|
334 |
fis = new FileInputStream(f);
|
|
|
335 |
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
|
|
|
336 |
String line;
|
|
|
337 |
while((line = br.readLine()) != null){
|
|
|
338 |
htmlString.append(line+"\n");
|
|
|
339 |
}
|
|
|
340 |
} catch (FileNotFoundException e) {
|
|
|
341 |
// TODO Auto-generated catch block
|
|
|
342 |
e.printStackTrace();
|
|
|
343 |
} catch (IOException e) {
|
|
|
344 |
// TODO Auto-generated catch block
|
|
|
345 |
e.printStackTrace();
|
|
|
346 |
}
|
|
|
347 |
finally {
|
|
|
348 |
if(fis != null) {
|
|
|
349 |
try {
|
|
|
350 |
fis.close();
|
|
|
351 |
} catch (IOException e) {
|
|
|
352 |
// TODO Auto-generated catch block
|
|
|
353 |
e.printStackTrace();
|
|
|
354 |
}
|
|
|
355 |
}
|
|
|
356 |
}
|
|
|
357 |
|
|
|
358 |
return htmlString.toString();
|
|
|
359 |
}
|
| 507 |
rajveer |
360 |
|
| 517 |
rajveer |
361 |
public String getMainMenuHtml() {
|
| 507 |
rajveer |
362 |
String htmlString = "";
|
|
|
363 |
VelocityContext context = new VelocityContext();
|
|
|
364 |
String templateFile = "templates/mainmenu.vm";
|
|
|
365 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
366 |
return htmlString;
|
|
|
367 |
}
|
|
|
368 |
|
|
|
369 |
|
| 517 |
rajveer |
370 |
public String getSearchBarHtml(long itemCounts, long categoryId) {
|
| 507 |
rajveer |
371 |
String htmlString = "";
|
|
|
372 |
VelocityContext context = new VelocityContext();
|
|
|
373 |
String templateFile = "templates/searchbar.vm";
|
| 550 |
rajveer |
374 |
|
|
|
375 |
context.put("itemCount", itemCounts+"");
|
|
|
376 |
context.put("categoryId", categoryId+"");
|
|
|
377 |
|
| 507 |
rajveer |
378 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
379 |
return htmlString;
|
|
|
380 |
}
|
|
|
381 |
|
|
|
382 |
|
|
|
383 |
|
| 924 |
vikas |
384 |
public String getHeaderHtml(boolean isLoggedIn, String userName, String url) {
|
| 550 |
rajveer |
385 |
VelocityContext context = new VelocityContext();
|
| 555 |
chandransh |
386 |
if (isLoggedIn) {
|
|
|
387 |
context.put("LOGGED_IN", "TRUE");
|
|
|
388 |
context.put("WELCOME_MESSAGE", "Hi, " + userName);
|
|
|
389 |
} else {
|
| 801 |
rajveer |
390 |
context.put("WELCOME_MESSAGE", "Hi, Welcome to Saholic");
|
| 924 |
vikas |
391 |
context.put("REDIRECT_URL", url);
|
| 555 |
chandransh |
392 |
}
|
| 507 |
rajveer |
393 |
|
|
|
394 |
String templateFile = "templates/header.vm";
|
| 550 |
rajveer |
395 |
|
| 590 |
chandransh |
396 |
return getHtmlFromVelocity(templateFile, context);
|
| 507 |
rajveer |
397 |
}
|
|
|
398 |
|
|
|
399 |
|
| 1527 |
ankur.sing |
400 |
public String getOrderDetailsHtml(long orderId, long userId) {
|
| 507 |
rajveer |
401 |
String htmlString = "";
|
|
|
402 |
VelocityContext context = new VelocityContext();
|
|
|
403 |
String templateFile = "templates/orderdetails.vm";
|
|
|
404 |
Order order = null;
|
| 517 |
rajveer |
405 |
Date orderedOn = null, deliveryEstimate = null;
|
| 843 |
chandransh |
406 |
Provider provider = null;
|
| 507 |
rajveer |
407 |
try{
|
| 843 |
chandransh |
408 |
TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
|
|
|
409 |
in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
|
| 1527 |
ankur.sing |
410 |
order = orderClient.getOrderForCustomer(orderId, userId);
|
| 517 |
rajveer |
411 |
orderedOn = new Date(order.getCreated_timestamp());
|
|
|
412 |
deliveryEstimate = new Date(order.getExpected_delivery_time());
|
| 843 |
chandransh |
413 |
|
|
|
414 |
if(order.getLogistics_provider_id() != 0){
|
|
|
415 |
LogisticsServiceClient logisticsServiceClient = new LogisticsServiceClient();
|
|
|
416 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
|
|
|
417 |
provider = logisticsClient.getProvider(order.getLogistics_provider_id());
|
|
|
418 |
}
|
| 507 |
rajveer |
419 |
}catch (Exception e){
|
|
|
420 |
|
|
|
421 |
}
|
| 517 |
rajveer |
422 |
|
|
|
423 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
|
| 583 |
rajveer |
424 |
SimpleDateFormat dateformat1 = new SimpleDateFormat("dd/MM/yyyy");
|
| 507 |
rajveer |
425 |
context.put("order", order);
|
| 517 |
rajveer |
426 |
context.put("orderedOn", dateformat.format(orderedOn));
|
| 583 |
rajveer |
427 |
context.put("deliveryEstimate", dateformat1.format(deliveryEstimate));
|
| 843 |
chandransh |
428 |
if(provider!=null){
|
|
|
429 |
context.put("providerName", provider.getName());
|
|
|
430 |
}
|
|
|
431 |
|
| 507 |
rajveer |
432 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
433 |
return htmlString;
|
|
|
434 |
}
|
|
|
435 |
|
| 650 |
rajveer |
436 |
public String getMyaccountDetailsHtml(long userId) {
|
| 507 |
rajveer |
437 |
String htmlString = "";
|
|
|
438 |
VelocityContext context = new VelocityContext();
|
|
|
439 |
String templateFile = "templates/myaccount.vm";
|
|
|
440 |
List<Order> orders = null;
|
| 745 |
chandransh |
441 |
Map<Long, String> providerNames = new HashMap<Long, String>();
|
| 507 |
rajveer |
442 |
try{
|
| 745 |
chandransh |
443 |
TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
|
|
|
444 |
in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
|
| 507 |
rajveer |
445 |
orders = orderClient.getOrdersForCustomer(userId, 0, (new Date()).getTime(), null);
|
|
|
446 |
|
| 745 |
chandransh |
447 |
LogisticsServiceClient logisticsServiceClient = new LogisticsServiceClient();
|
|
|
448 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
|
|
|
449 |
List<Provider> providers = logisticsClient.getAllProviders();
|
|
|
450 |
for(Provider provider: providers)
|
|
|
451 |
providerNames.put(provider.getId(), provider.getName());
|
| 507 |
rajveer |
452 |
}catch (Exception e){
|
| 1275 |
varun.gupt |
453 |
e.printStackTrace();
|
| 507 |
rajveer |
454 |
}
|
| 741 |
rajveer |
455 |
List<String> orderDate = new ArrayList<String>();
|
|
|
456 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
|
| 888 |
chandransh |
457 |
if(orders!=null && !orders.isEmpty()){
|
| 762 |
rajveer |
458 |
for(Order order: orders){
|
|
|
459 |
Date orderedOn = new Date(order.getCreated_timestamp());
|
|
|
460 |
orderDate.add(dateformat.format(orderedOn));
|
|
|
461 |
}
|
| 741 |
rajveer |
462 |
}
|
| 507 |
rajveer |
463 |
context.put("orders", orders);
|
| 741 |
rajveer |
464 |
context.put("orderDate", orderDate);
|
| 745 |
chandransh |
465 |
context.put("providerNames", providerNames);
|
| 507 |
rajveer |
466 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
467 |
return htmlString;
|
|
|
468 |
}
|
|
|
469 |
|
|
|
470 |
|
| 650 |
rajveer |
471 |
public String getLoginDetailsHtml(long userId) {
|
| 507 |
rajveer |
472 |
String htmlString = "";
|
|
|
473 |
VelocityContext context = new VelocityContext();
|
|
|
474 |
String templateFile = "templates/logindetails.vm";
|
|
|
475 |
String email = "";
|
|
|
476 |
try{
|
| 762 |
rajveer |
477 |
email = getEmailId(userId);
|
| 507 |
rajveer |
478 |
}catch (Exception e){
|
|
|
479 |
|
|
|
480 |
}
|
|
|
481 |
context.put("email", email);
|
|
|
482 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
483 |
return htmlString;
|
|
|
484 |
}
|
|
|
485 |
|
| 762 |
rajveer |
486 |
public String getEmailId(long userId){
|
|
|
487 |
String email = " ";
|
|
|
488 |
|
|
|
489 |
try {
|
|
|
490 |
UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
|
|
|
491 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
|
|
492 |
if(userClient.getUserById(userId).getEmail() != null){
|
|
|
493 |
email = userClient.getUserById(userId).getEmail();
|
|
|
494 |
}
|
|
|
495 |
} catch (UserContextException e) {
|
|
|
496 |
e.printStackTrace();
|
|
|
497 |
} catch (TException e) {
|
|
|
498 |
e.printStackTrace();
|
|
|
499 |
} catch (Exception e) {
|
|
|
500 |
e.printStackTrace();
|
|
|
501 |
}
|
|
|
502 |
return email;
|
|
|
503 |
}
|
|
|
504 |
|
|
|
505 |
|
| 595 |
rajveer |
506 |
public String getPersonalDetailsHtml(long userId) {
|
| 507 |
rajveer |
507 |
String htmlString = "";
|
|
|
508 |
VelocityContext context = new VelocityContext();
|
|
|
509 |
String templateFile = "templates/personaldetails.vm";
|
|
|
510 |
String email = "";
|
| 517 |
rajveer |
511 |
String name = "";
|
| 569 |
rajveer |
512 |
String dateOfBirth = "";
|
| 517 |
rajveer |
513 |
String sex = "";
|
|
|
514 |
String subscribe = "false";
|
| 507 |
rajveer |
515 |
UserContextServiceClient userContextServiceClient = null;
|
|
|
516 |
in.shop2020.model.v1.user.UserContextService.Client userClient = null;
|
|
|
517 |
try{
|
| 555 |
chandransh |
518 |
User user = null;
|
| 507 |
rajveer |
519 |
userContextServiceClient = new UserContextServiceClient();
|
|
|
520 |
userClient = userContextServiceClient.getClient();
|
| 555 |
chandransh |
521 |
user = userClient.getUserById(userId);
|
| 507 |
rajveer |
522 |
|
| 555 |
chandransh |
523 |
email = user.getCommunicationEmail();
|
|
|
524 |
name = user.getName();
|
| 517 |
rajveer |
525 |
|
| 569 |
rajveer |
526 |
dateOfBirth = user.getDateOfBirth();
|
| 507 |
rajveer |
527 |
}catch (Exception e){
|
| 555 |
chandransh |
528 |
e.printStackTrace();
|
| 507 |
rajveer |
529 |
}
|
| 517 |
rajveer |
530 |
context.put("name", name);
|
|
|
531 |
context.put("email", email);
|
| 569 |
rajveer |
532 |
context.put("dateOfBirth", dateOfBirth+"");
|
| 517 |
rajveer |
533 |
context.put("subscribe", subscribe);
|
|
|
534 |
context.put("sex", sex);
|
| 507 |
rajveer |
535 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
536 |
return htmlString;
|
|
|
537 |
}
|
|
|
538 |
|
| 620 |
rajveer |
539 |
public String getCompletedOrdersHtml(long userId) {
|
| 507 |
rajveer |
540 |
String htmlString = "";
|
|
|
541 |
VelocityContext context = new VelocityContext();
|
|
|
542 |
String templateFile = "templates/completedorders.vm";
|
|
|
543 |
TransactionServiceClient transactionServiceClient = null;
|
|
|
544 |
in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
|
| 1310 |
varun.gupt |
545 |
|
| 507 |
rajveer |
546 |
List<Order> orders = null;
|
| 1310 |
varun.gupt |
547 |
List<String> orderDate = new ArrayList<String>();
|
| 1316 |
varun.gupt |
548 |
Map<Long, String> providerNames = new HashMap<Long, String>();
|
| 1310 |
varun.gupt |
549 |
|
| 507 |
rajveer |
550 |
try{
|
|
|
551 |
transactionServiceClient = new TransactionServiceClient();
|
|
|
552 |
orderClient = transactionServiceClient.getClient();
|
|
|
553 |
orders = orderClient.getOrdersForCustomer(userId, 0, (new Date()).getTime(), OrderStatus.DELIVERY_SUCCESS);
|
| 1316 |
varun.gupt |
554 |
|
|
|
555 |
LogisticsServiceClient logisticsServiceClient = new LogisticsServiceClient();
|
|
|
556 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
|
|
|
557 |
List<Provider> providers = logisticsClient.getAllProviders();
|
|
|
558 |
for(Provider provider: providers)
|
|
|
559 |
providerNames.put(provider.getId(), provider.getName());
|
|
|
560 |
|
| 1310 |
varun.gupt |
561 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
|
|
|
562 |
|
|
|
563 |
if(orders != null && !orders.isEmpty()){
|
|
|
564 |
for(Order order: orders){
|
|
|
565 |
Date orderedOn = new Date(order.getCreated_timestamp());
|
|
|
566 |
orderDate.add(dateformat.format(orderedOn));
|
|
|
567 |
}
|
|
|
568 |
}
|
| 507 |
rajveer |
569 |
}catch (Exception e){
|
|
|
570 |
|
|
|
571 |
}
|
|
|
572 |
context.put("orders", orders);
|
| 1310 |
varun.gupt |
573 |
context.put("orderDate", orderDate);
|
| 1316 |
varun.gupt |
574 |
context.put("providerNames", providerNames);
|
| 1310 |
varun.gupt |
575 |
|
| 507 |
rajveer |
576 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
577 |
return htmlString;
|
|
|
578 |
}
|
| 595 |
rajveer |
579 |
public String getMyaccountHeaderHtml() {
|
| 507 |
rajveer |
580 |
String htmlString = "";
|
|
|
581 |
VelocityContext context = new VelocityContext();
|
|
|
582 |
String templateFile = "templates/myaccountheader.vm";
|
|
|
583 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
584 |
return htmlString;
|
|
|
585 |
}
|
|
|
586 |
|
|
|
587 |
|
| 822 |
vikas |
588 |
public String getShippingAddressDetailsHtml(long userId, String errorMsg){
|
| 507 |
rajveer |
589 |
String htmlString = "";
|
|
|
590 |
VelocityContext context = new VelocityContext();
|
|
|
591 |
String templateFile = "templates/shippingaddressdetails.vm";
|
|
|
592 |
long defaultAddressId = 0;
|
| 517 |
rajveer |
593 |
List<Address> addresses = null;
|
| 507 |
rajveer |
594 |
|
|
|
595 |
UserContextServiceClient userContextServiceClient = null;
|
|
|
596 |
in.shop2020.model.v1.user.UserContextService.Client userClient = null;
|
|
|
597 |
try {
|
|
|
598 |
userContextServiceClient = new UserContextServiceClient();
|
|
|
599 |
userClient = userContextServiceClient.getClient();
|
| 620 |
rajveer |
600 |
|
|
|
601 |
addresses = userClient.getAllAddressesForUser(userId);
|
|
|
602 |
defaultAddressId = userClient.getDefaultAddressId(userId);
|
| 507 |
rajveer |
603 |
} catch (Exception e) {
|
|
|
604 |
e.printStackTrace();
|
|
|
605 |
}
|
| 517 |
rajveer |
606 |
context.put("defaultAddressId", defaultAddressId+"");
|
| 507 |
rajveer |
607 |
context.put("addresses", addresses);
|
| 822 |
vikas |
608 |
context.put("errorMsg", errorMsg);
|
| 507 |
rajveer |
609 |
|
|
|
610 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
611 |
return htmlString;
|
|
|
612 |
}
|
|
|
613 |
|
|
|
614 |
public String getHtmlFromVelocity(String templateFile, VelocityContext context){
|
|
|
615 |
Properties p = new Properties();
|
|
|
616 |
p.setProperty("resource.loader", "class");
|
|
|
617 |
p.setProperty("class.resource.loader.class",
|
|
|
618 |
"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
|
| 832 |
rajveer |
619 |
p.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogSystem");
|
|
|
620 |
|
| 507 |
rajveer |
621 |
try {
|
|
|
622 |
Velocity.init(p);
|
| 762 |
rajveer |
623 |
//Velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, value)
|
| 507 |
rajveer |
624 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
625 |
if(template != null) {
|
|
|
626 |
StringWriter writer = new StringWriter();
|
|
|
627 |
template.merge(context, writer);
|
|
|
628 |
writer.flush();
|
|
|
629 |
writer.close();
|
|
|
630 |
return writer.toString();
|
|
|
631 |
}
|
|
|
632 |
|
|
|
633 |
} catch (ResourceNotFoundException e) {
|
|
|
634 |
// TODO Auto-generated catch block
|
|
|
635 |
e.printStackTrace();
|
|
|
636 |
} catch (ParseErrorException e) {
|
|
|
637 |
// TODO Auto-generated catch block
|
|
|
638 |
e.printStackTrace();
|
|
|
639 |
} catch (MethodInvocationException e) {
|
|
|
640 |
// TODO Auto-generated catch block
|
|
|
641 |
e.printStackTrace();
|
|
|
642 |
} catch (IOException e) {
|
|
|
643 |
// TODO Auto-generated catch block
|
|
|
644 |
e.printStackTrace();
|
|
|
645 |
} catch (Exception e) {
|
|
|
646 |
// TODO Auto-generated catch block
|
|
|
647 |
e.printStackTrace();
|
|
|
648 |
}
|
|
|
649 |
|
|
|
650 |
return null;
|
|
|
651 |
}
|
| 1549 |
rajveer |
652 |
}
|