| 3381 |
chandransh |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.thrift.clients.WarehouseClient;
|
|
|
4 |
import in.shop2020.warehouse.ScanType;
|
|
|
5 |
import in.shop2020.warehouse.WarehouseServiceException;
|
|
|
6 |
import in.shop2020.warehouse.WarehouseService.Client;
|
|
|
7 |
|
|
|
8 |
import javax.servlet.ServletContext;
|
|
|
9 |
import javax.servlet.http.HttpServletRequest;
|
|
|
10 |
|
| 3867 |
chandransh |
11 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
12 |
import org.apache.struts2.convention.annotation.Results;
|
| 3381 |
chandransh |
13 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
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 |
|
| 3423 |
chandransh |
20 |
import com.opensymphony.xwork2.ValidationAwareSupport;
|
| 3381 |
chandransh |
21 |
|
| 3423 |
chandransh |
22 |
@SuppressWarnings("serial")
|
| 3867 |
chandransh |
23 |
@Results({
|
|
|
24 |
@Result(name="redirect", type="redirectAction", params = {"actionName" , "warehouse"})
|
|
|
25 |
})
|
| 3423 |
chandransh |
26 |
public class PurchaseController extends ValidationAwareSupport implements ServletRequestAware, ServletContextAware {
|
|
|
27 |
|
| 3381 |
chandransh |
28 |
private static Logger logger = LoggerFactory.getLogger(PurchaseController.class);
|
|
|
29 |
|
|
|
30 |
protected HttpServletRequest request;
|
|
|
31 |
private ServletContext context;
|
|
|
32 |
private String id;
|
|
|
33 |
private String errorMsg="";
|
|
|
34 |
|
|
|
35 |
private String purchaseOrderId;
|
|
|
36 |
|
|
|
37 |
public String editNew(){
|
|
|
38 |
purchaseOrderId = request.getParameter("poId");
|
|
|
39 |
return "new";
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
public String create(){
|
|
|
43 |
this.purchaseOrderId = request.getParameter("poId");
|
|
|
44 |
long poId = Long.parseLong(purchaseOrderId);
|
|
|
45 |
String invoiceNumber = request.getParameter("invoiceNo");
|
|
|
46 |
String fc = request.getParameter("freightCharges").trim();
|
|
|
47 |
double freightCharges = 0;
|
|
|
48 |
if(fc != null && !fc.isEmpty())
|
|
|
49 |
freightCharges = Double.parseDouble(fc);
|
|
|
50 |
try {
|
|
|
51 |
WarehouseClient warehouseClient = new WarehouseClient();
|
|
|
52 |
Client client = warehouseClient.getClient();
|
|
|
53 |
id = "" + client.startPurchase(poId, invoiceNumber, freightCharges);
|
|
|
54 |
} catch (TTransportException e) {
|
|
|
55 |
errorMsg = "Error while establishing connection to the warehouse server";
|
|
|
56 |
logger.error(errorMsg, e);
|
|
|
57 |
} catch (WarehouseServiceException e) {
|
| 3423 |
chandransh |
58 |
errorMsg = e.getMessage();
|
| 3381 |
chandransh |
59 |
logger.error(errorMsg, e);
|
|
|
60 |
} catch (TException e) {
|
|
|
61 |
errorMsg = "Error while scanning in the item";
|
|
|
62 |
logger.error(errorMsg, e);
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
if(errorMsg.isEmpty())
|
|
|
66 |
return "create";
|
| 3423 |
chandransh |
67 |
else{
|
|
|
68 |
addActionError(errorMsg);
|
| 3381 |
chandransh |
69 |
return "new";
|
| 3423 |
chandransh |
70 |
}
|
|
|
71 |
|
| 3381 |
chandransh |
72 |
}
|
|
|
73 |
|
|
|
74 |
public String show(){
|
|
|
75 |
return "show";
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
public String update(){
|
|
|
79 |
long id = Long.parseLong(this.id);
|
|
|
80 |
String itemNumber = request.getParameter("itemNo");
|
|
|
81 |
String imeiNumber = request.getParameter("imeiNo");
|
|
|
82 |
|
|
|
83 |
try {
|
|
|
84 |
WarehouseClient warehouseClient = new WarehouseClient();
|
|
|
85 |
Client client = warehouseClient.getClient();
|
|
|
86 |
client.scanIn(id, itemNumber, imeiNumber, ScanType.PURCHASE);
|
|
|
87 |
} catch (TTransportException e) {
|
|
|
88 |
errorMsg = "Error while establishing connection to the warehouse server";
|
|
|
89 |
logger.error(errorMsg, e);
|
|
|
90 |
} catch (WarehouseServiceException e) {
|
| 3423 |
chandransh |
91 |
errorMsg = e.getMessage();
|
| 3381 |
chandransh |
92 |
logger.error(errorMsg, e);
|
|
|
93 |
} catch (TException e) {
|
|
|
94 |
errorMsg = "Error while scanning in the item";
|
|
|
95 |
logger.error(errorMsg, e);
|
|
|
96 |
}
|
| 3423 |
chandransh |
97 |
if(!errorMsg.isEmpty()){
|
|
|
98 |
addActionError(errorMsg);
|
|
|
99 |
}
|
| 3381 |
chandransh |
100 |
return "show";
|
|
|
101 |
}
|
|
|
102 |
|
| 3867 |
chandransh |
103 |
public String destroy(){
|
|
|
104 |
long id = Long.parseLong(this.id);
|
|
|
105 |
|
|
|
106 |
try {
|
|
|
107 |
WarehouseClient warehouseClient = new WarehouseClient();
|
|
|
108 |
Client client = warehouseClient.getClient();
|
|
|
109 |
client.closePurchase(id);
|
|
|
110 |
}catch (TTransportException e) {
|
|
|
111 |
errorMsg = "Error while establishing connection to the warehouse server";
|
|
|
112 |
logger.error(errorMsg, e);
|
|
|
113 |
} catch (WarehouseServiceException e) {
|
|
|
114 |
errorMsg = e.getMessage();
|
|
|
115 |
logger.error(errorMsg, e);
|
|
|
116 |
} catch (TException e) {
|
|
|
117 |
errorMsg = "Error while scanning in the item";
|
|
|
118 |
logger.error(errorMsg, e);
|
|
|
119 |
}
|
|
|
120 |
return "redirect";
|
|
|
121 |
}
|
|
|
122 |
|
| 3381 |
chandransh |
123 |
public void setId(String id){
|
|
|
124 |
this.id = id;
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
public String getId(){
|
|
|
128 |
return id;
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
public String getErrorMessage(){
|
|
|
132 |
return errorMsg;
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
public String getPurchaseOrderId() {
|
|
|
136 |
return purchaseOrderId;
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
@Override
|
|
|
140 |
public void setServletRequest(HttpServletRequest request) {
|
|
|
141 |
this.request = request;
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
@Override
|
|
|
145 |
public void setServletContext(ServletContext context) {
|
|
|
146 |
this.context = context;
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
public String getServletContextPath() {
|
|
|
150 |
return context.getContextPath();
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
}
|