Subversion Repositories SmartDukaan

Rev

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

Rev 421 Rev 424
Line 1... Line 1...
1
package in.shop2020.serving.utils;
1
package in.shop2020.serving.utils;
2
 
2
 
-
 
3
import java.util.ArrayList;
-
 
4
import java.util.HashMap;
3
import java.util.Iterator;
5
import java.util.Iterator;
4
import java.util.List;
6
import java.util.List;
5
import java.util.Map;
7
import java.util.Map;
-
 
8
import java.util.Map.Entry;
6
 
9
 
7
import in.shop2020.model.v1.catalog.InventoryServiceException;
10
import in.shop2020.model.v1.catalog.InventoryServiceException;
-
 
11
import in.shop2020.model.v1.catalog.Item;
-
 
12
import in.shop2020.model.v1.catalog.InventoryService.Client;
-
 
13
import in.shop2020.model.v1.shoppingcart.Cart;
8
import in.shop2020.model.v1.shoppingcart.Line;
14
import in.shop2020.model.v1.shoppingcart.Line;
9
import in.shop2020.model.v1.shoppingcart.ShoppingCartException;
15
import in.shop2020.model.v1.shoppingcart.ShoppingCartException;
10
import in.shop2020.model.v1.user.Address;
16
import in.shop2020.model.v1.user.Address;
11
import in.shop2020.model.v1.user.UserContextException;
17
import in.shop2020.model.v1.user.UserContextException;
12
import in.shop2020.thrift.clients.CatalogServiceClient;
18
import in.shop2020.thrift.clients.CatalogServiceClient;
Line 147... Line 153...
147
		} catch (TException e) {
153
		} catch (TException e) {
148
			// TODO Auto-generated catch block
154
			// TODO Auto-generated catch block
149
			e.printStackTrace();
155
			e.printStackTrace();
150
		}
156
		}
151
		for (Line line : lineItems) {
157
		for (Line line : lineItems) {
152
			orderDetails.append("Item Id : " + line.getItemId() + "\n");
158
			orderDetails.append("Item Id : " + line.getItemId() + "   ");
153
			orderDetails.append("Item Name : " + Utils.getItemName(line.getItemId()) + "\n");
159
			orderDetails.append("Item Name : " + Utils.getItemName(line.getItemId()) + "   ");
154
			orderDetails.append("Item Quantity : " + line.getQuantity() + "\n");
160
			orderDetails.append("Item Quantity : " + line.getQuantity() + "   ");
155
		}
161
		}
156
		return orderDetails.toString();
162
		return orderDetails.toString();
157
	}
163
	}
158
	
164
	
159
	public static String getContactNumber(long cartId){
165
	public static String getContactNumber(long cartId){
Line 161... Line 167...
161
//		in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
167
//		in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
162
		
168
		
163
//		userClient.getPrimaryInfo(userId, false).getAddresses()
169
//		userClient.getPrimaryInfo(userId, false).getAddresses()
164
//		cartClient.getCart(cartId).getAddressId()
170
//		cartClient.getCart(cartId).getAddressId()
165
//TODO		write function to get address from addressId
171
//TODO		write function to get address from addressId
166
		return "";
172
		return " test ";
167
	}
173
	}
168
 
174
 
169
	public static String getBillingAddress(long cartId){
175
	public static String getBillingAddress(long cartId){
170
		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
176
		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
171
		//TODO		write function to get shipping and billing address
177
		//TODO		write function to get shipping and billing address
172
		return "";
178
		return " test ";
173
	}
179
	}
174
	
180
	
175
	public static String getItemName(long itemId){
181
	public static String getItemName(long itemId){
176
		//TODO		write function to get item name given item id
182
		//TODO		write function to get item name given item id
177
		return "";
183
		return "test";
-
 
184
	}
-
 
185
 
-
 
186
 
-
 
187
	public static String getNameOfUser(long userId) {
-
 
188
		in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
189
		String name = "";
-
 
190
		
-
 
191
		try {
-
 
192
			name = userClient.getPrimaryInfo(userId, false).getFirstName();
-
 
193
		} catch (UserContextException e) {
-
 
194
			// TODO Auto-generated catch block
-
 
195
			e.printStackTrace();
-
 
196
		} catch (TException e) {
-
 
197
			// TODO Auto-generated catch block
-
 
198
			e.printStackTrace();
-
 
199
		}
-
 
200
		return name; 
-
 
201
	}
-
 
202
	
-
 
203
	public static double getPaymentAmount(long cartId){
-
 
204
		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
-
 
205
		double totalAmount = 0;
-
 
206
		
-
 
207
		Cart cart;
-
 
208
		try {
-
 
209
			cart = cartClient.getCart(cartId);
-
 
210
		
-
 
211
			List<Line> lineItems = cart.getLines(); 
-
 
212
		
-
 
213
			for (Line line : lineItems) {
-
 
214
				long productId = line.getItemId();
-
 
215
				totalAmount =  totalAmount + line.getQuantity() * Utils.getItemPriceByCatalogId(productId);
-
 
216
			}
-
 
217
 
-
 
218
		} catch (ShoppingCartException e) {
-
 
219
			// TODO Auto-generated catch block
-
 
220
			e.printStackTrace();
-
 
221
		} catch (TException e) {
-
 
222
			// TODO Auto-generated catch block
-
 
223
			e.printStackTrace();
-
 
224
		}
-
 
225
 
-
 
226
		return totalAmount;
178
	}
227
	}
179
	
228
	
-
 
229
	public static double getItemPriceByCatalogId(long productId){
-
 
230
		CatalogServiceClient catalogServiceClient = null;
-
 
231
		Client client = null;
-
 
232
		Double itemPrice = 0.0;
-
 
233
		try {
-
 
234
			catalogServiceClient = new CatalogServiceClient();
-
 
235
			client = catalogServiceClient.getClient();
-
 
236
			Item item = client.getItemByCatalogId(productId);
-
 
237
			Map<Long,Double> priceMap = item.getPrice();
-
 
238
			if(priceMap == null || priceMap.isEmpty()){
-
 
239
				System.out.println("Price Not Found");
-
 
240
			}else{
-
 
241
				for(Entry<Long, Double> e: priceMap.entrySet()){
-
 
242
					itemPrice = e.getValue();
-
 
243
				}
-
 
244
			}
-
 
245
		}
-
 
246
		catch(Exception e){
-
 
247
			e.printStackTrace();
-
 
248
		}
-
 
249
		return itemPrice;
-
 
250
	}
-
 
251
 
180
}
252
}
181
	
253
	
182
254