| Line 18... |
Line 18... |
| 18 |
import in.shop2020.model.v1.catalog.ItemPricing;
|
18 |
import in.shop2020.model.v1.catalog.ItemPricing;
|
| 19 |
import in.shop2020.model.v1.catalog.CatalogService.Client;
|
19 |
import in.shop2020.model.v1.catalog.CatalogService.Client;
|
| 20 |
import in.shop2020.model.v1.dtr.BulkItems;
|
20 |
import in.shop2020.model.v1.dtr.BulkItems;
|
| 21 |
import in.shop2020.model.v1.inventory.BulkAddInventory;
|
21 |
import in.shop2020.model.v1.inventory.BulkAddInventory;
|
| 22 |
import in.shop2020.model.v1.inventory.InventoryServiceException;
|
22 |
import in.shop2020.model.v1.inventory.InventoryServiceException;
|
| - |
|
23 |
import in.shop2020.model.v1.inventory.ItemInventory;
|
| 23 |
import in.shop2020.model.v1.inventory.Vendor;
|
24 |
import in.shop2020.model.v1.inventory.Vendor;
|
| 24 |
import in.shop2020.model.v1.inventory.VendorItemPricing;
|
25 |
import in.shop2020.model.v1.inventory.VendorItemPricing;
|
| 25 |
import in.shop2020.model.v1.inventory.Warehouse;
|
26 |
import in.shop2020.model.v1.inventory.Warehouse;
|
| 26 |
import in.shop2020.model.v1.order.AmazonOrder;
|
27 |
import in.shop2020.model.v1.order.AmazonOrder;
|
| 27 |
import in.shop2020.support.utils.ReportsUtils;
|
28 |
import in.shop2020.support.utils.ReportsUtils;
|
| Line 77... |
Line 78... |
| 77 |
private HttpSession session;
|
78 |
private HttpSession session;
|
| 78 |
private ServletContext context;
|
79 |
private ServletContext context;
|
| 79 |
private String id;
|
80 |
private String id;
|
| 80 |
private String result;
|
81 |
private String result;
|
| 81 |
private File file;
|
82 |
private File file;
|
| - |
|
83 |
private String virtualWarehouseId;
|
| - |
|
84 |
|
| - |
|
85 |
public String getVirtualWarehouseId() {
|
| - |
|
86 |
return virtualWarehouseId;
|
| - |
|
87 |
}
|
| - |
|
88 |
|
| - |
|
89 |
public void setVirtualWarehouseId(String virtualWarehouseId) {
|
| - |
|
90 |
this.virtualWarehouseId = virtualWarehouseId;
|
| - |
|
91 |
}
|
| 82 |
|
92 |
|
| 83 |
public String index() {
|
93 |
public String index() {
|
| 84 |
if (!ReportsUtils.canAccessReport((Long) session.getAttribute(ReportsUtils.ROLE),request.getServletPath())) {
|
94 |
if (!ReportsUtils.canAccessReport((Long) session.getAttribute(ReportsUtils.ROLE),request.getServletPath())) {
|
| 85 |
return "authfail";
|
95 |
return "authfail";
|
| 86 |
}
|
96 |
}
|
| Line 137... |
Line 147... |
| 137 |
return "authfail";
|
147 |
return "authfail";
|
| 138 |
}
|
148 |
}
|
| 139 |
return "dtr-bulk-add";
|
149 |
return "dtr-bulk-add";
|
| 140 |
}
|
150 |
}
|
| 141 |
|
151 |
|
| - |
|
152 |
public String loadDownloadVirtualDiv(){
|
| - |
|
153 |
if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
|
| - |
|
154 |
logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
|
| - |
|
155 |
return "authfail";
|
| - |
|
156 |
}
|
| - |
|
157 |
return "download-virtual-div";
|
| - |
|
158 |
}
|
| - |
|
159 |
|
| 142 |
public String uploadItemsDtr() throws IOException, CatalogServiceException, TException{
|
160 |
public String uploadItemsDtr() throws IOException, CatalogServiceException, TException{
|
| 143 |
if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
|
161 |
if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
|
| 144 |
logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
|
162 |
logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
|
| 145 |
return "authfail";
|
163 |
return "authfail";
|
| 146 |
}
|
164 |
}
|
| Line 579... |
Line 597... |
| 579 |
setResult("Warehouse Streaming done");
|
597 |
setResult("Warehouse Streaming done");
|
| 580 |
return "item-details-json";
|
598 |
return "item-details-json";
|
| 581 |
|
599 |
|
| 582 |
}
|
600 |
}
|
| 583 |
|
601 |
|
| - |
|
602 |
public String downloadVirtualInventoryForWarehouse() throws NumberFormatException, TException, IOException{
|
| - |
|
603 |
try{
|
| - |
|
604 |
InventoryClient inventoryServiceClient = new InventoryClient();
|
| - |
|
605 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
|
| - |
|
606 |
Map<Long, ItemInventory> inventoryMap = inventoryClient.getInventorySnapshot(Long.valueOf(virtualWarehouseId));
|
| - |
|
607 |
File file = new File("/tmp/currentinventory.xls");
|
| - |
|
608 |
HSSFWorkbook hwb=new HSSFWorkbook();
|
| - |
|
609 |
HSSFSheet sheet = hwb.createSheet("Inventory");
|
| - |
|
610 |
HSSFRow rowhead= sheet.createRow((short)0);
|
| - |
|
611 |
rowhead.createCell((short) 0).setCellValue("item_id");
|
| - |
|
612 |
rowhead.createCell((short) 1).setCellValue("Availability");
|
| - |
|
613 |
rowhead.createCell((short) 2).setCellValue("Reserved");
|
| - |
|
614 |
rowhead.createCell((short) 3).setCellValue("Held");
|
| - |
|
615 |
|
| - |
|
616 |
int iterator= 1;
|
| - |
|
617 |
for (Map.Entry<Long,ItemInventory> entry : inventoryMap.entrySet()) {
|
| - |
|
618 |
HSSFRow row = sheet.createRow((short)iterator);
|
| - |
|
619 |
row.createCell((short) 0).setCellValue(entry.getKey());
|
| - |
|
620 |
row.createCell((short) 1).setCellValue(entry.getValue().getAvailability().get(Long.valueOf(virtualWarehouseId)));
|
| - |
|
621 |
row.createCell((short) 2).setCellValue(entry.getValue().getReserved().get(Long.valueOf(virtualWarehouseId)));
|
| - |
|
622 |
row.createCell((short) 3).setCellValue(entry.getValue().getHeld().get(Long.valueOf(virtualWarehouseId)));
|
| - |
|
623 |
iterator++;
|
| - |
|
624 |
}
|
| - |
|
625 |
|
| - |
|
626 |
FileOutputStream fileOut = null;
|
| - |
|
627 |
try {
|
| - |
|
628 |
fileOut = new FileOutputStream(file);
|
| - |
|
629 |
} catch (FileNotFoundException e) {
|
| - |
|
630 |
// TODO Auto-generated catch block
|
| - |
|
631 |
e.printStackTrace();
|
| - |
|
632 |
}
|
| - |
|
633 |
try {
|
| - |
|
634 |
hwb.write(fileOut);
|
| - |
|
635 |
} catch (IOException e) {
|
| - |
|
636 |
// TODO Auto-generated catch block
|
| - |
|
637 |
e.printStackTrace();
|
| - |
|
638 |
}
|
| - |
|
639 |
try {
|
| - |
|
640 |
fileOut.close();
|
| - |
|
641 |
} catch (IOException e) {
|
| - |
|
642 |
// TODO Auto-generated catch block
|
| - |
|
643 |
e.printStackTrace();
|
| - |
|
644 |
}
|
| - |
|
645 |
byte[] buffer = new byte[(int)file.length()];
|
| - |
|
646 |
InputStream input = null;
|
| - |
|
647 |
try {
|
| - |
|
648 |
int totalBytesRead = 0;
|
| - |
|
649 |
input = new BufferedInputStream(new FileInputStream(file));
|
| - |
|
650 |
while(totalBytesRead < buffer.length){
|
| - |
|
651 |
int bytesRemaining = buffer.length - totalBytesRead;
|
| - |
|
652 |
int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining);
|
| - |
|
653 |
if (bytesRead > 0){
|
| - |
|
654 |
totalBytesRead = totalBytesRead + bytesRead;
|
| - |
|
655 |
}
|
| - |
|
656 |
}
|
| - |
|
657 |
}
|
| - |
|
658 |
finally {
|
| - |
|
659 |
input.close();
|
| - |
|
660 |
file.delete();
|
| - |
|
661 |
}
|
| - |
|
662 |
|
| - |
|
663 |
response.setHeader("Content-Disposition", "attachment; filename=\"Inventory.xls\"");
|
| - |
|
664 |
response.setContentType("application/octet-stream");
|
| - |
|
665 |
ServletOutputStream sos;
|
| - |
|
666 |
try {
|
| - |
|
667 |
sos = response.getOutputStream();
|
| - |
|
668 |
sos.write(buffer);
|
| - |
|
669 |
sos.flush();
|
| - |
|
670 |
} catch (IOException e) {
|
| - |
|
671 |
System.out.println("Unable to stream the manifest file");
|
| - |
|
672 |
}
|
| - |
|
673 |
}
|
| - |
|
674 |
catch(Exception e){
|
| - |
|
675 |
setResult("Something went wrong");
|
| - |
|
676 |
return "item-details-json";
|
| - |
|
677 |
}
|
| - |
|
678 |
setResult("Streaming done");
|
| - |
|
679 |
return "item-details-json";
|
| - |
|
680 |
}
|
| - |
|
681 |
|
| 584 |
|
682 |
|
| 585 |
public boolean checkEmptyString(Cell cell){
|
683 |
public boolean checkEmptyString(Cell cell){
|
| 586 |
if (cell==null || cell.getCellType() == Cell.CELL_TYPE_BLANK){
|
684 |
if (cell==null || cell.getCellType() == Cell.CELL_TYPE_BLANK){
|
| 587 |
return true;
|
685 |
return true;
|
| 588 |
}
|
686 |
}
|
| Line 663... |
Line 761... |
| 663 |
|
761 |
|
| 664 |
public void setFile(File file) {
|
762 |
public void setFile(File file) {
|
| 665 |
this.file = file;
|
763 |
this.file = file;
|
| 666 |
}
|
764 |
}
|
| 667 |
|
765 |
|
| - |
|
766 |
public static void main(String args[]) throws NumberFormatException, TException, IOException{
|
| - |
|
767 |
BulkAddController b = new BulkAddController();
|
| - |
|
768 |
b.setVirtualWarehouseId("3295");
|
| - |
|
769 |
b.downloadVirtualInventoryForWarehouse();
|
| - |
|
770 |
}
|
| - |
|
771 |
|
| 668 |
|
772 |
|
| 669 |
}
|
773 |
}
|
| 670 |
|
774 |
|