Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
2674 vikas 1
package in.shop2020.serving.controllers;
2
 
3
import in.shop2020.model.v1.user.Address;
4
import in.shop2020.model.v1.user.User;
3128 rajveer 5
import in.shop2020.thrift.clients.UserClient;
2674 vikas 6
 
7
import java.util.List;
8
 
9
import org.apache.log4j.Logger;
3499 mandeep.dh 10
import org.apache.shiro.SecurityUtils;
2674 vikas 11
 
12
/**
13
 * @author vikas
14
 *
15
 */
16
@SuppressWarnings("serial")
17
public class UserInfoController extends BaseController {
18
    private static Logger log = Logger.getLogger(Class.class);
3499 mandeep.dh 19
    private String id;
2674 vikas 20
    private long userId;
21
    private User user;
22
    private List<Address> userAddresses;
23
    private Address primaryAdddress;
3499 mandeep.dh 24
    private String trustLevelDelta;
2674 vikas 25
 
26
    public String index() throws Exception {
3128 rajveer 27
    	UserClient userServiceClient = new UserClient();
28
        in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
2674 vikas 29
        user = userClient.getUserById(userId);
30
        userAddresses = user.getAddresses();
4086 mandeep.dh 31
 
32
        //
33
        // For cases where Default Address is NULL in db, we get 0 as long here
34
        // Skipping such cases to avoid exception. Ideally UserContextService should simply
35
        // return null in such cases.
36
        //
37
        if (user.getDefaultAddressId() != 0) {
38
            primaryAdddress = userClient.getAddressById(user.getDefaultAddressId());
39
        }
40
 
3499 mandeep.dh 41
        return INDEX;
2674 vikas 42
    }
43
 
3499 mandeep.dh 44
    public String update() throws Exception {
45
        userId = Long.parseLong(id);
46
        userContextServiceClient = new UserClient().getClient();
47
        userContextServiceClient.increaseTrustLevel(userId, Double.parseDouble(trustLevelDelta));
48
        return index();
49
    }
50
 
2674 vikas 51
    public void setUserId(String userId) {
52
        try {
53
            this.userId = Long.parseLong(userId);
54
        }
55
        catch (NumberFormatException e) {
56
            log.error(e);
57
        }
58
    }
59
 
3499 mandeep.dh 60
    public boolean isTrustLevelEditable() {
3701 mandeep.dh 61
        return SecurityUtils.getSubject().hasRole("TeamLead") && SecurityUtils.getSubject().hasRole("Outbound");
3499 mandeep.dh 62
    }
63
 
2674 vikas 64
    public Long getUserId() {
65
        return userId;
66
    }
67
 
68
    public User getUser() {
69
        return user;
70
    }
71
 
72
    public List<Address> getUserAddresses() {
73
        return userAddresses;
74
    }
75
 
76
    public Address getPrimaryAdddress() {
77
        return primaryAdddress;
78
    }
3499 mandeep.dh 79
 
80
    public String getTrustLevelDelta() {
81
        return trustLevelDelta;
82
    }
83
 
84
    public void setTrustLevelDelta(String trustLevelDelta) {
85
        this.trustLevelDelta = trustLevelDelta;
86
    }
87
 
88
    public String getId() {
89
        return id;
90
    }
91
 
92
    public void setId(String id) {
93
        this.id = id;
94
    }
2674 vikas 95
}