| 5559 |
rajveer |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
|
| 5678 |
rajveer |
5 |
import in.shop2020.model.v1.order.Attribute;
|
| 5559 |
rajveer |
6 |
import in.shop2020.model.v1.order.Order;
|
|
|
7 |
import in.shop2020.model.v1.order.TransactionService.Client;
|
|
|
8 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
|
|
9 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
10 |
|
| 5678 |
rajveer |
11 |
import java.util.ArrayList;
|
| 5559 |
rajveer |
12 |
import java.util.Calendar;
|
|
|
13 |
import java.util.List;
|
|
|
14 |
|
|
|
15 |
import javax.servlet.ServletContext;
|
|
|
16 |
import javax.servlet.http.HttpServletRequest;
|
|
|
17 |
import javax.servlet.http.HttpServletResponse;
|
|
|
18 |
|
|
|
19 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
20 |
import org.apache.struts2.interceptor.ServletResponseAware;
|
|
|
21 |
import org.apache.struts2.util.ServletContextAware;
|
|
|
22 |
import org.apache.thrift.TException;
|
|
|
23 |
import org.apache.thrift.transport.TTransportException;
|
|
|
24 |
import org.slf4j.Logger;
|
|
|
25 |
import org.slf4j.LoggerFactory;
|
|
|
26 |
|
|
|
27 |
public class PickupStoreController implements ServletResponseAware, ServletRequestAware, ServletContextAware {
|
|
|
28 |
|
|
|
29 |
private static Logger logger = LoggerFactory.getLogger(PickupStoreController.class);
|
|
|
30 |
|
|
|
31 |
private HttpServletRequest request;
|
|
|
32 |
private HttpServletResponse response;
|
|
|
33 |
private ServletContext context;
|
|
|
34 |
private String storeIdString;
|
|
|
35 |
private long storeId;
|
| 5678 |
rajveer |
36 |
private String id;
|
|
|
37 |
private String error = "";
|
| 5693 |
rajveer |
38 |
private Client client;
|
| 5559 |
rajveer |
39 |
|
| 5693 |
rajveer |
40 |
public PickupStoreController() throws TTransportException{
|
|
|
41 |
client = (new TransactionClient()).getClient();
|
|
|
42 |
}
|
|
|
43 |
|
| 5559 |
rajveer |
44 |
@Override
|
|
|
45 |
public void setServletRequest(HttpServletRequest req) {
|
|
|
46 |
this.request = req;
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
public HttpServletRequest getServletRequest() {
|
|
|
50 |
return request;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
@Override
|
|
|
54 |
public void setServletResponse(HttpServletResponse res) {
|
|
|
55 |
this.response = res;
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
public HttpServletResponse getServletResponse() {
|
|
|
59 |
return response;
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
@Override
|
|
|
63 |
public void setServletContext(ServletContext context) {
|
|
|
64 |
this.context = context;
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
public String getServletContextPath() {
|
|
|
68 |
return context.getContextPath();
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
public String index(){
|
|
|
72 |
storeIdString = (String) request.getSession().getAttribute("STORE_ID");
|
|
|
73 |
if(storeIdString == null){
|
|
|
74 |
storeIdString = request.getParameter("storeid");
|
|
|
75 |
if(storeIdString == null){
|
|
|
76 |
return "authfail";
|
|
|
77 |
}else{
|
|
|
78 |
request.getSession().setAttribute("STORE_ID", storeIdString);
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
storeId = Long.parseLong(storeIdString);
|
|
|
82 |
return "index";
|
|
|
83 |
}
|
| 5678 |
rajveer |
84 |
|
|
|
85 |
public String show(){
|
|
|
86 |
storeIdString = (String) request.getSession().getAttribute("STORE_ID");
|
|
|
87 |
if(storeIdString == null){
|
|
|
88 |
storeIdString = request.getParameter("storeid");
|
|
|
89 |
if(storeIdString == null){
|
|
|
90 |
return "authfail";
|
|
|
91 |
}else{
|
|
|
92 |
request.getSession().setAttribute("STORE_ID", storeIdString);
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
storeId = Long.parseLong(storeIdString);
|
|
|
96 |
return "show";
|
|
|
97 |
}
|
| 5559 |
rajveer |
98 |
|
|
|
99 |
// Handles the POST request (Form Submission)
|
|
|
100 |
public String create() {
|
|
|
101 |
storeIdString = (String) request.getSession().getAttribute("STORE_ID");
|
|
|
102 |
if(storeIdString == null){
|
|
|
103 |
return "authfail";
|
|
|
104 |
}
|
|
|
105 |
storeId = Long.parseLong(storeIdString);
|
|
|
106 |
String orderIdString = request.getParameter("orderid");
|
|
|
107 |
String action = request.getParameter("action");
|
| 5693 |
rajveer |
108 |
try {
|
|
|
109 |
Client client = (new TransactionClient()).getClient();
|
|
|
110 |
if(action.equals("markreceived")){
|
|
|
111 |
long orderId = Long.parseLong(orderIdString);
|
|
|
112 |
client.markOrderAsReceivedAtStore(orderId, Calendar.getInstance().getTimeInMillis());
|
|
|
113 |
}else if(action.equals("markdelivered")){
|
|
|
114 |
long orderId = Long.parseLong(orderIdString);
|
|
|
115 |
String receiver = request.getParameter("receiver");
|
|
|
116 |
String secretCode = request.getParameter("secretcode");
|
|
|
117 |
Order order = client.getOrder(orderId);
|
|
|
118 |
List<Attribute> attributes = client.getAllAttributesForOrderId(orderId);
|
|
|
119 |
for(Attribute attribute: attributes){
|
|
|
120 |
if(attribute.getName().equals("SECRET_CODE")){
|
|
|
121 |
if(!attribute.getValue().equalsIgnoreCase(secretCode)){
|
|
|
122 |
error = "Secret code does not match";
|
| 5678 |
rajveer |
123 |
}
|
|
|
124 |
}
|
| 5693 |
rajveer |
125 |
}
|
|
|
126 |
List<Attribute> newAttributes = new ArrayList<Attribute>();
|
|
|
127 |
if(order.isCod()){
|
|
|
128 |
double amount = Double.parseDouble(request.getParameter("amount"));
|
|
|
129 |
if(order.getTotal_amount() != amount){
|
|
|
130 |
error = "<br>Amount does not match";
|
|
|
131 |
}
|
|
|
132 |
}
|
|
|
133 |
if(!error.equalsIgnoreCase("")){
|
|
|
134 |
setId("deliver");
|
|
|
135 |
return show();
|
|
|
136 |
}else{
|
| 5678 |
rajveer |
137 |
if(order.isCod()){
|
| 5693 |
rajveer |
138 |
String paymentType = request.getParameter("paymenttype");
|
|
|
139 |
newAttributes.add(new Attribute("PAYMENT_MODE", paymentType));
|
|
|
140 |
client.setOrderAttributes(orderId, newAttributes);
|
| 5678 |
rajveer |
141 |
}
|
| 5559 |
rajveer |
142 |
}
|
| 5693 |
rajveer |
143 |
client.markOrderAsDelivered(Long.parseLong(orderIdString), Calendar.getInstance().getTimeInMillis(), receiver);
|
|
|
144 |
}else if(action.equals("markreturned")){
|
|
|
145 |
String orderIdsString = request.getParameter("orderIds");
|
|
|
146 |
long providerId = Long.parseLong(request.getParameter("providerID"));
|
|
|
147 |
List<Long> orderIds = new ArrayList<Long>();
|
|
|
148 |
for(String orderIdString1: orderIdsString.split(":")){
|
|
|
149 |
orderIds.add(Long.parseLong(orderIdString1));
|
|
|
150 |
}
|
|
|
151 |
client.markOrdersAsReturnedFromStore(providerId, orderIds);
|
| 5559 |
rajveer |
152 |
}
|
| 5693 |
rajveer |
153 |
|
|
|
154 |
return "index";
|
|
|
155 |
} catch (TTransportException e) {
|
|
|
156 |
// TODO Auto-generated catch block
|
|
|
157 |
e.printStackTrace();
|
|
|
158 |
} catch (NumberFormatException e) {
|
|
|
159 |
// TODO Auto-generated catch block
|
|
|
160 |
e.printStackTrace();
|
|
|
161 |
} catch (TransactionServiceException e) {
|
|
|
162 |
// TODO Auto-generated catch block
|
|
|
163 |
e.printStackTrace();
|
|
|
164 |
} catch (TException e) {
|
|
|
165 |
// TODO Auto-generated catch block
|
|
|
166 |
e.printStackTrace();
|
|
|
167 |
}
|
| 5559 |
rajveer |
168 |
return "index";
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
|
|
|
172 |
public List<Order> getReceivePendingOrders() throws TException{
|
|
|
173 |
Client client = (new TransactionClient()).getClient();
|
|
|
174 |
return client.getReceivePendingOrders(storeId);
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
public List<Order> getReceivedAtStoreOrders() throws TException{
|
|
|
178 |
Client client = (new TransactionClient()).getClient();
|
|
|
179 |
return client.getReceivedAtStoreOrders(storeId);
|
|
|
180 |
}
|
| 5678 |
rajveer |
181 |
|
| 5693 |
rajveer |
182 |
public String getSecretCode(long orderId) throws TException{
|
|
|
183 |
List<Attribute> attributes = client.getAllAttributesForOrderId(orderId);
|
|
|
184 |
for(Attribute attribute: attributes){
|
|
|
185 |
if(attribute.getName() == "SECRET_CODE"){
|
|
|
186 |
return attribute.getValue();
|
|
|
187 |
}
|
|
|
188 |
}
|
|
|
189 |
return "";
|
|
|
190 |
}
|
|
|
191 |
|
| 5678 |
rajveer |
192 |
public void setId(String id) {
|
|
|
193 |
this.id = id;
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
public String getId() {
|
|
|
197 |
return id;
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
public void setError(String error) {
|
|
|
201 |
this.error = error;
|
|
|
202 |
}
|
|
|
203 |
|
|
|
204 |
public String getError() {
|
|
|
205 |
return error;
|
|
|
206 |
}
|
|
|
207 |
|
|
|
208 |
public long getStoreId(){
|
|
|
209 |
return storeId;
|
|
|
210 |
}
|
|
|
211 |
|
| 5559 |
rajveer |
212 |
}
|