Subversion Repositories SmartDukaan

Rev

Rev 762 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 762 Rev 793
Line 28... Line 28...
28
	private long userId;
28
	private long userId;
29
	private String email;
29
	private String email;
30
	private String nameOfUser;
30
	private String nameOfUser;
31
	private int totalItems;
31
	private int totalItems;
32
	private long cartId;
32
	private long cartId;
-
 
33
	private String pincode;
33
	
34
	
34
	public UserSessionInfo(){
35
	public UserSessionInfo(){
35
		this.isLoggedIn = false;
36
		this.isLoggedIn = false;
36
		this.userId = -1;
37
		this.userId = -1;
37
		this.email = "";
38
		this.email = "";
38
		this.nameOfUser = "";
39
		this.nameOfUser = "";
39
		this.totalItems = 0;
40
		this.totalItems = 0;
40
		this.cartId = -1;
41
		this.cartId = -1;
-
 
42
		this.pincode = "110001";
41
	}
43
	}
42
 
44
 
43
	public UserSessionInfo(long userId, String jsessionId){
45
	public UserSessionInfo(long userId, String jsessionId){
44
		this();
46
		this();
45
		UserContextServiceClient ucsc = null;
47
		UserContextServiceClient ucsc = null;
Line 51... Line 53...
51
			existingUser = userClient.getUserById(userId);
53
			existingUser = userClient.getUserById(userId);
52
			if(existingUser == null || existingUser.getUserId() == -1){
54
			if(existingUser == null || existingUser.getUserId() == -1){
53
				existingUser = userClient.createAnonymousUser(jsessionId);
55
				existingUser = userClient.createAnonymousUser(jsessionId);
54
			}
56
			}
55
			totalItems = userClient.getCart(existingUser.getActiveCartId()).getLinesSize();
57
			totalItems = userClient.getCart(existingUser.getActiveCartId()).getLinesSize();
-
 
58
			pincode = userClient.getDefaultPincode(userId);
56
		} catch (UserContextException e) {
59
		} catch (UserContextException e) {
57
			e.printStackTrace();
60
			e.printStackTrace();
58
		} catch (TException e) {
61
		} catch (TException e) {
59
			e.printStackTrace();
62
			e.printStackTrace();
60
		} catch (Exception e) {
63
		} catch (Exception e) {
Line 63... Line 66...
63
		/*
66
		/*
64
		finally {
67
		finally {
65
			ucsc.closeConnection();
68
			ucsc.closeConnection();
66
		}
69
		}
67
		*/
70
		*/
68
		initialize(existingUser, totalItems);
71
		initialize(existingUser, totalItems, pincode);
69
	}
72
	}
70
 
73
 
71
	public UserSessionInfo(String jsessionId) {
74
	public UserSessionInfo(String jsessionId) {
72
		this();
75
		this();
73
		UserContextServiceClient ucsc = null;
76
		UserContextServiceClient ucsc = null;
74
		try {
77
		try {
75
			ucsc = new UserContextServiceClient();
78
			ucsc = new UserContextServiceClient();
76
			in.shop2020.model.v1.user.UserContextService.Client userClient = ucsc.getClient();
79
			in.shop2020.model.v1.user.UserContextService.Client userClient = ucsc.getClient();
77
			User anonUser = userClient.createAnonymousUser(jsessionId);
80
			User anonUser = userClient.createAnonymousUser(jsessionId);
78
			int totalItems= userClient.getCart(anonUser.getActiveCartId()).getLinesSize();
81
			int totalItems= userClient.getCart(anonUser.getActiveCartId()).getLinesSize();
-
 
82
			pincode = userClient.getDefaultPincode(userId);
79
			initialize(anonUser, totalItems);
83
			initialize(anonUser, totalItems, pincode);
80
		} catch (UserContextException e) {
84
		} catch (UserContextException e) {
81
			e.printStackTrace();
85
			e.printStackTrace();
82
		} catch (TException e) {
86
		} catch (TException e) {
83
			e.printStackTrace();
87
			e.printStackTrace();
84
		} catch (Exception e) {
88
		} catch (Exception e) {
Line 89... Line 93...
89
			ucsc.closeConnection();
93
			ucsc.closeConnection();
90
		}
94
		}
91
		*/
95
		*/
92
	}
96
	}
93
 
97
 
94
	private void initialize(User user, int totalItems){
98
	private void initialize(User user, int totalItems, String pincode){
95
		if(user!=null){
99
		if(user!=null){
96
			this.isLoggedIn = !user.isIsAnonymous();
100
			this.isLoggedIn = !user.isIsAnonymous();
97
			this.userId = user.getUserId();
101
			this.userId = user.getUserId();
98
			this.email = user.getEmail();
102
			this.email = user.getEmail();
99
			this.nameOfUser = user.getName();
103
			this.nameOfUser = user.getName();
100
			this.cartId = user.getActiveCartId();
104
			this.cartId = user.getActiveCartId();
101
			this.totalItems = totalItems;
105
			this.totalItems = totalItems;
-
 
106
			this.pincode = pincode;
102
		}else{
107
		}else{
103
			this.isLoggedIn = false;
108
			this.isLoggedIn = false;
104
			this.userId = -1;
109
			this.userId = -1;
105
			this.email = "";
110
			this.email = "";
106
			this.nameOfUser = "";
111
			this.nameOfUser = "";
107
			this.totalItems = 0;
112
			this.totalItems = 0;
108
			this.cartId = -1;
113
			this.cartId = -1;
-
 
114
			this.pincode = pincode;
109
		}			
115
		}			
110
	}
116
	}
111
	
117
	
112
	public boolean isSessionId() {
118
	public boolean isSessionId() {
113
		return !isLoggedIn;
119
		return !isLoggedIn;
Line 157... Line 163...
157
	}
163
	}
158
 
164
 
159
	public void setCartId(long cartId) {
165
	public void setCartId(long cartId) {
160
		this.cartId = cartId;
166
		this.cartId = cartId;
161
	}	
167
	}	
-
 
168
 
-
 
169
	public String getPincode() {
-
 
170
		return pincode;
162
	
171
	}
-
 
172
 
-
 
173
	public void setPincode(String pincode) {
-
 
174
		this.pincode = pincode;
-
 
175
	}
-
 
176
 
-
 
177
 
163
	public String toString(){
178
	public String toString(){
164
		StringBuffer representation = new StringBuffer();
179
		StringBuffer representation = new StringBuffer();
165
		representation.append("userId: " + userId + "\n");
180
		representation.append("userId: " + userId + "\n");
166
		representation.append("isLoggedIn: " + isLoggedIn + "\n");
181
		representation.append("isLoggedIn: " + isLoggedIn + "\n");
167
		representation.append("username: " + nameOfUser + "\n");
182
		representation.append("username: " + nameOfUser + "\n");