Subversion Repositories SmartDukaan

Rev

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

Rev 536 Rev 555
Line 10... Line 10...
10
import in.shop2020.model.v1.order.Payment;
10
import in.shop2020.model.v1.order.Payment;
11
import in.shop2020.model.v1.order.PaymentInfo;
11
import in.shop2020.model.v1.order.PaymentInfo;
12
import in.shop2020.model.v1.order.PaymentStatus;
12
import in.shop2020.model.v1.order.PaymentStatus;
13
import in.shop2020.model.v1.order.Transaction;
13
import in.shop2020.model.v1.order.Transaction;
14
import in.shop2020.model.v1.order.TransactionStatus;
14
import in.shop2020.model.v1.order.TransactionStatus;
15
import in.shop2020.model.v1.shoppingcart.Cart;
15
import in.shop2020.model.v1.user.Cart;
16
import in.shop2020.model.v1.shoppingcart.Line;
-
 
17
import in.shop2020.model.v1.shoppingcart.LineStatus;
16
import in.shop2020.model.v1.user.LineStatus;
18
import in.shop2020.model.v1.shoppingcart.ShoppingCartException;
17
import in.shop2020.model.v1.user.ShoppingCartException;
19
import in.shop2020.model.v1.user.Address;
18
import in.shop2020.model.v1.user.Address;
20
import in.shop2020.model.v1.user.UserContextException;
19
import in.shop2020.model.v1.user.UserContextException;
21
import in.shop2020.payments.PaymentException;
20
import in.shop2020.payments.PaymentException;
22
import in.shop2020.serving.controllers.BaseController;
21
import in.shop2020.serving.controllers.BaseController;
23
import in.shop2020.serving.pages.PageContentKeys;
22
import in.shop2020.serving.pages.PageContentKeys;
24
import in.shop2020.serving.pages.PageEnum;
23
import in.shop2020.serving.pages.PageEnum;
25
import in.shop2020.serving.pages.PageManager;
24
import in.shop2020.serving.pages.PageManager;
26
import in.shop2020.serving.services.PageLoaderHandler;
25
import in.shop2020.serving.services.PageLoaderHandler;
27
import in.shop2020.thrift.clients.CatalogServiceClient;
26
import in.shop2020.thrift.clients.CatalogServiceClient;
28
import in.shop2020.thrift.clients.LogisticsServiceClient;
27
import in.shop2020.thrift.clients.LogisticsServiceClient;
29
import in.shop2020.thrift.clients.ShoppingCartClient;
-
 
30
import in.shop2020.thrift.clients.TransactionServiceClient;
28
import in.shop2020.thrift.clients.TransactionServiceClient;
31
import in.shop2020.thrift.clients.UserContextServiceClient;
29
import in.shop2020.thrift.clients.UserContextServiceClient;
32
 
30
 
33
import java.util.*;
31
import java.util.*;
34
 
32
 
Line 73... Line 71...
73
    	Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
71
    	Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
74
    	
72
    	
75
    	params.put(PageContentKeys.ORDER_ID, id);
73
    	params.put(PageContentKeys.ORDER_ID, id);
76
    	params.put(PageContentKeys.USER_ID, new Long(userinfo.getUserId()).toString());
74
    	params.put(PageContentKeys.USER_ID, new Long(userinfo.getUserId()).toString());
77
    	params.put(PageContentKeys.CART_ID, new Long(userinfo.getCartId()).toString());
75
    	params.put(PageContentKeys.CART_ID, new Long(userinfo.getCartId()).toString());
78
    	params.put(PageContentKeys.SESSION_ID, new Long(userinfo.getSessionId()).toString());
-
 
79
    	params.put(PageContentKeys.USER_NAME, userinfo.getNameOfUser());
76
    	params.put(PageContentKeys.USER_NAME, userinfo.getNameOfUser());
80
    	params.put(PageContentKeys.ITEM_COUNT, new Long(userinfo.getTotalItems()).toString());
77
    	params.put(PageContentKeys.ITEM_COUNT, new Long(userinfo.getTotalItems()).toString());
81
    	
78
    	
82
    	htmlSnippets = pageManager.getPageContents(PageEnum.ORDER_DETAILS_PAGE, params);
79
    	htmlSnippets = pageManager.getPageContents(PageEnum.ORDER_DETAILS_PAGE, params);
83
    	return "show";
80
    	return "show";
Line 140... Line 137...
140
	}
137
	}
141
 
138
 
142
    // POST /order/
139
    // POST /order/
143
    public String create() throws Exception {
140
    public String create() throws Exception {
144
    	long addressId = Long.parseLong(this.request.getParameter("addressid"));
141
    	long addressId = Long.parseLong(this.request.getParameter("addressid"));
145
    	ShoppingCartClient cl = new ShoppingCartClient();
142
    	UserContextServiceClient cl = new UserContextServiceClient();
146
    	cl.getClient().addAddressToCart(userinfo.getCartId(), addressId);
143
    	cl.getClient().addAddressToCart(userinfo.getCartId(), addressId);
147
    	
144
    	
148
		Transaction t = getTransaction();
145
		Transaction t = getTransaction();
149
		TransactionServiceClient tsc = new TransactionServiceClient();
146
		TransactionServiceClient tsc = new TransactionServiceClient();
150
		long transaction_id = tsc.getClient().createTransaction(t);
147
		long transaction_id = tsc.getClient().createTransaction(t);
Line 163... Line 160...
163
		userinfo.setTotalItems(0);
160
		userinfo.setTotalItems(0);
164
		this.session.setAttribute("userinfo", userinfo);
161
		this.session.setAttribute("userinfo", userinfo);
165
		
162
		
166
		PageLoaderHandler pageLoader = new PageLoaderHandler();
163
		PageLoaderHandler pageLoader = new PageLoaderHandler();
167
		htmlSnippets = new HashMap<String, String>();
164
		htmlSnippets = new HashMap<String, String>();
168
		htmlSnippets.put("HEADER", pageLoader.getHeaderHtml(userinfo.getUserId(), userinfo.isSessionId(), userinfo.getNameOfUser()));
165
		htmlSnippets.put("HEADER", pageLoader.getHeaderHtml(userinfo.isLoggedIn(), userinfo.getNameOfUser()));
169
		htmlSnippets.put("MAIN_MENU", pageLoader.getMainMenuHtml());
166
		htmlSnippets.put("MAIN_MENU", pageLoader.getMainMenuHtml());
170
		htmlSnippets.put("SEARCH_BAR", pageLoader.getSearchBarHtml(userinfo.getTotalItems(), 10000));
167
		htmlSnippets.put("SEARCH_BAR", pageLoader.getSearchBarHtml(userinfo.getTotalItems(), 10000));
171
		htmlSnippets.put("CUSTOMER_SERVICE", pageLoader.getCustomerServiceHtml());
168
		htmlSnippets.put("CUSTOMER_SERVICE", pageLoader.getCustomerServiceHtml());
172
		htmlSnippets.put("FOOTER",pageLoader.getFooterHtml());
169
		htmlSnippets.put("FOOTER",pageLoader.getFooterHtml());
173
		
170
		
Line 193... Line 190...
193
		return t;
190
		return t;
194
	}
191
	}
195
 
192
 
196
	private List<Order> getOrders(){
193
	private List<Order> getOrders(){
197
		List<Order> orders = new ArrayList<Order>();
194
		List<Order> orders = new ArrayList<Order>();
198
		ShoppingCartClient cl = null;
195
		UserContextServiceClient usc = null;
199
		Cart c = null;
196
		Cart c = null;
200
		try {
197
		try {
201
			cl = new ShoppingCartClient();
198
			usc = new UserContextServiceClient();
202
			c = cl.getClient().getCart(userinfo.getCartId());
199
			c = usc.getClient().getCart(userinfo.getCartId());
203
		} catch (ShoppingCartException e) {
200
		} catch (ShoppingCartException e) {
204
			// TODO Auto-generated catch block
-
 
205
			e.printStackTrace();
201
			e.printStackTrace();
206
		} catch (TException e) {
202
		} catch (TException e) {
207
			// TODO Auto-generated catch block
-
 
208
			e.printStackTrace();
203
			e.printStackTrace();
209
		} catch (Exception e) {
204
		} catch (Exception e) {
210
			// TODO Auto-generated catch block
-
 
211
			e.printStackTrace();
205
			e.printStackTrace();
212
		}
206
		}
213
		List<Line> lines = c.getLines();
207
		List<in.shop2020.model.v1.user.Line> cartLines = c.getLines();
214
		
208
		
215
		for(Line line : lines){
209
		for(in.shop2020.model.v1.user.Line cartLine : cartLines){
216
			if(line.getLineStatus() == LineStatus.LINE_ACTIVE){
210
			if(cartLine.getLineStatus() == LineStatus.LINE_ACTIVE){
217
				//line is active
211
				//line is active
218
				LineItem lineItem = getLineItem(line.getItemId());
212
				LineItem lineItem = getLineItem(cartLine.getItemId());
219
				// create orders equivalent to quantity. Create one order per item.
213
				// create orders equivalent to quantity. Create one order per item.
220
				for(int i= 0; i<line.getQuantity(); i++){
214
				for(int i= 0; i<cartLine.getQuantity(); i++){
221
					//  set order
215
					//  set order
222
					Order order = getOrder(c.getAddressId(), lineItem);
216
					Order order = getOrder(c.getAddressId(), lineItem);
223
					order.addToLineitems(lineItem);
217
					order.addToLineitems(lineItem);
224
					orders.add(order);
218
					orders.add(order);
225
				}
219
				}
Line 298... Line 292...
298
	private Address getAddress(long addressId){
292
	private Address getAddress(long addressId){
299
		List<Address> addresses = null;
293
		List<Address> addresses = null;
300
		
294
		
301
		try {
295
		try {
302
			UserContextServiceClient usc = new UserContextServiceClient();
296
			UserContextServiceClient usc = new UserContextServiceClient();
303
			addresses = usc.getClient().getPrimaryInfo(userinfo.getUserId(), false).getAddresses();
297
			addresses = usc.getClient().getUserById(userinfo.getUserId()).getAddresses();
304
		} catch (UserContextException e) {
298
		} catch (UserContextException e) {
305
			// TODO Auto-generated catch block
-
 
306
			e.printStackTrace();
299
			e.printStackTrace();
307
		} catch (TException e) {
300
		} catch (TException e) {
308
			// TODO Auto-generated catch block
-
 
309
			e.printStackTrace();
301
			e.printStackTrace();
310
		} catch (Exception e) {
302
		} catch (Exception e) {
311
			// TODO Auto-generated catch block
-
 
312
			e.printStackTrace();
303
			e.printStackTrace();
313
		}
304
		}
314
		Address address = null;
305
		Address address = null;
315
		for(Address a : addresses){
306
		for(Address a : addresses){
316
			if(a.getId() == addressId){
307
			if(a.getId() == addressId){
Line 326... Line 317...
326
		Item item = null;
317
		Item item = null;
327
		try {
318
		try {
328
			CatalogServiceClient csc = new CatalogServiceClient();
319
			CatalogServiceClient csc = new CatalogServiceClient();
329
			item = csc.getClient().getItemByCatalogId(catelogItemId);
320
			item = csc.getClient().getItemByCatalogId(catelogItemId);
330
		} catch (InventoryServiceException e) {
321
		} catch (InventoryServiceException e) {
331
			// TODO Auto-generated catch block
-
 
332
			e.printStackTrace();
322
			e.printStackTrace();
333
		} catch (TException e) {
323
		} catch (TException e) {
334
			// TODO Auto-generated catch block
-
 
335
			e.printStackTrace();
324
			e.printStackTrace();
336
		} catch (Exception e) {
325
		} catch (Exception e) {
337
			// TODO Auto-generated catch block
-
 
338
			e.printStackTrace();
326
			e.printStackTrace();
339
		}
327
		}
340
	
328
	
341
		String model_name = item.getModelName();
329
		String model_name = item.getModelName();
342
		String model_number = item.getModelNumber();
330
		String model_number = item.getModelNumber();