| 507 |
rajveer |
1 |
package in.shop2020.serving.services;
|
|
|
2 |
|
| 2306 |
vikas |
3 |
import in.shop2020.logistics.Provider;
|
|
|
4 |
import in.shop2020.model.v1.order.Order;
|
|
|
5 |
import in.shop2020.model.v1.user.Address;
|
|
|
6 |
import in.shop2020.model.v1.user.User;
|
|
|
7 |
import in.shop2020.model.v1.user.UserContextException;
|
|
|
8 |
import in.shop2020.serving.utils.Utils;
|
|
|
9 |
import in.shop2020.thrift.clients.LogisticsServiceClient;
|
|
|
10 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
|
|
11 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
|
|
12 |
|
| 507 |
rajveer |
13 |
import java.io.BufferedReader;
|
|
|
14 |
import java.io.File;
|
|
|
15 |
import java.io.FileInputStream;
|
|
|
16 |
import java.io.FileNotFoundException;
|
|
|
17 |
import java.io.IOException;
|
|
|
18 |
import java.io.InputStreamReader;
|
|
|
19 |
import java.io.StringWriter;
|
| 517 |
rajveer |
20 |
import java.text.SimpleDateFormat;
|
| 507 |
rajveer |
21 |
import java.util.ArrayList;
|
|
|
22 |
import java.util.Date;
|
|
|
23 |
import java.util.HashMap;
|
|
|
24 |
import java.util.List;
|
|
|
25 |
import java.util.Map;
|
|
|
26 |
import java.util.Properties;
|
|
|
27 |
|
|
|
28 |
import org.apache.thrift.TException;
|
|
|
29 |
import org.apache.velocity.Template;
|
|
|
30 |
import org.apache.velocity.VelocityContext;
|
|
|
31 |
import org.apache.velocity.app.Velocity;
|
|
|
32 |
import org.apache.velocity.exception.MethodInvocationException;
|
|
|
33 |
import org.apache.velocity.exception.ParseErrorException;
|
|
|
34 |
import org.apache.velocity.exception.ResourceNotFoundException;
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
public class PageLoaderHandler {
|
|
|
38 |
|
| 620 |
rajveer |
39 |
public String getSlideGuideHtml(long productId) {
|
| 507 |
rajveer |
40 |
StringBuilder htmlString = new StringBuilder();
|
| 517 |
rajveer |
41 |
String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "SlideGuide.html";
|
| 507 |
rajveer |
42 |
File f = new File(filename);
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
FileInputStream fis = null;
|
|
|
46 |
try {
|
|
|
47 |
fis = new FileInputStream(f);
|
|
|
48 |
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
|
|
|
49 |
String line;
|
|
|
50 |
while((line = br.readLine()) != null){
|
|
|
51 |
htmlString.append(line+"\n");
|
|
|
52 |
}
|
|
|
53 |
} catch (FileNotFoundException e) {
|
|
|
54 |
// TODO Auto-generated catch block
|
|
|
55 |
e.printStackTrace();
|
|
|
56 |
} catch (IOException e) {
|
|
|
57 |
// TODO Auto-generated catch block
|
|
|
58 |
e.printStackTrace();
|
|
|
59 |
}
|
|
|
60 |
finally {
|
|
|
61 |
if(fis != null) {
|
|
|
62 |
try {
|
|
|
63 |
fis.close();
|
|
|
64 |
} catch (IOException e) {
|
|
|
65 |
// TODO Auto-generated catch block
|
|
|
66 |
e.printStackTrace();
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
return htmlString.toString();
|
|
|
72 |
}
|
|
|
73 |
|
| 517 |
rajveer |
74 |
public String getProductSummaryHtml(long productId) {
|
| 507 |
rajveer |
75 |
StringBuilder htmlString = new StringBuilder();
|
| 517 |
rajveer |
76 |
String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "ProductDetail.html";
|
| 507 |
rajveer |
77 |
File f = new File(filename);
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
FileInputStream fis = null;
|
|
|
81 |
try {
|
|
|
82 |
fis = new FileInputStream(f);
|
|
|
83 |
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
|
|
|
84 |
String line;
|
|
|
85 |
while((line = br.readLine()) != null){
|
|
|
86 |
htmlString.append(line+"\n");
|
|
|
87 |
}
|
|
|
88 |
} catch (FileNotFoundException e) {
|
|
|
89 |
// TODO Auto-generated catch block
|
|
|
90 |
e.printStackTrace();
|
|
|
91 |
} catch (IOException e) {
|
|
|
92 |
// TODO Auto-generated catch block
|
|
|
93 |
e.printStackTrace();
|
|
|
94 |
}
|
|
|
95 |
finally {
|
|
|
96 |
if(fis != null) {
|
|
|
97 |
try {
|
|
|
98 |
fis.close();
|
|
|
99 |
} catch (IOException e) {
|
|
|
100 |
// TODO Auto-generated catch block
|
|
|
101 |
e.printStackTrace();
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
return htmlString.toString();
|
|
|
107 |
}
|
|
|
108 |
|
| 2306 |
vikas |
109 |
public String getProductPropertiesHtml(long productId) {
|
| 974 |
vikas |
110 |
StringBuilder htmlString = new StringBuilder();
|
| 2306 |
vikas |
111 |
String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "ProductPropertiesSnippet.html";
|
| 974 |
vikas |
112 |
File f = new File(filename);
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
FileInputStream fis = null;
|
|
|
116 |
try {
|
|
|
117 |
fis = new FileInputStream(f);
|
|
|
118 |
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
|
|
|
119 |
String line;
|
|
|
120 |
while((line = br.readLine()) != null){
|
|
|
121 |
htmlString.append(line+"\n");
|
|
|
122 |
}
|
|
|
123 |
} catch (FileNotFoundException e) {
|
|
|
124 |
// TODO Auto-generated catch block
|
|
|
125 |
e.printStackTrace();
|
|
|
126 |
} catch (IOException e) {
|
|
|
127 |
// TODO Auto-generated catch block
|
|
|
128 |
e.printStackTrace();
|
|
|
129 |
}
|
|
|
130 |
finally {
|
|
|
131 |
if(fis != null) {
|
|
|
132 |
try {
|
|
|
133 |
fis.close();
|
|
|
134 |
} catch (IOException e) {
|
|
|
135 |
// TODO Auto-generated catch block
|
|
|
136 |
e.printStackTrace();
|
|
|
137 |
}
|
|
|
138 |
}
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
return htmlString.toString();
|
|
|
142 |
}
|
|
|
143 |
|
| 517 |
rajveer |
144 |
public String getSearchBarHtml(long itemCounts, long categoryId) {
|
| 507 |
rajveer |
145 |
String htmlString = "";
|
|
|
146 |
VelocityContext context = new VelocityContext();
|
|
|
147 |
String templateFile = "templates/searchbar.vm";
|
| 550 |
rajveer |
148 |
|
|
|
149 |
context.put("itemCount", itemCounts+"");
|
|
|
150 |
context.put("categoryId", categoryId+"");
|
|
|
151 |
|
| 507 |
rajveer |
152 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
153 |
return htmlString;
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
|
|
|
157 |
|
| 924 |
vikas |
158 |
public String getHeaderHtml(boolean isLoggedIn, String userName, String url) {
|
| 550 |
rajveer |
159 |
VelocityContext context = new VelocityContext();
|
| 555 |
chandransh |
160 |
if (isLoggedIn) {
|
|
|
161 |
context.put("LOGGED_IN", "TRUE");
|
|
|
162 |
context.put("WELCOME_MESSAGE", "Hi, " + userName);
|
|
|
163 |
} else {
|
| 801 |
rajveer |
164 |
context.put("WELCOME_MESSAGE", "Hi, Welcome to Saholic");
|
| 924 |
vikas |
165 |
context.put("REDIRECT_URL", url);
|
| 555 |
chandransh |
166 |
}
|
| 507 |
rajveer |
167 |
|
|
|
168 |
String templateFile = "templates/header.vm";
|
| 550 |
rajveer |
169 |
|
| 590 |
chandransh |
170 |
return getHtmlFromVelocity(templateFile, context);
|
| 507 |
rajveer |
171 |
}
|
|
|
172 |
|
|
|
173 |
|
| 1527 |
ankur.sing |
174 |
public String getOrderDetailsHtml(long orderId, long userId) {
|
| 507 |
rajveer |
175 |
String htmlString = "";
|
|
|
176 |
VelocityContext context = new VelocityContext();
|
|
|
177 |
String templateFile = "templates/orderdetails.vm";
|
|
|
178 |
Order order = null;
|
| 517 |
rajveer |
179 |
Date orderedOn = null, deliveryEstimate = null;
|
| 843 |
chandransh |
180 |
Provider provider = null;
|
| 507 |
rajveer |
181 |
try{
|
| 843 |
chandransh |
182 |
TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
|
|
|
183 |
in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
|
| 1527 |
ankur.sing |
184 |
order = orderClient.getOrderForCustomer(orderId, userId);
|
| 517 |
rajveer |
185 |
orderedOn = new Date(order.getCreated_timestamp());
|
|
|
186 |
deliveryEstimate = new Date(order.getExpected_delivery_time());
|
| 843 |
chandransh |
187 |
|
|
|
188 |
if(order.getLogistics_provider_id() != 0){
|
|
|
189 |
LogisticsServiceClient logisticsServiceClient = new LogisticsServiceClient();
|
|
|
190 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
|
|
|
191 |
provider = logisticsClient.getProvider(order.getLogistics_provider_id());
|
|
|
192 |
}
|
| 507 |
rajveer |
193 |
}catch (Exception e){
|
|
|
194 |
|
|
|
195 |
}
|
| 517 |
rajveer |
196 |
|
|
|
197 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
|
| 583 |
rajveer |
198 |
SimpleDateFormat dateformat1 = new SimpleDateFormat("dd/MM/yyyy");
|
| 507 |
rajveer |
199 |
context.put("order", order);
|
| 517 |
rajveer |
200 |
context.put("orderedOn", dateformat.format(orderedOn));
|
| 583 |
rajveer |
201 |
context.put("deliveryEstimate", dateformat1.format(deliveryEstimate));
|
| 843 |
chandransh |
202 |
if(provider!=null){
|
|
|
203 |
context.put("providerName", provider.getName());
|
|
|
204 |
}
|
|
|
205 |
|
| 507 |
rajveer |
206 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
207 |
return htmlString;
|
|
|
208 |
}
|
|
|
209 |
|
| 650 |
rajveer |
210 |
public String getMyaccountDetailsHtml(long userId) {
|
| 507 |
rajveer |
211 |
String htmlString = "";
|
|
|
212 |
VelocityContext context = new VelocityContext();
|
|
|
213 |
String templateFile = "templates/myaccount.vm";
|
|
|
214 |
List<Order> orders = null;
|
| 745 |
chandransh |
215 |
Map<Long, String> providerNames = new HashMap<Long, String>();
|
| 507 |
rajveer |
216 |
try{
|
| 745 |
chandransh |
217 |
TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
|
|
|
218 |
in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
|
| 507 |
rajveer |
219 |
orders = orderClient.getOrdersForCustomer(userId, 0, (new Date()).getTime(), null);
|
|
|
220 |
|
| 745 |
chandransh |
221 |
LogisticsServiceClient logisticsServiceClient = new LogisticsServiceClient();
|
|
|
222 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
|
|
|
223 |
List<Provider> providers = logisticsClient.getAllProviders();
|
|
|
224 |
for(Provider provider: providers)
|
|
|
225 |
providerNames.put(provider.getId(), provider.getName());
|
| 507 |
rajveer |
226 |
}catch (Exception e){
|
| 1275 |
varun.gupt |
227 |
e.printStackTrace();
|
| 507 |
rajveer |
228 |
}
|
| 741 |
rajveer |
229 |
List<String> orderDate = new ArrayList<String>();
|
|
|
230 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
|
| 888 |
chandransh |
231 |
if(orders!=null && !orders.isEmpty()){
|
| 762 |
rajveer |
232 |
for(Order order: orders){
|
|
|
233 |
Date orderedOn = new Date(order.getCreated_timestamp());
|
|
|
234 |
orderDate.add(dateformat.format(orderedOn));
|
|
|
235 |
}
|
| 741 |
rajveer |
236 |
}
|
| 507 |
rajveer |
237 |
context.put("orders", orders);
|
| 741 |
rajveer |
238 |
context.put("orderDate", orderDate);
|
| 745 |
chandransh |
239 |
context.put("providerNames", providerNames);
|
| 507 |
rajveer |
240 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
241 |
return htmlString;
|
|
|
242 |
}
|
|
|
243 |
|
|
|
244 |
|
| 650 |
rajveer |
245 |
public String getLoginDetailsHtml(long userId) {
|
| 507 |
rajveer |
246 |
String htmlString = "";
|
|
|
247 |
VelocityContext context = new VelocityContext();
|
|
|
248 |
String templateFile = "templates/logindetails.vm";
|
|
|
249 |
String email = "";
|
|
|
250 |
try{
|
| 762 |
rajveer |
251 |
email = getEmailId(userId);
|
| 507 |
rajveer |
252 |
}catch (Exception e){
|
|
|
253 |
|
|
|
254 |
}
|
|
|
255 |
context.put("email", email);
|
|
|
256 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
257 |
return htmlString;
|
|
|
258 |
}
|
|
|
259 |
|
| 762 |
rajveer |
260 |
public String getEmailId(long userId){
|
|
|
261 |
String email = " ";
|
|
|
262 |
|
|
|
263 |
try {
|
|
|
264 |
UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
|
|
|
265 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
|
|
266 |
if(userClient.getUserById(userId).getEmail() != null){
|
|
|
267 |
email = userClient.getUserById(userId).getEmail();
|
|
|
268 |
}
|
|
|
269 |
} catch (UserContextException e) {
|
|
|
270 |
e.printStackTrace();
|
|
|
271 |
} catch (TException e) {
|
|
|
272 |
e.printStackTrace();
|
|
|
273 |
} catch (Exception e) {
|
|
|
274 |
e.printStackTrace();
|
|
|
275 |
}
|
|
|
276 |
return email;
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
|
| 595 |
rajveer |
280 |
public String getPersonalDetailsHtml(long userId) {
|
| 507 |
rajveer |
281 |
String htmlString = "";
|
|
|
282 |
VelocityContext context = new VelocityContext();
|
|
|
283 |
String templateFile = "templates/personaldetails.vm";
|
|
|
284 |
String email = "";
|
| 517 |
rajveer |
285 |
String name = "";
|
| 569 |
rajveer |
286 |
String dateOfBirth = "";
|
| 517 |
rajveer |
287 |
String sex = "";
|
|
|
288 |
String subscribe = "false";
|
| 507 |
rajveer |
289 |
UserContextServiceClient userContextServiceClient = null;
|
|
|
290 |
in.shop2020.model.v1.user.UserContextService.Client userClient = null;
|
|
|
291 |
try{
|
| 555 |
chandransh |
292 |
User user = null;
|
| 507 |
rajveer |
293 |
userContextServiceClient = new UserContextServiceClient();
|
|
|
294 |
userClient = userContextServiceClient.getClient();
|
| 555 |
chandransh |
295 |
user = userClient.getUserById(userId);
|
| 507 |
rajveer |
296 |
|
| 555 |
chandransh |
297 |
email = user.getCommunicationEmail();
|
|
|
298 |
name = user.getName();
|
| 517 |
rajveer |
299 |
|
| 569 |
rajveer |
300 |
dateOfBirth = user.getDateOfBirth();
|
| 507 |
rajveer |
301 |
}catch (Exception e){
|
| 555 |
chandransh |
302 |
e.printStackTrace();
|
| 507 |
rajveer |
303 |
}
|
| 517 |
rajveer |
304 |
context.put("name", name);
|
|
|
305 |
context.put("email", email);
|
| 569 |
rajveer |
306 |
context.put("dateOfBirth", dateOfBirth+"");
|
| 517 |
rajveer |
307 |
context.put("subscribe", subscribe);
|
|
|
308 |
context.put("sex", sex);
|
| 507 |
rajveer |
309 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
310 |
return htmlString;
|
|
|
311 |
}
|
|
|
312 |
|
| 595 |
rajveer |
313 |
public String getMyaccountHeaderHtml() {
|
| 507 |
rajveer |
314 |
String htmlString = "";
|
|
|
315 |
VelocityContext context = new VelocityContext();
|
|
|
316 |
String templateFile = "templates/myaccountheader.vm";
|
|
|
317 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
318 |
return htmlString;
|
|
|
319 |
}
|
|
|
320 |
|
| 822 |
vikas |
321 |
public String getShippingAddressDetailsHtml(long userId, String errorMsg){
|
| 507 |
rajveer |
322 |
String htmlString = "";
|
|
|
323 |
VelocityContext context = new VelocityContext();
|
|
|
324 |
String templateFile = "templates/shippingaddressdetails.vm";
|
|
|
325 |
long defaultAddressId = 0;
|
| 517 |
rajveer |
326 |
List<Address> addresses = null;
|
| 507 |
rajveer |
327 |
|
|
|
328 |
UserContextServiceClient userContextServiceClient = null;
|
|
|
329 |
in.shop2020.model.v1.user.UserContextService.Client userClient = null;
|
|
|
330 |
try {
|
|
|
331 |
userContextServiceClient = new UserContextServiceClient();
|
|
|
332 |
userClient = userContextServiceClient.getClient();
|
| 620 |
rajveer |
333 |
|
|
|
334 |
addresses = userClient.getAllAddressesForUser(userId);
|
|
|
335 |
defaultAddressId = userClient.getDefaultAddressId(userId);
|
| 507 |
rajveer |
336 |
} catch (Exception e) {
|
|
|
337 |
e.printStackTrace();
|
|
|
338 |
}
|
| 517 |
rajveer |
339 |
context.put("defaultAddressId", defaultAddressId+"");
|
| 507 |
rajveer |
340 |
context.put("addresses", addresses);
|
| 822 |
vikas |
341 |
context.put("errorMsg", errorMsg);
|
| 507 |
rajveer |
342 |
|
|
|
343 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
344 |
return htmlString;
|
|
|
345 |
}
|
|
|
346 |
|
|
|
347 |
public String getHtmlFromVelocity(String templateFile, VelocityContext context){
|
|
|
348 |
Properties p = new Properties();
|
|
|
349 |
p.setProperty("resource.loader", "class");
|
|
|
350 |
p.setProperty("class.resource.loader.class",
|
|
|
351 |
"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
|
| 832 |
rajveer |
352 |
p.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogSystem");
|
|
|
353 |
|
| 507 |
rajveer |
354 |
try {
|
|
|
355 |
Velocity.init(p);
|
| 762 |
rajveer |
356 |
//Velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, value)
|
| 507 |
rajveer |
357 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
358 |
if(template != null) {
|
|
|
359 |
StringWriter writer = new StringWriter();
|
|
|
360 |
template.merge(context, writer);
|
|
|
361 |
writer.flush();
|
|
|
362 |
writer.close();
|
|
|
363 |
return writer.toString();
|
|
|
364 |
}
|
|
|
365 |
|
|
|
366 |
} catch (ResourceNotFoundException e) {
|
|
|
367 |
// TODO Auto-generated catch block
|
|
|
368 |
e.printStackTrace();
|
|
|
369 |
} catch (ParseErrorException e) {
|
|
|
370 |
// TODO Auto-generated catch block
|
|
|
371 |
e.printStackTrace();
|
|
|
372 |
} catch (MethodInvocationException e) {
|
|
|
373 |
// TODO Auto-generated catch block
|
|
|
374 |
e.printStackTrace();
|
|
|
375 |
} catch (IOException e) {
|
|
|
376 |
// TODO Auto-generated catch block
|
|
|
377 |
e.printStackTrace();
|
|
|
378 |
} catch (Exception e) {
|
|
|
379 |
// TODO Auto-generated catch block
|
|
|
380 |
e.printStackTrace();
|
|
|
381 |
}
|
|
|
382 |
|
|
|
383 |
return null;
|
|
|
384 |
}
|
| 1549 |
rajveer |
385 |
}
|