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