| 167 |
ashish |
1 |
package in.shop2020.hotspot.dashbaord.server.handler;
|
|
|
2 |
|
|
|
3 |
import java.util.ArrayList;
|
|
|
4 |
import java.util.Date;
|
|
|
5 |
import java.util.List;
|
|
|
6 |
|
|
|
7 |
import in.shop2020.hotspot.dashbaord.shared.actions.Order;
|
|
|
8 |
import in.shop2020.hotspot.dashbaord.shared.actions.OrderRequest;
|
|
|
9 |
import in.shop2020.hotspot.dashbaord.shared.actions.OrderResponse;
|
|
|
10 |
import in.shop2020.hotspot.dashbaord.shared.actions.OrderType;
|
| 306 |
ashish |
11 |
import in.shop2020.model.v1.order.Alert;
|
|
|
12 |
import in.shop2020.model.v1.order.ExtraOrderInfo;
|
| 167 |
ashish |
13 |
import in.shop2020.model.v1.order.Transaction;
|
|
|
14 |
import in.shop2020.model.v1.order.TransactionStatus;
|
|
|
15 |
import in.shop2020.model.v1.order.TransactionService.Client;
|
|
|
16 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
|
|
17 |
import net.customware.gwt.dispatch.server.ActionHandler;
|
|
|
18 |
import net.customware.gwt.dispatch.server.ExecutionContext;
|
|
|
19 |
import net.customware.gwt.dispatch.shared.ActionException;
|
|
|
20 |
|
|
|
21 |
public class OrderHandler implements ActionHandler<OrderRequest, OrderResponse>{
|
|
|
22 |
|
|
|
23 |
private OrderType type;
|
|
|
24 |
@Override
|
|
|
25 |
public OrderResponse execute(OrderRequest request, ExecutionContext context)
|
|
|
26 |
throws ActionException {
|
|
|
27 |
type = request.getType();
|
|
|
28 |
|
|
|
29 |
OrderResponse or = new OrderResponse(type, getInitTransactions());
|
|
|
30 |
return or;
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
@Override
|
|
|
34 |
public Class<OrderRequest> getActionType() {
|
|
|
35 |
// TODO Auto-generated method stub
|
|
|
36 |
return OrderRequest.class;
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
@Override
|
|
|
40 |
public void rollback(OrderRequest arg0, OrderResponse arg1,
|
|
|
41 |
ExecutionContext arg2) throws ActionException {
|
|
|
42 |
// TODO Auto-generated method stub
|
|
|
43 |
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
private List<Order> getInitTransactions(){
|
|
|
47 |
List<Order> orders = new ArrayList<Order>();
|
|
|
48 |
try{
|
|
|
49 |
TransactionServiceClient client = new TransactionServiceClient();
|
|
|
50 |
Client c = client.getClient();
|
|
|
51 |
List<Transaction> txns = c.getAllTransactions(TransactionStatus.INIT, 0L, new Date().getTime());
|
|
|
52 |
for (Transaction t: txns){
|
| 306 |
ashish |
53 |
long sku_id;
|
|
|
54 |
String model;
|
|
|
55 |
String vendor;
|
|
|
56 |
String colour;
|
|
|
57 |
ExtraOrderInfo eoi = c.getExtraInfo(t.getId());
|
|
|
58 |
if(eoi == null){
|
|
|
59 |
sku_id = 34;
|
|
|
60 |
model = "N 72";
|
|
|
61 |
colour = "Black";
|
|
|
62 |
vendor = "Nokia";
|
|
|
63 |
}else{
|
|
|
64 |
sku_id = eoi.getSku_id();
|
|
|
65 |
model = eoi.getModel_name();
|
|
|
66 |
vendor = eoi.getVendor_info();
|
|
|
67 |
colour = eoi.getColour();
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
Order o = new Order(t.getCustomer_id(), t.getId(), t.getCreatedOn(), t.getExpectedDeliveryTime(), t.getTransactionStatus().toString(), t.getStatusDescription(), model, colour, vendor, sku_id);
|
|
|
71 |
//Order o = new Order(t.getCustomer_id(), t.getId(), t.getCreatedOn(), t.getExpectedDeliveryTime(), t.getTransactionStatus().toString(), t.getStatusDescription());
|
| 167 |
ashish |
72 |
orders.add(o);
|
| 306 |
ashish |
73 |
//check if it has an associated alert
|
|
|
74 |
List<Alert> alerts = c.getAlerts(t.getId(), true);
|
|
|
75 |
if(alerts != null){
|
|
|
76 |
if (alerts.size() != 0){
|
|
|
77 |
o.setAlert(true);
|
|
|
78 |
o.setStatusMessage(alerts.iterator().next().getComment());
|
|
|
79 |
}
|
|
|
80 |
}else{
|
|
|
81 |
o.setAlert(false);
|
|
|
82 |
}
|
| 167 |
ashish |
83 |
}
|
|
|
84 |
}catch(Exception e){
|
|
|
85 |
System.out.println(e);
|
|
|
86 |
}
|
|
|
87 |
return orders;
|
|
|
88 |
}
|
|
|
89 |
}
|