| 3381 |
chandransh |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
| 4531 |
mandeep.dh |
3 |
import in.shop2020.model.v1.catalog.InventoryServiceException;
|
| 4497 |
mandeep.dh |
4 |
import in.shop2020.purchase.PurchaseServiceException;
|
| 4531 |
mandeep.dh |
5 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 4497 |
mandeep.dh |
6 |
import in.shop2020.thrift.clients.PurchaseClient;
|
| 3381 |
chandransh |
7 |
import in.shop2020.thrift.clients.WarehouseClient;
|
| 4555 |
mandeep.dh |
8 |
import in.shop2020.warehouse.InventoryItem;
|
| 3381 |
chandransh |
9 |
import in.shop2020.warehouse.ScanType;
|
| 4497 |
mandeep.dh |
10 |
import in.shop2020.warehouse.WarehouseService.Client;
|
| 3381 |
chandransh |
11 |
import in.shop2020.warehouse.WarehouseServiceException;
|
|
|
12 |
|
|
|
13 |
import javax.servlet.ServletContext;
|
|
|
14 |
import javax.servlet.http.HttpServletRequest;
|
|
|
15 |
|
| 3867 |
chandransh |
16 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
17 |
import org.apache.struts2.convention.annotation.Results;
|
| 3381 |
chandransh |
18 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
19 |
import org.apache.struts2.util.ServletContextAware;
|
|
|
20 |
import org.apache.thrift.TException;
|
|
|
21 |
import org.apache.thrift.transport.TTransportException;
|
|
|
22 |
import org.slf4j.Logger;
|
|
|
23 |
import org.slf4j.LoggerFactory;
|
|
|
24 |
|
| 3423 |
chandransh |
25 |
import com.opensymphony.xwork2.ValidationAwareSupport;
|
| 3381 |
chandransh |
26 |
|
| 3423 |
chandransh |
27 |
@SuppressWarnings("serial")
|
| 3867 |
chandransh |
28 |
@Results({
|
|
|
29 |
@Result(name="redirect", type="redirectAction", params = {"actionName" , "warehouse"})
|
|
|
30 |
})
|
| 3423 |
chandransh |
31 |
public class PurchaseController extends ValidationAwareSupport implements ServletRequestAware, ServletContextAware {
|
|
|
32 |
|
| 3381 |
chandransh |
33 |
private static Logger logger = LoggerFactory.getLogger(PurchaseController.class);
|
|
|
34 |
|
|
|
35 |
protected HttpServletRequest request;
|
|
|
36 |
private ServletContext context;
|
|
|
37 |
private String id;
|
| 4497 |
mandeep.dh |
38 |
private String itemId;
|
|
|
39 |
private String itemNo;
|
| 3381 |
chandransh |
40 |
private String errorMsg="";
|
|
|
41 |
|
|
|
42 |
private String purchaseOrderId;
|
|
|
43 |
|
|
|
44 |
public String editNew(){
|
|
|
45 |
purchaseOrderId = request.getParameter("poId");
|
|
|
46 |
return "new";
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
public String create(){
|
|
|
50 |
this.purchaseOrderId = request.getParameter("poId");
|
|
|
51 |
long poId = Long.parseLong(purchaseOrderId);
|
|
|
52 |
String invoiceNumber = request.getParameter("invoiceNo");
|
|
|
53 |
String fc = request.getParameter("freightCharges").trim();
|
|
|
54 |
double freightCharges = 0;
|
|
|
55 |
if(fc != null && !fc.isEmpty())
|
|
|
56 |
freightCharges = Double.parseDouble(fc);
|
|
|
57 |
try {
|
| 4497 |
mandeep.dh |
58 |
PurchaseClient purchaseClient = new PurchaseClient();
|
|
|
59 |
in.shop2020.purchase.PurchaseService.Client client = purchaseClient.getClient();
|
| 3381 |
chandransh |
60 |
id = "" + client.startPurchase(poId, invoiceNumber, freightCharges);
|
|
|
61 |
} catch (TTransportException e) {
|
|
|
62 |
errorMsg = "Error while establishing connection to the warehouse server";
|
|
|
63 |
logger.error(errorMsg, e);
|
|
|
64 |
} catch (TException e) {
|
|
|
65 |
errorMsg = "Error while scanning in the item";
|
|
|
66 |
logger.error(errorMsg, e);
|
| 4497 |
mandeep.dh |
67 |
} catch (PurchaseServiceException e) {
|
|
|
68 |
errorMsg = e.getMessage();
|
|
|
69 |
logger.error(errorMsg, e);
|
| 3381 |
chandransh |
70 |
}
|
|
|
71 |
|
|
|
72 |
if(errorMsg.isEmpty())
|
|
|
73 |
return "create";
|
| 3423 |
chandransh |
74 |
else{
|
|
|
75 |
addActionError(errorMsg);
|
| 3381 |
chandransh |
76 |
return "new";
|
| 3423 |
chandransh |
77 |
}
|
|
|
78 |
|
| 3381 |
chandransh |
79 |
}
|
|
|
80 |
|
|
|
81 |
public String show(){
|
|
|
82 |
return "show";
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
public String update(){
|
|
|
86 |
long id = Long.parseLong(this.id);
|
|
|
87 |
String itemNumber = request.getParameter("itemNo");
|
|
|
88 |
String imeiNumber = request.getParameter("imeiNo");
|
|
|
89 |
|
|
|
90 |
try {
|
|
|
91 |
WarehouseClient warehouseClient = new WarehouseClient();
|
|
|
92 |
Client client = warehouseClient.getClient();
|
| 4497 |
mandeep.dh |
93 |
long warehouseId = 7;
|
| 4555 |
mandeep.dh |
94 |
InventoryItem inventoryItem = client.createSerializedInventoryItemFromItemNumber(itemNumber, imeiNumber, id);
|
|
|
95 |
client.scanSerializedItem(inventoryItem.getId(), ScanType.PURCHASE, warehouseId);
|
| 4531 |
mandeep.dh |
96 |
in.shop2020.model.v1.catalog.InventoryService.Client catalaogClient = new CatalogClient().getClient();
|
| 4555 |
mandeep.dh |
97 |
catalaogClient.addInventory(inventoryItem.getItemId(), warehouseId, 1);
|
| 3381 |
chandransh |
98 |
} catch (TTransportException e) {
|
|
|
99 |
errorMsg = "Error while establishing connection to the warehouse server";
|
|
|
100 |
logger.error(errorMsg, e);
|
|
|
101 |
} catch (WarehouseServiceException e) {
|
| 3423 |
chandransh |
102 |
errorMsg = e.getMessage();
|
| 3381 |
chandransh |
103 |
logger.error(errorMsg, e);
|
|
|
104 |
} catch (TException e) {
|
|
|
105 |
errorMsg = "Error while scanning in the item";
|
|
|
106 |
logger.error(errorMsg, e);
|
| 4531 |
mandeep.dh |
107 |
} catch (InventoryServiceException e) {
|
|
|
108 |
errorMsg = "Error while incresing item's inventory availability";
|
|
|
109 |
logger.error(errorMsg, e);
|
| 3381 |
chandransh |
110 |
}
|
| 3423 |
chandransh |
111 |
if(!errorMsg.isEmpty()){
|
|
|
112 |
addActionError(errorMsg);
|
|
|
113 |
}
|
| 3381 |
chandransh |
114 |
return "show";
|
|
|
115 |
}
|
|
|
116 |
|
| 3867 |
chandransh |
117 |
public String destroy(){
|
|
|
118 |
long id = Long.parseLong(this.id);
|
|
|
119 |
|
|
|
120 |
try {
|
| 4497 |
mandeep.dh |
121 |
PurchaseClient warehouseClient = new PurchaseClient();
|
|
|
122 |
in.shop2020.purchase.PurchaseService.Client client = warehouseClient.getClient();
|
| 3867 |
chandransh |
123 |
client.closePurchase(id);
|
|
|
124 |
}catch (TTransportException e) {
|
|
|
125 |
errorMsg = "Error while establishing connection to the warehouse server";
|
|
|
126 |
logger.error(errorMsg, e);
|
|
|
127 |
} catch (TException e) {
|
|
|
128 |
errorMsg = "Error while scanning in the item";
|
|
|
129 |
logger.error(errorMsg, e);
|
| 4497 |
mandeep.dh |
130 |
} catch (PurchaseServiceException e) {
|
|
|
131 |
errorMsg = e.getMessage();
|
|
|
132 |
logger.error(errorMsg, e);
|
| 3867 |
chandransh |
133 |
}
|
|
|
134 |
return "redirect";
|
|
|
135 |
}
|
| 4497 |
mandeep.dh |
136 |
|
|
|
137 |
public String createItemNumberMapping() {
|
|
|
138 |
long itemIdLong = Long.parseLong(itemId);
|
|
|
139 |
|
|
|
140 |
try {
|
|
|
141 |
Client warehouseClient = new WarehouseClient().getClient();
|
|
|
142 |
warehouseClient.createItemNumberMapping(itemNo, itemIdLong);
|
|
|
143 |
} catch (TTransportException e) {
|
|
|
144 |
logger.error("Could not create thrift client", e);
|
|
|
145 |
} catch (TException e) {
|
|
|
146 |
logger.error("Could not create item number mapping", e);
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
return show();
|
|
|
150 |
}
|
|
|
151 |
|
| 3381 |
chandransh |
152 |
public void setId(String id){
|
|
|
153 |
this.id = id;
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
public String getId(){
|
|
|
157 |
return id;
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
public String getErrorMessage(){
|
|
|
161 |
return errorMsg;
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
public String getPurchaseOrderId() {
|
|
|
165 |
return purchaseOrderId;
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
@Override
|
|
|
169 |
public void setServletRequest(HttpServletRequest request) {
|
|
|
170 |
this.request = request;
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
@Override
|
|
|
174 |
public void setServletContext(ServletContext context) {
|
|
|
175 |
this.context = context;
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
public String getServletContextPath() {
|
|
|
179 |
return context.getContextPath();
|
|
|
180 |
}
|
|
|
181 |
|
| 4497 |
mandeep.dh |
182 |
public String getItemId() {
|
|
|
183 |
return itemId;
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
public void setItemId(String itemId) {
|
|
|
187 |
this.itemId = itemId;
|
|
|
188 |
}
|
|
|
189 |
|
|
|
190 |
public String getItemNo() {
|
|
|
191 |
return itemNo;
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
public void setItemNo(String itemNo) {
|
|
|
195 |
this.itemNo = itemNo;
|
|
|
196 |
}
|
|
|
197 |
|
| 3381 |
chandransh |
198 |
}
|