| 7283 |
kshitij.so |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
| 7524 |
kshitij.so |
3 |
import java.io.File;
|
|
|
4 |
import java.io.IOException;
|
| 7365 |
kshitij.so |
5 |
import java.util.HashMap;
|
| 7283 |
kshitij.so |
6 |
import java.util.List;
|
|
|
7 |
import java.util.Map;
|
|
|
8 |
|
| 7591 |
kshitij.so |
9 |
import javax.servlet.ServletContext;
|
| 7283 |
kshitij.so |
10 |
import javax.servlet.ServletRequest;
|
|
|
11 |
import javax.servlet.http.HttpServletRequest;
|
| 7591 |
kshitij.so |
12 |
import javax.servlet.http.HttpSession;
|
| 7283 |
kshitij.so |
13 |
|
|
|
14 |
import in.shop2020.model.v1.catalog.Amazonlisted;
|
|
|
15 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
|
|
16 |
import in.shop2020.model.v1.catalog.Item;
|
|
|
17 |
import in.shop2020.model.v1.inventory.AmazonInventorySnapshot;
|
|
|
18 |
import in.shop2020.model.v1.catalog.CatalogService.Client;
|
|
|
19 |
import in.shop2020.model.v1.inventory.InventoryServiceException;
|
| 7591 |
kshitij.so |
20 |
import in.shop2020.support.utils.ReportsUtils;
|
| 7283 |
kshitij.so |
21 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
22 |
import in.shop2020.thrift.clients.InventoryClient;
|
| 7365 |
kshitij.so |
23 |
import in.shop2020.thrift.clients.LogisticsClient;
|
|
|
24 |
import in.shop2020.logistics.DeliveryType;
|
|
|
25 |
import in.shop2020.logistics.LogisticsInfo;
|
|
|
26 |
import in.shop2020.logistics.LogisticsServiceException;
|
|
|
27 |
import in.shop2020.logistics.PickUpType;
|
| 7283 |
kshitij.so |
28 |
|
| 7524 |
kshitij.so |
29 |
import org.apache.commons.io.FileUtils;
|
| 7365 |
kshitij.so |
30 |
import org.apache.commons.lang.xwork.StringUtils;
|
| 7591 |
kshitij.so |
31 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
32 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
| 7283 |
kshitij.so |
33 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
34 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
35 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
36 |
import org.apache.thrift.TException;
|
|
|
37 |
import org.slf4j.Logger;
|
|
|
38 |
import org.slf4j.LoggerFactory;
|
|
|
39 |
|
|
|
40 |
import com.opensymphony.xwork2.ValidationAwareSupport;
|
|
|
41 |
|
|
|
42 |
@SuppressWarnings("serial")
|
| 7591 |
kshitij.so |
43 |
@InterceptorRefs({
|
|
|
44 |
@InterceptorRef("defaultStack"),
|
|
|
45 |
@InterceptorRef("login")
|
|
|
46 |
})
|
| 7283 |
kshitij.so |
47 |
@Results({
|
| 7524 |
kshitij.so |
48 |
@Result(name = "redirect", location = "${url}", type = "redirect"),
|
|
|
49 |
@Result(name="authsuccess", type="redirectAction", params = {"actionName" , "reports"})
|
|
|
50 |
})
|
|
|
51 |
public class AmazonListController extends ValidationAwareSupport implements ServletRequestAware {
|
| 7283 |
kshitij.so |
52 |
|
|
|
53 |
private static Logger logger = LoggerFactory.getLogger(AmazonListController.class);
|
|
|
54 |
|
| 7591 |
kshitij.so |
55 |
private HttpServletRequest request;
|
|
|
56 |
private HttpSession session;
|
|
|
57 |
private ServletContext context;
|
| 7283 |
kshitij.so |
58 |
private String url;
|
|
|
59 |
private String id;
|
|
|
60 |
private String itemId;
|
|
|
61 |
private String isFba;
|
|
|
62 |
private String isNonFba;
|
|
|
63 |
private String isInventoryOverride;
|
|
|
64 |
private String fbaPrice;
|
|
|
65 |
private String sellingPrice;
|
|
|
66 |
private String saholicPrice;
|
| 7365 |
kshitij.so |
67 |
private String isTime;
|
|
|
68 |
private String handlingTime;
|
|
|
69 |
private String customHandlingTime;
|
| 7461 |
kshitij.so |
70 |
private String holdInventory;
|
|
|
71 |
private String defaultInventory;
|
| 7524 |
kshitij.so |
72 |
private String fileUploadFileName;
|
|
|
73 |
private String fileUploadContentType;
|
|
|
74 |
private File file;
|
| 7283 |
kshitij.so |
75 |
|
|
|
76 |
public String index() {
|
| 7591 |
kshitij.so |
77 |
if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getServletPath())) {
|
|
|
78 |
return "authfail";
|
|
|
79 |
}
|
| 7283 |
kshitij.so |
80 |
return "index";
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
public List<Amazonlisted> fetchItems() throws TException {
|
| 7408 |
kshitij.so |
84 |
Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
|
| 7283 |
kshitij.so |
85 |
return CatalogClient.getAllAmazonListedItems();
|
|
|
86 |
}
|
|
|
87 |
|
| 7408 |
kshitij.so |
88 |
public Amazonlisted fetchItemDetail() throws NumberFormatException, TException {
|
|
|
89 |
Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
|
| 7283 |
kshitij.so |
90 |
return CatalogClient.getAmazonItemDetails(Long.valueOf(id));
|
|
|
91 |
}
|
|
|
92 |
|
| 7408 |
kshitij.so |
93 |
public Item getSaholicItem(String id) throws NumberFormatException, CatalogServiceException, TException {
|
|
|
94 |
Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
|
| 7283 |
kshitij.so |
95 |
return CatalogClient.getItem(Long.valueOf(id));
|
|
|
96 |
}
|
| 7365 |
kshitij.so |
97 |
|
|
|
98 |
|
|
|
99 |
|
| 7283 |
kshitij.so |
100 |
public String update() throws NumberFormatException, TException{
|
| 7408 |
kshitij.so |
101 |
Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
|
| 7283 |
kshitij.so |
102 |
if ( Double.valueOf(fbaPrice) > Double.valueOf(saholicPrice) || Double.valueOf(sellingPrice) > Double.valueOf(saholicPrice) ) {
|
| 7365 |
kshitij.so |
103 |
addActionError("Failed To Do Changes");
|
| 7283 |
kshitij.so |
104 |
}
|
|
|
105 |
else {
|
| 7365 |
kshitij.so |
106 |
boolean flag=false;
|
| 7591 |
kshitij.so |
107 |
long delay = Long.valueOf(customHandlingTime);
|
| 7365 |
kshitij.so |
108 |
if ( Boolean.valueOf(isTime)) {
|
|
|
109 |
flag = true;
|
|
|
110 |
}
|
| 7461 |
kshitij.so |
111 |
changeItemInventory();
|
| 7365 |
kshitij.so |
112 |
CatalogClient.updateAmazonItemDetails(Long.valueOf(itemId),Double.valueOf(fbaPrice),Double.valueOf(sellingPrice),Boolean.valueOf(isFba),Boolean.valueOf(isNonFba),Boolean.valueOf(isInventoryOverride),delay,flag);
|
| 7283 |
kshitij.so |
113 |
}
|
| 7591 |
kshitij.so |
114 |
//setUrl("/amazon-list/");
|
|
|
115 |
return "index";
|
| 7283 |
kshitij.so |
116 |
|
|
|
117 |
}
|
|
|
118 |
|
| 7524 |
kshitij.so |
119 |
public String upload() throws IOException {
|
|
|
120 |
File fileToCreate = new File("/tmp/", "Amazon-shipping.xls");
|
|
|
121 |
FileUtils.copyFile(this.file, fileToCreate);
|
|
|
122 |
return "authsuccess";
|
|
|
123 |
}
|
|
|
124 |
|
| 7461 |
kshitij.so |
125 |
private void changeItemInventory() throws NumberFormatException, TException {
|
|
|
126 |
Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
|
| 7524 |
kshitij.so |
127 |
|
| 7461 |
kshitij.so |
128 |
if (StringUtils.isEmpty(holdInventory)) {
|
|
|
129 |
holdInventory = "0";
|
|
|
130 |
}
|
|
|
131 |
if (StringUtils.isEmpty(defaultInventory)) {
|
|
|
132 |
defaultInventory = "0";
|
|
|
133 |
}
|
| 7524 |
kshitij.so |
134 |
|
| 7461 |
kshitij.so |
135 |
CatalogClient.updateItemInventory(Long.valueOf(itemId),Long.valueOf(holdInventory),Long.valueOf(defaultInventory));
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
|
| 7283 |
kshitij.so |
139 |
public Map<Long, Long> getAvailableItemInventory(String itemId) throws NumberFormatException, InventoryServiceException, TException{
|
|
|
140 |
InventoryClient inventoryServiceClient = new InventoryClient();
|
|
|
141 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
|
|
|
142 |
in.shop2020.model.v1.inventory.ItemInventory thriftItemInventory = inventoryClient.getItemInventoryByItemId(Long.valueOf(itemId));
|
|
|
143 |
return thriftItemInventory.getAvailability();
|
|
|
144 |
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
public Map<Long, Long> getReservedItemInventory(String itemId) throws NumberFormatException, InventoryServiceException, TException{
|
|
|
148 |
InventoryClient inventoryServiceClient = new InventoryClient();
|
|
|
149 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
|
|
|
150 |
in.shop2020.model.v1.inventory.ItemInventory thriftItemInventory = inventoryClient.getItemInventoryByItemId(Long.valueOf(itemId));
|
|
|
151 |
return thriftItemInventory.getReserved();
|
|
|
152 |
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
public String getWarehouseName(String warehouseId) throws NumberFormatException, TException {
|
|
|
156 |
InventoryClient inventoryServiceClient = new InventoryClient();
|
|
|
157 |
return inventoryServiceClient.getClient().getWarehouseName(Long.valueOf(warehouseId));
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
public AmazonInventorySnapshot getInventoryForAmazonItem(String itemId) throws NumberFormatException, TException {
|
|
|
161 |
InventoryClient inventoryServiceClient = new InventoryClient();
|
| 7365 |
kshitij.so |
162 |
try {
|
|
|
163 |
return inventoryServiceClient.getClient().getAmazonInventoryForItem(Long.valueOf(itemId));
|
|
|
164 |
}
|
|
|
165 |
catch (Exception e){
|
|
|
166 |
return null;
|
|
|
167 |
}
|
| 7283 |
kshitij.so |
168 |
}
|
|
|
169 |
|
| 7365 |
kshitij.so |
170 |
public Long getTimetoShip(String itemId) throws LogisticsServiceException, TException{
|
|
|
171 |
LogisticsClient logisticsClient = new LogisticsClient();
|
|
|
172 |
return logisticsClient.getClient().getLogisticsInfo("110001", Long.valueOf(itemId), DeliveryType.COD, PickUpType.COURIER).getShippingTime();
|
|
|
173 |
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
public Map<Long, String> getAliveItemMap() throws TException{
|
| 7408 |
kshitij.so |
177 |
Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
|
| 7365 |
kshitij.so |
178 |
List<Item> itemList = CatalogClient.getAllAliveItems();
|
|
|
179 |
Map<Long, String> itemMap = new HashMap<Long, String>();
|
|
|
180 |
for (Item o : itemList) {
|
|
|
181 |
itemMap.put((Long) o.getId(), (String) o.getBrand()+" "+o.getModelName()+" "+o.getModelNumber()+" "+o.getColor());
|
|
|
182 |
}
|
|
|
183 |
return itemMap;
|
|
|
184 |
}
|
|
|
185 |
|
| 7283 |
kshitij.so |
186 |
public String edit() {
|
| 7591 |
kshitij.so |
187 |
if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1])) {
|
|
|
188 |
return "authfail";
|
|
|
189 |
}
|
| 7283 |
kshitij.so |
190 |
return "edit";
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
public String show() {
|
|
|
194 |
return "show";
|
|
|
195 |
}
|
|
|
196 |
|
|
|
197 |
public String editNew() {
|
|
|
198 |
return "editNew";
|
|
|
199 |
}
|
|
|
200 |
|
|
|
201 |
public void setId(String id) {
|
|
|
202 |
this.id = id;
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
public void setUrl(String url) {
|
|
|
206 |
this.url = url;
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
public String getUrl() {
|
|
|
210 |
return url;
|
|
|
211 |
}
|
|
|
212 |
|
|
|
213 |
public String getId() {
|
|
|
214 |
return id;
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
public void setItemId(String itemId) {
|
|
|
218 |
this.itemId = itemId;
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
public String getItemId() {
|
|
|
222 |
return itemId;
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
public void setIsFba(String isFba) {
|
|
|
226 |
this.isFba = isFba;
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
public String getIsFba() {
|
|
|
230 |
return isFba;
|
|
|
231 |
}
|
|
|
232 |
|
|
|
233 |
public void setIsNonFba(String isNonFba) {
|
|
|
234 |
this.isNonFba = isNonFba;
|
|
|
235 |
}
|
|
|
236 |
|
|
|
237 |
public String getIsNonFba() {
|
|
|
238 |
return isNonFba;
|
|
|
239 |
}
|
|
|
240 |
|
|
|
241 |
public void setIsInventoryOverride(String isInventoryOverride) {
|
|
|
242 |
this.isInventoryOverride = isInventoryOverride;
|
|
|
243 |
}
|
|
|
244 |
|
|
|
245 |
public String getIsInventoryOverride() {
|
|
|
246 |
return isInventoryOverride;
|
|
|
247 |
}
|
|
|
248 |
|
|
|
249 |
public void setSellingPrice(String sellingPrice) {
|
|
|
250 |
this.sellingPrice = sellingPrice;
|
|
|
251 |
}
|
|
|
252 |
|
|
|
253 |
public String getSellingPrice() {
|
|
|
254 |
return sellingPrice;
|
|
|
255 |
}
|
|
|
256 |
|
|
|
257 |
public void setFbaPrice(String fbaPrice) {
|
|
|
258 |
this.fbaPrice = fbaPrice;
|
|
|
259 |
}
|
|
|
260 |
|
|
|
261 |
public String getFbaPrice() {
|
|
|
262 |
return fbaPrice;
|
|
|
263 |
}
|
| 7365 |
kshitij.so |
264 |
|
| 7283 |
kshitij.so |
265 |
public void setSaholicPrice(String saholicPrice) {
|
|
|
266 |
this.saholicPrice = saholicPrice;
|
|
|
267 |
}
|
|
|
268 |
|
|
|
269 |
public String getSaholicPrice() {
|
|
|
270 |
return saholicPrice;
|
|
|
271 |
}
|
|
|
272 |
|
| 7365 |
kshitij.so |
273 |
public void setIsTime(String isTime){
|
|
|
274 |
this.isTime = isTime;
|
|
|
275 |
}
|
|
|
276 |
|
| 7461 |
kshitij.so |
277 |
public String getIsTime(){
|
| 7365 |
kshitij.so |
278 |
return isTime;
|
|
|
279 |
}
|
|
|
280 |
|
|
|
281 |
public void setHandlingTime(String handlingTime){
|
|
|
282 |
this.handlingTime = handlingTime;
|
|
|
283 |
}
|
|
|
284 |
|
| 7461 |
kshitij.so |
285 |
public String getHandlingTime(){
|
| 7365 |
kshitij.so |
286 |
return handlingTime;
|
|
|
287 |
}
|
|
|
288 |
|
|
|
289 |
public void setCustomHandlingTime(String customHandlingTime){
|
|
|
290 |
this.customHandlingTime = customHandlingTime;
|
|
|
291 |
}
|
|
|
292 |
|
| 7461 |
kshitij.so |
293 |
public String getCustomHandlingTime(){
|
| 7365 |
kshitij.so |
294 |
return customHandlingTime;
|
|
|
295 |
}
|
| 7524 |
kshitij.so |
296 |
|
| 7461 |
kshitij.so |
297 |
public void setHoldInventory(String holdInventory){
|
|
|
298 |
this.holdInventory = holdInventory;
|
|
|
299 |
}
|
| 7365 |
kshitij.so |
300 |
|
| 7461 |
kshitij.so |
301 |
public String getHoldInventory(){
|
|
|
302 |
return holdInventory;
|
|
|
303 |
}
|
| 7524 |
kshitij.so |
304 |
|
| 7461 |
kshitij.so |
305 |
public void setDefaultInventory(String defaultInventory){
|
|
|
306 |
this.defaultInventory = defaultInventory;
|
|
|
307 |
}
|
|
|
308 |
|
|
|
309 |
public String getDefaultInventory(){
|
|
|
310 |
return defaultInventory;
|
|
|
311 |
}
|
|
|
312 |
|
| 7524 |
kshitij.so |
313 |
public File getFile() {
|
|
|
314 |
return file;
|
|
|
315 |
}
|
|
|
316 |
|
|
|
317 |
public void setFile(File file) {
|
|
|
318 |
this.file = file;
|
|
|
319 |
}
|
|
|
320 |
|
|
|
321 |
public String getFileUploadContentType() {
|
|
|
322 |
return fileUploadContentType;
|
|
|
323 |
}
|
|
|
324 |
|
|
|
325 |
public void setFileUploadContentType(String fileUploadContentType) {
|
|
|
326 |
this.fileUploadContentType = fileUploadContentType;
|
|
|
327 |
}
|
|
|
328 |
|
|
|
329 |
public String getFileUploadFileName() {
|
|
|
330 |
return fileUploadFileName;
|
|
|
331 |
}
|
|
|
332 |
|
|
|
333 |
public void setFileUploadFileName(String fileUploadFileName) {
|
|
|
334 |
this.fileUploadFileName = fileUploadFileName;
|
|
|
335 |
}
|
|
|
336 |
|
| 7591 |
kshitij.so |
337 |
public void setServletRequest(HttpServletRequest req) {
|
|
|
338 |
this.request = req;
|
|
|
339 |
this.session = req.getSession();
|
| 7283 |
kshitij.so |
340 |
}
|
|
|
341 |
|
|
|
342 |
public static void main(String[] args) throws NumberFormatException, InventoryServiceException, TException {
|
|
|
343 |
AmazonListController call = new AmazonListController();
|
| 7365 |
kshitij.so |
344 |
System.out.println(call.getInventoryForAmazonItem("5"));
|
| 7283 |
kshitij.so |
345 |
}
|
|
|
346 |
}
|