Subversion Repositories SmartDukaan

Rev

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

Rev 517 Rev 536
Line 27... Line 27...
27
import in.shop2020.thrift.clients.WidgetServiceClient;
27
import in.shop2020.thrift.clients.WidgetServiceClient;
28
 
28
 
29
import org.apache.thrift.TException;
29
import org.apache.thrift.TException;
30
 
30
 
31
public class Utils {
31
public class Utils {
-
 
32
	/*
32
	private static UserContextServiceClient userContextServiceClient;
33
	private static UserContextServiceClient userContextServiceClient;
33
	private static ShoppingCartClient shoppingCartClient;
34
	private static ShoppingCartClient shoppingCartClient;
34
	private static CatalogServiceClient catalogServiceClient;
35
	private static CatalogServiceClient catalogServiceClient;
35
	private static WidgetServiceClient widgetServiceClient;
36
	private static WidgetServiceClient widgetServiceClient;
36
	
37
	
Line 44... Line 45...
44
		} catch (Exception e) {
45
		} catch (Exception e) {
45
			// TODO Auto-generated catch block
46
			// TODO Auto-generated catch block
46
			e.printStackTrace();
47
			e.printStackTrace();
47
		}
48
		}
48
	}
49
	}
49
	
50
	*/
50
	public static boolean isUserLoggedIn(long userId){
51
	public static boolean isUserLoggedIn(long userId){ 
51
		in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
52
		boolean isLoggedin = false;
52
		boolean isLoggedin = false;
53
		try {
53
		try {
-
 
54
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
-
 
55
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
54
			isLoggedin = userClient.getState(userId, false).isIsLoggedIn();
56
			isLoggedin = userClient.getState(userId, false).isIsLoggedIn();
55
		} catch (UserContextException e) {
57
		} catch (UserContextException e) {
56
			// TODO Auto-generated catch block
58
			// TODO Auto-generated catch block
57
			e.printStackTrace();
59
			e.printStackTrace();
58
		} catch (TException e) {
60
		} catch (TException e) {
59
			// TODO Auto-generated catch block
61
			// TODO Auto-generated catch block
60
			e.printStackTrace();
62
			e.printStackTrace();
-
 
63
		} catch (Exception e) {
-
 
64
			// TODO Auto-generated catch block
-
 
65
			e.printStackTrace();
61
		}
66
		}
62
		return isLoggedin;
67
		return isLoggedin;
63
	}
68
	}
64
 
69
 
65
	
70
	
66
	public static String getEmailId(long userId){
71
	public static String getEmailId(long userId){
67
		in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
68
		String email = "";
72
		String email = "";
69
		
73
		
70
		try {
74
		try {
-
 
75
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
-
 
76
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
77
 
71
			email = userClient.getPrimaryInfo(userId, false).getEmail();
78
			email = userClient.getPrimaryInfo(userId, false).getEmail();
72
		} catch (UserContextException e) {
79
		} catch (UserContextException e) {
73
			// TODO Auto-generated catch block
80
			// TODO Auto-generated catch block
74
			e.printStackTrace();
81
			e.printStackTrace();
75
		} catch (TException e) {
82
		} catch (TException e) {
76
			// TODO Auto-generated catch block
83
			// TODO Auto-generated catch block
77
			e.printStackTrace();
84
			e.printStackTrace();
-
 
85
		} catch (Exception e) {
-
 
86
			// TODO Auto-generated catch block
-
 
87
			e.printStackTrace();
78
		}
88
		}
79
		return email; 
89
		return email; 
80
	}
90
	}
81
 
91
 
82
	public static int getNumberOfItemsInCart(long cartId) {
92
	public static int getNumberOfItemsInCart(long cartId) {
83
		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
-
 
-
 
93
		 
-
 
94
 
84
		int numberOfItems = 0;
95
		int numberOfItems = 0;
85
		try {
96
		try {
-
 
97
			ShoppingCartClient shoppingCartClient  = new ShoppingCartClient();
-
 
98
			in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
-
 
99
 
86
			numberOfItems = cartClient.getCart(cartId).getLinesSize();
100
			numberOfItems = cartClient.getCart(cartId).getLinesSize();
87
		} catch (ShoppingCartException e) {
101
		} catch (ShoppingCartException e) {
88
			// TODO Auto-generated catch block
102
			// TODO Auto-generated catch block
89
			e.printStackTrace();
103
			e.printStackTrace();
90
		} catch (TException e) {
104
		} catch (TException e) {
91
			// TODO Auto-generated catch block
105
			// TODO Auto-generated catch block
92
			e.printStackTrace();
106
			e.printStackTrace();
-
 
107
		} catch (Exception e) {
-
 
108
			// TODO Auto-generated catch block
-
 
109
			e.printStackTrace();
93
		}
110
		}
94
		return numberOfItems;
111
		return numberOfItems;
95
	}
112
	}
96
	
113
	
97
	
114
	
98
	public static long getCartId(long userId) {
115
	public static long getCartId(long userId) {
99
		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
-
 
100
		long cartId = 0;
116
		long cartId = 0;
101
		try {
117
		try {
-
 
118
			ShoppingCartClient shoppingCartClient = new ShoppingCartClient();
-
 
119
			in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
-
 
120
 
102
			cartId = cartClient.getCurrentCart(userId, false).getId();
121
			cartId = cartClient.getCurrentCart(userId, false).getId();
103
		} catch (ShoppingCartException e) {
122
		} catch (ShoppingCartException e) {
104
			// TODO Auto-generated catch block
123
			// TODO Auto-generated catch block
105
			e.printStackTrace();
124
			e.printStackTrace();
106
		} catch (TException e) {
125
		} catch (TException e) {
107
			// TODO Auto-generated catch block
126
			// TODO Auto-generated catch block
108
			e.printStackTrace();
127
			e.printStackTrace();
-
 
128
		} catch (Exception e) {
-
 
129
			// TODO Auto-generated catch block
-
 
130
			e.printStackTrace();
109
		}
131
		}
110
		return cartId;
132
		return cartId;
111
	}
133
	}
112
 
134
 
113
	
135
	
114
	public static long addItemToCart(long catalogItemId, long userId, boolean isSessionId){
136
	public static long addItemToCart(long catalogItemId, long userId, boolean isSessionId){
115
		in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
116
		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
-
 
117
		long cartId = -1;
137
		long cartId = -1;
118
		
138
		
119
		try {
139
		try {
120
//			userContextServiceClient = new UserContextServiceClient();
140
			ShoppingCartClient shoppingCartClient = new ShoppingCartClient();
121
//			userClient = userContextServiceClient.getClient();
141
			in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
122
//
142
 
123
//			shoppingCartClient = new ShoppingCartClient();
-
 
124
//			cartClient = shoppingCartClient.getClient();
-
 
125
			
143
			
126
			cartId = cartClient.createCart(userId, isSessionId);
144
			cartId = cartClient.createCart(userId, isSessionId);
127
			cartClient.addItemToCart(cartId, catalogItemId, 1);
145
			cartClient.addItemToCart(cartId, catalogItemId, 1);
128
	
146
	
129
		} catch (ShoppingCartException e) {
147
		} catch (ShoppingCartException e) {
Line 140... Line 158...
140
		//if user is logged in create  new cart
158
		//if user is logged in create  new cart
141
		//if( userClient.getState(userId, false).isIsLoggedIn()){
159
		//if( userClient.getState(userId, false).isIsLoggedIn()){
142
	}
160
	}
143
 
161
 
144
	public static boolean deleteItemFromCart(long cartId, long catalogItemId, long userId, boolean isSessionId){
162
	public static boolean deleteItemFromCart(long cartId, long catalogItemId, long userId, boolean isSessionId){
145
		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
-
 
146
		try {
163
		try {
-
 
164
			ShoppingCartClient shoppingCartClient = new ShoppingCartClient();
-
 
165
			in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
-
 
166
 
147
			cartClient.deleteItemFromCart(cartId, catalogItemId);
167
			cartClient.deleteItemFromCart(cartId, catalogItemId);
148
			return true;	
168
			return true;	
149
		} catch (ShoppingCartException e) {
169
		} catch (ShoppingCartException e) {
150
			// TODO Auto-generated catch block
170
			// TODO Auto-generated catch block
151
			e.printStackTrace();
171
			e.printStackTrace();
Line 159... Line 179...
159
		
179
		
160
		return false;
180
		return false;
161
	}
181
	}
162
 
182
 
163
	public static boolean updateItemQuantityInCart(long cartId, long itemId, long quantity){
183
	public static boolean updateItemQuantityInCart(long cartId, long itemId, long quantity){
164
		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
-
 
165
		try {
184
		try {
-
 
185
			ShoppingCartClient shoppingCartClient = new ShoppingCartClient();
-
 
186
			in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
-
 
187
 
166
			cartClient.changeQuantity(cartId, itemId, quantity);
188
			cartClient.changeQuantity(cartId, itemId, quantity);
167
			return true;
189
			return true;
168
		} catch (ShoppingCartException e) {
190
		} catch (ShoppingCartException e) {
169
			// TODO Auto-generated catch block
191
			// TODO Auto-generated catch block
170
			e.printStackTrace();
192
			e.printStackTrace();
171
		} catch (TException e) {
193
		} catch (TException e) {
172
			// TODO Auto-generated catch block
194
			// TODO Auto-generated catch block
173
			e.printStackTrace();
195
			e.printStackTrace();
-
 
196
		} catch (Exception e) {
-
 
197
			// TODO Auto-generated catch block
-
 
198
			e.printStackTrace();
174
		}
199
		}
175
		return false;
200
		return false;
176
	}
201
	}
177
	
202
	
178
	public static String getItemPrice(long itemId) throws InventoryServiceException, TException{
-
 
179
		in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = catalogServiceClient.getClient();
-
 
180
		/*Map priceMap = catalogClient.getItem(itemId).getPrice();
-
 
181
		return (String)priceMap.get("");
-
 
182
		catalogClient.getItem(itemId).getSellingPrice()
-
 
183
		*/
-
 
184
		return "100";
-
 
185
		// TODO to implement this function correctly
-
 
186
	}
-
 
187
	
203
	
188
	
204
	
189
	public static String getOrderDetails(long cartId){
205
	public static String getOrderDetails(long cartId){
190
		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
-
 
191
		List<Line> lineItems = null;
206
		List<Line> lineItems = null;
192
		StringBuilder orderDetails = new StringBuilder();
207
		StringBuilder orderDetails = new StringBuilder();
193
		try {
208
		try {
-
 
209
			ShoppingCartClient shoppingCartClient = new ShoppingCartClient();
-
 
210
			in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
-
 
211
 
194
			lineItems = cartClient.getCart(cartId).getLines();
212
			lineItems = cartClient.getCart(cartId).getLines();
195
		} catch (ShoppingCartException e) {
213
		} catch (ShoppingCartException e) {
196
			// TODO Auto-generated catch block
214
			// TODO Auto-generated catch block
197
			e.printStackTrace();
215
			e.printStackTrace();
198
		} catch (TException e) {
216
		} catch (TException e) {
199
			// TODO Auto-generated catch block
217
			// TODO Auto-generated catch block
200
			e.printStackTrace();
218
			e.printStackTrace();
-
 
219
		} catch (Exception e) {
-
 
220
			// TODO Auto-generated catch block
-
 
221
			e.printStackTrace();
201
		}
222
		}
202
		for (Line line : lineItems) {
223
		for (Line line : lineItems) {
203
			orderDetails.append("Item Id : " + line.getItemId() + "   ");
224
			orderDetails.append("Item Id : " + line.getItemId() + "   ");
204
			orderDetails.append("Item Name : " + Utils.getItemName(line.getItemId()) + "   ");
225
			orderDetails.append("Item Name : " + Utils.getItemName(line.getItemId()) + "   ");
205
			orderDetails.append("Item Quantity : " + line.getQuantity() + "   ");
226
			orderDetails.append("Item Quantity : " + line.getQuantity() + "   ");
Line 216... Line 237...
216
//TODO		write function to get address from addressId
237
//TODO		write function to get address from addressId
217
		return " test ";
238
		return " test ";
218
	}
239
	}
219
 
240
 
220
	public static String getBillingAddress(long cartId){
241
	public static String getBillingAddress(long cartId){
221
		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
242
		//in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
222
		//TODO		write function to get shipping and billing address
243
		//TODO		write function to get shipping and billing address
223
		return " test ";
244
		return " test ";
224
	}
245
	}
225
	
246
	
226
	public static String getItemName(long itemId){
247
	public static String getItemName(long itemId){
Line 228... Line 249...
228
		return "test";
249
		return "test";
229
	}
250
	}
230
 
251
 
231
 
252
 
232
	public static String getNameOfUser(long userId) {
253
	public static String getNameOfUser(long userId) {
233
		in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
234
		String name = "";
254
		String name = "";
235
		
-
 
236
		try {
255
		try {
-
 
256
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
-
 
257
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
258
			
-
 
259
 
237
			name = userClient.getPrimaryInfo(userId, false).getFirstName();
260
			name = userClient.getPrimaryInfo(userId, false).getFirstName();
238
		} catch (UserContextException e) {
261
		} catch (UserContextException e) {
239
			// TODO Auto-generated catch block
262
			// TODO Auto-generated catch block
240
			e.printStackTrace();
263
			e.printStackTrace();
241
		} catch (TException e) {
264
		} catch (TException e) {
242
			// TODO Auto-generated catch block
265
			// TODO Auto-generated catch block
243
			e.printStackTrace();
266
			e.printStackTrace();
-
 
267
		} catch (Exception e) {
-
 
268
			// TODO Auto-generated catch block
-
 
269
			e.printStackTrace();
244
		}
270
		}
245
		return name; 
271
		return name; 
246
	}
272
	}
247
	
273
	
248
	public static double getPaymentAmount(long cartId){
274
	public static double getPaymentAmount(long cartId){
249
		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
-
 
250
		double totalAmount = 0;
275
		double totalAmount = 0;
251
		
276
		
252
		Cart cart;
277
		Cart cart;
253
		try {
278
		try {
-
 
279
			ShoppingCartClient shoppingCartClient = new ShoppingCartClient();
-
 
280
			in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
-
 
281
 
254
			cart = cartClient.getCart(cartId);
282
			cart = cartClient.getCart(cartId);
255
		
283
		
256
			List<Line> lineItems = cart.getLines(); 
284
			List<Line> lineItems = cart.getLines(); 
257
		
285
		
258
			for (Line line : lineItems) {
286
			for (Line line : lineItems) {
Line 265... Line 293...
265
			// TODO Auto-generated catch block
293
			// TODO Auto-generated catch block
266
			e.printStackTrace();
294
			e.printStackTrace();
267
		} catch (TException e) {
295
		} catch (TException e) {
268
			// TODO Auto-generated catch block
296
			// TODO Auto-generated catch block
269
			e.printStackTrace();
297
			e.printStackTrace();
-
 
298
		} catch (Exception e) {
-
 
299
			// TODO Auto-generated catch block
-
 
300
			e.printStackTrace();
270
		}
301
		}
271
 
302
 
272
		return totalAmount;
303
		return totalAmount;
273
	}
304
	}
274
	
305
	
Line 279... Line 310...
279
		try {
310
		try {
280
			catalogServiceClient = new CatalogServiceClient();
311
			catalogServiceClient = new CatalogServiceClient();
281
			client = catalogServiceClient.getClient();
312
			client = catalogServiceClient.getClient();
282
			Item item = client.getItemByCatalogId(productId);
313
			Item item = client.getItemByCatalogId(productId);
283
			itemPrice = item.getSellingPrice();
314
			itemPrice = item.getSellingPrice();
284
			/*
-
 
285
			Map<Long,Double> priceMap = item.getPrice();
-
 
286
			if(priceMap == null || priceMap.isEmpty()){
-
 
287
				System.out.println("Price Not Found");
-
 
288
			}else{
-
 
289
				for(Entry<Long, Double> e: priceMap.entrySet()){
-
 
290
					itemPrice = e.getValue();
-
 
291
				}
-
 
292
			}
315
			
293
			*/
-
 
294
		}
316
		}
295
		catch(Exception e){
317
		catch(Exception e){
296
			e.printStackTrace();
318
			e.printStackTrace();
297
		}
319
		}
298
		return itemPrice;
320
		return itemPrice;
299
	}
321
	}
300
 
322
 
301
 
323
 
302
	public static void deleteFromMyResearch(long userId, long itemId) {
324
	public static void deleteFromMyResearch(long userId, long itemId) {
303
		in.shop2020.model.v1.widgets.WidgetService.Client widgetClient = widgetServiceClient.getClient();
-
 
-
 
325
		
304
		try {
326
		try {
-
 
327
			WidgetServiceClient widgetServiceClient = new WidgetServiceClient();
-
 
328
			in.shop2020.model.v1.widgets.WidgetService.Client widgetClient = widgetServiceClient.getClient();
305
			widgetClient.deleteItemFromMyResearch(userId, itemId);
329
			widgetClient.deleteItemFromMyResearch(userId, itemId);
306
		} catch (WidgetException e) {
330
		} catch (WidgetException e) {
307
			// TODO Auto-generated catch block
331
			// TODO Auto-generated catch block
308
			e.printStackTrace();
332
			e.printStackTrace();
309
		} catch (TException e) {
333
		} catch (TException e) {
310
			// TODO Auto-generated catch block
334
			// TODO Auto-generated catch block
311
			e.printStackTrace();
335
			e.printStackTrace();
-
 
336
		} catch (Exception e) {
-
 
337
			// TODO Auto-generated catch block
-
 
338
			e.printStackTrace();
312
		}
339
		}
313
		
340
		
314
	}
341
	}
315
 
342
 
316
 
343
 
317
	public static boolean ChangePassword(long userId, String email, String oldPassword,
344
	public static boolean ChangePassword(long userId, String email, String oldPassword,
318
			String newPassword) {
345
			String newPassword) {
319
		in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
-
 
346
 
320
		
347
		
321
		try {
348
		try {
-
 
349
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
-
 
350
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
351
 
322
			userClient.updatePassword(userId, newPassword);
352
			userClient.updatePassword(userId, newPassword);
323
			return true;
353
			return true;
324
		} catch (UserContextException e) {
354
		} catch (UserContextException e) {
325
			// TODO Auto-generated catch block
355
			// TODO Auto-generated catch block
326
			e.printStackTrace();
356
			e.printStackTrace();
327
		} catch (TException e) {
357
		} catch (TException e) {
328
			// TODO Auto-generated catch block
358
			// TODO Auto-generated catch block
329
			e.printStackTrace();
359
			e.printStackTrace();
-
 
360
		} catch (Exception e) {
-
 
361
			// TODO Auto-generated catch block
-
 
362
			e.printStackTrace();
330
		}
363
		}
331
		return false;
364
		return false;
332
	}
365
	}
333
 
366
 
334
 
367
 
335
	public static boolean UpdatePersonalDetails(long userId,  String name, int month,
368
	public static boolean UpdatePersonalDetails(long userId,  String name, int month,
336
			int day, int year, String sex, String communicationEmail,
369
			int day, int year, String sex, String communicationEmail,
337
			String subscribeNewsletter) {
370
			String subscribeNewsletter) {
338
		
371
		
339
		in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
340
		
372
		
341
		try {
373
		try {
-
 
374
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
-
 
375
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
376
 
342
			UserContext context = userClient.getContextFromId(userId, false);
377
			UserContext context = userClient.getContextFromId(userId, false);
343
			UserPrimaryInfo primaryInfo = context.getPrimaryInfo();
378
			UserPrimaryInfo primaryInfo = context.getPrimaryInfo();
344
			Calendar calendar = Calendar.getInstance();
379
			Calendar calendar = Calendar.getInstance();
345
			calendar.set(year + 1900, month, day);
380
			calendar.set(year + 1900, month, day);
346
			long dateOfBirth = calendar.getTimeInMillis();
381
			long dateOfBirth = calendar.getTimeInMillis();
Line 355... Line 390...
355
			// TODO Auto-generated catch block
390
			// TODO Auto-generated catch block
356
			e.printStackTrace();
391
			e.printStackTrace();
357
		} catch (TException e) {
392
		} catch (TException e) {
358
			// TODO Auto-generated catch block
393
			// TODO Auto-generated catch block
359
			e.printStackTrace();
394
			e.printStackTrace();
-
 
395
		} catch (Exception e) {
-
 
396
			// TODO Auto-generated catch block
-
 
397
			e.printStackTrace();
360
		}
398
		}
361
		return false;
399
		return false;
362
	}
400
	}
-
 
401
 
-
 
402
 
-
 
403
	public static void mergeCarts(long fromCartId, long toCartId){
-
 
404
		ShoppingCartClient shoppingCartClient;
-
 
405
		try {
-
 
406
			shoppingCartClient = new ShoppingCartClient();
-
 
407
			in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
-
 
408
			cartClient.mergeCart(fromCartId, toCartId);
-
 
409
		} catch (Exception e) {
-
 
410
			// TODO Auto-generated catch block
-
 
411
			e.printStackTrace();
-
 
412
		}
-
 
413
		
-
 
414
	}
363
	
415
	
364
}
416
}
365
	
417
	
366
418