Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
19248 kshitij.so 1
package in.shop2020.support.controllers;
2
 
3
 
4
import java.io.BufferedInputStream;
5
import java.io.File;
6
import java.io.FileInputStream;
7
import java.io.FileNotFoundException;
8
import java.io.FileOutputStream;
9
import java.io.IOException;
10
import java.io.InputStream;
11
import java.util.ArrayList;
12
import java.util.HashMap;
13
import java.util.List;
14
import java.util.Map;
15
 
16
import in.shop2020.model.v1.catalog.CatalogServiceException;
17
import in.shop2020.model.v1.catalog.Item;
18
import in.shop2020.model.v1.catalog.ItemPricing;
19
import in.shop2020.model.v1.catalog.CatalogService.Client;
20
import in.shop2020.model.v1.dtr.BulkItems;
21
import in.shop2020.model.v1.inventory.BulkAddInventory;
22
import in.shop2020.model.v1.inventory.InventoryServiceException;
23
import in.shop2020.model.v1.inventory.Vendor;
24
import in.shop2020.model.v1.inventory.VendorItemPricing;
25
import in.shop2020.model.v1.inventory.Warehouse;
26
import in.shop2020.model.v1.order.AmazonOrder;
27
import in.shop2020.support.utils.ReportsUtils;
28
import in.shop2020.thrift.clients.CatalogClient;
29
import in.shop2020.thrift.clients.DtrClient;
30
import in.shop2020.thrift.clients.InventoryClient;
31
import in.shop2020.thrift.clients.TransactionClient;
32
 
33
import org.apache.commons.io.FileUtils;
34
import org.apache.commons.lang.xwork.StringUtils;
35
 
36
import javax.servlet.ServletContext;
37
import javax.servlet.ServletOutputStream;
38
import javax.servlet.http.HttpServletRequest;
39
import javax.servlet.http.HttpServletResponse;
40
import javax.servlet.http.HttpSession;
41
 
42
import org.apache.poi.hssf.usermodel.HSSFRow;
43
import org.apache.poi.hssf.usermodel.HSSFSheet;
44
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
45
import org.apache.poi.ss.usermodel.Cell;
46
import org.apache.struts2.convention.annotation.InterceptorRef;
47
import org.apache.struts2.convention.annotation.InterceptorRefs;
48
import org.apache.struts2.interceptor.ServletRequestAware;
49
import org.apache.struts2.interceptor.ServletResponseAware;
50
import org.apache.struts2.util.ServletContextAware;
51
import org.apache.thrift.TException;
52
import org.apache.thrift.transport.TTransportException;
53
import org.slf4j.Logger;
54
import org.slf4j.LoggerFactory;
55
 
56
import com.opensymphony.xwork2.ValidationAwareSupport;
57
 
58
@SuppressWarnings({"unused","deprecation"})
59
 
60
@InterceptorRefs({
61
	@InterceptorRef("defaultStack"),
62
	@InterceptorRef("login")
63
})
64
 
65
public class BulkAddController extends ValidationAwareSupport implements ServletRequestAware ,ServletResponseAware, ServletContextAware{
66
	/**
67
	 * 
68
	 */
69
	private static final long serialVersionUID = 1L;
70
 
71
 
72
	private static Logger logger = LoggerFactory.getLogger(BulkAddController.class);
73
 
74
 
75
	private HttpServletRequest request;
76
	private HttpServletResponse response;
77
	private HttpSession session;
78
	private ServletContext context;
79
	private String id;
80
	private String result;
81
	private File file;
82
 
83
	public String index() {
84
		if (!ReportsUtils.canAccessReport((Long) session.getAttribute(ReportsUtils.ROLE),request.getServletPath())) {
85
			return "authfail";
86
		}
87
		return "index";
88
	}
89
 
90
	public String edit() {
91
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1])) {
92
			return "authfail";
93
		}
94
		return "edit";
95
	}
96
 
97
 
98
	public String show() {
99
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1])) {
100
			return "authfail";
101
		}
102
		logger.info("Inside show for "+id);
103
 
104
		if (StringUtils.equals(id, "bulk-add-options")){
105
			return "bulk-add-options";
106
		}
107
		return "id";
108
	}
109
 
110
	public String loadVendorDiv(){
111
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
112
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
113
			return "authfail";
114
		}
115
		return "vendor-item-pricing-upload";
116
	}
117
 
118
	public String loadVirtualDiv(){
119
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
120
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
121
			return "authfail";
122
		}
123
		return "virtual-bulk-add";
124
	}
125
 
126
	public String loadCatalogDiv(){
127
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
128
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
129
			return "authfail";
130
		}
131
		return "catalog-bulk-add";
132
	}
133
 
134
	public String loadDtrDiv(){
135
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
136
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
137
			return "authfail";
138
		}
139
		return "dtr-bulk-add";
140
	}
141
 
142
	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])) {
144
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
145
			return "authfail";
146
		}
147
		File fileToCreate = new File("/tmp/", "dtr-items.xls");
148
		FileUtils.copyFile(this.file, fileToCreate);
149
		FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
150
		HSSFWorkbook workbook = new HSSFWorkbook(iFile);
151
		HSSFSheet sheet = workbook.getSheetAt(0);
152
 
153
		List<BulkItems> bulkItemsList= new ArrayList<BulkItems>();
154
 
155
		List<Long> items = new ArrayList<Long>();
156
 
157
		for (int iterator=sheet.getFirstRowNum()+1;iterator<=sheet.getLastRowNum();iterator++){
158
			long item_id = (long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
159
			items.add(item_id);
160
		}
161
 
162
		Client cc = new CatalogClient().getClient();
163
		Map<Long, Item> itemMap = cc.getItems(items);
164
		StringBuilder sb = new StringBuilder(); 
165
		for (int iterator=sheet.getFirstRowNum()+1;iterator<=sheet.getLastRowNum();iterator++){
166
			long itemId = (long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
167
			Item t_item = itemMap.get(itemId);
168
			if (t_item==null){
169
				sb.append("Item is not valid "+itemId+"\n");
170
				continue;
171
			}
172
			BulkItems b = new BulkItems();
173
			b.setItem_id(itemId);
174
			int show_mrp_flag = (int) sheet.getRow(iterator).getCell(1).getNumericCellValue();
175
			b.setShowMrpFlag(show_mrp_flag ==1 ? true : false);
176
			String tagline = sheet.getRow(iterator).getCell(2).getStringCellValue().toString();
177
			b.setTagline(tagline);
178
			String offer = sheet.getRow(iterator).getCell(3).getStringCellValue().toString();
179
			b.setOffer(offer);
180
			long category_id = (long) sheet.getRow(iterator).getCell(4).getNumericCellValue();
181
			if (category_id!=6L){
182
				sb.append("Category Id is not valid "+itemId+"\n");
183
			}
184
			b.setCategory_id(category_id);
185
			long sub_category_id = (long) sheet.getRow(iterator).getCell(5).getNumericCellValue();
186
			if (sub_category_id==0){
187
				sb.append("SubCategory Id is not valid "+itemId+"\n");
188
			}
189
			b.setSubCategoryId(sub_category_id);
190
			int show_net_price = (int) sheet.getRow(iterator).getCell(6).getNumericCellValue();
191
			b.setShowNetPrice(show_net_price ==1 ? true : false);
192
			long brand_id = (long) sheet.getRow(iterator).getCell(7).getNumericCellValue();
193
			if (brand_id==0){
194
				sb.append("Brand Id is not valid "+itemId+"\n");
195
			}
196
			b.setBrand_id(brand_id);
197
			b.setAvailable_price(t_item.getSellingPrice());
198
			b.setMrp(t_item.getMrp());
199
			b.setBrand(t_item.getBrand());
200
			b.setIdentifier(String.valueOf(t_item.getCatalogItemId()));
201
			b.setModel_name(t_item.getModelName()+" "+t_item.getModelNumber());
202
			b.setProduct_name(t_item.getBrand()+" "+t_item.getModelName()+" "+t_item.getModelNumber());
203
			b.setSource_product_name(t_item.getBrand()+" "+t_item.getModelName()+" "+t_item.getModelNumber());
204
			b.setQuantity(t_item.getPackQuantity());
205
			bulkItemsList.add(b);
206
		}
207
		if (sb.length()>0){
208
			setResult("Please correct error \n"+sb.toString());
209
			return "item-details-json";
210
		}
211
		in.shop2020.model.v1.dtr.DtrService.Client dc = new DtrClient("dtr_service_server_host","dtr_service_server_port").getClient(); 
212
		List<String> res = dc.addItemsInBulk(bulkItemsList);
213
		if (res.size()>0){
214
			for(String s : res){
215
				sb.append("Catalog ItemId not added "+s+"\n");
216
			}
217
			setResult(sb.toString());
218
		}else{
219
			setResult("Items added successfully");
220
		}
221
		return "item-details-json";
222
	}
223
 
224
	public String updateVirtualInventory() throws IOException, CatalogServiceException, TException, InventoryServiceException{
225
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
226
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
227
			return "authfail";
228
		}
229
 
230
		File fileToCreate = new File("/tmp/", "vendor-inventory.xls");
231
		FileUtils.copyFile(this.file, fileToCreate);
232
		FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
233
		HSSFWorkbook workbook = new HSSFWorkbook(iFile);
234
		HSSFSheet sheet = workbook.getSheetAt(0);
235
 
236
		List<BulkAddInventory> vendorInventory= new ArrayList<BulkAddInventory>();
237
 
238
		List<Long> items = new ArrayList<Long>();
239
 
240
		for (int iterator=sheet.getFirstRowNum()+1;iterator<=sheet.getLastRowNum();iterator++){
241
			long item_id = (long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
242
			items.add(item_id);
243
		}
244
		Client cc = new CatalogClient().getClient();
245
		Map<Long, Item> itemMap = cc.getItems(items);
246
 
247
		for (int iterator=sheet.getFirstRowNum()+1;iterator<=sheet.getLastRowNum();iterator++){
248
			long itemId = (long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
249
			if (itemMap.get(itemId)==null){
250
				continue;
251
			}
252
			BulkAddInventory b = new BulkAddInventory();
253
			b.setItem_id(itemId);
254
			long warehouseId = (long) sheet.getRow(iterator).getCell(1).getNumericCellValue();
255
			b.setWarehouse_id(warehouseId);
256
			long inventory = (long) sheet.getRow(iterator).getCell(2).getNumericCellValue();
257
			b.setInventory(inventory);
258
			vendorInventory.add(b);
259
		}
260
 
261
		InventoryClient inventoryServiceClient = new InventoryClient();
262
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
263
		inventoryClient.addInventoryInBulk(vendorInventory);
264
		setResult("Inventory updated successfully");
265
		return "item-details-json";
266
	}
267
 
268
	public String addVendorItemPricing() throws IOException, TException, CatalogServiceException{
269
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
270
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
271
			return "authfail";
272
		}
273
		File fileToCreate = new File("/tmp/", "vendor-pricing.xls");
274
		FileUtils.copyFile(this.file, fileToCreate);
275
		FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
276
		HSSFWorkbook workbook = new HSSFWorkbook(iFile);
277
		HSSFSheet sheet = workbook.getSheetAt(0);
278
 
279
		List<VendorItemPricing> vendorItemPricingList= new ArrayList<VendorItemPricing>();
280
		List<Long> items = new ArrayList<Long>();
281
 
282
		for (int iterator=sheet.getFirstRowNum()+1;iterator<=sheet.getLastRowNum();iterator++){
283
			long item_id = (long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
284
			items.add(item_id);
285
		}
286
		Client cc = new CatalogClient().getClient();
287
		Map<Long, Item> itemMap = cc.getItems(items);
288
 
289
		for (int iterator=sheet.getFirstRowNum()+1;iterator<=sheet.getLastRowNum();iterator++){
290
			long itemId = (long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
291
			if (itemMap.get(itemId)==null){
292
				continue;
293
			}
294
			VendorItemPricing v = new VendorItemPricing();
295
			v.setItemId(itemId);
296
			long vendorId = (long) sheet.getRow(iterator).getCell(1).getNumericCellValue();
297
			v.setVendorId(vendorId);
298
			double mop = (double) sheet.getRow(iterator).getCell(2).getNumericCellValue();
299
			v.setMop(mop);
300
			double dp = (double) sheet.getRow(iterator).getCell(3).getNumericCellValue();
301
			v.setDealerPrice(dp);
302
			double tp = (double) sheet.getRow(iterator).getCell(4).getNumericCellValue();
303
			v.setTransferPrice(tp);
304
			double nlc = (double) sheet.getRow(iterator).getCell(5).getNumericCellValue();
305
			v.setNlc(nlc);
306
			vendorItemPricingList.add(v);
307
			}
308
 
309
		InventoryClient inventoryServiceClient = new InventoryClient();
310
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
311
		List<Long> notUpdated = inventoryClient.addVendorItemPricingInBulk(vendorItemPricingList);
312
 
313
		if (notUpdated.size() > 0){
314
			StringBuilder sb = new StringBuilder();
315
			for (Long x : notUpdated){
316
				sb.append("Vendor Pricing not updated for "+x+"\n");
317
			}
318
			setResult(sb.toString());
319
		}
320
		else{
321
			setResult("Vendor item pricing updated.");
322
		}
323
		return "item-details-json";
324
	}
325
 
326
	public String updateItemPricing() throws IOException, CatalogServiceException, TException{
327
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
328
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
329
			return "authfail";
330
		}
331
		File fileToCreate = new File("/tmp/", "item-pricing.xls");
332
		FileUtils.copyFile(this.file, fileToCreate);
333
		FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
334
		HSSFWorkbook workbook = new HSSFWorkbook(iFile);
335
		HSSFSheet sheet = workbook.getSheetAt(0);
336
 
337
		List<ItemPricing> itemPricingList= new ArrayList<ItemPricing>();
338
		List<Long> items = new ArrayList<Long>();
339
 
340
		for (int iterator=sheet.getFirstRowNum()+1;iterator<=sheet.getLastRowNum();iterator++){
341
			long item_id = (long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
342
			items.add(item_id);
343
		}
344
		Client cc = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
345
		Map<Long, Item> itemMap = cc.getItems(items);
346
 
347
		for (int iterator=sheet.getFirstRowNum()+1;iterator<=sheet.getLastRowNum();iterator++){
348
			ItemPricing i = new ItemPricing();
349
			long item_id = (long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
350
			i.setItem_id(item_id);
351
			if (itemMap.get(item_id)!=null){
352
				if (checkEmptyString(sheet.getRow(iterator).getCell(1))){
353
					i.setSelling_price(itemMap.get(item_id).getSellingPrice());
354
				}
355
				else{
356
					double sellingPrice = (double) sheet.getRow(iterator).getCell(1).getNumericCellValue();
357
					i.setSelling_price(sellingPrice);
358
				}
359
				if (checkEmptyString(sheet.getRow(iterator).getCell(2))){
360
					i.setMrp(itemMap.get(item_id).getMrp());
361
				}
362
				else{
363
					double mrp = (double) sheet.getRow(iterator).getCell(2).getNumericCellValue();
364
					i.setMrp(mrp);
365
				}
366
				if (checkEmptyString(sheet.getRow(iterator).getCell(3))){
367
					i.setPreferred_vendor(itemMap.get(item_id).getPreferredVendor());
368
				}
369
				else{
370
					long preferred_vendor = (long) sheet.getRow(iterator).getCell(3).getNumericCellValue();
371
					i.setPreferred_vendor(preferred_vendor);
372
				}
373
				if (checkEmptyString(sheet.getRow(iterator).getCell(4))){
374
					i.setPrivate_deal_price(0);
375
				}
376
				else{
377
					double private_deal_price = (double) sheet.getRow(iterator).getCell(4).getNumericCellValue();
378
					i.setPrivate_deal_price(private_deal_price);
379
				}
19249 kshitij.so 380
				if (checkEmptyString(sheet.getRow(iterator).getCell(5))){
381
					i.setWeight(itemMap.get(item_id).getWeight());
382
				}
383
				else{
384
					double weight = (double) sheet.getRow(iterator).getCell(5).getNumericCellValue();
385
					i.setPrivate_deal_price(weight);
386
				}
19248 kshitij.so 387
			itemPricingList.add(i);
388
			}
389
		}
390
		boolean res = cc.updateItemPricing(itemPricingList);
391
		if (res){
392
			setResult("Pricing updated successfully");
393
		}
394
		else{
395
			setResult("Unable to update pricing");
396
		}
397
		return "item-details-json";
398
	}
399
 
400
	public String downloadVendors() throws TException, IOException{
401
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
402
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
403
			return "authfail";
404
		}
405
		InventoryClient inventoryServiceClient = new InventoryClient();
406
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
407
		List<Vendor> vendors = inventoryClient.getAllVendors();
408
 
409
		File file = new File("/tmp/vendors.xls");
410
		HSSFWorkbook hwb=new HSSFWorkbook();
411
		HSSFSheet sheet =  hwb.createSheet("Vendors");
412
		HSSFRow rowhead=   sheet.createRow((short)0);
413
		rowhead.createCell((short) 0).setCellValue("VENDOR_ID");
414
		rowhead.createCell((short) 1).setCellValue("VENDOR_NAME");
415
 
416
		int iterator= 1;
417
		for (Vendor v : vendors){
418
			HSSFRow row = sheet.createRow((short)iterator);
419
			row.createCell((short) 0).setCellValue(v.getId());
420
			row.createCell((short) 1).setCellValue(v.getName());
421
			iterator++;
422
		}
423
 
424
		FileOutputStream fileOut = null;
425
		try {
426
			fileOut = new FileOutputStream(file);
427
		} catch (FileNotFoundException e) {
428
			// TODO Auto-generated catch block
429
			e.printStackTrace();
430
		}
431
		try {
432
			hwb.write(fileOut);
433
		} catch (IOException e) {
434
			// TODO Auto-generated catch block
435
			e.printStackTrace();
436
		}
437
		try {
438
			fileOut.close();
439
		} catch (IOException e) {
440
			// TODO Auto-generated catch block
441
			e.printStackTrace();
442
		}
443
		byte[] buffer = new byte[(int)file.length()];
444
		InputStream input = null;
445
		try {
446
			int totalBytesRead = 0;
447
			input = new BufferedInputStream(new FileInputStream(file));
448
			while(totalBytesRead < buffer.length){
449
				int bytesRemaining = buffer.length - totalBytesRead;
450
				int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
451
				if (bytesRead > 0){
452
					totalBytesRead = totalBytesRead + bytesRead;
453
				}
454
			}
455
		}
456
		finally {
457
			input.close();
458
			file.delete();
459
		}
460
 
461
		response.setHeader("Content-Disposition", "attachment; filename=\"Vendors.xls\"");
462
		response.setContentType("application/octet-stream");
463
		ServletOutputStream sos;
464
		try {
465
			sos = response.getOutputStream();
466
			sos.write(buffer);
467
			sos.flush();
468
		} catch (IOException e) {
469
			System.out.println("Unable to stream the manifest file");
470
		}
471
		setResult("Vendor Streaming done");
472
		return "item-details-json";
473
 
474
	}
475
 
476
	public String downloadWarehouses() throws TException, IOException{
477
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
478
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
479
			return "authfail";
480
		}
481
		InventoryClient inventoryServiceClient = new InventoryClient();
482
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
483
		List<Warehouse> warehouses = inventoryClient.getWarehouses(null, null, 0, 0, 0);
484
 
485
		File file = new File("/tmp/warehouses.xls");
486
		HSSFWorkbook hwb=new HSSFWorkbook();
487
		HSSFSheet sheet =  hwb.createSheet("Warehouses");
488
		HSSFRow rowhead=   sheet.createRow((short)0);
489
		rowhead.createCell((short) 0).setCellValue("warehouse_id");
490
		rowhead.createCell((short) 1).setCellValue("display_name");
491
		rowhead.createCell((short) 2).setCellValue("location");
492
		rowhead.createCell((short) 3).setCellValue("vendor_id");
493
		rowhead.createCell((short) 4).setCellValue("vendor_name");
494
		rowhead.createCell((short) 5).setCellValue("inventory_type");
495
		rowhead.createCell((short) 6).setCellValue("warehouse_type");
496
		rowhead.createCell((short) 7).setCellValue("logistics_location");
497
		rowhead.createCell((short) 8).setCellValue("state_id");
498
 
499
		int iterator= 1;
500
		for (Warehouse w : warehouses){
501
			HSSFRow row = sheet.createRow((short)iterator);
502
			row.createCell((short) 0).setCellValue(w.getId());
503
			row.createCell((short) 1).setCellValue(w.getDisplayName());
504
			row.createCell((short) 2).setCellValue(w.getLocation());
505
			row.createCell((short) 3).setCellValue(w.getVendor().getId());
506
			row.createCell((short) 4).setCellValue(w.getVendor().getName());
507
			row.createCell((short) 5).setCellValue(w.getInventoryType().toString());
508
			row.createCell((short) 6).setCellValue(w.getWarehouseType().toString());
509
			row.createCell((short) 7).setCellValue(w.getLogisticsLocation().toString());
510
			row.createCell((short) 7).setCellValue(w.getStateId());
511
			iterator++;
512
		}
513
 
514
		FileOutputStream fileOut = null;
515
		try {
516
			fileOut = new FileOutputStream(file);
517
		} catch (FileNotFoundException e) {
518
			// TODO Auto-generated catch block
519
			e.printStackTrace();
520
		}
521
		try {
522
			hwb.write(fileOut);
523
		} catch (IOException e) {
524
			// TODO Auto-generated catch block
525
			e.printStackTrace();
526
		}
527
		try {
528
			fileOut.close();
529
		} catch (IOException e) {
530
			// TODO Auto-generated catch block
531
			e.printStackTrace();
532
		}
533
		byte[] buffer = new byte[(int)file.length()];
534
		InputStream input = null;
535
		try {
536
			int totalBytesRead = 0;
537
			input = new BufferedInputStream(new FileInputStream(file));
538
			while(totalBytesRead < buffer.length){
539
				int bytesRemaining = buffer.length - totalBytesRead;
540
				int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
541
				if (bytesRead > 0){
542
					totalBytesRead = totalBytesRead + bytesRead;
543
				}
544
			}
545
		}
546
		finally {
547
			input.close();
548
			file.delete();
549
		}
550
 
551
		response.setHeader("Content-Disposition", "attachment; filename=\"Warehouses.xls\"");
552
		response.setContentType("application/octet-stream");
553
		ServletOutputStream sos;
554
		try {
555
			sos = response.getOutputStream();
556
			sos.write(buffer);
557
			sos.flush();
558
		} catch (IOException e) {
559
			System.out.println("Unable to stream the manifest file");
560
		}
561
		setResult("Warehouse Streaming done");
562
		return "item-details-json";
563
 
564
	}
565
 
566
 
567
	public boolean checkEmptyString(Cell cell){
568
		if (cell==null || cell.getCellType() == Cell.CELL_TYPE_BLANK){
569
			return true;
570
		}
571
		return false;
572
	}
573
 
574
	public String getItemDetails(){
575
		return result;
576
	}
577
 
578
	public void setId(String id) {
579
		this.id = id;
580
	}
581
 
582
	public String getUserName(){
583
		return session.getAttribute(ReportsUtils.USER_NAME).toString();
584
	}
585
 
586
	public HttpServletRequest getRequest() {
587
		logger.info("set request"+request.toString());
588
		return request;
589
	}
590
 
591
	public void setRequest(HttpServletRequest request) {
592
		this.request = request;
593
	}
594
 
595
	public HttpServletResponse getResponse() {
596
		return response;
597
	}
598
 
599
	public void setResponse(HttpServletResponse response) {
600
		this.response = response;
601
	}
602
 
603
	public HttpSession getSession() {
604
		return session;
605
	}
606
 
607
	public void setSession(HttpSession session) {
608
		this.session = session;
609
	}
610
 
611
	public ServletContext getContext() {
612
		return context;
613
	}
614
 
615
	public void setContext(ServletContext context) {
616
		this.context = context;
617
	}
618
 
619
 
620
	public void setServletRequest(HttpServletRequest req) {
621
		this.request = req;
622
		this.session = req.getSession();        
623
	}
624
 
625
	public void setServletContext(ServletContext arg0) {
626
		// TODO Auto-generated method stub
627
 
628
	}
629
 
630
	public void setServletResponse(HttpServletResponse response) {
631
		this.response = response;
632
	}
633
 
634
	public String getResult() {
635
		return result;
636
	}
637
 
638
	public void setResult(String result) {
639
		this.result = result;
640
	}
641
 
642
	public File getFile() {
643
		return file;
644
	}
645
 
646
	public void setFile(File file) {
647
		this.file = file;
648
	}
649
 
650
 
651
}