| 507 |
rajveer |
1 |
package in.shop2020.serving.services;
|
|
|
2 |
|
| 5838 |
mandeep.dh |
3 |
import in.shop2020.logistics.PickupStore;
|
| 2306 |
vikas |
4 |
import in.shop2020.logistics.Provider;
|
| 8917 |
kshitij.so |
5 |
import in.shop2020.model.v1.catalog.Banner;
|
|
|
6 |
import in.shop2020.model.v1.catalog.BannerMap;
|
| 2306 |
vikas |
7 |
import in.shop2020.model.v1.order.Order;
|
| 7309 |
rajveer |
8 |
import in.shop2020.model.v1.order.OrderSource;
|
| 4815 |
phani.kuma |
9 |
import in.shop2020.model.v1.order.OrderStatus;
|
|
|
10 |
import in.shop2020.model.v1.order.OrderStatusGroups;
|
| 2306 |
vikas |
11 |
import in.shop2020.model.v1.user.Address;
|
|
|
12 |
import in.shop2020.model.v1.user.User;
|
|
|
13 |
import in.shop2020.model.v1.user.UserContextException;
|
| 3830 |
chandransh |
14 |
import in.shop2020.serving.utils.FormattingUtils;
|
| 2306 |
vikas |
15 |
import in.shop2020.serving.utils.Utils;
|
| 3126 |
rajveer |
16 |
import in.shop2020.thrift.clients.LogisticsClient;
|
|
|
17 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
18 |
import in.shop2020.thrift.clients.UserClient;
|
| 2306 |
vikas |
19 |
|
| 507 |
rajveer |
20 |
import java.io.BufferedReader;
|
|
|
21 |
import java.io.File;
|
|
|
22 |
import java.io.FileInputStream;
|
|
|
23 |
import java.io.FileNotFoundException;
|
|
|
24 |
import java.io.IOException;
|
|
|
25 |
import java.io.InputStreamReader;
|
|
|
26 |
import java.io.StringWriter;
|
| 517 |
rajveer |
27 |
import java.text.SimpleDateFormat;
|
| 507 |
rajveer |
28 |
import java.util.ArrayList;
|
|
|
29 |
import java.util.Date;
|
|
|
30 |
import java.util.HashMap;
|
|
|
31 |
import java.util.List;
|
|
|
32 |
import java.util.Map;
|
|
|
33 |
import java.util.Properties;
|
|
|
34 |
|
| 2949 |
chandransh |
35 |
import org.apache.log4j.Logger;
|
| 507 |
rajveer |
36 |
import org.apache.thrift.TException;
|
|
|
37 |
import org.apache.velocity.Template;
|
|
|
38 |
import org.apache.velocity.VelocityContext;
|
|
|
39 |
import org.apache.velocity.app.Velocity;
|
|
|
40 |
import org.apache.velocity.exception.MethodInvocationException;
|
|
|
41 |
import org.apache.velocity.exception.ParseErrorException;
|
|
|
42 |
import org.apache.velocity.exception.ResourceNotFoundException;
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
public class PageLoaderHandler {
|
|
|
46 |
|
| 2949 |
chandransh |
47 |
private static Logger logger = Logger.getLogger(PageLoaderHandler.class);
|
|
|
48 |
|
| 620 |
rajveer |
49 |
public String getSlideGuideHtml(long productId) {
|
| 507 |
rajveer |
50 |
StringBuilder htmlString = new StringBuilder();
|
| 517 |
rajveer |
51 |
String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "SlideGuide.html";
|
| 507 |
rajveer |
52 |
File f = new File(filename);
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
FileInputStream fis = null;
|
|
|
56 |
try {
|
|
|
57 |
fis = new FileInputStream(f);
|
|
|
58 |
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
|
|
|
59 |
String line;
|
|
|
60 |
while((line = br.readLine()) != null){
|
|
|
61 |
htmlString.append(line+"\n");
|
|
|
62 |
}
|
|
|
63 |
} catch (FileNotFoundException e) {
|
| 2949 |
chandransh |
64 |
logger.error("Unable to find the slide guide for " + productId, e);
|
| 507 |
rajveer |
65 |
} catch (IOException e) {
|
| 2949 |
chandransh |
66 |
logger.error("Unable to read the slide guide for " + productId, e);
|
| 507 |
rajveer |
67 |
}
|
|
|
68 |
finally {
|
|
|
69 |
if(fis != null) {
|
|
|
70 |
try {
|
|
|
71 |
fis.close();
|
|
|
72 |
} catch (IOException e) {
|
| 2949 |
chandransh |
73 |
logger.warn("Unable to close the slide guide for " + productId, e);
|
| 507 |
rajveer |
74 |
}
|
|
|
75 |
}
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
return htmlString.toString();
|
|
|
79 |
}
|
|
|
80 |
|
| 517 |
rajveer |
81 |
public String getProductSummaryHtml(long productId) {
|
| 507 |
rajveer |
82 |
StringBuilder htmlString = new StringBuilder();
|
| 517 |
rajveer |
83 |
String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "ProductDetail.html";
|
| 507 |
rajveer |
84 |
File f = new File(filename);
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
FileInputStream fis = null;
|
|
|
88 |
try {
|
|
|
89 |
fis = new FileInputStream(f);
|
|
|
90 |
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
|
|
|
91 |
String line;
|
|
|
92 |
while((line = br.readLine()) != null){
|
|
|
93 |
htmlString.append(line+"\n");
|
|
|
94 |
}
|
|
|
95 |
} catch (FileNotFoundException e) {
|
| 2949 |
chandransh |
96 |
logger.error("Unable to find the product summary file", e);
|
| 507 |
rajveer |
97 |
} catch (IOException e) {
|
| 2949 |
chandransh |
98 |
logger.error("Unable to read the product summary file", e);
|
| 507 |
rajveer |
99 |
}
|
|
|
100 |
finally {
|
|
|
101 |
if(fis != null) {
|
|
|
102 |
try {
|
|
|
103 |
fis.close();
|
|
|
104 |
} catch (IOException e) {
|
| 2949 |
chandransh |
105 |
logger.error("Unable to close the product summary file", e);
|
| 507 |
rajveer |
106 |
}
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
return htmlString.toString();
|
|
|
111 |
}
|
|
|
112 |
|
| 2306 |
vikas |
113 |
public String getProductPropertiesHtml(long productId) {
|
| 974 |
vikas |
114 |
StringBuilder htmlString = new StringBuilder();
|
| 2306 |
vikas |
115 |
String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "ProductPropertiesSnippet.html";
|
| 974 |
vikas |
116 |
File f = new File(filename);
|
|
|
117 |
|
|
|
118 |
|
|
|
119 |
FileInputStream fis = null;
|
|
|
120 |
try {
|
|
|
121 |
fis = new FileInputStream(f);
|
|
|
122 |
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
|
|
|
123 |
String line;
|
|
|
124 |
while((line = br.readLine()) != null){
|
|
|
125 |
htmlString.append(line+"\n");
|
|
|
126 |
}
|
|
|
127 |
} catch (FileNotFoundException e) {
|
| 2949 |
chandransh |
128 |
logger.error("Unable to find the product properties file", e);
|
| 974 |
vikas |
129 |
} catch (IOException e) {
|
| 2949 |
chandransh |
130 |
logger.error("Unable to read the product properties file", e);
|
|
|
131 |
} finally {
|
| 974 |
vikas |
132 |
if(fis != null) {
|
|
|
133 |
try {
|
|
|
134 |
fis.close();
|
|
|
135 |
} catch (IOException e) {
|
| 2949 |
chandransh |
136 |
logger.error("Unable to close the product properties file", e);
|
| 974 |
vikas |
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 |
}
|
| 4453 |
varun.gupt |
155 |
|
| 6152 |
amit.gupta |
156 |
public String getHeaderHtml(boolean isLoggedIn, String email, int totalItems, String url, long catId, boolean displayBestDealsImg) {
|
| 550 |
rajveer |
157 |
VelocityContext context = new VelocityContext();
|
| 4453 |
varun.gupt |
158 |
|
|
|
159 |
if (isLoggedIn) {
|
| 555 |
chandransh |
160 |
context.put("LOGGED_IN", "TRUE");
|
| 4453 |
varun.gupt |
161 |
context.put("WELCOME_MESSAGE", "Hi " + email.split("@")[0]);
|
|
|
162 |
|
|
|
163 |
} else {
|
| 801 |
rajveer |
164 |
context.put("WELCOME_MESSAGE", "Hi, Welcome to Saholic");
|
| 924 |
vikas |
165 |
context.put("REDIRECT_URL", url);
|
| 4453 |
varun.gupt |
166 |
}
|
| 507 |
rajveer |
167 |
|
| 3903 |
varun.gupt |
168 |
context.put("BEST_DEALS_BADGE", displayBestDealsImg);
|
| 3830 |
chandransh |
169 |
context.put("CAT_ID", catId);
|
| 6152 |
amit.gupta |
170 |
context.put("TOTAL_ITEMS", totalItems);
|
| 507 |
rajveer |
171 |
String templateFile = "templates/header.vm";
|
| 550 |
rajveer |
172 |
|
| 590 |
chandransh |
173 |
return getHtmlFromVelocity(templateFile, context);
|
| 507 |
rajveer |
174 |
}
|
| 6903 |
anupam.sin |
175 |
|
|
|
176 |
public String getThinHeaderHtml(boolean isLoggedIn, String email, int totalItems, String url, long catId, boolean displayBestDealsImg) {
|
|
|
177 |
VelocityContext context = new VelocityContext();
|
|
|
178 |
|
|
|
179 |
if (isLoggedIn) {
|
|
|
180 |
context.put("LOGGED_IN", "TRUE");
|
|
|
181 |
context.put("WELCOME_MESSAGE", "Hi " + email.split("@")[0]);
|
|
|
182 |
|
|
|
183 |
} else {
|
|
|
184 |
context.put("WELCOME_MESSAGE", "Hi, Welcome to Saholic");
|
|
|
185 |
context.put("REDIRECT_URL", url);
|
|
|
186 |
}
|
|
|
187 |
|
|
|
188 |
context.put("BEST_DEALS_BADGE", displayBestDealsImg);
|
|
|
189 |
context.put("CAT_ID", catId);
|
|
|
190 |
context.put("TOTAL_ITEMS", totalItems);
|
|
|
191 |
String templateFile = "templates/thinheader.vm";
|
|
|
192 |
|
|
|
193 |
return getHtmlFromVelocity(templateFile, context);
|
|
|
194 |
}
|
| 507 |
rajveer |
195 |
|
|
|
196 |
|
| 4815 |
phani.kuma |
197 |
public String getOrderDetailsHtml(long orderId, UserSessionInfo userinfo) {
|
|
|
198 |
long userId = userinfo.getUserId();
|
| 507 |
rajveer |
199 |
String htmlString = "";
|
|
|
200 |
VelocityContext context = new VelocityContext();
|
|
|
201 |
String templateFile = "templates/orderdetails.vm";
|
|
|
202 |
Order order = null;
|
| 517 |
rajveer |
203 |
Date orderedOn = null, deliveryEstimate = null;
|
| 843 |
chandransh |
204 |
Provider provider = null;
|
| 4325 |
mandeep.dh |
205 |
List<Address> addresses = null;
|
|
|
206 |
Long defaultAddressId = null;
|
| 4815 |
phani.kuma |
207 |
boolean initiateOrderCancelation = false;
|
|
|
208 |
boolean requestOrderCancelation = false;
|
|
|
209 |
OrderStatusGroups Groups = new OrderStatusGroups();
|
|
|
210 |
List<OrderStatus> codCancellable = Groups.getCodCancellable();
|
|
|
211 |
List<OrderStatus> prepaidCancellableBeforeBilled = Groups.getPrepaidCancellableBeforeBilled();
|
|
|
212 |
List<OrderStatus> prepaidCancellableAfterBilled = Groups.getPrepaidCancellableAfterBilled();
|
|
|
213 |
|
| 4325 |
mandeep.dh |
214 |
try{
|
| 3126 |
rajveer |
215 |
TransactionClient transactionServiceClient = new TransactionClient();
|
| 843 |
chandransh |
216 |
in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
|
| 1527 |
ankur.sing |
217 |
order = orderClient.getOrderForCustomer(orderId, userId);
|
| 517 |
rajveer |
218 |
orderedOn = new Date(order.getCreated_timestamp());
|
| 6672 |
amit.gupta |
219 |
deliveryEstimate = new Date(order.getPromised_delivery_time());
|
| 4815 |
phani.kuma |
220 |
|
| 7309 |
rajveer |
221 |
if(order.getSource() == OrderSource.WEBSITE.getValue()){
|
|
|
222 |
if(order.isCod()){
|
|
|
223 |
if(codCancellable.contains(order.getStatus())){
|
|
|
224 |
initiateOrderCancelation = true;
|
|
|
225 |
}
|
| 4815 |
phani.kuma |
226 |
}
|
| 7309 |
rajveer |
227 |
else {
|
|
|
228 |
if(prepaidCancellableBeforeBilled.contains(order.getStatus())){
|
|
|
229 |
initiateOrderCancelation = true;
|
|
|
230 |
}
|
|
|
231 |
else if(prepaidCancellableAfterBilled.contains(order.getStatus())){
|
|
|
232 |
requestOrderCancelation = true;
|
|
|
233 |
}
|
| 4815 |
phani.kuma |
234 |
}
|
|
|
235 |
}
|
| 843 |
chandransh |
236 |
|
| 4325 |
mandeep.dh |
237 |
in.shop2020.model.v1.user.UserContextService.Client userClient = new UserClient().getClient();
|
|
|
238 |
addresses = userClient.getAllAddressesForUser(userId);
|
|
|
239 |
defaultAddressId = userClient.getDefaultAddressId(userId);
|
|
|
240 |
logger.info("Found addresses: " + addresses + " for userId: " + userId);
|
|
|
241 |
|
| 843 |
chandransh |
242 |
if(order.getLogistics_provider_id() != 0){
|
| 3126 |
rajveer |
243 |
LogisticsClient logisticsServiceClient = new LogisticsClient();
|
| 843 |
chandransh |
244 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
|
|
|
245 |
provider = logisticsClient.getProvider(order.getLogistics_provider_id());
|
|
|
246 |
}
|
| 5838 |
mandeep.dh |
247 |
|
|
|
248 |
if (order.getPickupStoreId() != 0) {
|
|
|
249 |
in.shop2020.logistics.LogisticsService.Client logisticsServiceClient = new LogisticsClient().getClient();
|
|
|
250 |
PickupStore store = logisticsServiceClient.getPickupStore(order.getPickupStoreId());
|
|
|
251 |
order.setCustomer_name(store.getName());
|
|
|
252 |
order.setCustomer_address1(store.getLine1());
|
|
|
253 |
order.setCustomer_address2(store.getLine2());
|
|
|
254 |
order.setCustomer_city(store.getCity());
|
|
|
255 |
order.setCustomer_pincode(store.getPin());
|
|
|
256 |
order.setCustomer_state(store.getState());
|
|
|
257 |
order.setCustomer_mobilenumber(store.getPhone());
|
|
|
258 |
}
|
| 4453 |
varun.gupt |
259 |
} catch (Exception e){
|
| 507 |
rajveer |
260 |
|
|
|
261 |
}
|
| 517 |
rajveer |
262 |
|
|
|
263 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
|
| 583 |
rajveer |
264 |
SimpleDateFormat dateformat1 = new SimpleDateFormat("dd/MM/yyyy");
|
| 4325 |
mandeep.dh |
265 |
|
| 507 |
rajveer |
266 |
context.put("order", order);
|
| 6561 |
amit.gupta |
267 |
context.put("isShipped", Groups.getShippedOrders().contains(order.getStatus()));
|
|
|
268 |
context.put("isDelivered", order.getStatus().equals(OrderStatus.DELIVERY_SUCCESS));
|
|
|
269 |
context.put("isOpen", Groups.getShippedOrders().contains(order.getStatus()));
|
|
|
270 |
context.put("order", order);
|
| 517 |
rajveer |
271 |
context.put("orderedOn", dateformat.format(orderedOn));
|
| 6561 |
amit.gupta |
272 |
context.put("fdaOn", dateformat1.format(new Date(order.getFirst_attempt_timestamp())));
|
| 6672 |
amit.gupta |
273 |
context.put("promisedDeliveryDate", dateformat1.format(deliveryEstimate));
|
| 6561 |
amit.gupta |
274 |
context.put("deliveredOn", dateformat1.format(new Date(order.getDelivery_timestamp())));
|
| 4325 |
mandeep.dh |
275 |
context.put("addresses", addresses);
|
|
|
276 |
context.put("defaultAddressId", defaultAddressId);
|
| 4815 |
phani.kuma |
277 |
context.put("userinfo", userinfo);
|
|
|
278 |
context.put("initiateOrderCancelation", initiateOrderCancelation);
|
|
|
279 |
context.put("requestOrderCancelation", requestOrderCancelation);
|
| 4325 |
mandeep.dh |
280 |
|
| 843 |
chandransh |
281 |
if(provider!=null){
|
|
|
282 |
context.put("providerName", provider.getName());
|
|
|
283 |
}
|
|
|
284 |
|
| 507 |
rajveer |
285 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
286 |
return htmlString;
|
|
|
287 |
}
|
|
|
288 |
|
| 650 |
rajveer |
289 |
public String getMyaccountDetailsHtml(long userId) {
|
| 507 |
rajveer |
290 |
String htmlString = "";
|
|
|
291 |
VelocityContext context = new VelocityContext();
|
|
|
292 |
String templateFile = "templates/myaccount.vm";
|
|
|
293 |
List<Order> orders = null;
|
| 745 |
chandransh |
294 |
Map<Long, String> providerNames = new HashMap<Long, String>();
|
| 507 |
rajveer |
295 |
try{
|
| 3126 |
rajveer |
296 |
TransactionClient transactionServiceClient = new TransactionClient();
|
| 745 |
chandransh |
297 |
in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
|
| 507 |
rajveer |
298 |
orders = orderClient.getOrdersForCustomer(userId, 0, (new Date()).getTime(), null);
|
|
|
299 |
|
| 3126 |
rajveer |
300 |
LogisticsClient logisticsServiceClient = new LogisticsClient();
|
| 745 |
chandransh |
301 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
|
|
|
302 |
List<Provider> providers = logisticsClient.getAllProviders();
|
|
|
303 |
for(Provider provider: providers)
|
|
|
304 |
providerNames.put(provider.getId(), provider.getName());
|
| 507 |
rajveer |
305 |
}catch (Exception e){
|
| 2949 |
chandransh |
306 |
logger.error("Unable to get order or provider details", e);
|
| 507 |
rajveer |
307 |
}
|
| 741 |
rajveer |
308 |
List<String> orderDate = new ArrayList<String>();
|
|
|
309 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
|
| 888 |
chandransh |
310 |
if(orders!=null && !orders.isEmpty()){
|
| 762 |
rajveer |
311 |
for(Order order: orders){
|
|
|
312 |
Date orderedOn = new Date(order.getCreated_timestamp());
|
|
|
313 |
orderDate.add(dateformat.format(orderedOn));
|
|
|
314 |
}
|
| 741 |
rajveer |
315 |
}
|
| 507 |
rajveer |
316 |
context.put("orders", orders);
|
| 741 |
rajveer |
317 |
context.put("orderDate", orderDate);
|
| 745 |
chandransh |
318 |
context.put("providerNames", providerNames);
|
| 507 |
rajveer |
319 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
320 |
return htmlString;
|
|
|
321 |
}
|
|
|
322 |
|
|
|
323 |
|
| 650 |
rajveer |
324 |
public String getLoginDetailsHtml(long userId) {
|
| 507 |
rajveer |
325 |
String htmlString = "";
|
|
|
326 |
VelocityContext context = new VelocityContext();
|
|
|
327 |
String templateFile = "templates/logindetails.vm";
|
|
|
328 |
String email = "";
|
|
|
329 |
try{
|
| 762 |
rajveer |
330 |
email = getEmailId(userId);
|
| 507 |
rajveer |
331 |
}catch (Exception e){
|
|
|
332 |
|
|
|
333 |
}
|
|
|
334 |
context.put("email", email);
|
|
|
335 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
336 |
return htmlString;
|
|
|
337 |
}
|
|
|
338 |
|
| 762 |
rajveer |
339 |
public String getEmailId(long userId){
|
|
|
340 |
String email = " ";
|
|
|
341 |
|
|
|
342 |
try {
|
| 3126 |
rajveer |
343 |
UserClient userContextServiceClient = new UserClient();
|
| 762 |
rajveer |
344 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
| 2949 |
chandransh |
345 |
String userEmail = userClient.getUserById(userId).getEmail();
|
|
|
346 |
if( userEmail != null){
|
|
|
347 |
email = userEmail;
|
| 762 |
rajveer |
348 |
}
|
|
|
349 |
} catch (UserContextException e) {
|
| 2949 |
chandransh |
350 |
logger.error("Unable to get the user for " + userId, e);
|
| 762 |
rajveer |
351 |
} catch (TException e) {
|
| 2949 |
chandransh |
352 |
logger.error("Unable to get the user for " + userId, e);
|
| 762 |
rajveer |
353 |
} catch (Exception e) {
|
| 2949 |
chandransh |
354 |
logger.error("Unable to get the user for " + userId, e);
|
| 762 |
rajveer |
355 |
}
|
|
|
356 |
return email;
|
|
|
357 |
}
|
|
|
358 |
|
|
|
359 |
|
| 595 |
rajveer |
360 |
public String getPersonalDetailsHtml(long userId) {
|
| 507 |
rajveer |
361 |
String htmlString = "";
|
|
|
362 |
VelocityContext context = new VelocityContext();
|
|
|
363 |
String templateFile = "templates/personaldetails.vm";
|
|
|
364 |
String email = "";
|
| 517 |
rajveer |
365 |
String name = "";
|
| 569 |
rajveer |
366 |
String dateOfBirth = "";
|
| 517 |
rajveer |
367 |
String sex = "";
|
|
|
368 |
String subscribe = "false";
|
| 3126 |
rajveer |
369 |
UserClient userContextServiceClient = null;
|
| 507 |
rajveer |
370 |
in.shop2020.model.v1.user.UserContextService.Client userClient = null;
|
|
|
371 |
try{
|
| 555 |
chandransh |
372 |
User user = null;
|
| 3126 |
rajveer |
373 |
userContextServiceClient = new UserClient();
|
| 507 |
rajveer |
374 |
userClient = userContextServiceClient.getClient();
|
| 555 |
chandransh |
375 |
user = userClient.getUserById(userId);
|
| 507 |
rajveer |
376 |
|
| 555 |
chandransh |
377 |
email = user.getCommunicationEmail();
|
|
|
378 |
name = user.getName();
|
| 517 |
rajveer |
379 |
|
| 569 |
rajveer |
380 |
dateOfBirth = user.getDateOfBirth();
|
| 507 |
rajveer |
381 |
}catch (Exception e){
|
| 2949 |
chandransh |
382 |
logger.error("Unable to get the user for " + userId, e);
|
| 507 |
rajveer |
383 |
}
|
| 517 |
rajveer |
384 |
context.put("name", name);
|
|
|
385 |
context.put("email", email);
|
| 569 |
rajveer |
386 |
context.put("dateOfBirth", dateOfBirth+"");
|
| 517 |
rajveer |
387 |
context.put("subscribe", subscribe);
|
|
|
388 |
context.put("sex", sex);
|
| 507 |
rajveer |
389 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
390 |
return htmlString;
|
|
|
391 |
}
|
|
|
392 |
|
| 595 |
rajveer |
393 |
public String getMyaccountHeaderHtml() {
|
| 507 |
rajveer |
394 |
String htmlString = "";
|
|
|
395 |
VelocityContext context = new VelocityContext();
|
|
|
396 |
String templateFile = "templates/myaccountheader.vm";
|
|
|
397 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
398 |
return htmlString;
|
|
|
399 |
}
|
|
|
400 |
|
| 822 |
vikas |
401 |
public String getShippingAddressDetailsHtml(long userId, String errorMsg){
|
| 507 |
rajveer |
402 |
String htmlString = "";
|
|
|
403 |
VelocityContext context = new VelocityContext();
|
|
|
404 |
String templateFile = "templates/shippingaddressdetails.vm";
|
|
|
405 |
long defaultAddressId = 0;
|
| 517 |
rajveer |
406 |
List<Address> addresses = null;
|
| 507 |
rajveer |
407 |
|
| 3126 |
rajveer |
408 |
UserClient userContextServiceClient = null;
|
| 507 |
rajveer |
409 |
in.shop2020.model.v1.user.UserContextService.Client userClient = null;
|
|
|
410 |
try {
|
| 3126 |
rajveer |
411 |
userContextServiceClient = new UserClient();
|
| 507 |
rajveer |
412 |
userClient = userContextServiceClient.getClient();
|
| 620 |
rajveer |
413 |
|
|
|
414 |
addresses = userClient.getAllAddressesForUser(userId);
|
|
|
415 |
defaultAddressId = userClient.getDefaultAddressId(userId);
|
| 507 |
rajveer |
416 |
} catch (Exception e) {
|
| 2949 |
chandransh |
417 |
logger.error("Unable to get either the user for " + userId + " or his address", e);
|
| 507 |
rajveer |
418 |
}
|
| 517 |
rajveer |
419 |
context.put("defaultAddressId", defaultAddressId+"");
|
| 507 |
rajveer |
420 |
context.put("addresses", addresses);
|
| 822 |
vikas |
421 |
context.put("errorMsg", errorMsg);
|
| 507 |
rajveer |
422 |
|
|
|
423 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
424 |
return htmlString;
|
|
|
425 |
}
|
|
|
426 |
|
|
|
427 |
public String getHtmlFromVelocity(String templateFile, VelocityContext context){
|
|
|
428 |
Properties p = new Properties();
|
|
|
429 |
p.setProperty("resource.loader", "class");
|
|
|
430 |
p.setProperty("class.resource.loader.class",
|
|
|
431 |
"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
|
| 832 |
rajveer |
432 |
p.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogSystem");
|
|
|
433 |
|
| 2949 |
chandransh |
434 |
try {
|
|
|
435 |
Velocity.init(p);
|
|
|
436 |
// Velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, value)
|
|
|
437 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
438 |
if (template != null) {
|
|
|
439 |
StringWriter writer = new StringWriter();
|
|
|
440 |
template.merge(context, writer);
|
|
|
441 |
writer.flush();
|
|
|
442 |
writer.close();
|
|
|
443 |
return writer.toString();
|
|
|
444 |
}
|
|
|
445 |
|
|
|
446 |
} catch (ResourceNotFoundException e) {
|
|
|
447 |
logger.error("Unable to find the template file " + templateFile, e);
|
|
|
448 |
} catch (ParseErrorException e) {
|
|
|
449 |
logger.error("Unable to parse the template file " + templateFile, e);
|
|
|
450 |
} catch (MethodInvocationException e) {
|
|
|
451 |
logger.error("Unable to invoke methods for the velocity template file " + templateFile, e);
|
|
|
452 |
} catch (IOException e) {
|
|
|
453 |
logger.error("Unable to read the template file " + templateFile, e);
|
|
|
454 |
} catch (Exception e) {
|
|
|
455 |
logger.error("Unable to generate the HTML from the template file " + templateFile, e);
|
|
|
456 |
}
|
| 507 |
rajveer |
457 |
|
|
|
458 |
return null;
|
|
|
459 |
}
|
| 3830 |
chandransh |
460 |
|
| 9155 |
kshitij.so |
461 |
public String getCartWidgetSnippet(int totalItems, double totalAmount, long catId, List<Banner> bannerList, Map<String, List<BannerMap>> sideBannersMap) {
|
| 3830 |
chandransh |
462 |
String htmlString = "";
|
|
|
463 |
VelocityContext context = new VelocityContext();
|
|
|
464 |
String templateFile = "templates/cartwidget.vm";
|
| 6710 |
kshitij.so |
465 |
context.put("CAT_ID", catId);
|
| 8917 |
kshitij.so |
466 |
context.put("BANNERS", bannerList);
|
| 9155 |
kshitij.so |
467 |
context.put("ALL_BANNER_MAP",sideBannersMap);
|
| 3830 |
chandransh |
468 |
htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
469 |
return htmlString;
|
|
|
470 |
}
|
|
|
471 |
|
| 1549 |
rajveer |
472 |
}
|