| 419 |
rajveer |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
| 517 |
rajveer |
3 |
import in.shop2020.model.v1.order.Order;
|
| 419 |
rajveer |
4 |
import in.shop2020.serving.controllers.BaseController;
|
|
|
5 |
import in.shop2020.serving.pages.PageContentKeys;
|
|
|
6 |
import in.shop2020.serving.pages.PageEnum;
|
|
|
7 |
import in.shop2020.serving.pages.PageManager;
|
| 536 |
rajveer |
8 |
import in.shop2020.serving.services.PageLoaderHandler;
|
| 517 |
rajveer |
9 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
|
|
10 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
|
|
11 |
|
| 419 |
rajveer |
12 |
import java.util.*;
|
|
|
13 |
|
|
|
14 |
import org.apache.juli.logging.Log;
|
|
|
15 |
import org.apache.juli.logging.LogFactory;
|
|
|
16 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
17 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
18 |
import org.apache.struts2.interceptor.ParameterAware;
|
| 517 |
rajveer |
19 |
import org.apache.thrift.TException;
|
| 419 |
rajveer |
20 |
|
|
|
21 |
@Results({
|
| 507 |
rajveer |
22 |
@Result(name="redirect", location="${url}", type="redirect")
|
| 419 |
rajveer |
23 |
})
|
|
|
24 |
public class OrderController extends BaseController implements ParameterAware {
|
|
|
25 |
|
|
|
26 |
private static final long serialVersionUID = 1L;
|
|
|
27 |
|
| 507 |
rajveer |
28 |
private PageManager pageManager = null;
|
| 419 |
rajveer |
29 |
private Map<String, String[]> reqparams;
|
| 507 |
rajveer |
30 |
private String redirectUrl;
|
| 419 |
rajveer |
31 |
private static Log log = LogFactory.getLog(OrderController.class);
|
| 507 |
rajveer |
32 |
private String id;
|
| 419 |
rajveer |
33 |
private Map<String,String> htmlSnippets;
|
| 517 |
rajveer |
34 |
|
|
|
35 |
private String message;
|
| 419 |
rajveer |
36 |
|
|
|
37 |
public OrderController(){
|
| 507 |
rajveer |
38 |
super();
|
|
|
39 |
pageManager = PageManager.getPageManager();
|
| 419 |
rajveer |
40 |
}
|
|
|
41 |
|
| 507 |
rajveer |
42 |
// GET /order/ orderid
|
|
|
43 |
public String show() {
|
|
|
44 |
log.info("id=" + id);
|
| 424 |
rajveer |
45 |
if(!userinfo.isLoggedIn()){
|
| 507 |
rajveer |
46 |
this.redirectUrl = "login";
|
|
|
47 |
return "redirect";
|
| 424 |
rajveer |
48 |
}
|
| 419 |
rajveer |
49 |
|
| 507 |
rajveer |
50 |
Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
|
|
|
51 |
|
|
|
52 |
params.put(PageContentKeys.ORDER_ID, id);
|
|
|
53 |
params.put(PageContentKeys.USER_ID, new Long(userinfo.getUserId()).toString());
|
|
|
54 |
params.put(PageContentKeys.CART_ID, new Long(userinfo.getCartId()).toString());
|
|
|
55 |
params.put(PageContentKeys.USER_NAME, userinfo.getNameOfUser());
|
|
|
56 |
params.put(PageContentKeys.ITEM_COUNT, new Long(userinfo.getTotalItems()).toString());
|
|
|
57 |
|
|
|
58 |
htmlSnippets = pageManager.getPageContents(PageEnum.ORDER_DETAILS_PAGE, params);
|
|
|
59 |
return "show";
|
| 419 |
rajveer |
60 |
}
|
| 517 |
rajveer |
61 |
|
| 572 |
chandransh |
62 |
// POST /order/
|
|
|
63 |
public String create(){
|
|
|
64 |
long addressId = Long.parseLong(this.request.getParameter("addressid"));
|
|
|
65 |
long currentCartId = userinfo.getCartId();
|
|
|
66 |
List<Order> orders = null;
|
|
|
67 |
try {
|
|
|
68 |
UserContextServiceClient userServiceClient = new UserContextServiceClient();
|
|
|
69 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
|
|
|
70 |
|
|
|
71 |
userClient.addAddressToCart(currentCartId, addressId);
|
|
|
72 |
Long txn_id = userClient.commitCart(currentCartId);
|
|
|
73 |
|
|
|
74 |
TransactionServiceClient tsc = new TransactionServiceClient();
|
|
|
75 |
orders = tsc.getClient().getOrdersForTransaction(txn_id);
|
|
|
76 |
|
|
|
77 |
long newCartId = userClient.getUserById(userinfo.getUserId()).getActiveCartId();
|
|
|
78 |
userinfo.setCartId(newCartId);
|
|
|
79 |
userinfo.setTotalItems(0);
|
|
|
80 |
} catch (TException e) {
|
|
|
81 |
e.printStackTrace();
|
|
|
82 |
} catch (Exception e) {
|
|
|
83 |
e.printStackTrace();
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
this.message = "Your order numbers are as below:";
|
|
|
87 |
|
|
|
88 |
for(Order order: orders){
|
|
|
89 |
this.message = this.message + "<br> <a href=\"./order/" + order.getId() + "\">" + order.getId() + "</a>";
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
PageLoaderHandler pageLoader = new PageLoaderHandler();
|
|
|
93 |
htmlSnippets = new HashMap<String, String>();
|
|
|
94 |
htmlSnippets.put("HEADER", pageLoader.getHeaderHtml(userinfo.isLoggedIn(), userinfo.getNameOfUser()));
|
|
|
95 |
htmlSnippets.put("MAIN_MENU", pageLoader.getMainMenuHtml());
|
|
|
96 |
htmlSnippets.put("SEARCH_BAR", pageLoader.getSearchBarHtml(userinfo.getTotalItems(), 10000));
|
|
|
97 |
htmlSnippets.put("CUSTOMER_SERVICE", pageLoader.getCustomerServiceHtml());
|
|
|
98 |
htmlSnippets.put("FOOTER",pageLoader.getFooterHtml());
|
|
|
99 |
|
|
|
100 |
return "success";
|
|
|
101 |
}
|
|
|
102 |
|
| 507 |
rajveer |
103 |
public String getId(){
|
|
|
104 |
return id;
|
|
|
105 |
}
|
| 419 |
rajveer |
106 |
|
| 507 |
rajveer |
107 |
public void setId(String id){
|
|
|
108 |
this.id = id;
|
|
|
109 |
}
|
| 419 |
rajveer |
110 |
|
| 507 |
rajveer |
111 |
@Override
|
| 419 |
rajveer |
112 |
public void setParameters(Map<String, String[]> reqmap) {
|
|
|
113 |
log.info("setParameters:" + reqmap);
|
|
|
114 |
|
|
|
115 |
this.reqparams = reqmap;
|
|
|
116 |
}
|
| 507 |
rajveer |
117 |
|
|
|
118 |
public String getHeaderSnippet(){
|
|
|
119 |
return htmlSnippets.get("HEADER");
|
|
|
120 |
}
|
| 419 |
rajveer |
121 |
|
| 507 |
rajveer |
122 |
public String getMainMenuSnippet(){
|
|
|
123 |
return htmlSnippets.get("MAIN_MENU");
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
public String getSearchBarSnippet(){
|
|
|
127 |
return htmlSnippets.get("SEARCH_BAR");
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
|
|
|
131 |
public String getCustomerServiceSnippet(){
|
|
|
132 |
return htmlSnippets.get("CUSTOMER_SERVICE");
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
public String getMyaccountHeaderSnippet(){
|
|
|
136 |
return htmlSnippets.get("MYACCOUNT_HEADER");
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
public String getOrderDetailsSnippet(){
|
|
|
140 |
return htmlSnippets.get("ORDER_DETAILS");
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
public String getMyResearchSnippet(){
|
|
|
144 |
return htmlSnippets.get("MY_RESEARCH");
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
public String getFooterSnippet(){
|
|
|
148 |
return htmlSnippets.get("FOOTER");
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
public String getJsFileSnippet(){
|
|
|
152 |
return htmlSnippets.get("JS_FILES");
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
public String getCssFileSnippet(){
|
|
|
156 |
return htmlSnippets.get("CSS_FILES");
|
|
|
157 |
}
|
|
|
158 |
|
| 517 |
rajveer |
159 |
public String getMessage(){
|
|
|
160 |
return this.message;
|
|
|
161 |
}
|
|
|
162 |
|
| 419 |
rajveer |
163 |
}
|