Subversion Repositories SmartDukaan

Rev

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

Rev 681 Rev 741
Line 6... Line 6...
6
import java.io.ObjectOutputStream;
6
import java.io.ObjectOutputStream;
7
import java.util.List;
7
import java.util.List;
8
 
8
 
9
import in.shop2020.model.v1.catalog.Item;
9
import in.shop2020.model.v1.catalog.Item;
10
import in.shop2020.model.v1.catalog.InventoryService.Client;
10
import in.shop2020.model.v1.catalog.InventoryService.Client;
-
 
11
import in.shop2020.model.v1.order.LineItem;
-
 
12
import in.shop2020.model.v1.order.Order;
-
 
13
import in.shop2020.model.v1.order.Transaction;
11
import in.shop2020.model.v1.user.Cart;
14
import in.shop2020.model.v1.user.Cart;
12
 
15
 
13
import in.shop2020.model.v1.user.Line;
16
import in.shop2020.model.v1.user.Line;
14
import in.shop2020.model.v1.user.Sex;
17
import in.shop2020.model.v1.user.Sex;
15
import in.shop2020.model.v1.user.ShoppingCartException;
18
import in.shop2020.model.v1.user.ShoppingCartException;
16
import in.shop2020.model.v1.user.User;
19
import in.shop2020.model.v1.user.User;
17
import in.shop2020.model.v1.user.UserContextException;
20
import in.shop2020.model.v1.user.UserContextException;
18
import in.shop2020.model.v1.user.WidgetException;
21
import in.shop2020.model.v1.user.WidgetException;
19
import in.shop2020.thrift.clients.CatalogServiceClient;
22
import in.shop2020.thrift.clients.CatalogServiceClient;
-
 
23
import in.shop2020.thrift.clients.TransactionServiceClient;
20
import in.shop2020.thrift.clients.UserContextServiceClient;
24
import in.shop2020.thrift.clients.UserContextServiceClient;
21
 
25
 
22
import org.apache.thrift.TException;
26
import org.apache.thrift.TException;
23
 
27
 
24
public class Utils {
28
public class Utils {
Line 59... Line 63...
59
		return !isNotLoggedIn;
63
		return !isNotLoggedIn;
60
	}
64
	}
61
 
65
 
62
	
66
	
63
	public static String getEmailId(long userId){
67
	public static String getEmailId(long userId){
64
		String email = "";
68
		String email = " ";
65
		
69
		
66
		try {
70
		try {
67
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
71
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
68
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
72
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
69
 
-
 
-
 
73
			if(userClient.getUserById(userId).getEmail() != null){
70
			email = userClient.getUserById(userId).getEmail();
74
				email = userClient.getUserById(userId).getEmail();
-
 
75
			}
71
		} catch (UserContextException e) {
76
		} catch (UserContextException e) {
72
			e.printStackTrace();
77
			e.printStackTrace();
73
		} catch (TException e) {
78
		} catch (TException e) {
74
			e.printStackTrace();
79
			e.printStackTrace();
75
		} catch (Exception e) {
80
		} catch (Exception e) {
Line 176... Line 181...
176
		return false;
181
		return false;
177
	}
182
	}
178
	
183
	
179
	
184
	
180
	
185
	
181
	public static String getOrderDetails(long cartId){
186
	public static String getOrderDetails(long txnId){
182
		List<Line> lineItems = null;
187
		Transaction transaction;
183
		StringBuilder orderDetails = new StringBuilder();
188
		StringBuilder orderDetails = new StringBuilder();
184
		try {
189
		try {
185
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
190
			TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
186
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
191
			in.shop2020.model.v1.order.TransactionService.Client txnClient = transactionServiceClient.getClient();
187
 
192
 
188
			lineItems = userClient.getCart(cartId).getLines();
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
			
189
		} catch (ShoppingCartException e) {
213
		} catch (ShoppingCartException e) {
190
			e.printStackTrace();
214
			e.printStackTrace();
191
		} catch (TException e) {
215
		} catch (TException e) {
192
			e.printStackTrace();
216
			e.printStackTrace();
193
		} catch (Exception e) {
217
		} catch (Exception e) {
194
			e.printStackTrace();
218
			e.printStackTrace();
195
		}
219
		}
196
		for (Line line : lineItems) {
-
 
197
			orderDetails.append("Item Id : " + line.getItemId() + "   ");
-
 
198
			orderDetails.append("Item Name : " + Utils.getItemName(line.getItemId()) + "   ");
-
 
199
			orderDetails.append("Item Quantity : " + line.getQuantity() + "   ");
-
 
200
		}
-
 
201
		return orderDetails.toString();
220
		return orderDetails.toString() + " ";
202
	}
221
	}
203
	
222
	
204
	public static String getContactNumber(long cartId){
223
	public static String getContactNumber(long txnId){
-
 
224
		Transaction transaction;
-
 
225
		StringBuilder orderDetails = new StringBuilder();
-
 
226
		try {
205
//		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
227
			TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
206
//		in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
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
		}
207
		
245
		
208
//		userClient.getPrimaryInfo(userId, false).getAddresses()
-
 
209
//		cartClient.getCart(cartId).getAddressId()
-
 
210
//TODO		write function to get address from addressId
-
 
211
		return " test ";
246
		return orderDetails.toString() + " ";
212
	}
247
	}
213
 
248
 
214
	public static String getBillingAddress(long cartId){
249
	public static String getBillingAddress(long txnId){		
-
 
250
	Transaction transaction;
-
 
251
	StringBuilder orderDetails = new StringBuilder();
-
 
252
	try {
-
 
253
		TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
215
		//in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
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_address()!=null){
216
		//TODO		write function to get shipping and billing address
263
				orderDetails.append(order.getCustomer_address());
-
 
264
			}
-
 
265
			if(order.getCustomer_city()!=null){
-
 
266
				orderDetails.append(order.getCustomer_city());
-
 
267
			}
-
 
268
			if(order.getCustomer_state()!=null){
-
 
269
				orderDetails.append(order.getCustomer_state());
-
 
270
			}
-
 
271
			if(order.getCustomer_pincode()!=null){
-
 
272
				orderDetails.append(order.getCustomer_pincode());
-
 
273
			}
-
 
274
		}
-
 
275
		
-
 
276
	} catch (ShoppingCartException e) {
-
 
277
		e.printStackTrace();
-
 
278
	} catch (TException e) {
-
 
279
		e.printStackTrace();
-
 
280
	} catch (Exception e) {
217
		return " test ";
281
		e.printStackTrace();
218
	}
282
	}
219
	
283
	
220
	public static String getItemName(long itemId){
284
	return orderDetails.toString() + " ";
221
		//TODO		write function to get item name given item id
-
 
222
		return "test";
-
 
223
	}
-
 
224
 
-
 
225
 
285
 
-
 
286
	}
-
 
287
	
-
 
288
	
226
	public static String getNameOfUser(long userId) {
289
	public static String getNameOfUser(long userId) {
227
		String name = "";
290
		String name = " ";
228
		try {
291
		try {
229
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
292
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
230
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
293
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
231
			
294
			
232
			name = userClient.getUserById(userId).getName();
295
			name = userClient.getUserById(userId).getName();