Subversion Repositories SmartDukaan

Rev

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

Rev 745 Rev 762
Line 26... Line 26...
26
import org.apache.thrift.TException;
26
import org.apache.thrift.TException;
27
 
27
 
28
public class Utils {
28
public class Utils {
29
	//FIXME: Read this path from the config server
29
	//FIXME: Read this path from the config server
30
	public static final String EXPORT_ENTITIES_PATH =	"/var/lib/tomcat6/webapps/export/html/entities/";
30
	public static final String EXPORT_ENTITIES_PATH =	"/var/lib/tomcat6/webapps/export/html/entities/";
31
	/*
-
 
32
	private static UserContextServiceClient userContextServiceClient;
-
 
33
	private static ShoppingCartClient shoppingCartClient;
-
 
34
	private static CatalogServiceClient catalogServiceClient;
-
 
35
	private static WidgetServiceClient widgetServiceClient;
-
 
36
	
-
 
37
	
-
 
38
	static {
-
 
39
		try {
-
 
40
			userContextServiceClient = new UserContextServiceClient();
-
 
41
			shoppingCartClient = new ShoppingCartClient();
-
 
42
			catalogServiceClient = new CatalogServiceClient();
-
 
43
			widgetServiceClient = new WidgetServiceClient();
-
 
44
		} catch (Exception e) {
-
 
45
			// TODO Auto-generated catch block
-
 
46
			e.printStackTrace();
-
 
47
		}
-
 
48
	}
-
 
49
	*/
-
 
50
	public static boolean isUserLoggedIn(long userId){ 
-
 
51
		boolean isNotLoggedIn = true;
-
 
52
		try {
-
 
53
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
-
 
54
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
55
			isNotLoggedIn = userClient.getUserById(userId).isIsAnonymous();
-
 
56
		} catch (UserContextException e) {
-
 
57
			e.printStackTrace();
-
 
58
		} catch (TException e) {
-
 
59
			e.printStackTrace();
-
 
60
		} catch (Exception e) {
-
 
61
			e.printStackTrace();
-
 
62
		}
-
 
63
		return !isNotLoggedIn;
-
 
64
	}
-
 
65
 
-
 
66
	
-
 
67
	public static String getEmailId(long userId){
-
 
68
		String email = " ";
-
 
69
		
-
 
70
		try {
-
 
71
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
-
 
72
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
73
			if(userClient.getUserById(userId).getEmail() != null){
-
 
74
				email = userClient.getUserById(userId).getEmail();
-
 
75
			}
-
 
76
		} catch (UserContextException e) {
-
 
77
			e.printStackTrace();
-
 
78
		} catch (TException e) {
-
 
79
			e.printStackTrace();
-
 
80
		} catch (Exception e) {
-
 
81
			e.printStackTrace();
-
 
82
		}
-
 
83
		return email; 
-
 
84
	}
-
 
85
 
-
 
86
	public static int getNumberOfItemsInCart(long cartId) {
-
 
87
		 
-
 
88
 
-
 
89
		int numberOfItems = 0;
-
 
90
		try {
-
 
91
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
-
 
92
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
93
 
-
 
94
			numberOfItems = userClient.getCart(cartId).getLinesSize();
-
 
95
		} catch (ShoppingCartException e) {
-
 
96
			e.printStackTrace();
-
 
97
		} catch (TException e) {
-
 
98
			e.printStackTrace();
-
 
99
		} catch (Exception e) {
-
 
100
			e.printStackTrace();
-
 
101
		}
-
 
102
		return numberOfItems;
-
 
103
	}
-
 
104
	
-
 
105
	
-
 
106
	public static long getCartId(long userId) {
-
 
107
		long cartId = 0;
-
 
108
		try {
-
 
109
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
-
 
110
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
111
 
-
 
112
			cartId = userClient.getCurrentCart(userId).getId();
-
 
113
		} catch (ShoppingCartException e) {
-
 
114
			e.printStackTrace();
-
 
115
		} catch (TException e) {
-
 
116
			e.printStackTrace();
-
 
117
		} catch (Exception e) {
-
 
118
			e.printStackTrace();
-
 
119
		}
-
 
120
		return cartId;
-
 
121
	}
-
 
122
 
-
 
123
	
-
 
124
	public static long addItemToCart(long catalogItemId, long userId, boolean isSessionId){
-
 
125
		long cartId = -1;
-
 
126
		
-
 
127
		try {
-
 
128
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
-
 
129
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
130
			
-
 
131
			cartId = userClient.createCart(userId);
-
 
132
			userClient.addItemToCart(cartId, catalogItemId, 1);
-
 
133
	
-
 
134
		} catch (ShoppingCartException e) {
-
 
135
			// TODO Auto-generated catch block
-
 
136
			e.printStackTrace();
-
 
137
		} catch (TException e) {
-
 
138
			// TODO Auto-generated catch block
-
 
139
			e.printStackTrace();
-
 
140
		} catch (Exception e) {
-
 
141
			// TODO Auto-generated catch block
-
 
142
			e.printStackTrace();
-
 
143
		}
-
 
144
		return cartId;
-
 
145
		//if user is logged in create  new cart
-
 
146
		//if( userClient.getState(userId, false).isIsLoggedIn()){
-
 
147
	}
-
 
148
 
-
 
149
	public static boolean deleteItemFromCart(long cartId, long catalogItemId, long userId, boolean isSessionId){
-
 
150
		try {
-
 
151
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
-
 
152
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
153
 
-
 
154
			userClient.deleteItemFromCart(cartId, catalogItemId);
-
 
155
			return true;	
-
 
156
		} catch (ShoppingCartException e) {
-
 
157
			e.printStackTrace();
-
 
158
		} catch (TException e) {
-
 
159
			e.printStackTrace();
-
 
160
		} catch (Exception e) {
-
 
161
			e.printStackTrace();
-
 
162
		}
-
 
163
		
-
 
164
		return false;
-
 
165
	}
-
 
166
 
-
 
167
	public static boolean updateItemQuantityInCart(long cartId, long itemId, long quantity){
-
 
168
		try {
-
 
169
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
-
 
170
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
171
 
-
 
172
			userClient.changeQuantity(cartId, itemId, quantity);
-
 
173
			return true;
-
 
174
		} catch (ShoppingCartException e) {
-
 
175
			e.printStackTrace();
-
 
176
		} catch (TException e) {
-
 
177
			e.printStackTrace();
-
 
178
		} catch (Exception e) {
-
 
179
			e.printStackTrace();
-
 
180
		}
-
 
181
		return false;
-
 
182
	}
-
 
183
	
-
 
184
	
-
 
185
	
-
 
186
	public static String getOrderDetails(long txnId){
-
 
187
		Transaction transaction;
-
 
188
		StringBuilder orderDetails = new StringBuilder();
-
 
189
		try {
-
 
190
			TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
-
 
191
			in.shop2020.model.v1.order.TransactionService.Client txnClient = transactionServiceClient.getClient();
-
 
192
 
-
 
193
			transaction = txnClient.getTransaction(txnId);
-
 
194
			
-
 
195
			for (Order order : transaction.getOrders()) {
-
 
196
				for(LineItem line: order.getLineitems()){
-
 
197
					if(line.getBrand() != null){
-
 
198
						orderDetails.append(line.getBrand());
-
 
199
					}
-
 
200
					if(line.getModel_name() != null){
-
 
201
						orderDetails.append(line.getModel_name()); 
-
 
202
					}
-
 
203
					if(line.getModel_number() != null){
-
 
204
						orderDetails.append(line.getModel_number());
-
 
205
					}
-
 
206
					if(line.getColor() != null){
-
 
207
						orderDetails.append(line.getColor());
-
 
208
					}
-
 
209
				}
-
 
210
				
-
 
211
			}
-
 
212
			
-
 
213
		} catch (ShoppingCartException e) {
-
 
214
			e.printStackTrace();
-
 
215
		} catch (TException e) {
-
 
216
			e.printStackTrace();
-
 
217
		} catch (Exception e) {
-
 
218
			e.printStackTrace();
-
 
219
		}
-
 
220
		return orderDetails.toString() + " ";
-
 
221
	}
-
 
222
	
-
 
223
	public static String getContactNumber(long txnId){
-
 
224
		Transaction transaction;
-
 
225
		StringBuilder orderDetails = new StringBuilder();
-
 
226
		try {
-
 
227
			TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
-
 
228
			in.shop2020.model.v1.order.TransactionService.Client txnClient = transactionServiceClient.getClient();
-
 
229
 
-
 
230
			transaction = txnClient.getTransaction(txnId);
-
 
231
			for (Order order : transaction.getOrders()) {
-
 
232
				if(order.getCustomer_mobilenumber() != null){
-
 
233
					orderDetails.append(order.getCustomer_mobilenumber()) ;	
-
 
234
				}
-
 
235
				
-
 
236
			}
-
 
237
			
-
 
238
		} catch (ShoppingCartException e) {
-
 
239
			e.printStackTrace();
-
 
240
		} catch (TException e) {
-
 
241
			e.printStackTrace();
-
 
242
		} catch (Exception e) {
-
 
243
			e.printStackTrace();
-
 
244
		}
-
 
245
		
31
		
246
		return orderDetails.toString() + " ";
-
 
247
	}
-
 
248
 
-
 
249
	public static String getBillingAddress(long txnId){		
-
 
250
	Transaction transaction;
-
 
251
	StringBuilder orderDetails = new StringBuilder();
-
 
252
	try {
-
 
253
		TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
-
 
254
		in.shop2020.model.v1.order.TransactionService.Client txnClient = transactionServiceClient.getClient();
-
 
255
 
-
 
256
		transaction = txnClient.getTransaction(txnId);
-
 
257
		
-
 
258
		for (Order order : transaction.getOrders()) {
-
 
259
			if(order.getCustomer_name()!=null){
-
 
260
				orderDetails.append(order.getCustomer_name());
-
 
261
			}
-
 
262
			if(order.getCustomer_address1()!=null){
-
 
263
				orderDetails.append(order.getCustomer_address1());
-
 
264
			}
-
 
265
			if(order.getCustomer_address2()!=null){
-
 
266
				orderDetails.append(order.getCustomer_address2());
-
 
267
			}
-
 
268
			if(order.getCustomer_city()!=null){
-
 
269
				orderDetails.append(order.getCustomer_city());
-
 
270
			}
-
 
271
			if(order.getCustomer_state()!=null){
-
 
272
				orderDetails.append(order.getCustomer_state());
-
 
273
			}
-
 
274
			if(order.getCustomer_pincode()!=null){
-
 
275
				orderDetails.append(order.getCustomer_pincode());
-
 
276
			}
-
 
277
		}
-
 
278
		
-
 
279
	} catch (ShoppingCartException e) {
-
 
280
		e.printStackTrace();
-
 
281
	} catch (TException e) {
-
 
282
		e.printStackTrace();
-
 
283
	} catch (Exception e) {
-
 
284
		e.printStackTrace();
-
 
285
	}
-
 
286
	
-
 
287
	return orderDetails.toString() + " ";
-
 
288
 
-
 
289
	}
-
 
290
	
-
 
291
	
-
 
292
	public static String getNameOfUser(long userId) {
-
 
293
		String name = " ";
-
 
294
		try {
-
 
295
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
-
 
296
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
297
			
-
 
298
			name = userClient.getUserById(userId).getName();
-
 
299
		} catch (UserContextException e) {
-
 
300
			// TODO Auto-generated catch block
-
 
301
			e.printStackTrace();
-
 
302
		} catch (TException e) {
-
 
303
			// TODO Auto-generated catch block
-
 
304
			e.printStackTrace();
-
 
305
		} catch (Exception e) {
-
 
306
			// TODO Auto-generated catch block
-
 
307
			e.printStackTrace();
-
 
308
		}
-
 
309
		return name; 
-
 
310
	}
-
 
311
	
-
 
312
	public static double getPaymentAmount(long cartId){
32
	public static double getPaymentAmount(long cartId){
313
		double totalAmount = 0;
33
		double totalAmount = 0;
314
		
34
		
315
		Cart cart;
35
		Cart cart;
316
		try {
36
		try {
Line 353... Line 73...
353
		}
73
		}
354
		return itemPrice;
74
		return itemPrice;
355
	}
75
	}
356
 
76
 
357
 
77
 
358
	public static void deleteFromMyResearch(long userId, long itemId) {
-
 
359
		
-
 
360
		try {
-
 
361
			UserContextServiceClient userServiceClient = new UserContextServiceClient();
-
 
362
			in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
-
 
363
			userClient.deleteItemFromMyResearch(userId, itemId);
-
 
364
		} catch (WidgetException e) {
-
 
365
			e.printStackTrace();
-
 
366
		} catch (TException e) {
-
 
367
			e.printStackTrace();
-
 
368
		} catch (Exception e) {
-
 
369
			e.printStackTrace();
-
 
370
		}
-
 
371
		
-
 
372
	}
-
 
373
 
-
 
374
 
-
 
375
	public static boolean ChangePassword(long userId, String email, String oldPassword,
-
 
376
			String newPassword) {
-
 
377
 
-
 
378
		
-
 
379
		try {
-
 
380
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
-
 
381
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
382
 
-
 
383
			return userClient.updatePassword(userId,oldPassword, newPassword);
-
 
384
		} catch (UserContextException e) {
-
 
385
			e.printStackTrace();
-
 
386
		} catch (TException e) {
-
 
387
			e.printStackTrace();
-
 
388
		} catch (Exception e) {
-
 
389
			e.printStackTrace();
-
 
390
		}
-
 
391
		return false;
-
 
392
	}
-
 
393
 
-
 
394
 
-
 
395
	public static boolean UpdatePersonalDetails(long userId,  String name,  String phone, String dateOfBirth, String sex, String communicationEmail,
-
 
396
			String subscribeNewsletter) {
-
 
397
		
-
 
398
		try {
-
 
399
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
-
 
400
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
401
 
-
 
402
			
-
 
403
			User user = userClient.getUserById(userId);		
-
 
404
			user.setDateOfBirth(dateOfBirth);
-
 
405
			user.setName(name);
-
 
406
			user.setCommunicationEmail(communicationEmail);
-
 
407
			user.setSex(Sex.findByValue(Integer.parseInt(sex)));
-
 
408
			user.setMobileNumber(phone);
-
 
409
			userClient.updateUser(user);
-
 
410
			
-
 
411
			return true;
-
 
412
		} catch (UserContextException e) {
-
 
413
			e.printStackTrace();
-
 
414
		} catch (TException e) {
-
 
415
			e.printStackTrace();
-
 
416
		} catch (Exception e) {
-
 
417
			e.printStackTrace();
-
 
418
		}
-
 
419
		return false;
-
 
420
	}
-
 
421
 
-
 
422
 
-
 
423
	public static void mergeCarts(long fromCartId, long toCartId){
-
 
424
		try {
-
 
425
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
-
 
426
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
427
			userClient.mergeCart(fromCartId, toCartId);
-
 
428
		} catch (Exception e) {
-
 
429
			// TODO Auto-generated catch block
-
 
430
			e.printStackTrace();
-
 
431
		}
-
 
432
		
-
 
433
	}
-
 
434
	
78
	
435
	public static void storeCategories(Object obj) throws Exception {
79
	public static void storeCategories(Object obj) throws Exception {
436
	
80
	
437
		ByteArrayOutputStream bStream = new ByteArrayOutputStream();
81
		ByteArrayOutputStream bStream = new ByteArrayOutputStream();
438
		ObjectOutputStream oStream = new ObjectOutputStream( bStream );
82
		ObjectOutputStream oStream = new ObjectOutputStream( bStream );