Rev 4142 | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.serving.controllers;import in.shop2020.model.v1.catalog.CatalogServiceException;import in.shop2020.model.v1.catalog.Item;import in.shop2020.model.v1.user.Line;import in.shop2020.model.v1.user.ShoppingCartException;import in.shop2020.model.v1.user.UserContextException;import in.shop2020.thrift.clients.CatalogClient;import in.shop2020.thrift.clients.UserClient;import in.shop2020.utils.ModelUtils;import java.util.List;import org.apache.log4j.Logger;import org.apache.thrift.TException;/*** @author vikas**/@SuppressWarnings("serial")public class UserCartController extends BaseController {private static Logger log = Logger.getLogger(Class.class);private long userId;private long cartId;private List<Line> lines;public String index() {try {UserClient userServiceClient = new UserClient();in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();if (userClient.getUserById(userId).getActiveCartId() == cartId) {lines = userClient.getCart(cartId).getLines();}} catch (UserContextException e) {addActionError("Error fetching cart details");} catch (TException e) {addActionError("Error fetching cart details");} catch (ShoppingCartException e) {addActionError("Error fetching cart details");}return INDEX;}public String getProductName(Line line) {String productName = "";try {CatalogClient catalogServiceClient = new CatalogClient();in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient.getClient();Item item = catalogClient.getItem(line.getItemId());productName = ModelUtils.extractProductNameFromItem(item);}catch (TException e) {log.error("Could not fetch Item id: " + line.getItemId(), e);}catch (CatalogServiceException e) {log.error("Could not fetch Item id: " + line.getItemId(), e);}return productName;}public int convertDouble(double value) {return (int)value;}public void setUserId(String userId) {try {this.userId = Long.parseLong(userId);}catch (NumberFormatException e) {log.error(e);}}public void setCartId(String cartId) {try {this.cartId = Long.parseLong(cartId);}catch (NumberFormatException e) {log.error(e);}}public Long getUserId() {return userId;}public List<Line> getLines() {return lines;}public void setLines(List<Line> lines) {this.lines = lines;}}