Subversion Repositories SmartDukaan

Rev

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

Rev 536 Rev 555
Line 10... Line 10...
10
import java.util.Map.Entry;
10
import java.util.Map.Entry;
11
 
11
 
12
import in.shop2020.model.v1.catalog.InventoryServiceException;
12
import in.shop2020.model.v1.catalog.InventoryServiceException;
13
import in.shop2020.model.v1.catalog.Item;
13
import in.shop2020.model.v1.catalog.Item;
14
import in.shop2020.model.v1.catalog.InventoryService.Client;
14
import in.shop2020.model.v1.catalog.InventoryService.Client;
15
import in.shop2020.model.v1.shoppingcart.Cart;
15
import in.shop2020.model.v1.user.Cart;
-
 
16
 
16
import in.shop2020.model.v1.shoppingcart.Line;
17
import in.shop2020.model.v1.user.Line;
17
import in.shop2020.model.v1.shoppingcart.LineStatus;
18
import in.shop2020.model.v1.user.LineStatus;
18
import in.shop2020.model.v1.shoppingcart.ShoppingCartException;
19
import in.shop2020.model.v1.user.ShoppingCartException;
19
import in.shop2020.model.v1.user.Address;
20
import in.shop2020.model.v1.user.Address;
20
import in.shop2020.model.v1.user.UserContext;
21
import in.shop2020.model.v1.user.User;
21
import in.shop2020.model.v1.user.UserContextException;
22
import in.shop2020.model.v1.user.UserContextException;
22
import in.shop2020.model.v1.user.UserPrimaryInfo;
-
 
23
import in.shop2020.model.v1.widgets.WidgetException;
23
import in.shop2020.model.v1.widgets.WidgetException;
24
import in.shop2020.thrift.clients.CatalogServiceClient;
24
import in.shop2020.thrift.clients.CatalogServiceClient;
25
import in.shop2020.thrift.clients.ShoppingCartClient;
-
 
26
import in.shop2020.thrift.clients.UserContextServiceClient;
25
import in.shop2020.thrift.clients.UserContextServiceClient;
27
import in.shop2020.thrift.clients.WidgetServiceClient;
26
import in.shop2020.thrift.clients.WidgetServiceClient;
28
 
27
 
29
import org.apache.thrift.TException;
28
import org.apache.thrift.TException;
30
 
29
 
Line 47... Line 46...
47
			e.printStackTrace();
46
			e.printStackTrace();
48
		}
47
		}
49
	}
48
	}
50
	*/
49
	*/
51
	public static boolean isUserLoggedIn(long userId){ 
50
	public static boolean isUserLoggedIn(long userId){ 
52
		boolean isLoggedin = false;
51
		boolean isNotLoggedIn = true;
53
		try {
52
		try {
54
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
53
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
55
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
54
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
56
			isLoggedin = userClient.getState(userId, false).isIsLoggedIn();
55
			isNotLoggedIn = userClient.getUserById(userId).isIsAnonymous();
57
		} catch (UserContextException e) {
56
		} catch (UserContextException e) {
58
			// TODO Auto-generated catch block
-
 
59
			e.printStackTrace();
57
			e.printStackTrace();
60
		} catch (TException e) {
58
		} catch (TException e) {
61
			// TODO Auto-generated catch block
-
 
62
			e.printStackTrace();
59
			e.printStackTrace();
63
		} catch (Exception e) {
60
		} catch (Exception e) {
64
			// TODO Auto-generated catch block
-
 
65
			e.printStackTrace();
61
			e.printStackTrace();
66
		}
62
		}
67
		return isLoggedin;
63
		return !isNotLoggedIn;
68
	}
64
	}
69
 
65
 
70
	
66
	
71
	public static String getEmailId(long userId){
67
	public static String getEmailId(long userId){
72
		String email = "";
68
		String email = "";
73
		
69
		
74
		try {
70
		try {
75
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
71
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
76
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
72
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
77
 
73
 
78
			email = userClient.getPrimaryInfo(userId, false).getEmail();
74
			email = userClient.getUserById(userId).getEmail();
79
		} catch (UserContextException e) {
75
		} catch (UserContextException e) {
80
			// TODO Auto-generated catch block
-
 
81
			e.printStackTrace();
76
			e.printStackTrace();
82
		} catch (TException e) {
77
		} catch (TException e) {
83
			// TODO Auto-generated catch block
-
 
84
			e.printStackTrace();
78
			e.printStackTrace();
85
		} catch (Exception e) {
79
		} catch (Exception e) {
86
			// TODO Auto-generated catch block
-
 
87
			e.printStackTrace();
80
			e.printStackTrace();
88
		}
81
		}
89
		return email; 
82
		return email; 
90
	}
83
	}
91
 
84
 
92
	public static int getNumberOfItemsInCart(long cartId) {
85
	public static int getNumberOfItemsInCart(long cartId) {
93
		 
86
		 
94
 
87
 
95
		int numberOfItems = 0;
88
		int numberOfItems = 0;
96
		try {
89
		try {
97
			ShoppingCartClient shoppingCartClient  = new ShoppingCartClient();
90
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
98
			in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
91
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
99
 
92
 
100
			numberOfItems = cartClient.getCart(cartId).getLinesSize();
93
			numberOfItems = userClient.getCart(cartId).getLinesSize();
101
		} catch (ShoppingCartException e) {
94
		} catch (ShoppingCartException e) {
102
			// TODO Auto-generated catch block
-
 
103
			e.printStackTrace();
95
			e.printStackTrace();
104
		} catch (TException e) {
96
		} catch (TException e) {
105
			// TODO Auto-generated catch block
-
 
106
			e.printStackTrace();
97
			e.printStackTrace();
107
		} catch (Exception e) {
98
		} catch (Exception e) {
108
			// TODO Auto-generated catch block
-
 
109
			e.printStackTrace();
99
			e.printStackTrace();
110
		}
100
		}
111
		return numberOfItems;
101
		return numberOfItems;
112
	}
102
	}
113
	
103
	
114
	
104
	
115
	public static long getCartId(long userId) {
105
	public static long getCartId(long userId) {
116
		long cartId = 0;
106
		long cartId = 0;
117
		try {
107
		try {
118
			ShoppingCartClient shoppingCartClient = new ShoppingCartClient();
108
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
119
			in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
109
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
120
 
110
 
121
			cartId = cartClient.getCurrentCart(userId, false).getId();
111
			cartId = userClient.getCurrentCart(userId).getId();
122
		} catch (ShoppingCartException e) {
112
		} catch (ShoppingCartException e) {
123
			// TODO Auto-generated catch block
-
 
124
			e.printStackTrace();
113
			e.printStackTrace();
125
		} catch (TException e) {
114
		} catch (TException e) {
126
			// TODO Auto-generated catch block
-
 
127
			e.printStackTrace();
115
			e.printStackTrace();
128
		} catch (Exception e) {
116
		} catch (Exception e) {
129
			// TODO Auto-generated catch block
-
 
130
			e.printStackTrace();
117
			e.printStackTrace();
131
		}
118
		}
132
		return cartId;
119
		return cartId;
133
	}
120
	}
134
 
121
 
135
	
122
	
136
	public static long addItemToCart(long catalogItemId, long userId, boolean isSessionId){
123
	public static long addItemToCart(long catalogItemId, long userId, boolean isSessionId){
137
		long cartId = -1;
124
		long cartId = -1;
138
		
125
		
139
		try {
126
		try {
140
			ShoppingCartClient shoppingCartClient = new ShoppingCartClient();
127
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
141
			in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
128
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
142
 
-
 
143
			
129
			
144
			cartId = cartClient.createCart(userId, isSessionId);
130
			cartId = userClient.createCart(userId);
145
			cartClient.addItemToCart(cartId, catalogItemId, 1);
131
			userClient.addItemToCart(cartId, catalogItemId, 1);
146
	
132
	
147
		} catch (ShoppingCartException e) {
133
		} catch (ShoppingCartException e) {
148
			// TODO Auto-generated catch block
134
			// TODO Auto-generated catch block
149
			e.printStackTrace();
135
			e.printStackTrace();
150
		} catch (TException e) {
136
		} catch (TException e) {
Line 159... Line 145...
159
		//if( userClient.getState(userId, false).isIsLoggedIn()){
145
		//if( userClient.getState(userId, false).isIsLoggedIn()){
160
	}
146
	}
161
 
147
 
162
	public static boolean deleteItemFromCart(long cartId, long catalogItemId, long userId, boolean isSessionId){
148
	public static boolean deleteItemFromCart(long cartId, long catalogItemId, long userId, boolean isSessionId){
163
		try {
149
		try {
164
			ShoppingCartClient shoppingCartClient = new ShoppingCartClient();
150
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
165
			in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
151
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
166
 
152
 
167
			cartClient.deleteItemFromCart(cartId, catalogItemId);
153
			userClient.deleteItemFromCart(cartId, catalogItemId);
168
			return true;	
154
			return true;	
169
		} catch (ShoppingCartException e) {
155
		} catch (ShoppingCartException e) {
170
			// TODO Auto-generated catch block
-
 
171
			e.printStackTrace();
156
			e.printStackTrace();
172
		} catch (TException e) {
157
		} catch (TException e) {
173
			// TODO Auto-generated catch block
-
 
174
			e.printStackTrace();
158
			e.printStackTrace();
175
		} catch (Exception e) {
159
		} catch (Exception e) {
176
			// TODO Auto-generated catch block
-
 
177
			e.printStackTrace();
160
			e.printStackTrace();
178
		}
161
		}
179
		
162
		
180
		return false;
163
		return false;
181
	}
164
	}
182
 
165
 
183
	public static boolean updateItemQuantityInCart(long cartId, long itemId, long quantity){
166
	public static boolean updateItemQuantityInCart(long cartId, long itemId, long quantity){
184
		try {
167
		try {
185
			ShoppingCartClient shoppingCartClient = new ShoppingCartClient();
168
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
186
			in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
169
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
187
 
170
 
188
			cartClient.changeQuantity(cartId, itemId, quantity);
171
			userClient.changeQuantity(cartId, itemId, quantity);
189
			return true;
172
			return true;
190
		} catch (ShoppingCartException e) {
173
		} catch (ShoppingCartException e) {
191
			// TODO Auto-generated catch block
-
 
192
			e.printStackTrace();
174
			e.printStackTrace();
193
		} catch (TException e) {
175
		} catch (TException e) {
194
			// TODO Auto-generated catch block
-
 
195
			e.printStackTrace();
176
			e.printStackTrace();
196
		} catch (Exception e) {
177
		} catch (Exception e) {
197
			// TODO Auto-generated catch block
-
 
198
			e.printStackTrace();
178
			e.printStackTrace();
199
		}
179
		}
200
		return false;
180
		return false;
201
	}
181
	}
202
	
182
	
Line 204... Line 184...
204
	
184
	
205
	public static String getOrderDetails(long cartId){
185
	public static String getOrderDetails(long cartId){
206
		List<Line> lineItems = null;
186
		List<Line> lineItems = null;
207
		StringBuilder orderDetails = new StringBuilder();
187
		StringBuilder orderDetails = new StringBuilder();
208
		try {
188
		try {
209
			ShoppingCartClient shoppingCartClient = new ShoppingCartClient();
189
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
210
			in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
190
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
211
 
191
 
212
			lineItems = cartClient.getCart(cartId).getLines();
192
			lineItems = userClient.getCart(cartId).getLines();
213
		} catch (ShoppingCartException e) {
193
		} catch (ShoppingCartException e) {
214
			// TODO Auto-generated catch block
-
 
215
			e.printStackTrace();
194
			e.printStackTrace();
216
		} catch (TException e) {
195
		} catch (TException e) {
217
			// TODO Auto-generated catch block
-
 
218
			e.printStackTrace();
196
			e.printStackTrace();
219
		} catch (Exception e) {
197
		} catch (Exception e) {
220
			// TODO Auto-generated catch block
-
 
221
			e.printStackTrace();
198
			e.printStackTrace();
222
		}
199
		}
223
		for (Line line : lineItems) {
200
		for (Line line : lineItems) {
224
			orderDetails.append("Item Id : " + line.getItemId() + "   ");
201
			orderDetails.append("Item Id : " + line.getItemId() + "   ");
225
			orderDetails.append("Item Name : " + Utils.getItemName(line.getItemId()) + "   ");
202
			orderDetails.append("Item Name : " + Utils.getItemName(line.getItemId()) + "   ");
Line 254... Line 231...
254
		String name = "";
231
		String name = "";
255
		try {
232
		try {
256
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
233
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
257
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
234
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
258
			
235
			
259
 
-
 
260
			name = userClient.getPrimaryInfo(userId, false).getFirstName();
236
			name = userClient.getUserById(userId).getName();
261
		} catch (UserContextException e) {
237
		} catch (UserContextException e) {
262
			// TODO Auto-generated catch block
238
			// TODO Auto-generated catch block
263
			e.printStackTrace();
239
			e.printStackTrace();
264
		} catch (TException e) {
240
		} catch (TException e) {
265
			// TODO Auto-generated catch block
241
			// TODO Auto-generated catch block
Line 274... Line 250...
274
	public static double getPaymentAmount(long cartId){
250
	public static double getPaymentAmount(long cartId){
275
		double totalAmount = 0;
251
		double totalAmount = 0;
276
		
252
		
277
		Cart cart;
253
		Cart cart;
278
		try {
254
		try {
279
			ShoppingCartClient shoppingCartClient = new ShoppingCartClient();
255
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
280
			in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
256
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
281
 
257
 
282
			cart = cartClient.getCart(cartId);
258
			cart = userClient.getCart(cartId);
283
		
259
		
284
			List<Line> lineItems = cart.getLines(); 
260
			List<Line> lineItems = cart.getLines(); 
285
		
261
		
286
			for (Line line : lineItems) {
262
			for (Line line : lineItems) {
287
				long productId = line.getItemId();
263
				long productId = line.getItemId();
288
				totalAmount =  totalAmount + line.getQuantity() * Utils.getItemPriceByCatalogId(productId);
264
				totalAmount =  totalAmount + line.getQuantity() * Utils.getItemPriceByCatalogId(productId);
289
				
-
 
290
			}
265
			}
291
 
266
 
292
		} catch (ShoppingCartException e) {
267
		} catch (ShoppingCartException e) {
293
			// TODO Auto-generated catch block
-
 
294
			e.printStackTrace();
268
			e.printStackTrace();
295
		} catch (TException e) {
269
		} catch (TException e) {
296
			// TODO Auto-generated catch block
-
 
297
			e.printStackTrace();
270
			e.printStackTrace();
298
		} catch (Exception e) {
271
		} catch (Exception e) {
299
			// TODO Auto-generated catch block
-
 
300
			e.printStackTrace();
272
			e.printStackTrace();
301
		}
273
		}
302
 
274
 
303
		return totalAmount;
275
		return totalAmount;
304
	}
276
	}
Line 322... Line 294...
322
 
294
 
323
 
295
 
324
	public static void deleteFromMyResearch(long userId, long itemId) {
296
	public static void deleteFromMyResearch(long userId, long itemId) {
325
		
297
		
326
		try {
298
		try {
327
			WidgetServiceClient widgetServiceClient = new WidgetServiceClient();
299
			UserContextServiceClient userServiceClient = new UserContextServiceClient();
328
			in.shop2020.model.v1.widgets.WidgetService.Client widgetClient = widgetServiceClient.getClient();
300
			in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
329
			widgetClient.deleteItemFromMyResearch(userId, itemId);
301
			userClient.deleteItemFromMyResearch(userId, itemId);
330
		} catch (WidgetException e) {
302
		} catch (WidgetException e) {
331
			// TODO Auto-generated catch block
-
 
332
			e.printStackTrace();
303
			e.printStackTrace();
333
		} catch (TException e) {
304
		} catch (TException e) {
334
			// TODO Auto-generated catch block
-
 
335
			e.printStackTrace();
305
			e.printStackTrace();
336
		} catch (Exception e) {
306
		} catch (Exception e) {
337
			// TODO Auto-generated catch block
-
 
338
			e.printStackTrace();
307
			e.printStackTrace();
339
		}
308
		}
340
		
309
		
341
	}
310
	}
342
 
311
 
Line 350... Line 319...
350
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
319
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
351
 
320
 
352
			userClient.updatePassword(userId, newPassword);
321
			userClient.updatePassword(userId, newPassword);
353
			return true;
322
			return true;
354
		} catch (UserContextException e) {
323
		} catch (UserContextException e) {
355
			// TODO Auto-generated catch block
-
 
356
			e.printStackTrace();
324
			e.printStackTrace();
357
		} catch (TException e) {
325
		} catch (TException e) {
358
			// TODO Auto-generated catch block
-
 
359
			e.printStackTrace();
326
			e.printStackTrace();
360
		} catch (Exception e) {
327
		} catch (Exception e) {
361
			// TODO Auto-generated catch block
-
 
362
			e.printStackTrace();
328
			e.printStackTrace();
363
		}
329
		}
364
		return false;
330
		return false;
365
	}
331
	}
366
 
332
 
Line 372... Line 338...
372
		
338
		
373
		try {
339
		try {
374
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
340
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
375
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
341
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
376
 
342
 
377
			UserContext context = userClient.getContextFromId(userId, false);
-
 
378
			UserPrimaryInfo primaryInfo = context.getPrimaryInfo();
-
 
379
			Calendar calendar = Calendar.getInstance();
343
			Calendar calendar = Calendar.getInstance();
380
			calendar.set(year + 1900, month, day);
344
			calendar.set(year + 1900, month, day);
381
			long dateOfBirth = calendar.getTimeInMillis();
345
			long dateOfBirth = calendar.getTimeInMillis();
382
			
346
			
-
 
347
			User user = userClient.getUserById(userId);		
383
			primaryInfo.setDateOfBirth(dateOfBirth);
348
			user.setDateOfBirth(dateOfBirth);
384
			primaryInfo.setFirstName(name);
349
			user.setName(name);
385
			primaryInfo.setCommunicationEmail(communicationEmail);
350
			user.setCommunicationEmail(communicationEmail);
386
			context.setPrimaryInfo(primaryInfo);
-
 
387
			userClient.createContext(context, true);
351
			userClient.updateUser(user);
388
			return true;
352
			return true;
389
		} catch (UserContextException e) {
353
		} catch (UserContextException e) {
390
			// TODO Auto-generated catch block
-
 
391
			e.printStackTrace();
354
			e.printStackTrace();
392
		} catch (TException e) {
355
		} catch (TException e) {
393
			// TODO Auto-generated catch block
-
 
394
			e.printStackTrace();
356
			e.printStackTrace();
395
		} catch (Exception e) {
357
		} catch (Exception e) {
396
			// TODO Auto-generated catch block
-
 
397
			e.printStackTrace();
358
			e.printStackTrace();
398
		}
359
		}
399
		return false;
360
		return false;
400
	}
361
	}
401
 
362
 
402
 
363
 
403
	public static void mergeCarts(long fromCartId, long toCartId){
364
	public static void mergeCarts(long fromCartId, long toCartId){
404
		ShoppingCartClient shoppingCartClient;
-
 
405
		try {
365
		try {
406
			shoppingCartClient = new ShoppingCartClient();
366
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
407
			in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
367
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
408
			cartClient.mergeCart(fromCartId, toCartId);
368
			userClient.mergeCart(fromCartId, toCartId);
409
		} catch (Exception e) {
369
		} catch (Exception e) {
410
			// TODO Auto-generated catch block
370
			// TODO Auto-generated catch block
411
			e.printStackTrace();
371
			e.printStackTrace();
412
		}
372
		}
413
		
373