Subversion Repositories SmartDukaan

Rev

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

Rev 424 Rev 507
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
3
import in.shop2020.model.v1.order.LineItem;
-
 
4
import in.shop2020.model.v1.order.OrderInfo;
-
 
5
import in.shop2020.model.v1.order.Transaction;
-
 
6
import in.shop2020.model.v1.shoppingcart.Cart;
-
 
7
import in.shop2020.model.v1.shoppingcart.Line;
-
 
8
import in.shop2020.model.v1.shoppingcart.ShadowCart;
-
 
9
import in.shop2020.model.v1.shoppingcart.ShoppingCartException;
-
 
10
import in.shop2020.serving.controllers.BaseController;
3
import in.shop2020.serving.controllers.BaseController;
11
import in.shop2020.serving.pages.PageContentKeys;
4
import in.shop2020.serving.pages.PageContentKeys;
12
import in.shop2020.serving.pages.PageEnum;
5
import in.shop2020.serving.pages.PageEnum;
13
import in.shop2020.serving.pages.PageManager;
6
import in.shop2020.serving.pages.PageManager;
14
import in.shop2020.thrift.clients.ShoppingCartClient;
-
 
15
import in.shop2020.thrift.clients.TransactionServiceClient;
-
 
16
import in.shop2020.thrift.clients.UserContextServiceClient;
-
 
17
 
-
 
18
import java.util.*;
7
import java.util.*;
19
 
8
 
20
import javax.servlet.http.Cookie;
-
 
21
import javax.servlet.http.HttpServletRequest;
-
 
22
 
-
 
23
import org.apache.commons.lang.StringUtils;
-
 
24
import org.apache.juli.logging.Log;
9
import org.apache.juli.logging.Log;
25
import org.apache.juli.logging.LogFactory;
10
import org.apache.juli.logging.LogFactory;
26
import org.apache.struts2.convention.annotation.Result;
11
import org.apache.struts2.convention.annotation.Result;
27
import org.apache.struts2.convention.annotation.Results;
12
import org.apache.struts2.convention.annotation.Results;
28
import org.apache.struts2.interceptor.ParameterAware;
13
import org.apache.struts2.interceptor.ParameterAware;
29
import org.apache.struts2.interceptor.ServletRequestAware;
-
 
30
import org.apache.struts2.rest.DefaultHttpHeaders;
14
import org.apache.struts2.rest.DefaultHttpHeaders;
31
import org.apache.struts2.rest.HttpHeaders;
15
import org.apache.struts2.rest.HttpHeaders;
32
import org.apache.thrift.TException;
-
 
33
 
-
 
34
import com.opensymphony.xwork2.ValidationAwareSupport;
-
 
35
 
16
 
36
@Results({
17
@Results({
37
    @Result(name="success", type="redirectAction", 
18
	@Result(name="redirect", location="${url}", type="redirect")
38
    		params = {"actionName" , "order"})
-
 
39
})
19
})
40
 
-
 
41
public class OrderController extends BaseController implements ParameterAware {
20
public class OrderController extends BaseController implements ParameterAware {
42
	
21
	
43
	private static final long serialVersionUID = 1L;
22
	private static final long serialVersionUID = 1L;
44
	
23
	
-
 
24
	private PageManager pageManager = null;
45
	private Map<String, String[]> reqparams;
25
	private Map<String, String[]> reqparams;
46
	private Map<String, Object> sessions;
-
 
47
	private String redirectURL;
26
	private String redirectUrl;
48
	private static Log log = LogFactory.getLog(OrderController.class);
27
	private static Log log = LogFactory.getLog(OrderController.class);
49
	private String cartId;
28
	private String id;
50
	//HttpServletRequest request;
-
 
51
	private Map<String,String> htmlSnippets;
29
	private Map<String,String> htmlSnippets;
52
	
30
	
53
	public OrderController(){
31
	public OrderController(){
54
		
32
		super();
-
 
33
		pageManager = PageManager.getPageManager();
55
	}
34
	}
56
	
35
	
57
	
36
	
58
	 // GET /entity
-
 
59
    public HttpHeaders index() {
-
 
60
    	return new DefaultHttpHeaders("index").disableCaching();
-
 
61
    }
-
 
62
    
-
 
63
    // POST /entity
37
    // GET /order/ orderid
64
    public String create() {
38
    public String show() {
65
    	log.info("OrderController.create");
39
    	log.info("id=" + id);
66
    	if(!userinfo.isLoggedIn()){
40
    	if(!userinfo.isLoggedIn()){
67
    		//redirect to the login or signIn page and it should be redirected back once user is logged in 
-
 
68
    	}else{
-
 
69
    		//Display the cart, amount, payment options and address along with pay button
-
 
70
    		
-
 
71
    		long userId = this.userinfo.getUserId();
41
    		this.redirectUrl = "login";
72
    		createOrderFromCart(userId);
42
    		return "redirect";
73
    	}
43
    	}
74
    	
44
    	
-
 
45
    	Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
-
 
46
    	
-
 
47
    	params.put(PageContentKeys.ORDER_ID, id);
-
 
48
    	params.put(PageContentKeys.USER_ID, new Long(userinfo.getUserId()).toString());
-
 
49
    	params.put(PageContentKeys.CART_ID, new Long(userinfo.getCartId()).toString());
-
 
50
    	params.put(PageContentKeys.SESSION_ID, new Long(userinfo.getSessionId()).toString());
-
 
51
    	params.put(PageContentKeys.USER_NAME, userinfo.getNameOfUser());
-
 
52
    	params.put(PageContentKeys.ITEM_COUNT, new Long(userinfo.getTotalItems()).toString());
-
 
53
    	
-
 
54
    	htmlSnippets = pageManager.getPageContents(PageEnum.ORDER_DETAILS_PAGE, params);
75
		return "success";
55
    	return "show";
76
    }
56
    }
77
    
57
    
78
  
-
 
79
    
-
 
80
    private	void createOrderFromCart(long userId){
-
 
81
		ShoppingCartClient shoppingCartClient = null;
-
 
82
		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = null;
-
 
83
		try{
-
 
84
			shoppingCartClient = new ShoppingCartClient();
-
 
85
			cartClient = shoppingCartClient.getClient();
-
 
86
			
-
 
87
			long cartId = cartClient.getCurrentCart(userId, false).getId();
-
 
88
			
-
 
89
			cartClient.commitCart(cartId);
-
 
90
		} catch (ShoppingCartException e) {
-
 
91
			// TODO Auto-generated catch block
-
 
92
			e.printStackTrace();
58
	public String getId(){
93
		} catch (TException e) {
-
 
94
			// TODO Auto-generated catch block
-
 
95
			e.printStackTrace();
59
		return id;
96
		} catch (Exception e) {
-
 
97
			// TODO Auto-generated catch block
-
 
98
			e.printStackTrace();
-
 
99
		}
60
	}
100
    }
-
 
101
	
61
	
-
 
62
	public void setId(String id){
-
 
63
		this.id = id;
-
 
64
	}
102
	
65
	
103
	@Override
66
    @Override
104
	public void setParameters(Map<String, String[]> reqmap) {
67
	public void setParameters(Map<String, String[]> reqmap) {
105
		log.info("setParameters:" + reqmap);
68
		log.info("setParameters:" + reqmap);
106
		
69
		
107
		this.reqparams = reqmap;
70
		this.reqparams = reqmap;
108
	}
71
	}
-
 
72
	 
-
 
73
    public String getHeaderSnippet(){
-
 
74
		return htmlSnippets.get("HEADER");
-
 
75
	}
-
 
76
	
-
 
77
	public String getMainMenuSnippet(){
-
 
78
		return htmlSnippets.get("MAIN_MENU");
-
 
79
	}
-
 
80
	
-
 
81
	public String getSearchBarSnippet(){
-
 
82
		return htmlSnippets.get("SEARCH_BAR");
-
 
83
	}
-
 
84
			
-
 
85
	
-
 
86
	public String getCustomerServiceSnippet(){
-
 
87
		return htmlSnippets.get("CUSTOMER_SERVICE");
-
 
88
	}
-
 
89
	
-
 
90
	public String getMyaccountHeaderSnippet(){
-
 
91
		return htmlSnippets.get("MYACCOUNT_HEADER");
-
 
92
	}
-
 
93
	
-
 
94
	public String getOrderDetailsSnippet(){
-
 
95
		return htmlSnippets.get("ORDER_DETAILS");
-
 
96
	}
-
 
97
	
-
 
98
	public String getMyResearchSnippet(){
-
 
99
		return htmlSnippets.get("MY_RESEARCH");
-
 
100
	}
-
 
101
				
-
 
102
	public String getFooterSnippet(){
-
 
103
		return htmlSnippets.get("FOOTER");
-
 
104
	}
-
 
105
	
-
 
106
	public String getJsFileSnippet(){
-
 
107
		return htmlSnippets.get("JS_FILES");
-
 
108
	}
-
 
109
	
-
 
110
	public String getCssFileSnippet(){
-
 
111
		return htmlSnippets.get("CSS_FILES");
-
 
112
	}
109
	
113
	
110
//	@Override
-
 
111
//	public void setServletRequest(HttpServletRequest request) {
-
 
112
//		this.request = request;
-
 
113
//	}
-
 
114
//    
-
 
115
}
114
}