| 3381 |
chandransh |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.thrift.clients.WarehouseClient;
|
|
|
4 |
import in.shop2020.warehouse.POStatus;
|
|
|
5 |
import in.shop2020.warehouse.Purchase;
|
|
|
6 |
import in.shop2020.warehouse.PurchaseOrder;
|
|
|
7 |
import in.shop2020.warehouse.WarehouseService.Client;
|
|
|
8 |
import in.shop2020.warehouse.WarehouseServiceException;
|
|
|
9 |
|
|
|
10 |
import java.util.List;
|
|
|
11 |
|
|
|
12 |
import javax.servlet.ServletContext;
|
|
|
13 |
|
|
|
14 |
import org.apache.struts2.util.ServletContextAware;
|
|
|
15 |
import org.apache.thrift.TException;
|
|
|
16 |
import org.apache.thrift.transport.TTransportException;
|
|
|
17 |
import org.slf4j.Logger;
|
|
|
18 |
import org.slf4j.LoggerFactory;
|
|
|
19 |
|
|
|
20 |
public class PurchaseOrderController implements ServletContextAware{
|
|
|
21 |
|
|
|
22 |
private static Logger logger = LoggerFactory.getLogger(PurchaseOrderController.class);
|
|
|
23 |
|
|
|
24 |
private ServletContext context;
|
|
|
25 |
private String id;
|
|
|
26 |
|
|
|
27 |
private List<PurchaseOrder> purchaseOrders;
|
|
|
28 |
|
|
|
29 |
private PurchaseOrder purchaseOrder;
|
|
|
30 |
private List<Purchase> purchases;
|
|
|
31 |
|
|
|
32 |
public String index(){
|
|
|
33 |
//Get a list of all the open purchase orders
|
|
|
34 |
try {
|
|
|
35 |
WarehouseClient warehouseClient = new WarehouseClient();
|
|
|
36 |
Client client = warehouseClient.getClient();
|
| 3449 |
chandransh |
37 |
purchaseOrders = client.getAllPurchaseOrders(POStatus.READY);
|
| 3381 |
chandransh |
38 |
purchaseOrders.addAll(client.getAllPurchaseOrders(POStatus.PARTIALLY_FULFILLED));
|
|
|
39 |
} catch (TTransportException e) {
|
| 3449 |
chandransh |
40 |
logger.error("Unable to get the list of all purchase orders.", e);
|
| 3381 |
chandransh |
41 |
} catch (WarehouseServiceException e) {
|
| 3449 |
chandransh |
42 |
logger.error("Error while getting the list of all purchase orders.", e);
|
| 3381 |
chandransh |
43 |
} catch (TException e) {
|
| 3449 |
chandransh |
44 |
logger.error("Error while communicating to the warehouse server.", e);
|
| 3381 |
chandransh |
45 |
}
|
|
|
46 |
|
|
|
47 |
return "index";
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
public String show(){
|
|
|
51 |
//Get a list of all the open purchase orders
|
|
|
52 |
try {
|
|
|
53 |
WarehouseClient warehouseClient = new WarehouseClient();
|
|
|
54 |
Client client = warehouseClient.getClient();
|
|
|
55 |
purchaseOrder = client.getPurchaseOrder(Long.parseLong(id));
|
|
|
56 |
purchases = client.getAllPurchases(purchaseOrder.getId(), true);
|
|
|
57 |
} catch (TTransportException e) {
|
| 3449 |
chandransh |
58 |
logger.error("Unable to get the list of all purchases.", e);
|
| 3381 |
chandransh |
59 |
} catch (WarehouseServiceException e) {
|
| 3449 |
chandransh |
60 |
logger.error("Error while getting the list of all purchases.", e);
|
| 3381 |
chandransh |
61 |
} catch (TException e) {
|
| 3449 |
chandransh |
62 |
logger.error("Error while communicating to the warehouse server.", e);
|
| 3381 |
chandransh |
63 |
}
|
|
|
64 |
return "show";
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
public void setId(String id){
|
|
|
68 |
this.id = id;
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
public List<PurchaseOrder> getPurchaseOrders(){
|
|
|
72 |
return purchaseOrders;
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
public PurchaseOrder getPurchaseOrder(){
|
|
|
76 |
return purchaseOrder;
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
public List<Purchase> getPurchases(){
|
|
|
80 |
return purchases;
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
@Override
|
|
|
84 |
public void setServletContext(ServletContext context) {
|
|
|
85 |
this.context = context;
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
public String getServletContextPath() {
|
|
|
89 |
return context.getContextPath();
|
|
|
90 |
}
|
|
|
91 |
}
|