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