Subversion Repositories SmartDukaan

Rev

Rev 3128 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2714 vikas 1
package in.shop2020.serving.controllers;
2
 
4142 mandeep.dh 3
import in.shop2020.model.v1.catalog.InventoryServiceException;
2714 vikas 4
import in.shop2020.model.v1.catalog.Item;
5
import in.shop2020.model.v1.user.Line;
4142 mandeep.dh 6
import in.shop2020.model.v1.user.ShoppingCartException;
7
import in.shop2020.model.v1.user.UserContextException;
3128 rajveer 8
import in.shop2020.thrift.clients.CatalogClient;
9
import in.shop2020.thrift.clients.UserClient;
4142 mandeep.dh 10
import in.shop2020.utils.ModelUtils;
2714 vikas 11
 
12
import java.util.List;
13
 
14
import org.apache.log4j.Logger;
4142 mandeep.dh 15
import org.apache.thrift.TException;
2714 vikas 16
 
17
/**
18
 * @author vikas
19
 *
20
 */
21
@SuppressWarnings("serial")
22
public class UserCartController extends BaseController {
23
    private static Logger log = Logger.getLogger(Class.class);
24
    private long userId;
25
    private long cartId;
4142 mandeep.dh 26
    private List<Line> lines;
2714 vikas 27
 
4142 mandeep.dh 28
    public String index() {
29
        try {
30
            UserClient userServiceClient = new UserClient();
31
            in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
2714 vikas 32
 
4142 mandeep.dh 33
            if (userClient.getUserById(userId).getActiveCartId() == cartId) {
34
                lines = userClient.getCart(cartId).getLines();
35
            }
36
        } catch (UserContextException e) {
37
            addActionError("Error fetching cart details");
38
        } catch (TException e) {
39
            addActionError("Error fetching cart details");
40
        } catch (ShoppingCartException e) {
41
            addActionError("Error fetching cart details");
2714 vikas 42
        }
43
 
4142 mandeep.dh 44
        return INDEX;
45
    }
46
 
47
    public String getProductName(Line line) {
48
        String productName = "";
49
 
50
        try {
51
            CatalogClient catalogServiceClient = new CatalogClient();
52
            in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = catalogServiceClient
53
                    .getClient();
2714 vikas 54
            Item item = catalogClient.getItem(line.getItemId());
4142 mandeep.dh 55
            productName = ModelUtils.extractProductNameFromItem(item);
2714 vikas 56
        }
4142 mandeep.dh 57
        catch (TException e) {
58
            log.error("Could not fetch Item id: " + line.getItemId(), e);
59
        }
60
        catch (InventoryServiceException e) {
61
            log.error("Could not fetch Item id: " + line.getItemId(), e);
62
        }
63
 
64
        return productName;
2714 vikas 65
    }
66
 
4142 mandeep.dh 67
    public int convertDouble(double value) {
68
        return (int)value;
69
    }
70
 
2714 vikas 71
    public void setUserId(String userId) {
72
        try {
73
            this.userId = Long.parseLong(userId);
74
        }
75
        catch (NumberFormatException e) {
76
            log.error(e);
77
        }
78
    }
79
 
80
    public void setCartId(String cartId) {
81
        try {
82
            this.cartId = Long.parseLong(cartId);
83
        }
84
        catch (NumberFormatException e) {
85
            log.error(e);
86
        }
87
    }
88
 
89
    public Long getUserId() {
90
        return userId;
91
    }
92
 
4142 mandeep.dh 93
    public List<Line> getLines() {
94
        return lines;
2714 vikas 95
    }
4142 mandeep.dh 96
 
97
    public void setLines(List<Line> lines) {
98
        this.lines = lines;
99
    }
2714 vikas 100
}