Subversion Repositories SmartDukaan

Rev

Rev 8396 | Rev 10097 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7283 kshitij.so 1
package in.shop2020.support.controllers;
2
 
8362 kshitij.so 3
import java.io.BufferedInputStream;
7524 kshitij.so 4
import java.io.File;
7741 kshitij.so 5
import java.io.FileInputStream;
8362 kshitij.so 6
import java.io.FileWriter;
7524 kshitij.so 7
import java.io.IOException;
8362 kshitij.so 8
import java.io.InputStream;
8620 kshitij.so 9
import java.util.Arrays;
7365 kshitij.so 10
import java.util.HashMap;
7283 kshitij.so 11
import java.util.List;
12
import java.util.Map;
13
 
7591 kshitij.so 14
import javax.servlet.ServletContext;
8362 kshitij.so 15
import javax.servlet.ServletOutputStream;
7283 kshitij.so 16
import javax.servlet.ServletRequest;
17
import javax.servlet.http.HttpServletRequest;
8168 kshitij.so 18
import javax.servlet.http.HttpServletResponse;
7591 kshitij.so 19
import javax.servlet.http.HttpSession;
7283 kshitij.so 20
 
21
import in.shop2020.model.v1.catalog.Amazonlisted;
22
import in.shop2020.model.v1.catalog.CatalogServiceException;
23
import in.shop2020.model.v1.catalog.Item;
24
import in.shop2020.model.v1.inventory.AmazonInventorySnapshot;
25
import in.shop2020.model.v1.catalog.CatalogService.Client;
26
import in.shop2020.model.v1.inventory.InventoryServiceException;
7741 kshitij.so 27
import in.shop2020.model.v1.order.AmazonOrder;
7591 kshitij.so 28
import in.shop2020.support.utils.ReportsUtils;
7283 kshitij.so 29
import in.shop2020.thrift.clients.CatalogClient;
30
import in.shop2020.thrift.clients.InventoryClient;
7365 kshitij.so 31
import in.shop2020.thrift.clients.LogisticsClient;
7741 kshitij.so 32
import in.shop2020.thrift.clients.TransactionClient;
7365 kshitij.so 33
import in.shop2020.logistics.DeliveryType;
34
import in.shop2020.logistics.LogisticsInfo;
35
import in.shop2020.logistics.LogisticsServiceException;
36
import in.shop2020.logistics.PickUpType;
7283 kshitij.so 37
 
7524 kshitij.so 38
import org.apache.commons.io.FileUtils;
7365 kshitij.so 39
import org.apache.commons.lang.xwork.StringUtils;
7741 kshitij.so 40
import org.apache.poi.hssf.usermodel.HSSFSheet;
41
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
8168 kshitij.so 42
import org.apache.poi.ss.usermodel.Cell;
7591 kshitij.so 43
import org.apache.struts2.convention.annotation.InterceptorRef;
44
import org.apache.struts2.convention.annotation.InterceptorRefs;
7283 kshitij.so 45
import org.apache.struts2.convention.annotation.Result;
46
import org.apache.struts2.convention.annotation.Results;
47
import org.apache.struts2.interceptor.ServletRequestAware;
8168 kshitij.so 48
import org.apache.struts2.interceptor.ServletResponseAware;
49
import org.apache.struts2.util.ServletContextAware;
7283 kshitij.so 50
import org.apache.thrift.TException;
7741 kshitij.so 51
import org.apache.thrift.transport.TTransportException;
7283 kshitij.so 52
import org.slf4j.Logger;
53
import org.slf4j.LoggerFactory;
54
 
55
import com.opensymphony.xwork2.ValidationAwareSupport;
56
 
57
@SuppressWarnings("serial")
8620 kshitij.so 58
 
7591 kshitij.so 59
@InterceptorRefs({
60
	@InterceptorRef("defaultStack"),
61
	@InterceptorRef("login")
62
})
7283 kshitij.so 63
@Results({
7524 kshitij.so 64
	@Result(name = "redirect", location = "${url}", type = "redirect"),
65
	@Result(name="authsuccess", type="redirectAction", params = {"actionName" , "reports"})
66
})
8168 kshitij.so 67
public class AmazonListController extends ValidationAwareSupport implements ServletRequestAware ,ServletResponseAware, ServletContextAware{
7283 kshitij.so 68
 
69
	private static Logger logger = LoggerFactory.getLogger(AmazonListController.class);
70
 
7591 kshitij.so 71
	private HttpServletRequest request;
72
	private HttpSession session;
73
	private ServletContext context;
8362 kshitij.so 74
	private HttpServletResponse response;
7283 kshitij.so 75
	private String url;
76
	private String id;
77
	private String itemId;
78
	private String isFba;
79
	private String isNonFba;
80
	private String isInventoryOverride;
81
	private String fbaPrice;
82
	private String sellingPrice;
83
	private String saholicPrice;
7365 kshitij.so 84
	private String isTime;
85
	private String handlingTime;
86
	private String customHandlingTime;
7461 kshitij.so 87
	private String holdInventory;
88
	private String defaultInventory;
7524 kshitij.so 89
	private String fileUploadFileName;
90
	private String fileUploadContentType;
8168 kshitij.so 91
	private String suppressMfnPriceUpdate;
92
	private String suppressFbaPriceUpdate;
7524 kshitij.so 93
	private File file;
8362 kshitij.so 94
	private String errMsg;
8620 kshitij.so 95
	private String next;
96
	private List<Amazonlisted> amazonItems;
97
	private String searchText;
98
	private long searchCount;
99
	private long totalCount;
100
	private String taxCode;
7283 kshitij.so 101
 
102
	public String index() {
8620 kshitij.so 103
		if (!ReportsUtils.canAccessReport((Long) session.getAttribute(ReportsUtils.ROLE),request.getServletPath())) {
7591 kshitij.so 104
			return "authfail";
105
		}
7283 kshitij.so 106
		return "index";
107
	}
108
 
8620 kshitij.so 109
	public String fetchItems() throws TException {
7408 kshitij.so 110
		Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
8620 kshitij.so 111
		if (searchText.length() == 0) {
112
			amazonItems = CatalogClient.getAmazonListedItems(Long.valueOf(next), 10);
113
			totalCount = CatalogClient.getCountForAmazonlistedItems();
114
			setSearchCount(totalCount);
115
		} else {
116
			List<String> subString = Arrays.asList(searchText.split(" "));
117
			amazonItems = CatalogClient.searchAmazonItems(subString,Long.valueOf(next), 10);
118
			totalCount = CatalogClient.getCountForAmazonlistedItems();
119
			searchCount = CatalogClient.getAmazonSearchResultCount(subString);
120
		}
121
		return "amazon-item-table";
7283 kshitij.so 122
	}
123
 
8620 kshitij.so 124
 
7408 kshitij.so 125
	public Amazonlisted fetchItemDetail() throws NumberFormatException, TException {
126
		Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
7283 kshitij.so 127
		return CatalogClient.getAmazonItemDetails(Long.valueOf(id));
128
	}
129
 
7408 kshitij.so 130
	public Item getSaholicItem(String id) throws NumberFormatException, CatalogServiceException, TException {
131
		Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
7283 kshitij.so 132
		return CatalogClient.getItem(Long.valueOf(id));
133
	}
7365 kshitij.so 134
 
135
 
136
 
7283 kshitij.so 137
	public String update() throws NumberFormatException, TException{
7408 kshitij.so 138
		Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
8168 kshitij.so 139
		boolean flag=false;
140
		boolean commit=false;
141
		long delay = Long.valueOf(customHandlingTime);
142
		if ( Boolean.valueOf(isTime)) {
143
			flag = true;
144
		}
145
		changeItemInventory();
146
		Amazonlisted amazonlisted = CatalogClient.getAmazonItemDetails(Long.valueOf(itemId));
147
		if (amazonlisted.getSellingPrice()!=Double.valueOf(sellingPrice)){
148
			amazonlisted.setSellingPrice(Double.valueOf(sellingPrice));
149
			commit=true;
150
		}
151
		if (amazonlisted.getFbaPrice()!=Double.valueOf(fbaPrice)){
152
			amazonlisted.setFbaPrice(Double.valueOf(fbaPrice));
153
			commit=true;
154
		}
155
		if (amazonlisted.isIsFba()!=Boolean.valueOf(isFba)){
156
			amazonlisted.setIsFba(Boolean.valueOf(isFba));
157
			commit=true;
158
		}
159
		if (amazonlisted.isIsNonFba()!=Boolean.valueOf(isNonFba)){
160
			amazonlisted.setIsNonFba(Boolean.valueOf(isNonFba));
161
			commit=true;
162
		}
163
		if (amazonlisted.isIsCustomTime()!=flag){
164
			amazonlisted.setIsCustomTime(flag);
165
			commit=true;
166
		}
167
		if (amazonlisted.getHandlingTime()!=delay){
168
			amazonlisted.setHandlingTime(delay);
169
			commit=true;
170
		}
171
		if(amazonlisted.isIsInventoryOverride()!=Boolean.valueOf(isInventoryOverride)){
172
			amazonlisted.setIsInventoryOverride(Boolean.valueOf(isInventoryOverride));
173
			commit=true;
174
		}
175
		if(amazonlisted.isSuppressMfnPriceUpdate()!=Boolean.valueOf(suppressMfnPriceUpdate)){
176
			amazonlisted.setSuppressMfnPriceUpdate(Boolean.valueOf(suppressMfnPriceUpdate));
177
			commit=true;
178
		}
179
		if(amazonlisted.isSuppressFbaPriceUpdate()!=Boolean.valueOf(suppressFbaPriceUpdate)){
180
			amazonlisted.setSuppressFbaPriceUpdate(Boolean.valueOf(suppressFbaPriceUpdate));
181
			commit=true;
182
		}
8620 kshitij.so 183
 
184
		if(!StringUtils.equals(amazonlisted.getTaxCode(), taxCode)){
185
			amazonlisted.setTaxCode(taxCode);
186
			commit=true;
187
		}
188
 
8168 kshitij.so 189
		if(commit){
190
			CatalogClient.updateAmazonItemDetails(amazonlisted);
191
		}
192
		else{
193
			logger.info("Nothing new to commit");
194
		}
7591 kshitij.so 195
		return "index";
7283 kshitij.so 196
 
197
	}
198
 
8168 kshitij.so 199
	public void upload() throws IOException, TException {
7524 kshitij.so 200
		File fileToCreate = new File("/tmp/", "Amazon-shipping.xls");
201
		FileUtils.copyFile(this.file, fileToCreate);
7741 kshitij.so 202
		FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
203
		HSSFWorkbook workbook = new HSSFWorkbook(iFile);
204
		HSSFSheet sheet = workbook.getSheetAt(0);
7762 kshitij.so 205
		Map<Long,Map<String,String>> amazonOrderMap = new HashMap<Long,Map<String,String>>();
7741 kshitij.so 206
		for (int iterator=sheet.getFirstRowNum();iterator<=sheet.getLastRowNum();iterator++){
207
			TransactionClient tcl = new TransactionClient();
208
			List<AmazonOrder> orders = tcl.getClient().getAmazonOrderByAmazonOrderId(sheet.getRow(iterator).getCell(0).getStringCellValue());
209
			for (AmazonOrder order : orders){
7753 kshitij.so 210
				if (StringUtils.equals(order.getStatus(), "Order-Payment-Success")){
7762 kshitij.so 211
					Map<String,String> dateMap = new HashMap<String,String>();
212
					dateMap.put(sheet.getRow(iterator).getCell(1).getStringCellValue(), sheet.getRow(iterator).getCell(2).getStringCellValue());
213
					amazonOrderMap.put(order.getOrderId(), dateMap);
7741 kshitij.so 214
				}
215
			}
216
		}
217
		TransactionClient tcl = new TransactionClient();
218
		tcl.getClient().updateTimestampForAmazonOrder(amazonOrderMap);
7524 kshitij.so 219
	}
220
 
8620 kshitij.so 221
 
222
 
7461 kshitij.so 223
	private void changeItemInventory() throws NumberFormatException, TException {
224
		Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
7524 kshitij.so 225
 
7461 kshitij.so 226
		if (StringUtils.isEmpty(holdInventory)) {
227
			holdInventory = "0";
228
		}
229
		if (StringUtils.isEmpty(defaultInventory)) {
230
			defaultInventory = "0";
231
		}
232
		CatalogClient.updateItemInventory(Long.valueOf(itemId),Long.valueOf(holdInventory),Long.valueOf(defaultInventory));
233
	}
234
 
235
 
7283 kshitij.so 236
	public Map<Long, Long> getAvailableItemInventory(String itemId) throws NumberFormatException, InventoryServiceException, TException{
237
		InventoryClient inventoryServiceClient = new InventoryClient();
238
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
239
		in.shop2020.model.v1.inventory.ItemInventory thriftItemInventory = inventoryClient.getItemInventoryByItemId(Long.valueOf(itemId));
240
		return thriftItemInventory.getAvailability();
241
 
242
	}
243
 
244
	public Map<Long, Long> getReservedItemInventory(String itemId) throws NumberFormatException, InventoryServiceException, TException{
245
		InventoryClient inventoryServiceClient = new InventoryClient();
246
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
247
		in.shop2020.model.v1.inventory.ItemInventory thriftItemInventory = inventoryClient.getItemInventoryByItemId(Long.valueOf(itemId));
248
		return thriftItemInventory.getReserved();
249
 
250
	}
251
 
252
	public String getWarehouseName(String warehouseId) throws NumberFormatException, TException { 
253
		InventoryClient inventoryServiceClient = new InventoryClient();
254
		return inventoryServiceClient.getClient().getWarehouseName(Long.valueOf(warehouseId));
255
	}
256
 
257
	public AmazonInventorySnapshot getInventoryForAmazonItem(String itemId) throws NumberFormatException, TException {
258
		InventoryClient inventoryServiceClient = new InventoryClient();
7365 kshitij.so 259
		try { 
260
			return inventoryServiceClient.getClient().getAmazonInventoryForItem(Long.valueOf(itemId));
261
		}
262
		catch (Exception e){
263
			return null;
264
		}
7283 kshitij.so 265
	}
266
 
8620 kshitij.so 267
	public long getFbaInventoryForAmazonItem(String itemId) throws NumberFormatException, TException {
268
		InventoryClient inventoryServiceClient = new InventoryClient();
269
		try { 
270
			return inventoryServiceClient.getClient().getAmazonFbaItemInventory(Long.valueOf(itemId));
271
		}
272
		catch (Exception e){
273
			return 0;
274
		}
275
	}
276
 
7365 kshitij.so 277
	public Long getTimetoShip(String itemId) throws LogisticsServiceException, TException{
278
		LogisticsClient logisticsClient = new LogisticsClient();
279
		return logisticsClient.getClient().getLogisticsInfo("110001", Long.valueOf(itemId), DeliveryType.COD, PickUpType.COURIER).getShippingTime();
280
 
281
	}
282
 
8168 kshitij.so 283
	public String runAsinJob() throws IOException, InterruptedException {
284
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
285
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
286
			return "authfail";
287
		}
288
		ProcessBuilder testProcess = new ProcessBuilder("/bin/bash");
8396 kshitij.so 289
		String[] command = {"/bin/bash", "-c", "sudo /root/code/trunk/AmazonFeeds/RunAsinJob.sh"};
8168 kshitij.so 290
		testProcess.command(command);
291
		logger.info(testProcess.command().toString());
292
		Process process = testProcess.start();
293
		process.waitFor();
294
		logger.info(String.valueOf(process.exitValue()));
295
		return "asinjob";
8070 kshitij.so 296
 
8168 kshitij.so 297
	}
8620 kshitij.so 298
 
8396 kshitij.so 299
	public String runFbaListingJob() throws IOException, InterruptedException {
300
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
301
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
302
			return "authfail";
303
		}
304
		ProcessBuilder testProcess = new ProcessBuilder("/bin/bash");
305
		String[] command = {"/bin/bash", "-c", "sudo /root/code/trunk/AmazonFeeds/RunFbaListingJob.sh"};
306
		testProcess.command(command);
307
		logger.info(testProcess.command().toString());
308
		Process process = testProcess.start();
309
		process.waitFor();
310
		logger.info(String.valueOf(process.exitValue()));
311
		return "asinjob";
312
	}
8620 kshitij.so 313
 
8396 kshitij.so 314
	public String runNonFbaListingJob() throws IOException, InterruptedException {
315
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
316
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
317
			return "authfail";
318
		}
319
		ProcessBuilder testProcess = new ProcessBuilder("/bin/bash");
320
		String[] command = {"/bin/bash", "-c", "sudo /root/code/trunk/AmazonFeeds/RunNonFbaListingJob.sh"};
321
		testProcess.command(command);
322
		logger.info(testProcess.command().toString());
323
		Process process = testProcess.start();
324
		process.waitFor();
325
		logger.info(String.valueOf(process.exitValue()));
326
		return "asinjob";
327
	}
8073 kshitij.so 328
 
8620 kshitij.so 329
	public void uploadAsinFile() throws IOException, TException{
330
		File fileToCreate = new File("/tmp/", "Amazon-asin-upload.xls");
331
		FileUtils.copyFile(this.file, fileToCreate);
332
		FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
333
		HSSFWorkbook workbook = new HSSFWorkbook(iFile);
334
		HSSFSheet sheet = workbook.getSheetAt(0);
335
		Map<Long,Item> amazonAsin = new HashMap<Long,Item>();
336
		StringBuilder sb =new StringBuilder();
337
		Client CatalogClient=null;
338
		try {
339
			CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
340
		} catch (TTransportException e) {
341
			e.printStackTrace();
342
		}
343
		for (int iterator=(sheet.getFirstRowNum()+1);iterator<=sheet.getLastRowNum();iterator++){
344
			Item item=null;
345
			Long sku;
346
			String asin;
347
			if (checkEmptyString(sheet.getRow(iterator).getCell(0))){
348
				continue;
349
			}
350
			else {
351
				sku=(long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
352
				try {
353
					item = CatalogClient.getItem(sku);
354
				} catch (Exception e) {
355
					logger.info("Unable to fetch item details ID= "+sku);
356
					logger.info("Unable to fetch item. "+e);
357
					sb.append("Service exception ItemId not updated Id= "+sku+"\n");
358
					continue;
359
				} 
360
			}
361
 
362
			if(item.getId() == 0){
363
				logger.info("Item Id doesn't exist in catalog Id= "+sku);
364
				sb.append("Item Id doesn't exist in catalog Id= "+sku+"\n");
365
				continue;
366
			}
367
 
368
			if (!checkEmptyString(sheet.getRow(iterator).getCell(1))){
369
				asin = sheet.getRow(iterator).getCell(1).getStringCellValue();
370
				item.setAsin(asin);
371
			}
372
 
373
			if (!checkEmptyString(sheet.getRow(iterator).getCell(2))){
374
				long virtualInventory =(long) sheet.getRow(iterator).getCell(2).getNumericCellValue();
375
				item.setDefaultInventory(virtualInventory);
376
			}
377
 
378
			if (!checkEmptyString(sheet.getRow(iterator).getCell(3))){
379
				long riskyInventory =(long) sheet.getRow(iterator).getCell(3).getNumericCellValue();
380
				item.setHoldInventory(riskyInventory);
381
			}
382
 
383
			amazonAsin.put(sku, item);
384
		}
385
		CatalogClient.updateAsin(amazonAsin);
386
 
387
		logger.info("Amazon Asin Map "+amazonAsin.toString());
388
		CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
389
		CatalogClient.updateAsin(amazonAsin);
390
		File file = new File("/tmp/asinfile");
391
		FileWriter writer = new FileWriter(file);
392
		writer.append(sb.toString());
393
		writer.close();
394
		byte[] buffer = new byte[(int)file.length()];
395
		InputStream input = null;
396
		try {
397
			int totalBytesRead = 0;
398
			input = new BufferedInputStream(new FileInputStream(file));
399
			while(totalBytesRead < buffer.length){
400
				int bytesRemaining = buffer.length - totalBytesRead;
401
				int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
402
				if (bytesRead > 0){
403
					totalBytesRead = totalBytesRead + bytesRead;
404
				}
405
			}
406
		}
407
		finally {
408
			input.close();
409
			file.delete();
410
		}
411
 
412
		response.setHeader("Content-Type", "text/javascript");
413
 
414
		ServletOutputStream sos;
415
		try {
416
			sos = response.getOutputStream();
417
			sos.write(buffer);
418
			sos.flush();
419
		} catch (IOException e) {
420
			System.out.println("Unable to stream the manifest file");
421
		}   
422
	}
423
 
8168 kshitij.so 424
	public void uploadBulkFile() throws IOException, TException{
425
		File fileToCreate = new File("/tmp/", "Amazon-bulk-upload.xls");
426
		FileUtils.copyFile(this.file, fileToCreate);
427
		FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
428
		HSSFWorkbook workbook = new HSSFWorkbook(iFile);
429
		HSSFSheet sheet = workbook.getSheetAt(0);
430
		Map<Long,Amazonlisted> amazonBulkUpdate = new HashMap<Long,Amazonlisted>();
431
		Client CatalogClient=null;
8362 kshitij.so 432
		StringBuilder sb = new StringBuilder();
8168 kshitij.so 433
		try {
434
			CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
435
		} catch (TTransportException e) {
436
			// TODO Auto-generated catch block
437
			e.printStackTrace();
438
		}
439
		for (int iterator=(sheet.getFirstRowNum()+1);iterator<=sheet.getLastRowNum();iterator++){
440
			Amazonlisted amazonlisted =null;
441
			Long sku;
442
			if (checkEmptyString(sheet.getRow(iterator).getCell(0))){
443
				continue;
444
			}
445
			else {
446
				sku=(long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
8362 kshitij.so 447
				try {
448
					amazonlisted = CatalogClient.getAmazonItemDetails(sku);
449
				} catch (TException e) {
450
					logger.info("Unable to fetch item details ID= "+sku);
451
					sb.append("Service exception ItemId not updated Id= "+sku+"\n");
452
					continue;
453
				}
8168 kshitij.so 454
			}
8620 kshitij.so 455
 
8362 kshitij.so 456
			if(amazonlisted.getItemid() == 0){
457
				logger.info("Item Id doesn't exist in amazonlisted Id= "+sku);
458
				sb.append("Item Id doesn't exist in amazonlisted Id= "+sku+"\n");
459
				continue;
460
			}
8168 kshitij.so 461
 
462
			if (!checkEmptyString(sheet.getRow(iterator).getCell(1))){
463
				double mfnPrice = sheet.getRow(iterator).getCell(1).getNumericCellValue();
464
				amazonlisted.setSellingPrice(mfnPrice);
465
			}
466
 
467
			if (!checkEmptyString(sheet.getRow(iterator).getCell(2))){
468
				double fbaSellingPrice = sheet.getRow(iterator).getCell(2).getNumericCellValue();
469
				amazonlisted.setFbaPrice(fbaSellingPrice);
470
			}
471
 
472
			if (!checkEmptyString(sheet.getRow(iterator).getCell(3))){
473
				if ((long)sheet.getRow(iterator).getCell(3).getNumericCellValue()==1){
474
					amazonlisted.setIsNonFba(true);
475
				}
476
				if ((long)sheet.getRow(iterator).getCell(3).getNumericCellValue()==0){
477
					amazonlisted.setIsNonFba(false);
478
				}
479
			}
480
 
481
			if (!checkEmptyString(sheet.getRow(iterator).getCell(4))){
482
				if ((long)sheet.getRow(iterator).getCell(4).getNumericCellValue()==1){
483
					amazonlisted.setIsFba(true);
484
				}
485
				if ((long)sheet.getRow(iterator).getCell(4).getNumericCellValue()==0){
486
					amazonlisted.setIsFba(false);
487
				}
488
			}
489
			if (!checkEmptyString(sheet.getRow(iterator).getCell(5))){
490
				if ((long)sheet.getRow(iterator).getCell(5).getNumericCellValue()==1){
491
					amazonlisted.setIsInventoryOverride(true);
492
				}
493
				if ((long)sheet.getRow(iterator).getCell(5).getNumericCellValue()==0){
494
					amazonlisted.setIsInventoryOverride(false);
495
				}
496
			}
497
			if (!checkEmptyString(sheet.getRow(iterator).getCell(6))){
498
				if ((long)sheet.getRow(iterator).getCell(6).getNumericCellValue()==1){
499
					amazonlisted.setSuppressMfnPriceUpdate(true);
500
				}
501
				if ((long)sheet.getRow(iterator).getCell(6).getNumericCellValue()==0){
502
					amazonlisted.setSuppressMfnPriceUpdate(false);
503
				}
504
			}
505
 
506
			if (!checkEmptyString(sheet.getRow(iterator).getCell(7))){
507
				if ((long)sheet.getRow(iterator).getCell(7).getNumericCellValue()==1){
508
					amazonlisted.setSuppressFbaPriceUpdate(true);
509
				}
510
				if ((long)sheet.getRow(iterator).getCell(7).getNumericCellValue()==0){
511
					amazonlisted.setSuppressFbaPriceUpdate(false);
512
				}
513
			}
8620 kshitij.so 514
 
515
			if (!checkEmptyString(sheet.getRow(iterator).getCell(8))){
516
				String taxCode = sheet.getRow(iterator).getCell(8).getStringCellValue();
517
				amazonlisted.setTaxCode(taxCode);
518
			}
8168 kshitij.so 519
			amazonBulkUpdate.put(sku, amazonlisted);
520
		}
521
		logger.info("Amazon Bulk Map "+amazonBulkUpdate.toString());
522
		CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
523
		CatalogClient.updateAmazonAttributesInBulk(amazonBulkUpdate);
8620 kshitij.so 524
		File file = new File("/tmp/amazonbulk");
8362 kshitij.so 525
		FileWriter writer = new FileWriter(file);
526
		writer.append(sb.toString());
527
		writer.close();
528
		byte[] buffer = new byte[(int)file.length()];
529
		InputStream input = null;
530
		try {
531
			int totalBytesRead = 0;
532
			input = new BufferedInputStream(new FileInputStream(file));
533
			while(totalBytesRead < buffer.length){
534
				int bytesRemaining = buffer.length - totalBytesRead;
535
				int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
536
				if (bytesRead > 0){
537
					totalBytesRead = totalBytesRead + bytesRead;
538
				}
539
			}
540
		}
541
		finally {
542
			input.close();
543
			file.delete();
544
		}
545
 
546
		response.setHeader("Content-Type", "text/javascript");
547
 
548
		ServletOutputStream sos;
549
		try {
550
			sos = response.getOutputStream();
551
			sos.write(buffer);
552
			sos.flush();
553
		} catch (IOException e) {
554
			System.out.println("Unable to stream the manifest file");
555
		}   
8168 kshitij.so 556
	}
557
 
558
 
8620 kshitij.so 559
 
560
 
8168 kshitij.so 561
	public boolean checkEmptyString(Cell cell){
562
		if (cell==null){
563
			return true;
564
		}
565
		return false;
566
	}
567
 
568
	public String uploadSheet(){
569
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
570
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
571
			return "authfail";
572
		}
573
		return "amazon-shipping-upload";
574
	}
575
 
8620 kshitij.so 576
	public String uploadAsin(){
577
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
578
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
579
			return "authfail";
580
		}
581
		return "amazon-asin-upload";
582
	}
583
 
8168 kshitij.so 584
	public String uploadBulkSheet(){
585
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
586
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
587
			return "authfail";
588
		}
589
		return "amazon-bulk-upload";
590
	}
591
 
592
 
7283 kshitij.so 593
	public String edit() {
7591 kshitij.so 594
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1])) {
595
			return "authfail";
596
		}
7283 kshitij.so 597
		return "edit";
598
	}
599
 
600
	public String show() {
8168 kshitij.so 601
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1])) {
602
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1]);
603
			return "authfail";
604
		}
605
 
606
		if (StringUtils.equals(id, "options")){
607
			return "options";
608
		}
8620 kshitij.so 609
 
610
		if (StringUtils.equals(id, "item-table")){
611
			return "amazon-item-table";
612
		}
613
 
8168 kshitij.so 614
		return "id";
7283 kshitij.so 615
	}
616
 
617
	public String editNew() {
618
		return "editNew";
8168 kshitij.so 619
	}	
7283 kshitij.so 620
 
621
	public void setId(String id) {
8168 kshitij.so 622
		logger.info(id);
7283 kshitij.so 623
		this.id = id;
624
	}
625
 
626
	public void setUrl(String url) {
627
		this.url = url;
628
	}
629
 
630
	public String getUrl() {
631
		return url;
632
	}
633
 
634
	public String getId() {
635
		return id;
636
	}
637
 
638
	public void setItemId(String itemId) {
639
		this.itemId = itemId;
640
	}
641
 
642
	public String getItemId() {
643
		return itemId;
644
	}
645
 
646
	public void setIsFba(String isFba) {
647
		this.isFba = isFba;
648
	}
649
 
650
	public String getIsFba() {
651
		return isFba;
652
	}
653
 
654
	public void setIsNonFba(String isNonFba) {
655
		this.isNonFba = isNonFba;
656
	}
657
 
658
	public String getIsNonFba() {
659
		return isNonFba;
660
	}
661
 
662
	public void setIsInventoryOverride(String isInventoryOverride) {
663
		this.isInventoryOverride = isInventoryOverride;
664
	}
665
 
666
	public String getIsInventoryOverride() {
667
		return isInventoryOverride;
668
	}
669
 
670
	public void setSellingPrice(String sellingPrice) {
671
		this.sellingPrice = sellingPrice;
672
	}
673
 
674
	public String getSellingPrice() {
675
		return sellingPrice;
676
	}
677
 
678
	public void setFbaPrice(String fbaPrice) {
679
		this.fbaPrice = fbaPrice;
680
	}
681
 
682
	public String getFbaPrice() {
683
		return fbaPrice;
684
	}
7365 kshitij.so 685
 
7283 kshitij.so 686
	public void setSaholicPrice(String saholicPrice) {
687
		this.saholicPrice = saholicPrice;
688
	}
689
 
690
	public String getSaholicPrice() {
691
		return saholicPrice;
692
	}
693
 
7365 kshitij.so 694
	public void setIsTime(String isTime){
8620 kshitij.so 695
		logger.info("set istime"+isTime);
7365 kshitij.so 696
		this.isTime = isTime;
697
	}
698
 
7461 kshitij.so 699
	public String getIsTime(){
7365 kshitij.so 700
		return isTime;
701
	}
702
 
703
	public void setHandlingTime(String handlingTime){
704
		this.handlingTime = handlingTime;
705
	}
706
 
7461 kshitij.so 707
	public String getHandlingTime(){
7365 kshitij.so 708
		return handlingTime;
709
	}
8168 kshitij.so 710
 
7365 kshitij.so 711
	public void setCustomHandlingTime(String customHandlingTime){
8620 kshitij.so 712
		logger.info("set custom handling time"+customHandlingTime);
7365 kshitij.so 713
		this.customHandlingTime = customHandlingTime;
714
	}
715
 
7461 kshitij.so 716
	public String getCustomHandlingTime(){
7365 kshitij.so 717
		return customHandlingTime;
718
	}
7524 kshitij.so 719
 
7461 kshitij.so 720
	public void setHoldInventory(String holdInventory){
721
		this.holdInventory = holdInventory;
722
	}
7365 kshitij.so 723
 
7461 kshitij.so 724
	public String getHoldInventory(){
725
		return holdInventory;
726
	}
7524 kshitij.so 727
 
7461 kshitij.so 728
	public void setDefaultInventory(String defaultInventory){
729
		this.defaultInventory = defaultInventory;
730
	}
731
 
732
	public String getDefaultInventory(){
733
		return defaultInventory;
734
	}
735
 
7524 kshitij.so 736
	public File getFile() {
737
		return file;
738
	}
739
 
740
	public void setFile(File file) {
741
		this.file = file;
742
	}
743
 
744
	public String getFileUploadContentType() {
745
		return fileUploadContentType;
746
	}
747
 
748
	public void setFileUploadContentType(String fileUploadContentType) {
749
		this.fileUploadContentType = fileUploadContentType;
750
	}
751
 
752
	public String getFileUploadFileName() {
753
		return fileUploadFileName;
754
	}
755
 
756
	public void setFileUploadFileName(String fileUploadFileName) {
757
		this.fileUploadFileName = fileUploadFileName;
758
	}
759
 
7591 kshitij.so 760
	public void setServletRequest(HttpServletRequest req) {
761
		this.request = req;
762
		this.session = req.getSession();        
7283 kshitij.so 763
	}
764
 
8168 kshitij.so 765
	@Override
766
	public void setServletContext(ServletContext arg0) {
767
		// TODO Auto-generated method stub
768
 
769
	}
770
 
771
 
772
	public void setSuppressMfnPriceUpdate(String suppressMfnPriceUpdate) {
773
		this.suppressMfnPriceUpdate = suppressMfnPriceUpdate;
774
	}
775
 
776
	public String getSuppressMfnPriceUpdate() {
777
		return suppressMfnPriceUpdate;
778
	}
779
 
780
	public void setSuppressFbaPriceUpdate(String suppressFbaPriceUpdate) {
781
		this.suppressFbaPriceUpdate = suppressFbaPriceUpdate;
782
	}
783
 
784
	public String getSuppressFbaPriceUpdate() {
785
		return suppressFbaPriceUpdate;
786
	}
8362 kshitij.so 787
 
788
	public void setErrMsg(String errMsg) {
789
		this.errMsg = errMsg;
790
	}
791
 
792
	public String getErrMsg() {
793
		return errMsg;
794
	}
8620 kshitij.so 795
 
8362 kshitij.so 796
	public void setServletResponse(HttpServletResponse response) {
797
		this.response = response;
798
	}
799
 
8620 kshitij.so 800
	public void setNext(String next) {
801
		logger.info("next is"+next);
802
		this.next = next;
803
	}
804
 
805
	public String getNext() {
806
		return next;
807
	}
808
 
809
	public void setAmazonItems(List<Amazonlisted> amazonItems) {
810
		this.amazonItems = amazonItems;
811
	}
812
 
813
	public List<Amazonlisted> getAmazonItems() {
814
		return amazonItems;
815
	}
816
 
817
	public void setSearchText(String searchText) {
818
		this.searchText = searchText;
819
	}
820
 
821
	public String getSearchText() {
822
		return searchText;
823
	}
824
 
825
	public long getSearchCount() {
826
		return searchCount;
827
	}
828
 
829
	public long getTotalCount() {
830
		return totalCount;
831
	}
832
 
833
	public void setSearchCount(long count) {
834
		this.searchCount = count;
835
	}
836
 
837
	public void setTaxCode(String taxCode) {
838
		this.taxCode = taxCode;
839
	}
840
 
841
	public String getTaxCode() {
842
		return taxCode;
843
	}
844
 
7283 kshitij.so 845
}