Subversion Repositories SmartDukaan

Rev

Rev 19249 | Go to most recent revision | Details | 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
				}
380
			itemPricingList.add(i);
381
			}
382
		}
383
		boolean res = cc.updateItemPricing(itemPricingList);
384
		if (res){
385
			setResult("Pricing updated successfully");
386
		}
387
		else{
388
			setResult("Unable to update pricing");
389
		}
390
		return "item-details-json";
391
	}
392
 
393
	public String downloadVendors() throws TException, IOException{
394
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
395
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
396
			return "authfail";
397
		}
398
		InventoryClient inventoryServiceClient = new InventoryClient();
399
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
400
		List<Vendor> vendors = inventoryClient.getAllVendors();
401
 
402
		File file = new File("/tmp/vendors.xls");
403
		HSSFWorkbook hwb=new HSSFWorkbook();
404
		HSSFSheet sheet =  hwb.createSheet("Vendors");
405
		HSSFRow rowhead=   sheet.createRow((short)0);
406
		rowhead.createCell((short) 0).setCellValue("VENDOR_ID");
407
		rowhead.createCell((short) 1).setCellValue("VENDOR_NAME");
408
 
409
		int iterator= 1;
410
		for (Vendor v : vendors){
411
			HSSFRow row = sheet.createRow((short)iterator);
412
			row.createCell((short) 0).setCellValue(v.getId());
413
			row.createCell((short) 1).setCellValue(v.getName());
414
			iterator++;
415
		}
416
 
417
		FileOutputStream fileOut = null;
418
		try {
419
			fileOut = new FileOutputStream(file);
420
		} catch (FileNotFoundException e) {
421
			// TODO Auto-generated catch block
422
			e.printStackTrace();
423
		}
424
		try {
425
			hwb.write(fileOut);
426
		} catch (IOException e) {
427
			// TODO Auto-generated catch block
428
			e.printStackTrace();
429
		}
430
		try {
431
			fileOut.close();
432
		} catch (IOException e) {
433
			// TODO Auto-generated catch block
434
			e.printStackTrace();
435
		}
436
		byte[] buffer = new byte[(int)file.length()];
437
		InputStream input = null;
438
		try {
439
			int totalBytesRead = 0;
440
			input = new BufferedInputStream(new FileInputStream(file));
441
			while(totalBytesRead < buffer.length){
442
				int bytesRemaining = buffer.length - totalBytesRead;
443
				int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
444
				if (bytesRead > 0){
445
					totalBytesRead = totalBytesRead + bytesRead;
446
				}
447
			}
448
		}
449
		finally {
450
			input.close();
451
			file.delete();
452
		}
453
 
454
		response.setHeader("Content-Disposition", "attachment; filename=\"Vendors.xls\"");
455
		response.setContentType("application/octet-stream");
456
		ServletOutputStream sos;
457
		try {
458
			sos = response.getOutputStream();
459
			sos.write(buffer);
460
			sos.flush();
461
		} catch (IOException e) {
462
			System.out.println("Unable to stream the manifest file");
463
		}
464
		setResult("Vendor Streaming done");
465
		return "item-details-json";
466
 
467
	}
468
 
469
	public String downloadWarehouses() throws TException, IOException{
470
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
471
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
472
			return "authfail";
473
		}
474
		InventoryClient inventoryServiceClient = new InventoryClient();
475
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
476
		List<Warehouse> warehouses = inventoryClient.getWarehouses(null, null, 0, 0, 0);
477
 
478
		File file = new File("/tmp/warehouses.xls");
479
		HSSFWorkbook hwb=new HSSFWorkbook();
480
		HSSFSheet sheet =  hwb.createSheet("Warehouses");
481
		HSSFRow rowhead=   sheet.createRow((short)0);
482
		rowhead.createCell((short) 0).setCellValue("warehouse_id");
483
		rowhead.createCell((short) 1).setCellValue("display_name");
484
		rowhead.createCell((short) 2).setCellValue("location");
485
		rowhead.createCell((short) 3).setCellValue("vendor_id");
486
		rowhead.createCell((short) 4).setCellValue("vendor_name");
487
		rowhead.createCell((short) 5).setCellValue("inventory_type");
488
		rowhead.createCell((short) 6).setCellValue("warehouse_type");
489
		rowhead.createCell((short) 7).setCellValue("logistics_location");
490
		rowhead.createCell((short) 8).setCellValue("state_id");
491
 
492
		int iterator= 1;
493
		for (Warehouse w : warehouses){
494
			HSSFRow row = sheet.createRow((short)iterator);
495
			row.createCell((short) 0).setCellValue(w.getId());
496
			row.createCell((short) 1).setCellValue(w.getDisplayName());
497
			row.createCell((short) 2).setCellValue(w.getLocation());
498
			row.createCell((short) 3).setCellValue(w.getVendor().getId());
499
			row.createCell((short) 4).setCellValue(w.getVendor().getName());
500
			row.createCell((short) 5).setCellValue(w.getInventoryType().toString());
501
			row.createCell((short) 6).setCellValue(w.getWarehouseType().toString());
502
			row.createCell((short) 7).setCellValue(w.getLogisticsLocation().toString());
503
			row.createCell((short) 7).setCellValue(w.getStateId());
504
			iterator++;
505
		}
506
 
507
		FileOutputStream fileOut = null;
508
		try {
509
			fileOut = new FileOutputStream(file);
510
		} catch (FileNotFoundException e) {
511
			// TODO Auto-generated catch block
512
			e.printStackTrace();
513
		}
514
		try {
515
			hwb.write(fileOut);
516
		} catch (IOException e) {
517
			// TODO Auto-generated catch block
518
			e.printStackTrace();
519
		}
520
		try {
521
			fileOut.close();
522
		} catch (IOException e) {
523
			// TODO Auto-generated catch block
524
			e.printStackTrace();
525
		}
526
		byte[] buffer = new byte[(int)file.length()];
527
		InputStream input = null;
528
		try {
529
			int totalBytesRead = 0;
530
			input = new BufferedInputStream(new FileInputStream(file));
531
			while(totalBytesRead < buffer.length){
532
				int bytesRemaining = buffer.length - totalBytesRead;
533
				int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
534
				if (bytesRead > 0){
535
					totalBytesRead = totalBytesRead + bytesRead;
536
				}
537
			}
538
		}
539
		finally {
540
			input.close();
541
			file.delete();
542
		}
543
 
544
		response.setHeader("Content-Disposition", "attachment; filename=\"Warehouses.xls\"");
545
		response.setContentType("application/octet-stream");
546
		ServletOutputStream sos;
547
		try {
548
			sos = response.getOutputStream();
549
			sos.write(buffer);
550
			sos.flush();
551
		} catch (IOException e) {
552
			System.out.println("Unable to stream the manifest file");
553
		}
554
		setResult("Warehouse Streaming done");
555
		return "item-details-json";
556
 
557
	}
558
 
559
 
560
	public boolean checkEmptyString(Cell cell){
561
		if (cell==null || cell.getCellType() == Cell.CELL_TYPE_BLANK){
562
			return true;
563
		}
564
		return false;
565
	}
566
 
567
	public String getItemDetails(){
568
		return result;
569
	}
570
 
571
	public void setId(String id) {
572
		this.id = id;
573
	}
574
 
575
	public String getUserName(){
576
		return session.getAttribute(ReportsUtils.USER_NAME).toString();
577
	}
578
 
579
	public HttpServletRequest getRequest() {
580
		logger.info("set request"+request.toString());
581
		return request;
582
	}
583
 
584
	public void setRequest(HttpServletRequest request) {
585
		this.request = request;
586
	}
587
 
588
	public HttpServletResponse getResponse() {
589
		return response;
590
	}
591
 
592
	public void setResponse(HttpServletResponse response) {
593
		this.response = response;
594
	}
595
 
596
	public HttpSession getSession() {
597
		return session;
598
	}
599
 
600
	public void setSession(HttpSession session) {
601
		this.session = session;
602
	}
603
 
604
	public ServletContext getContext() {
605
		return context;
606
	}
607
 
608
	public void setContext(ServletContext context) {
609
		this.context = context;
610
	}
611
 
612
 
613
	public void setServletRequest(HttpServletRequest req) {
614
		this.request = req;
615
		this.session = req.getSession();        
616
	}
617
 
618
	public void setServletContext(ServletContext arg0) {
619
		// TODO Auto-generated method stub
620
 
621
	}
622
 
623
	public void setServletResponse(HttpServletResponse response) {
624
		this.response = response;
625
	}
626
 
627
	public String getResult() {
628
		return result;
629
	}
630
 
631
	public void setResult(String result) {
632
		this.result = result;
633
	}
634
 
635
	public File getFile() {
636
		return file;
637
	}
638
 
639
	public void setFile(File file) {
640
		this.file = file;
641
	}
642
 
643
 
644
}