| 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 |
|
| 637 |
rajveer |
50 |
public String getRegistrationFormHtml() {
|
| 507 |
rajveer |
51 |
String htmlString = "";
|
|
|
52 |
VelocityContext context = new VelocityContext();
|
|
|
53 |
String templateFile = "templates/registrationform.vm";
|
|
|
54 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
55 |
return htmlString;
|
|
|
56 |
}
|
|
|
57 |
|
| 637 |
rajveer |
58 |
public String getLoginFormHtml() {
|
|
|
59 |
String htmlString = "";
|
|
|
60 |
VelocityContext context = new VelocityContext();
|
|
|
61 |
String templateFile = "templates/loginform.vm";
|
|
|
62 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
63 |
return htmlString;
|
|
|
64 |
}
|
| 507 |
rajveer |
65 |
|
| 637 |
rajveer |
66 |
public String getRegistrationHeaderHtml() {
|
| 507 |
rajveer |
67 |
String htmlString = "";
|
|
|
68 |
VelocityContext context = new VelocityContext();
|
|
|
69 |
String templateFile = "templates/registrationheader.vm";
|
|
|
70 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
71 |
return htmlString;
|
|
|
72 |
}
|
| 1184 |
varun.gupt |
73 |
|
| 507 |
rajveer |
74 |
|
| 637 |
rajveer |
75 |
public String getLoginHeaderHtml() {
|
|
|
76 |
String htmlString = "";
|
|
|
77 |
VelocityContext context = new VelocityContext();
|
|
|
78 |
String templateFile = "templates/loginheader.vm";
|
|
|
79 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
80 |
return htmlString;
|
|
|
81 |
}
|
|
|
82 |
|
| 507 |
rajveer |
83 |
|
| 650 |
rajveer |
84 |
public String getMainBannerHtml() {
|
| 507 |
rajveer |
85 |
String htmlString = "";
|
|
|
86 |
VelocityContext context = new VelocityContext();
|
|
|
87 |
String templateFile = "templates/mainbanner.vm";
|
|
|
88 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
89 |
return htmlString;
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
|
| 650 |
rajveer |
93 |
public String getBestSellersHtml() {
|
| 507 |
rajveer |
94 |
String htmlString = "";
|
|
|
95 |
VelocityContext context = new VelocityContext();
|
|
|
96 |
String templateFile = "templates/bestsellers.vm";
|
|
|
97 |
|
|
|
98 |
CatalogServiceClient catalogServiceClient = null;
|
|
|
99 |
Client client = null;
|
|
|
100 |
|
|
|
101 |
try {
|
|
|
102 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
103 |
client = catalogServiceClient.getClient();
|
| 1923 |
rajveer |
104 |
List<Long> items = client.getBestSellersCatalogIds(1, 4, null, -1);
|
| 507 |
rajveer |
105 |
List<String> itemList = new ArrayList<String>();
|
|
|
106 |
for(Long item: items){
|
| 517 |
rajveer |
107 |
itemList.add(FileUtils.read( Utils.EXPORT_ENTITIES_PATH + item + File.separator +"HomeSnippet.html"));
|
| 507 |
rajveer |
108 |
}
|
|
|
109 |
context.put("itemList", itemList);
|
|
|
110 |
|
|
|
111 |
} catch(Exception e){
|
|
|
112 |
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
| 517 |
rajveer |
116 |
return htmlString;
|
|
|
117 |
}
|
| 507 |
rajveer |
118 |
|
|
|
119 |
|
| 650 |
rajveer |
120 |
public String getLatestArrivalsHtml() {
|
| 507 |
rajveer |
121 |
String htmlString = "";
|
|
|
122 |
VelocityContext context = new VelocityContext();
|
|
|
123 |
String templateFile = "templates/latestarrivals.vm";
|
|
|
124 |
|
|
|
125 |
CatalogServiceClient catalogServiceClient = null;
|
|
|
126 |
Client client = null;
|
|
|
127 |
|
|
|
128 |
try {
|
|
|
129 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
130 |
client = catalogServiceClient.getClient();
|
| 1923 |
rajveer |
131 |
List<Long> items = client.getLatestArrivalsCatalogIds(1, 4, null, 10003);
|
| 507 |
rajveer |
132 |
List<String> itemList = new ArrayList<String>();
|
|
|
133 |
for(Long item: items){
|
| 968 |
chandransh |
134 |
try{
|
|
|
135 |
itemList.add(FileUtils.read( Utils.EXPORT_ENTITIES_PATH + item + File.separator +"HomeSnippet.html"));
|
|
|
136 |
}catch(IOException ioex){
|
|
|
137 |
ioex.printStackTrace();
|
|
|
138 |
}
|
| 507 |
rajveer |
139 |
}
|
|
|
140 |
context.put("itemList", itemList);
|
|
|
141 |
|
|
|
142 |
} catch(Exception e){
|
| 968 |
chandransh |
143 |
e.printStackTrace();
|
| 507 |
rajveer |
144 |
}
|
|
|
145 |
|
|
|
146 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
147 |
return htmlString;
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
|
| 650 |
rajveer |
151 |
public String getBestDealsHtml() {
|
| 507 |
rajveer |
152 |
String htmlString = "";
|
|
|
153 |
VelocityContext context = new VelocityContext();
|
|
|
154 |
String templateFile = "templates/bestdeals.vm";
|
|
|
155 |
|
|
|
156 |
CatalogServiceClient catalogServiceClient = null;
|
|
|
157 |
Client client = null;
|
|
|
158 |
|
|
|
159 |
try {
|
|
|
160 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
161 |
client = catalogServiceClient.getClient();
|
| 1923 |
rajveer |
162 |
List<Long> items = client.getBestDealsCatalogIds(0,4, null, -1);
|
| 507 |
rajveer |
163 |
List<String> itemList = new ArrayList<String>();
|
|
|
164 |
for(Long item: items){
|
| 517 |
rajveer |
165 |
itemList.add(FileUtils.read( Utils.EXPORT_ENTITIES_PATH + item + File.separator +"HomeSnippet.html"));
|
| 507 |
rajveer |
166 |
}
|
|
|
167 |
context.put("itemList", itemList);
|
|
|
168 |
|
| 786 |
rajveer |
169 |
} catch (InventoryServiceException e) {
|
|
|
170 |
// TODO Auto-generated catch block
|
|
|
171 |
e.printStackTrace();
|
|
|
172 |
} catch (TException e) {
|
|
|
173 |
// TODO Auto-generated catch block
|
|
|
174 |
e.printStackTrace();
|
|
|
175 |
} catch (Exception e) {
|
|
|
176 |
// TODO Auto-generated catch block
|
|
|
177 |
e.printStackTrace();
|
| 1614 |
rajveer |
178 |
}
|
| 507 |
rajveer |
179 |
|
|
|
180 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
181 |
return htmlString;
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
|
| 517 |
rajveer |
185 |
public String getFooterHtml() {
|
| 507 |
rajveer |
186 |
String htmlString = "";
|
|
|
187 |
VelocityContext context = new VelocityContext();
|
|
|
188 |
String templateFile = "templates/footer.vm";
|
|
|
189 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
190 |
return htmlString;
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
|
| 620 |
rajveer |
195 |
public String getAccessoriesHtml(long productId) {
|
| 637 |
rajveer |
196 |
return "";
|
|
|
197 |
//return getWidgetDiv(0, WidgetType.ACCESSORIES, "accessories.vm");
|
| 507 |
rajveer |
198 |
}
|
|
|
199 |
|
|
|
200 |
|
|
|
201 |
|
| 620 |
rajveer |
202 |
public String getSimilarProductsHtml(long productId) {
|
| 637 |
rajveer |
203 |
return "";
|
|
|
204 |
//return getWidgetDiv(0, WidgetType.SIMILAR_ITEMS, "similaritems.vm");
|
| 507 |
rajveer |
205 |
}
|
|
|
206 |
|
|
|
207 |
|
|
|
208 |
|
| 620 |
rajveer |
209 |
public String getRecommendationsHtml() {
|
| 637 |
rajveer |
210 |
return "";
|
|
|
211 |
//return getWidgetDiv( 0, WidgetType.RECOMMENDED_ITEMS, "recommendations.vm");
|
| 507 |
rajveer |
212 |
}
|
|
|
213 |
|
|
|
214 |
|
|
|
215 |
|
| 1934 |
vikas |
216 |
public String getMyResearchHtml() {
|
|
|
217 |
String htmlString = "";
|
|
|
218 |
VelocityContext context = new VelocityContext();
|
|
|
219 |
String templateFile = "templates/myresearch.vm";
|
|
|
220 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
221 |
return htmlString;
|
| 507 |
rajveer |
222 |
}
|
|
|
223 |
|
| 1934 |
vikas |
224 |
public String getBrowseHistoryHtml() {
|
|
|
225 |
String htmlString = "";
|
|
|
226 |
VelocityContext context = new VelocityContext();
|
|
|
227 |
String templateFile = "templates/browsehistory.vm";
|
|
|
228 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
229 |
return htmlString;
|
| 507 |
rajveer |
230 |
}
|
|
|
231 |
|
| 517 |
rajveer |
232 |
public String getCustomerServiceHtml() {
|
| 507 |
rajveer |
233 |
String htmlString = "";
|
|
|
234 |
VelocityContext context = new VelocityContext();
|
|
|
235 |
String templateFile = "templates/customerservice.vm";
|
|
|
236 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
237 |
return htmlString;
|
|
|
238 |
}
|
|
|
239 |
|
|
|
240 |
|
|
|
241 |
|
| 620 |
rajveer |
242 |
public String getReviewsHtml(long productId) {
|
| 507 |
rajveer |
243 |
String htmlString = "";
|
|
|
244 |
VelocityContext context = new VelocityContext();
|
|
|
245 |
Map<String, String> params = new HashMap<String, String>();
|
|
|
246 |
params.put("PRODUCT_ID", productId+"");
|
|
|
247 |
context.put("params", params);
|
|
|
248 |
String templateFile = "templates/reviews.vm";
|
|
|
249 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
250 |
return htmlString;
|
|
|
251 |
}
|
|
|
252 |
|
|
|
253 |
|
|
|
254 |
|
| 620 |
rajveer |
255 |
public String getLocatorHtml() {
|
| 507 |
rajveer |
256 |
String htmlString = "";
|
|
|
257 |
VelocityContext context = new VelocityContext();
|
|
|
258 |
String templateFile = "templates/locator.vm";
|
|
|
259 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
260 |
return htmlString;
|
|
|
261 |
}
|
|
|
262 |
|
|
|
263 |
|
| 620 |
rajveer |
264 |
public String getSlideGuideHtml(long productId) {
|
| 507 |
rajveer |
265 |
StringBuilder htmlString = new StringBuilder();
|
| 517 |
rajveer |
266 |
String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "SlideGuide.html";
|
| 507 |
rajveer |
267 |
File f = new File(filename);
|
|
|
268 |
|
|
|
269 |
|
|
|
270 |
FileInputStream fis = null;
|
|
|
271 |
try {
|
|
|
272 |
fis = new FileInputStream(f);
|
|
|
273 |
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
|
|
|
274 |
String line;
|
|
|
275 |
while((line = br.readLine()) != null){
|
|
|
276 |
htmlString.append(line+"\n");
|
|
|
277 |
}
|
|
|
278 |
} catch (FileNotFoundException e) {
|
|
|
279 |
// TODO Auto-generated catch block
|
|
|
280 |
e.printStackTrace();
|
|
|
281 |
} catch (IOException e) {
|
|
|
282 |
// TODO Auto-generated catch block
|
|
|
283 |
e.printStackTrace();
|
|
|
284 |
}
|
|
|
285 |
finally {
|
|
|
286 |
if(fis != null) {
|
|
|
287 |
try {
|
|
|
288 |
fis.close();
|
|
|
289 |
} catch (IOException e) {
|
|
|
290 |
// TODO Auto-generated catch block
|
|
|
291 |
e.printStackTrace();
|
|
|
292 |
}
|
|
|
293 |
}
|
|
|
294 |
}
|
|
|
295 |
|
|
|
296 |
return htmlString.toString();
|
|
|
297 |
}
|
|
|
298 |
|
| 517 |
rajveer |
299 |
public String getProductSummaryHtml(long productId) {
|
| 507 |
rajveer |
300 |
StringBuilder htmlString = new StringBuilder();
|
| 517 |
rajveer |
301 |
String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "ProductDetail.html";
|
| 507 |
rajveer |
302 |
File f = new File(filename);
|
|
|
303 |
|
|
|
304 |
|
|
|
305 |
FileInputStream fis = null;
|
|
|
306 |
try {
|
|
|
307 |
fis = new FileInputStream(f);
|
|
|
308 |
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
|
|
|
309 |
String line;
|
|
|
310 |
while((line = br.readLine()) != null){
|
|
|
311 |
htmlString.append(line+"\n");
|
|
|
312 |
}
|
|
|
313 |
} catch (FileNotFoundException e) {
|
|
|
314 |
// TODO Auto-generated catch block
|
|
|
315 |
e.printStackTrace();
|
|
|
316 |
} catch (IOException e) {
|
|
|
317 |
// TODO Auto-generated catch block
|
|
|
318 |
e.printStackTrace();
|
|
|
319 |
}
|
|
|
320 |
finally {
|
|
|
321 |
if(fis != null) {
|
|
|
322 |
try {
|
|
|
323 |
fis.close();
|
|
|
324 |
} catch (IOException e) {
|
|
|
325 |
// TODO Auto-generated catch block
|
|
|
326 |
e.printStackTrace();
|
|
|
327 |
}
|
|
|
328 |
}
|
|
|
329 |
}
|
|
|
330 |
|
|
|
331 |
return htmlString.toString();
|
|
|
332 |
}
|
|
|
333 |
|
| 974 |
vikas |
334 |
public String getPageTitleHtml(long productId) {
|
|
|
335 |
StringBuilder htmlString = new StringBuilder();
|
| 989 |
vikas |
336 |
String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "TitleSnippet.html";
|
| 974 |
vikas |
337 |
File f = new File(filename);
|
|
|
338 |
|
|
|
339 |
|
|
|
340 |
FileInputStream fis = null;
|
|
|
341 |
try {
|
|
|
342 |
fis = new FileInputStream(f);
|
|
|
343 |
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
|
|
|
344 |
String line;
|
|
|
345 |
while((line = br.readLine()) != null){
|
|
|
346 |
htmlString.append(line+"\n");
|
|
|
347 |
}
|
|
|
348 |
} catch (FileNotFoundException e) {
|
|
|
349 |
// TODO Auto-generated catch block
|
|
|
350 |
e.printStackTrace();
|
|
|
351 |
} catch (IOException e) {
|
|
|
352 |
// TODO Auto-generated catch block
|
|
|
353 |
e.printStackTrace();
|
|
|
354 |
}
|
|
|
355 |
finally {
|
|
|
356 |
if(fis != null) {
|
|
|
357 |
try {
|
|
|
358 |
fis.close();
|
|
|
359 |
} catch (IOException e) {
|
|
|
360 |
// TODO Auto-generated catch block
|
|
|
361 |
e.printStackTrace();
|
|
|
362 |
}
|
|
|
363 |
}
|
|
|
364 |
}
|
|
|
365 |
|
|
|
366 |
return htmlString.toString();
|
|
|
367 |
}
|
|
|
368 |
|
|
|
369 |
public String getPageMetaDescriptionHtml(long productId) {
|
|
|
370 |
StringBuilder htmlString = new StringBuilder();
|
| 989 |
vikas |
371 |
String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "MetaDescriptionSnippet.html";
|
| 974 |
vikas |
372 |
File f = new File(filename);
|
|
|
373 |
|
|
|
374 |
|
|
|
375 |
FileInputStream fis = null;
|
|
|
376 |
try {
|
|
|
377 |
fis = new FileInputStream(f);
|
|
|
378 |
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
|
|
|
379 |
String line;
|
|
|
380 |
while((line = br.readLine()) != null){
|
|
|
381 |
htmlString.append(line+"\n");
|
|
|
382 |
}
|
|
|
383 |
} catch (FileNotFoundException e) {
|
|
|
384 |
// TODO Auto-generated catch block
|
|
|
385 |
e.printStackTrace();
|
|
|
386 |
} catch (IOException e) {
|
|
|
387 |
// TODO Auto-generated catch block
|
|
|
388 |
e.printStackTrace();
|
|
|
389 |
}
|
|
|
390 |
finally {
|
|
|
391 |
if(fis != null) {
|
|
|
392 |
try {
|
|
|
393 |
fis.close();
|
|
|
394 |
} catch (IOException e) {
|
|
|
395 |
// TODO Auto-generated catch block
|
|
|
396 |
e.printStackTrace();
|
|
|
397 |
}
|
|
|
398 |
}
|
|
|
399 |
}
|
|
|
400 |
|
|
|
401 |
return htmlString.toString();
|
|
|
402 |
}
|
|
|
403 |
|
|
|
404 |
public String getPageMetaKeywordsHtml(long productId) {
|
|
|
405 |
StringBuilder htmlString = new StringBuilder();
|
| 989 |
vikas |
406 |
String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "MetaKeywordsSnippet.html";
|
| 974 |
vikas |
407 |
File f = new File(filename);
|
|
|
408 |
|
|
|
409 |
|
|
|
410 |
FileInputStream fis = null;
|
|
|
411 |
try {
|
|
|
412 |
fis = new FileInputStream(f);
|
|
|
413 |
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
|
|
|
414 |
String line;
|
|
|
415 |
while((line = br.readLine()) != null){
|
|
|
416 |
htmlString.append(line+"\n");
|
|
|
417 |
}
|
|
|
418 |
} catch (FileNotFoundException e) {
|
|
|
419 |
// TODO Auto-generated catch block
|
|
|
420 |
e.printStackTrace();
|
|
|
421 |
} catch (IOException e) {
|
|
|
422 |
// TODO Auto-generated catch block
|
|
|
423 |
e.printStackTrace();
|
|
|
424 |
}
|
|
|
425 |
finally {
|
|
|
426 |
if(fis != null) {
|
|
|
427 |
try {
|
|
|
428 |
fis.close();
|
|
|
429 |
} catch (IOException e) {
|
|
|
430 |
// TODO Auto-generated catch block
|
|
|
431 |
e.printStackTrace();
|
|
|
432 |
}
|
|
|
433 |
}
|
|
|
434 |
}
|
|
|
435 |
|
|
|
436 |
return htmlString.toString();
|
|
|
437 |
}
|
| 507 |
rajveer |
438 |
|
| 517 |
rajveer |
439 |
public String getMainMenuHtml() {
|
| 507 |
rajveer |
440 |
String htmlString = "";
|
|
|
441 |
VelocityContext context = new VelocityContext();
|
|
|
442 |
String templateFile = "templates/mainmenu.vm";
|
|
|
443 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
444 |
return htmlString;
|
|
|
445 |
}
|
|
|
446 |
|
|
|
447 |
|
| 517 |
rajveer |
448 |
public String getSearchBarHtml(long itemCounts, long categoryId) {
|
| 507 |
rajveer |
449 |
String htmlString = "";
|
|
|
450 |
VelocityContext context = new VelocityContext();
|
|
|
451 |
String templateFile = "templates/searchbar.vm";
|
| 550 |
rajveer |
452 |
|
|
|
453 |
context.put("itemCount", itemCounts+"");
|
|
|
454 |
context.put("categoryId", categoryId+"");
|
|
|
455 |
|
| 507 |
rajveer |
456 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
457 |
return htmlString;
|
|
|
458 |
}
|
|
|
459 |
|
|
|
460 |
|
|
|
461 |
|
| 924 |
vikas |
462 |
public String getHeaderHtml(boolean isLoggedIn, String userName, String url) {
|
| 550 |
rajveer |
463 |
VelocityContext context = new VelocityContext();
|
| 555 |
chandransh |
464 |
if (isLoggedIn) {
|
|
|
465 |
context.put("LOGGED_IN", "TRUE");
|
|
|
466 |
context.put("WELCOME_MESSAGE", "Hi, " + userName);
|
|
|
467 |
} else {
|
| 801 |
rajveer |
468 |
context.put("WELCOME_MESSAGE", "Hi, Welcome to Saholic");
|
| 924 |
vikas |
469 |
context.put("REDIRECT_URL", url);
|
| 555 |
chandransh |
470 |
}
|
| 507 |
rajveer |
471 |
|
|
|
472 |
String templateFile = "templates/header.vm";
|
| 550 |
rajveer |
473 |
|
| 590 |
chandransh |
474 |
return getHtmlFromVelocity(templateFile, context);
|
| 507 |
rajveer |
475 |
}
|
|
|
476 |
|
|
|
477 |
|
|
|
478 |
|
| 650 |
rajveer |
479 |
public String getWidgetDiv(long userId, WidgetType widgetType, String templateFile){
|
| 507 |
rajveer |
480 |
|
| 555 |
chandransh |
481 |
UserContextServiceClient userServiceClient = null;
|
|
|
482 |
in.shop2020.model.v1.user.UserContextService.Client client = null;
|
| 507 |
rajveer |
483 |
Widget widget = null;
|
|
|
484 |
try {
|
| 555 |
chandransh |
485 |
userServiceClient = new UserContextServiceClient();
|
|
|
486 |
client = userServiceClient.getClient();
|
| 1623 |
rajveer |
487 |
if(widgetType == WidgetType.MY_RESEARCH && userId != -1){
|
| 773 |
rajveer |
488 |
widget = client.getMyResearch(userId);
|
|
|
489 |
}
|
|
|
490 |
if(widgetType == WidgetType.BROWSE_HISTORY){
|
|
|
491 |
widget = client.getBrowseHistory(userId);
|
|
|
492 |
}
|
|
|
493 |
|
| 507 |
rajveer |
494 |
} catch (Exception e) {
|
|
|
495 |
e.printStackTrace();
|
|
|
496 |
}
|
|
|
497 |
|
|
|
498 |
|
|
|
499 |
List<Map<String, String>> itemDetails = null;
|
|
|
500 |
|
|
|
501 |
if(widget != null){
|
|
|
502 |
List<WidgetItem> items = widget.getItems();
|
|
|
503 |
itemDetails = new ArrayList<Map<String, String>>();
|
|
|
504 |
|
|
|
505 |
for(WidgetItem item: items){
|
|
|
506 |
Map<String, String> itemDetail = new HashMap<String, String>();
|
| 1110 |
rajveer |
507 |
String itemSnippet;
|
| 507 |
rajveer |
508 |
|
| 1110 |
rajveer |
509 |
try {
|
|
|
510 |
itemSnippet = FileUtils.read( Utils.EXPORT_ENTITIES_PATH + item.getItem_id() + File.separator + "WidgetSnippet.html");
|
|
|
511 |
} catch (IOException e) {
|
|
|
512 |
e.printStackTrace();
|
|
|
513 |
continue;
|
|
|
514 |
}
|
|
|
515 |
|
| 507 |
rajveer |
516 |
itemDetail.put("ITEM_ID", item.getItem_id()+"");
|
| 1110 |
rajveer |
517 |
itemDetail.put("ITEM_SNIPPET", itemSnippet);
|
| 507 |
rajveer |
518 |
itemDetails.add(itemDetail);
|
|
|
519 |
}
|
|
|
520 |
}else{
|
|
|
521 |
System.out.println("widget not found");
|
|
|
522 |
}
|
|
|
523 |
|
|
|
524 |
VelocityContext context = new VelocityContext();
|
| 620 |
rajveer |
525 |
context.put("userId", userId);
|
| 507 |
rajveer |
526 |
context.put("itemDetails", itemDetails);
|
|
|
527 |
|
|
|
528 |
return getHtmlFromVelocity("templates/"+templateFile, context);
|
|
|
529 |
}
|
|
|
530 |
|
|
|
531 |
|
| 1527 |
ankur.sing |
532 |
public String getOrderDetailsHtml(long orderId, long userId) {
|
| 507 |
rajveer |
533 |
String htmlString = "";
|
|
|
534 |
VelocityContext context = new VelocityContext();
|
|
|
535 |
String templateFile = "templates/orderdetails.vm";
|
|
|
536 |
Order order = null;
|
| 517 |
rajveer |
537 |
Date orderedOn = null, deliveryEstimate = null;
|
| 843 |
chandransh |
538 |
Provider provider = null;
|
| 507 |
rajveer |
539 |
try{
|
| 843 |
chandransh |
540 |
TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
|
|
|
541 |
in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
|
| 1527 |
ankur.sing |
542 |
order = orderClient.getOrderForCustomer(orderId, userId);
|
| 517 |
rajveer |
543 |
orderedOn = new Date(order.getCreated_timestamp());
|
|
|
544 |
deliveryEstimate = new Date(order.getExpected_delivery_time());
|
| 843 |
chandransh |
545 |
|
|
|
546 |
if(order.getLogistics_provider_id() != 0){
|
|
|
547 |
LogisticsServiceClient logisticsServiceClient = new LogisticsServiceClient();
|
|
|
548 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
|
|
|
549 |
provider = logisticsClient.getProvider(order.getLogistics_provider_id());
|
|
|
550 |
}
|
| 507 |
rajveer |
551 |
}catch (Exception e){
|
|
|
552 |
|
|
|
553 |
}
|
| 517 |
rajveer |
554 |
|
|
|
555 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
|
| 583 |
rajveer |
556 |
SimpleDateFormat dateformat1 = new SimpleDateFormat("dd/MM/yyyy");
|
| 507 |
rajveer |
557 |
context.put("order", order);
|
| 517 |
rajveer |
558 |
context.put("orderedOn", dateformat.format(orderedOn));
|
| 583 |
rajveer |
559 |
context.put("deliveryEstimate", dateformat1.format(deliveryEstimate));
|
| 843 |
chandransh |
560 |
if(provider!=null){
|
|
|
561 |
context.put("providerName", provider.getName());
|
|
|
562 |
}
|
|
|
563 |
|
| 507 |
rajveer |
564 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
565 |
return htmlString;
|
|
|
566 |
}
|
|
|
567 |
|
| 650 |
rajveer |
568 |
public String getMyaccountDetailsHtml(long userId) {
|
| 507 |
rajveer |
569 |
String htmlString = "";
|
|
|
570 |
VelocityContext context = new VelocityContext();
|
|
|
571 |
String templateFile = "templates/myaccount.vm";
|
|
|
572 |
List<Order> orders = null;
|
| 745 |
chandransh |
573 |
Map<Long, String> providerNames = new HashMap<Long, String>();
|
| 507 |
rajveer |
574 |
try{
|
| 745 |
chandransh |
575 |
TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
|
|
|
576 |
in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
|
| 507 |
rajveer |
577 |
orders = orderClient.getOrdersForCustomer(userId, 0, (new Date()).getTime(), null);
|
|
|
578 |
|
| 745 |
chandransh |
579 |
LogisticsServiceClient logisticsServiceClient = new LogisticsServiceClient();
|
|
|
580 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
|
|
|
581 |
List<Provider> providers = logisticsClient.getAllProviders();
|
|
|
582 |
for(Provider provider: providers)
|
|
|
583 |
providerNames.put(provider.getId(), provider.getName());
|
| 507 |
rajveer |
584 |
}catch (Exception e){
|
| 1275 |
varun.gupt |
585 |
e.printStackTrace();
|
| 507 |
rajveer |
586 |
}
|
| 741 |
rajveer |
587 |
List<String> orderDate = new ArrayList<String>();
|
|
|
588 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
|
| 888 |
chandransh |
589 |
if(orders!=null && !orders.isEmpty()){
|
| 762 |
rajveer |
590 |
for(Order order: orders){
|
|
|
591 |
Date orderedOn = new Date(order.getCreated_timestamp());
|
|
|
592 |
orderDate.add(dateformat.format(orderedOn));
|
|
|
593 |
}
|
| 741 |
rajveer |
594 |
}
|
| 507 |
rajveer |
595 |
context.put("orders", orders);
|
| 741 |
rajveer |
596 |
context.put("orderDate", orderDate);
|
| 745 |
chandransh |
597 |
context.put("providerNames", providerNames);
|
| 507 |
rajveer |
598 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
599 |
return htmlString;
|
|
|
600 |
}
|
|
|
601 |
|
|
|
602 |
|
| 650 |
rajveer |
603 |
public String getLoginDetailsHtml(long userId) {
|
| 507 |
rajveer |
604 |
String htmlString = "";
|
|
|
605 |
VelocityContext context = new VelocityContext();
|
|
|
606 |
String templateFile = "templates/logindetails.vm";
|
|
|
607 |
String email = "";
|
|
|
608 |
try{
|
| 762 |
rajveer |
609 |
email = getEmailId(userId);
|
| 507 |
rajveer |
610 |
}catch (Exception e){
|
|
|
611 |
|
|
|
612 |
}
|
|
|
613 |
context.put("email", email);
|
|
|
614 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
615 |
return htmlString;
|
|
|
616 |
}
|
|
|
617 |
|
| 762 |
rajveer |
618 |
public String getEmailId(long userId){
|
|
|
619 |
String email = " ";
|
|
|
620 |
|
|
|
621 |
try {
|
|
|
622 |
UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
|
|
|
623 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
|
|
624 |
if(userClient.getUserById(userId).getEmail() != null){
|
|
|
625 |
email = userClient.getUserById(userId).getEmail();
|
|
|
626 |
}
|
|
|
627 |
} catch (UserContextException e) {
|
|
|
628 |
e.printStackTrace();
|
|
|
629 |
} catch (TException e) {
|
|
|
630 |
e.printStackTrace();
|
|
|
631 |
} catch (Exception e) {
|
|
|
632 |
e.printStackTrace();
|
|
|
633 |
}
|
|
|
634 |
return email;
|
|
|
635 |
}
|
|
|
636 |
|
|
|
637 |
|
| 595 |
rajveer |
638 |
public String getPersonalDetailsHtml(long userId) {
|
| 507 |
rajveer |
639 |
String htmlString = "";
|
|
|
640 |
VelocityContext context = new VelocityContext();
|
|
|
641 |
String templateFile = "templates/personaldetails.vm";
|
|
|
642 |
String email = "";
|
| 517 |
rajveer |
643 |
String name = "";
|
| 569 |
rajveer |
644 |
String dateOfBirth = "";
|
| 517 |
rajveer |
645 |
String sex = "";
|
|
|
646 |
String subscribe = "false";
|
| 507 |
rajveer |
647 |
UserContextServiceClient userContextServiceClient = null;
|
|
|
648 |
in.shop2020.model.v1.user.UserContextService.Client userClient = null;
|
|
|
649 |
try{
|
| 555 |
chandransh |
650 |
User user = null;
|
| 507 |
rajveer |
651 |
userContextServiceClient = new UserContextServiceClient();
|
|
|
652 |
userClient = userContextServiceClient.getClient();
|
| 555 |
chandransh |
653 |
user = userClient.getUserById(userId);
|
| 507 |
rajveer |
654 |
|
| 555 |
chandransh |
655 |
email = user.getCommunicationEmail();
|
|
|
656 |
name = user.getName();
|
| 517 |
rajveer |
657 |
|
| 569 |
rajveer |
658 |
dateOfBirth = user.getDateOfBirth();
|
| 507 |
rajveer |
659 |
}catch (Exception e){
|
| 555 |
chandransh |
660 |
e.printStackTrace();
|
| 507 |
rajveer |
661 |
}
|
| 517 |
rajveer |
662 |
context.put("name", name);
|
|
|
663 |
context.put("email", email);
|
| 569 |
rajveer |
664 |
context.put("dateOfBirth", dateOfBirth+"");
|
| 517 |
rajveer |
665 |
context.put("subscribe", subscribe);
|
|
|
666 |
context.put("sex", sex);
|
| 507 |
rajveer |
667 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
668 |
return htmlString;
|
|
|
669 |
}
|
|
|
670 |
|
| 620 |
rajveer |
671 |
public String getCompletedOrdersHtml(long userId) {
|
| 507 |
rajveer |
672 |
String htmlString = "";
|
|
|
673 |
VelocityContext context = new VelocityContext();
|
|
|
674 |
String templateFile = "templates/completedorders.vm";
|
|
|
675 |
TransactionServiceClient transactionServiceClient = null;
|
|
|
676 |
in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
|
| 1310 |
varun.gupt |
677 |
|
| 507 |
rajveer |
678 |
List<Order> orders = null;
|
| 1310 |
varun.gupt |
679 |
List<String> orderDate = new ArrayList<String>();
|
| 1316 |
varun.gupt |
680 |
Map<Long, String> providerNames = new HashMap<Long, String>();
|
| 1310 |
varun.gupt |
681 |
|
| 507 |
rajveer |
682 |
try{
|
|
|
683 |
transactionServiceClient = new TransactionServiceClient();
|
|
|
684 |
orderClient = transactionServiceClient.getClient();
|
|
|
685 |
orders = orderClient.getOrdersForCustomer(userId, 0, (new Date()).getTime(), OrderStatus.DELIVERY_SUCCESS);
|
| 1316 |
varun.gupt |
686 |
|
|
|
687 |
LogisticsServiceClient logisticsServiceClient = new LogisticsServiceClient();
|
|
|
688 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
|
|
|
689 |
List<Provider> providers = logisticsClient.getAllProviders();
|
|
|
690 |
for(Provider provider: providers)
|
|
|
691 |
providerNames.put(provider.getId(), provider.getName());
|
|
|
692 |
|
| 1310 |
varun.gupt |
693 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
|
|
|
694 |
|
|
|
695 |
if(orders != null && !orders.isEmpty()){
|
|
|
696 |
for(Order order: orders){
|
|
|
697 |
Date orderedOn = new Date(order.getCreated_timestamp());
|
|
|
698 |
orderDate.add(dateformat.format(orderedOn));
|
|
|
699 |
}
|
|
|
700 |
}
|
| 507 |
rajveer |
701 |
}catch (Exception e){
|
|
|
702 |
|
|
|
703 |
}
|
|
|
704 |
context.put("orders", orders);
|
| 1310 |
varun.gupt |
705 |
context.put("orderDate", orderDate);
|
| 1316 |
varun.gupt |
706 |
context.put("providerNames", providerNames);
|
| 1310 |
varun.gupt |
707 |
|
| 507 |
rajveer |
708 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
709 |
return htmlString;
|
|
|
710 |
}
|
| 595 |
rajveer |
711 |
public String getMyaccountHeaderHtml() {
|
| 507 |
rajveer |
712 |
String htmlString = "";
|
|
|
713 |
VelocityContext context = new VelocityContext();
|
|
|
714 |
String templateFile = "templates/myaccountheader.vm";
|
|
|
715 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
716 |
return htmlString;
|
|
|
717 |
}
|
|
|
718 |
|
|
|
719 |
|
| 822 |
vikas |
720 |
public String getShippingAddressDetailsHtml(long userId, String errorMsg){
|
| 507 |
rajveer |
721 |
String htmlString = "";
|
|
|
722 |
VelocityContext context = new VelocityContext();
|
|
|
723 |
String templateFile = "templates/shippingaddressdetails.vm";
|
|
|
724 |
long defaultAddressId = 0;
|
| 517 |
rajveer |
725 |
List<Address> addresses = null;
|
| 507 |
rajveer |
726 |
|
|
|
727 |
UserContextServiceClient userContextServiceClient = null;
|
|
|
728 |
in.shop2020.model.v1.user.UserContextService.Client userClient = null;
|
|
|
729 |
try {
|
|
|
730 |
userContextServiceClient = new UserContextServiceClient();
|
|
|
731 |
userClient = userContextServiceClient.getClient();
|
| 620 |
rajveer |
732 |
|
|
|
733 |
addresses = userClient.getAllAddressesForUser(userId);
|
|
|
734 |
defaultAddressId = userClient.getDefaultAddressId(userId);
|
| 507 |
rajveer |
735 |
} catch (Exception e) {
|
|
|
736 |
e.printStackTrace();
|
|
|
737 |
}
|
| 517 |
rajveer |
738 |
context.put("defaultAddressId", defaultAddressId+"");
|
| 507 |
rajveer |
739 |
context.put("addresses", addresses);
|
| 822 |
vikas |
740 |
context.put("errorMsg", errorMsg);
|
| 507 |
rajveer |
741 |
|
|
|
742 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
743 |
return htmlString;
|
|
|
744 |
}
|
|
|
745 |
|
|
|
746 |
public String getHtmlFromVelocity(String templateFile, VelocityContext context){
|
|
|
747 |
Properties p = new Properties();
|
|
|
748 |
p.setProperty("resource.loader", "class");
|
|
|
749 |
p.setProperty("class.resource.loader.class",
|
|
|
750 |
"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
|
| 832 |
rajveer |
751 |
p.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogSystem");
|
|
|
752 |
|
| 507 |
rajveer |
753 |
try {
|
|
|
754 |
Velocity.init(p);
|
| 762 |
rajveer |
755 |
//Velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, value)
|
| 507 |
rajveer |
756 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
757 |
if(template != null) {
|
|
|
758 |
StringWriter writer = new StringWriter();
|
|
|
759 |
template.merge(context, writer);
|
|
|
760 |
writer.flush();
|
|
|
761 |
writer.close();
|
|
|
762 |
return writer.toString();
|
|
|
763 |
}
|
|
|
764 |
|
|
|
765 |
} catch (ResourceNotFoundException e) {
|
|
|
766 |
// TODO Auto-generated catch block
|
|
|
767 |
e.printStackTrace();
|
|
|
768 |
} catch (ParseErrorException e) {
|
|
|
769 |
// TODO Auto-generated catch block
|
|
|
770 |
e.printStackTrace();
|
|
|
771 |
} catch (MethodInvocationException e) {
|
|
|
772 |
// TODO Auto-generated catch block
|
|
|
773 |
e.printStackTrace();
|
|
|
774 |
} catch (IOException e) {
|
|
|
775 |
// TODO Auto-generated catch block
|
|
|
776 |
e.printStackTrace();
|
|
|
777 |
} catch (Exception e) {
|
|
|
778 |
// TODO Auto-generated catch block
|
|
|
779 |
e.printStackTrace();
|
|
|
780 |
}
|
|
|
781 |
|
|
|
782 |
return null;
|
|
|
783 |
}
|
| 1549 |
rajveer |
784 |
}
|