Subversion Repositories SmartDukaan

Rev

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

Rev 458 Rev 507
Line 1... Line 1...
1
package in.shop2020.serving.utils;
1
package in.shop2020.serving.utils;
2
 
2
 
3
import java.util.ArrayList;
3
import java.util.ArrayList;
-
 
4
import java.util.Date;
4
import java.util.HashMap;
5
import java.util.HashMap;
5
import java.util.Iterator;
6
import java.util.Iterator;
6
import java.util.List;
7
import java.util.List;
7
import java.util.Map;
8
import java.util.Map;
8
import java.util.Map.Entry;
9
import java.util.Map.Entry;
Line 10... Line 11...
10
import in.shop2020.model.v1.catalog.InventoryServiceException;
11
import in.shop2020.model.v1.catalog.InventoryServiceException;
11
import in.shop2020.model.v1.catalog.Item;
12
import in.shop2020.model.v1.catalog.Item;
12
import in.shop2020.model.v1.catalog.InventoryService.Client;
13
import in.shop2020.model.v1.catalog.InventoryService.Client;
13
import in.shop2020.model.v1.shoppingcart.Cart;
14
import in.shop2020.model.v1.shoppingcart.Cart;
14
import in.shop2020.model.v1.shoppingcart.Line;
15
import in.shop2020.model.v1.shoppingcart.Line;
-
 
16
import in.shop2020.model.v1.shoppingcart.LineStatus;
15
import in.shop2020.model.v1.shoppingcart.ShoppingCartException;
17
import in.shop2020.model.v1.shoppingcart.ShoppingCartException;
16
import in.shop2020.model.v1.user.Address;
18
import in.shop2020.model.v1.user.Address;
-
 
19
import in.shop2020.model.v1.user.UserContext;
17
import in.shop2020.model.v1.user.UserContextException;
20
import in.shop2020.model.v1.user.UserContextException;
-
 
21
import in.shop2020.model.v1.user.UserPrimaryInfo;
18
import in.shop2020.model.v1.widgets.WidgetException;
22
import in.shop2020.model.v1.widgets.WidgetException;
19
import in.shop2020.thrift.clients.CatalogServiceClient;
23
import in.shop2020.thrift.clients.CatalogServiceClient;
20
import in.shop2020.thrift.clients.ShoppingCartClient;
24
import in.shop2020.thrift.clients.ShoppingCartClient;
21
import in.shop2020.thrift.clients.UserContextServiceClient;
25
import in.shop2020.thrift.clients.UserContextServiceClient;
22
import in.shop2020.thrift.clients.WidgetServiceClient;
26
import in.shop2020.thrift.clients.WidgetServiceClient;
Line 76... Line 80...
76
 
80
 
77
	public static int getNumberOfItemsInCart(long cartId) {
81
	public static int getNumberOfItemsInCart(long cartId) {
78
		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
82
		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
79
		int numberOfItems = 0;
83
		int numberOfItems = 0;
80
		try {
84
		try {
81
			numberOfItems = cartClient.getShadowCart(cartId).getLinesSize();
85
			numberOfItems = cartClient.getCart(cartId).getLinesSize();
82
		} catch (ShoppingCartException e) {
86
		} catch (ShoppingCartException e) {
83
			// TODO Auto-generated catch block
87
			// TODO Auto-generated catch block
84
			e.printStackTrace();
88
			e.printStackTrace();
85
		} catch (TException e) {
89
		} catch (TException e) {
86
			// TODO Auto-generated catch block
90
			// TODO Auto-generated catch block
Line 134... Line 138...
134
		return cartId;
138
		return cartId;
135
		//if user is logged in create  new cart
139
		//if user is logged in create  new cart
136
		//if( userClient.getState(userId, false).isIsLoggedIn()){
140
		//if( userClient.getState(userId, false).isIsLoggedIn()){
137
	}
141
	}
138
 
142
 
-
 
143
	public static boolean deleteItemFromCart(long catalogItemId, long userId, boolean isSessionId){
-
 
144
		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
-
 
145
		long cartId = -1;
-
 
146
		
-
 
147
		try {
-
 
148
			
-
 
149
			cartId = cartClient.createCart(userId, isSessionId);
-
 
150
			cartClient.deleteItemFromCart(cartId, catalogItemId);
-
 
151
			//cartClient.changeItemStatus(cartId, catalogItemId, LineStatus.LINE_DELETED);
-
 
152
			return true;	
-
 
153
		} catch (ShoppingCartException e) {
-
 
154
			// TODO Auto-generated catch block
-
 
155
			e.printStackTrace();
-
 
156
		} catch (TException e) {
-
 
157
			// TODO Auto-generated catch block
-
 
158
			e.printStackTrace();
-
 
159
		} catch (Exception e) {
-
 
160
			// TODO Auto-generated catch block
-
 
161
			e.printStackTrace();
-
 
162
		}
-
 
163
		
-
 
164
		return false;
-
 
165
	}
-
 
166
 
-
 
167
	public static boolean updateItemQuantityInCart(long cartId, long itemId, long quantity){
-
 
168
		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
-
 
169
		try {
-
 
170
			cartClient.changeQuantity(cartId, itemId, quantity);
-
 
171
			return true;
-
 
172
		} catch (ShoppingCartException e) {
-
 
173
			// TODO Auto-generated catch block
-
 
174
			e.printStackTrace();
-
 
175
		} catch (TException e) {
-
 
176
			// TODO Auto-generated catch block
-
 
177
			e.printStackTrace();
-
 
178
		}
-
 
179
		return false;
-
 
180
	}
139
	
181
	
140
	public static String getItemPrice(long itemId) throws InventoryServiceException, TException{
182
	public static String getItemPrice(long itemId) throws InventoryServiceException, TException{
141
		in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = catalogServiceClient.getClient();
183
		in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = catalogServiceClient.getClient();
142
		Map priceMap = catalogClient.getItem(itemId).getPrice();
184
		/*Map priceMap = catalogClient.getItem(itemId).getPrice();
143
		return (String)priceMap.get("");
185
		return (String)priceMap.get("");
-
 
186
		catalogClient.getItem(itemId).getSellingPrice()
-
 
187
		*/
-
 
188
		return "100";
144
		// TODO to implement this function correctly
189
		// TODO to implement this function correctly
145
	}
190
	}
146
	
191
	
147
	
192
	
148
	public static String getOrderDetails(long cartId){
193
	public static String getOrderDetails(long cartId){
Line 236... Line 281...
236
		Double itemPrice = 0.0;
281
		Double itemPrice = 0.0;
237
		try {
282
		try {
238
			catalogServiceClient = new CatalogServiceClient();
283
			catalogServiceClient = new CatalogServiceClient();
239
			client = catalogServiceClient.getClient();
284
			client = catalogServiceClient.getClient();
240
			Item item = client.getItemByCatalogId(productId);
285
			Item item = client.getItemByCatalogId(productId);
-
 
286
			/*
241
			Map<Long,Double> priceMap = item.getPrice();
287
			Map<Long,Double> priceMap = item.getPrice();
242
			if(priceMap == null || priceMap.isEmpty()){
288
			if(priceMap == null || priceMap.isEmpty()){
243
				System.out.println("Price Not Found");
289
				System.out.println("Price Not Found");
244
			}else{
290
			}else{
245
				for(Entry<Long, Double> e: priceMap.entrySet()){
291
				for(Entry<Long, Double> e: priceMap.entrySet()){
246
					itemPrice = e.getValue();
292
					itemPrice = e.getValue();
247
				}
293
				}
248
			}
294
			}
-
 
295
			*/
249
		}
296
		}
250
		catch(Exception e){
297
		catch(Exception e){
251
			e.printStackTrace();
298
			e.printStackTrace();
252
		}
299
		}
253
		return itemPrice;
300
		return itemPrice;
Line 266... Line 313...
266
			e.printStackTrace();
313
			e.printStackTrace();
267
		}
314
		}
268
		
315
		
269
	}
316
	}
270
 
317
 
-
 
318
 
-
 
319
	public static boolean ChangePassword(long userId, String email, String oldPassword,
-
 
320
			String newPassword) {
-
 
321
		in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
322
		
-
 
323
		try {
-
 
324
			userClient.updatePassword(userId, newPassword);
-
 
325
			return true;
-
 
326
		} catch (UserContextException e) {
-
 
327
			// TODO Auto-generated catch block
-
 
328
			e.printStackTrace();
-
 
329
		} catch (TException e) {
-
 
330
			// TODO Auto-generated catch block
-
 
331
			e.printStackTrace();
-
 
332
		}
-
 
333
		return false;
-
 
334
	}
-
 
335
 
-
 
336
 
-
 
337
	public static boolean UpdatePersonalDetails(long userId,  String name, int month,
-
 
338
			int day, int year, String sex, String communicationEmail,
-
 
339
			String subscribeNewsletter) {
-
 
340
		
-
 
341
		in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
342
		
-
 
343
		try {
-
 
344
			UserContext context = userClient.getContextFromId(userId, false);
-
 
345
			UserPrimaryInfo primaryInfo = context.getPrimaryInfo();
-
 
346
			long dateOfBirth = (new Date(year, month, day)).getTime();
-
 
347
			
-
 
348
			primaryInfo.setDateOfBirth(dateOfBirth);
-
 
349
			primaryInfo.setFirstName(name);
-
 
350
			context.setPrimaryInfo(primaryInfo);
-
 
351
			userClient.createContext(context, true);
-
 
352
			return true;
-
 
353
		} catch (UserContextException e) {
-
 
354
			// TODO Auto-generated catch block
-
 
355
			e.printStackTrace();
-
 
356
		} catch (TException e) {
-
 
357
			// TODO Auto-generated catch block
-
 
358
			e.printStackTrace();
-
 
359
		}
-
 
360
		return false;
-
 
361
	}
-
 
362
	
271
}
363
}
272
	
364
	
273
365