Subversion Repositories SmartDukaan

Rev

Rev 8168 | Rev 8396 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8168 Rev 8362
Line 1... Line 1...
1
package in.shop2020.support.controllers;
1
package in.shop2020.support.controllers;
2
 
2
 
-
 
3
import java.io.BufferedInputStream;
3
import java.io.File;
4
import java.io.File;
4
import java.io.FileInputStream;
5
import java.io.FileInputStream;
-
 
6
import java.io.FileWriter;
5
import java.io.IOException;
7
import java.io.IOException;
-
 
8
import java.io.InputStream;
6
import java.util.HashMap;
9
import java.util.HashMap;
7
import java.util.List;
10
import java.util.List;
8
import java.util.Map;
11
import java.util.Map;
9
 
12
 
10
import javax.servlet.ServletContext;
13
import javax.servlet.ServletContext;
-
 
14
import javax.servlet.ServletOutputStream;
11
import javax.servlet.ServletRequest;
15
import javax.servlet.ServletRequest;
12
import javax.servlet.http.HttpServletRequest;
16
import javax.servlet.http.HttpServletRequest;
13
import javax.servlet.http.HttpServletResponse;
17
import javax.servlet.http.HttpServletResponse;
14
import javax.servlet.http.HttpSession;
18
import javax.servlet.http.HttpSession;
15
 
19
 
Line 63... Line 67...
63
	private static Logger logger = LoggerFactory.getLogger(AmazonListController.class);
67
	private static Logger logger = LoggerFactory.getLogger(AmazonListController.class);
64
 
68
 
65
	private HttpServletRequest request;
69
	private HttpServletRequest request;
66
	private HttpSession session;
70
	private HttpSession session;
67
	private ServletContext context;
71
	private ServletContext context;
-
 
72
	private HttpServletResponse response;
68
	private String url;
73
	private String url;
69
	private String id;
74
	private String id;
70
	private String itemId;
75
	private String itemId;
71
	private String isFba;
76
	private String isFba;
72
	private String isNonFba;
77
	private String isNonFba;
Line 82... Line 87...
82
	private String fileUploadFileName;
87
	private String fileUploadFileName;
83
	private String fileUploadContentType;
88
	private String fileUploadContentType;
84
	private String suppressMfnPriceUpdate;
89
	private String suppressMfnPriceUpdate;
85
	private String suppressFbaPriceUpdate;
90
	private String suppressFbaPriceUpdate;
86
	private File file;
91
	private File file;
-
 
92
	private String errMsg;
87
 
93
 
88
	public String index() {
94
	public String index() {
89
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getServletPath())) {
95
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getServletPath())) {
90
			return "authfail";
96
			return "authfail";
91
		}
97
		}
Line 290... Line 296...
290
		FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
296
		FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
291
		HSSFWorkbook workbook = new HSSFWorkbook(iFile);
297
		HSSFWorkbook workbook = new HSSFWorkbook(iFile);
292
		HSSFSheet sheet = workbook.getSheetAt(0);
298
		HSSFSheet sheet = workbook.getSheetAt(0);
293
		Map<Long,Amazonlisted> amazonBulkUpdate = new HashMap<Long,Amazonlisted>();
299
		Map<Long,Amazonlisted> amazonBulkUpdate = new HashMap<Long,Amazonlisted>();
294
		Client CatalogClient=null;
300
		Client CatalogClient=null;
-
 
301
		StringBuilder sb = new StringBuilder();
295
		try {
302
		try {
296
			CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
303
			CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
297
		} catch (TTransportException e) {
304
		} catch (TTransportException e) {
298
			// TODO Auto-generated catch block
305
			// TODO Auto-generated catch block
299
			e.printStackTrace();
306
			e.printStackTrace();
Line 304... Line 311...
304
			if (checkEmptyString(sheet.getRow(iterator).getCell(0))){
311
			if (checkEmptyString(sheet.getRow(iterator).getCell(0))){
305
				continue;
312
				continue;
306
			}
313
			}
307
			else {
314
			else {
308
				sku=(long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
315
				sku=(long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
-
 
316
				try {
309
				amazonlisted = CatalogClient.getAmazonItemDetails(sku);
317
					amazonlisted = CatalogClient.getAmazonItemDetails(sku);
-
 
318
				} catch (TException e) {
-
 
319
					logger.info("Unable to fetch item details ID= "+sku);
-
 
320
					sb.append("Service exception ItemId not updated Id= "+sku+"\n");
-
 
321
					continue;
-
 
322
				}
-
 
323
			}
-
 
324
			
-
 
325
			if(amazonlisted.getItemid() == 0){
-
 
326
				logger.info("Item Id doesn't exist in amazonlisted Id= "+sku);
-
 
327
				sb.append("Item Id doesn't exist in amazonlisted Id= "+sku+"\n");
-
 
328
				continue;
310
			}
329
			}
311
 
330
 
312
			if (!checkEmptyString(sheet.getRow(iterator).getCell(1))){
331
			if (!checkEmptyString(sheet.getRow(iterator).getCell(1))){
313
				double mfnPrice = sheet.getRow(iterator).getCell(1).getNumericCellValue();
332
				double mfnPrice = sheet.getRow(iterator).getCell(1).getNumericCellValue();
314
				amazonlisted.setSellingPrice(mfnPrice);
333
				amazonlisted.setSellingPrice(mfnPrice);
Line 364... Line 383...
364
			amazonBulkUpdate.put(sku, amazonlisted);
383
			amazonBulkUpdate.put(sku, amazonlisted);
365
		}
384
		}
366
		logger.info("Amazon Bulk Map "+amazonBulkUpdate.toString());
385
		logger.info("Amazon Bulk Map "+amazonBulkUpdate.toString());
367
		CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
386
		CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
368
		CatalogClient.updateAmazonAttributesInBulk(amazonBulkUpdate);
387
		CatalogClient.updateAmazonAttributesInBulk(amazonBulkUpdate);
-
 
388
		File file = new File("/tmp/temp");
-
 
389
		FileWriter writer = new FileWriter(file);
-
 
390
		writer.append(sb.toString());
-
 
391
		writer.close();
-
 
392
		byte[] buffer = new byte[(int)file.length()];
-
 
393
		InputStream input = null;
-
 
394
		try {
-
 
395
			int totalBytesRead = 0;
-
 
396
			input = new BufferedInputStream(new FileInputStream(file));
-
 
397
			while(totalBytesRead < buffer.length){
-
 
398
				int bytesRemaining = buffer.length - totalBytesRead;
-
 
399
				int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
-
 
400
				if (bytesRead > 0){
-
 
401
					totalBytesRead = totalBytesRead + bytesRead;
-
 
402
				}
-
 
403
			}
-
 
404
		}
-
 
405
		finally {
-
 
406
			input.close();
-
 
407
			file.delete();
-
 
408
		}
-
 
409
 
-
 
410
		response.setHeader("Content-Type", "text/javascript");
-
 
411
 
-
 
412
		ServletOutputStream sos;
-
 
413
		try {
-
 
414
			sos = response.getOutputStream();
-
 
415
			sos.write(buffer);
-
 
416
			sos.flush();
-
 
417
		} catch (IOException e) {
-
 
418
			System.out.println("Unable to stream the manifest file");
-
 
419
		}   
369
	}
420
	}
370
 
421
 
371
 
422
 
372
	public boolean checkEmptyString(Cell cell){
423
	public boolean checkEmptyString(Cell cell){
373
		if (cell==null){
424
		if (cell==null){
Line 567... Line 618...
567
	public void setServletContext(ServletContext arg0) {
618
	public void setServletContext(ServletContext arg0) {
568
		// TODO Auto-generated method stub
619
		// TODO Auto-generated method stub
569
 
620
 
570
	}
621
	}
571
 
622
 
572
	@Override
-
 
573
	public void setServletResponse(HttpServletResponse arg0) {
-
 
574
		// TODO Auto-generated method stub
-
 
575
 
-
 
576
	}
-
 
577
 
623
 
578
	public void setSuppressMfnPriceUpdate(String suppressMfnPriceUpdate) {
624
	public void setSuppressMfnPriceUpdate(String suppressMfnPriceUpdate) {
579
		this.suppressMfnPriceUpdate = suppressMfnPriceUpdate;
625
		this.suppressMfnPriceUpdate = suppressMfnPriceUpdate;
580
	}
626
	}
581
 
627
 
Line 588... Line 634...
588
	}
634
	}
589
 
635
 
590
	public String getSuppressFbaPriceUpdate() {
636
	public String getSuppressFbaPriceUpdate() {
591
		return suppressFbaPriceUpdate;
637
		return suppressFbaPriceUpdate;
592
	}
638
	}
-
 
639
 
-
 
640
	public void setErrMsg(String errMsg) {
-
 
641
		this.errMsg = errMsg;
-
 
642
	}
-
 
643
 
-
 
644
	public String getErrMsg() {
-
 
645
		return errMsg;
-
 
646
	}
-
 
647
	
-
 
648
	public void setServletResponse(HttpServletResponse response) {
-
 
649
		this.response = response;
-
 
650
	}
-
 
651
 
593
}
652
}