| Line 7... |
Line 7... |
| 7 |
import in.shop2020.model.v1.user.ShoppingCartException;
|
7 |
import in.shop2020.model.v1.user.ShoppingCartException;
|
| 8 |
import in.shop2020.model.v1.user.UserContextService;
|
8 |
import in.shop2020.model.v1.user.UserContextService;
|
| 9 |
import in.shop2020.serving.utils.FileUtils;
|
9 |
import in.shop2020.serving.utils.FileUtils;
|
| 10 |
import in.shop2020.serving.utils.FormattingUtils;
|
10 |
import in.shop2020.serving.utils.FormattingUtils;
|
| 11 |
import in.shop2020.serving.utils.Utils;
|
11 |
import in.shop2020.serving.utils.Utils;
|
| 12 |
import in.shop2020.thrift.clients.CatalogServiceClient;
|
12 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 13 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
13 |
import in.shop2020.thrift.clients.UserClient;
|
| 14 |
import in.shop2020.utils.DataLogger;
|
14 |
import in.shop2020.utils.DataLogger;
|
| 15 |
|
15 |
|
| 16 |
import java.io.File;
|
16 |
import java.io.File;
|
| 17 |
import java.io.FileNotFoundException;
|
17 |
import java.io.FileNotFoundException;
|
| 18 |
import java.io.IOException;
|
18 |
import java.io.IOException;
|
| Line 67... |
Line 67... |
| 67 |
@Action(value="cart",interceptorRefs={@InterceptorRef("myDefault")})
|
67 |
@Action(value="cart",interceptorRefs={@InterceptorRef("myDefault")})
|
| 68 |
public String index() {
|
68 |
public String index() {
|
| 69 |
long cartId = userinfo.getCartId();
|
69 |
long cartId = userinfo.getCartId();
|
| 70 |
if(cartId != -1){
|
70 |
if(cartId != -1){
|
| 71 |
try {
|
71 |
try {
|
| 72 |
UserContextService.Client userClient = (new UserContextServiceClient()).getClient();
|
72 |
UserContextService.Client userClient = (new UserClient()).getClient();
|
| 73 |
errorMsg = userClient.validateCart(cartId);
|
73 |
errorMsg = userClient.validateCart(cartId);
|
| 74 |
log.info("Error Message rcvd from the service is:" + errorMsg);
|
74 |
log.info("Error Message rcvd from the service is:" + errorMsg);
|
| 75 |
} catch (Exception e) {
|
75 |
} catch (Exception e) {
|
| 76 |
// This exception can be ignored for showing the cart. Not so
|
76 |
// This exception can be ignored for showing the cart. Not so
|
| 77 |
// innocent when this occurs at the time of checkout or when the
|
77 |
// innocent when this occurs at the time of checkout or when the
|
| Line 107... |
Line 107... |
| 107 |
StringTokenizer tokenizer = new StringTokenizer(itemIds, "_");
|
107 |
StringTokenizer tokenizer = new StringTokenizer(itemIds, "_");
|
| 108 |
while (tokenizer.hasMoreTokens()) {
|
108 |
while (tokenizer.hasMoreTokens()) {
|
| 109 |
itemId = Long.parseLong(tokenizer.nextToken());
|
109 |
itemId = Long.parseLong(tokenizer.nextToken());
|
| 110 |
|
110 |
|
| 111 |
try {
|
111 |
try {
|
| 112 |
UserContextServiceClient userServiceClient = new UserContextServiceClient();
|
112 |
UserClient userServiceClient = new UserClient();
|
| 113 |
UserContextService.Client userClient = userServiceClient.getClient();
|
113 |
UserContextService.Client userClient = userServiceClient.getClient();
|
| 114 |
if (cartId == 0){
|
114 |
if (cartId == 0){
|
| 115 |
cartId = userClient.createCart(userId);
|
115 |
cartId = userClient.createCart(userId);
|
| 116 |
}
|
116 |
}
|
| 117 |
if(cartMsg.equals("")){
|
117 |
if(cartMsg.equals("")){
|
| Line 194... |
Line 194... |
| 194 |
log.info(this.reqparams);
|
194 |
log.info(this.reqparams);
|
| 195 |
}
|
195 |
}
|
| 196 |
|
196 |
|
| 197 |
private boolean updateItemQuantityInCart(long cartId, long itemId, long quantity){
|
197 |
private boolean updateItemQuantityInCart(long cartId, long itemId, long quantity){
|
| 198 |
try {
|
198 |
try {
|
| 199 |
UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
|
199 |
UserClient userContextServiceClient = new UserClient();
|
| 200 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
200 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
| 201 |
|
201 |
|
| 202 |
userClient.changeQuantity(cartId, itemId, quantity);
|
202 |
userClient.changeQuantity(cartId, itemId, quantity);
|
| 203 |
return true;
|
203 |
return true;
|
| 204 |
} catch (ShoppingCartException e) {
|
204 |
} catch (ShoppingCartException e) {
|
| Line 211... |
Line 211... |
| 211 |
return false;
|
211 |
return false;
|
| 212 |
}
|
212 |
}
|
| 213 |
|
213 |
|
| 214 |
private boolean deleteItemFromCart(long cartId, long catalogItemId, long userId, boolean isSessionId){
|
214 |
private boolean deleteItemFromCart(long cartId, long catalogItemId, long userId, boolean isSessionId){
|
| 215 |
try {
|
215 |
try {
|
| 216 |
UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
|
216 |
UserClient userContextServiceClient = new UserClient();
|
| 217 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
217 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
| 218 |
|
218 |
|
| 219 |
userClient.deleteItemFromCart(cartId, catalogItemId);
|
219 |
userClient.deleteItemFromCart(cartId, catalogItemId);
|
| 220 |
return true;
|
220 |
return true;
|
| 221 |
} catch (ShoppingCartException e) {
|
221 |
} catch (ShoppingCartException e) {
|
| Line 229... |
Line 229... |
| 229 |
return false;
|
229 |
return false;
|
| 230 |
}
|
230 |
}
|
| 231 |
|
231 |
|
| 232 |
private int getNumberOfItemsInCart(long cartId) {
|
232 |
private int getNumberOfItemsInCart(long cartId) {
|
| 233 |
int numberOfItems = 0;
|
233 |
int numberOfItems = 0;
|
| 234 |
UserContextServiceClient userContextServiceClient = null;
|
234 |
UserClient userContextServiceClient = null;
|
| 235 |
try {
|
235 |
try {
|
| 236 |
userContextServiceClient = new UserContextServiceClient();
|
236 |
userContextServiceClient = new UserClient();
|
| 237 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
237 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
| 238 |
|
238 |
|
| 239 |
numberOfItems = userClient.getCart(cartId).getLinesSize();
|
239 |
numberOfItems = userClient.getCart(cartId).getLinesSize();
|
| 240 |
} catch (ShoppingCartException e) {
|
240 |
} catch (ShoppingCartException e) {
|
| 241 |
log.error("Unable to get the cart from service: ", e);
|
241 |
log.error("Unable to get the cart from service: ", e);
|
| Line 248... |
Line 248... |
| 248 |
}
|
248 |
}
|
| 249 |
|
249 |
|
| 250 |
public List<Map<String,String>> getCartItems() {
|
250 |
public List<Map<String,String>> getCartItems() {
|
| 251 |
List<Map<String,String>> items = null;
|
251 |
List<Map<String,String>> items = null;
|
| 252 |
|
252 |
|
| 253 |
UserContextServiceClient userServiceClient = null;
|
253 |
UserClient userServiceClient = null;
|
| 254 |
in.shop2020.model.v1.user.UserContextService.Client userClient = null;
|
254 |
in.shop2020.model.v1.user.UserContextService.Client userClient = null;
|
| 255 |
CatalogServiceClient catalogServiceClient = null;
|
255 |
CatalogClient catalogServiceClient = null;
|
| 256 |
in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = null;
|
256 |
in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = null;
|
| 257 |
|
257 |
|
| 258 |
FormattingUtils formattingUtils = new FormattingUtils();
|
258 |
FormattingUtils formattingUtils = new FormattingUtils();
|
| 259 |
|
259 |
|
| 260 |
try {
|
260 |
try {
|
| 261 |
catalogServiceClient = new CatalogServiceClient();
|
261 |
catalogServiceClient = new CatalogClient();
|
| 262 |
catalogClient = catalogServiceClient.getClient();
|
262 |
catalogClient = catalogServiceClient.getClient();
|
| 263 |
userServiceClient = new UserContextServiceClient();
|
263 |
userServiceClient = new UserClient();
|
| 264 |
userClient = userServiceClient.getClient();
|
264 |
userClient = userServiceClient.getClient();
|
| 265 |
|
265 |
|
| 266 |
pincode = userClient.getDefaultPincode(userinfo.getUserId());
|
266 |
pincode = userClient.getDefaultPincode(userinfo.getUserId());
|
| 267 |
Cart cart = userClient.getCart(userinfo.getCartId());
|
267 |
Cart cart = userClient.getCart(userinfo.getCartId());
|
| 268 |
List<Line> lineItems = cart.getLines();
|
268 |
List<Line> lineItems = cart.getLines();
|
| Line 337... |
Line 337... |
| 337 |
}
|
337 |
}
|
| 338 |
|
338 |
|
| 339 |
|
339 |
|
| 340 |
public String getSnippets(){
|
340 |
public String getSnippets(){
|
| 341 |
String snippets = "";
|
341 |
String snippets = "";
|
| 342 |
CatalogServiceClient csc;
|
342 |
CatalogClient csc;
|
| 343 |
try {
|
343 |
try {
|
| 344 |
csc = new CatalogServiceClient();
|
344 |
csc = new CatalogClient();
|
| 345 |
List<Long> similarItems = csc.getClient().getSimilarItemsCatalogIds(0, 4, itemId);
|
345 |
List<Long> similarItems = csc.getClient().getSimilarItemsCatalogIds(0, 4, itemId);
|
| 346 |
for(Long catalogId: similarItems){
|
346 |
for(Long catalogId: similarItems){
|
| 347 |
try {
|
347 |
try {
|
| 348 |
snippets += FileUtils.read( Utils.EXPORT_ENTITIES_PATH + catalogId + File.separator + "WidgetSnippet.html");
|
348 |
snippets += FileUtils.read( Utils.EXPORT_ENTITIES_PATH + catalogId + File.separator + "WidgetSnippet.html");
|
| 349 |
}
|
349 |
}
|