Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
5711 mandeep.dh 1
/**
2
 * 
3
 */
4
package in.shop2020.inventory.controllers;
5
 
10689 manish.sha 6
import in.shop2020.model.v1.catalog.CatalogService;
7
import in.shop2020.model.v1.inventory.AmazonFbaInventorySnapshot;
8
import in.shop2020.model.v1.inventory.InventoryService;
9
import in.shop2020.thrift.clients.CatalogClient;
10
import in.shop2020.thrift.clients.InventoryClient;
5711 mandeep.dh 11
import in.shop2020.thrift.clients.WarehouseClient;
10689 manish.sha 12
import in.shop2020.warehouse.AmazonTransferredSkuDetail;
5711 mandeep.dh 13
import in.shop2020.warehouse.InventoryAge;
10689 manish.sha 14
import in.shop2020.warehouse.Scan;
15
import in.shop2020.warehouse.ScanType;
5711 mandeep.dh 16
import in.shop2020.warehouse.WarehouseService.Client;
17
 
18
import java.io.BufferedInputStream;
19
import java.io.BufferedWriter;
20
import java.io.File;
21
import java.io.FileInputStream;
10689 manish.sha 22
import java.io.FileNotFoundException;
23
import java.io.FileReader;
5711 mandeep.dh 24
import java.io.FileWriter;
25
import java.io.InputStream;
10689 manish.sha 26
import java.util.ArrayList;
27
import java.util.HashMap;
5711 mandeep.dh 28
import java.util.List;
10689 manish.sha 29
import java.util.Map;
5711 mandeep.dh 30
 
31
import javax.servlet.ServletOutputStream;
32
 
33
import org.apache.commons.lang.StringUtils;
34
import org.apache.commons.logging.Log;
35
import org.apache.commons.logging.LogFactory;
36
 
10689 manish.sha 37
 
38
 
5711 mandeep.dh 39
/**
40
 * @author mandeep
41
 *
42
 */
43
public class InventoryAgeController extends BaseController {
10689 manish.sha 44
	private static Log logger = LogFactory.getLog(InventoryAgeController.class);
5711 mandeep.dh 45
 
10689 manish.sha 46
	public String index() {
47
		try {
48
			Client client = new WarehouseClient().getClient();
49
			List<InventoryAge> inventoryAge = client.getInventoryAge();
50
			List<InventoryAge> inventoryAgeAmazon = getAmazonInventoryAge();
51
			byte[] buffer = null;
52
			File file = createFile(inventoryAge, inventoryAgeAmazon);
53
			Thread.sleep(30000);
54
			buffer = new byte[(int) file.length()];
55
			InputStream input = null;
56
			try {
57
				int totalBytesRead = 0;
58
				input = new BufferedInputStream(new FileInputStream(file));
59
				while (totalBytesRead < buffer.length) {
60
					int bytesRemaining = buffer.length - totalBytesRead;
61
					// input.read() returns -1, 0, or more :
62
					int bytesRead = input.read(buffer, totalBytesRead,
63
							bytesRemaining);
64
					if (bytesRead > 0) {
65
						totalBytesRead = totalBytesRead + bytesRead;
66
					}
67
				}
68
				/*
69
				 * the above style is a bit tricky: it places bytes into the
70
				 * 'buffer' array; 'buffer' is an output parameter; the while
71
				 * loop usually has a single iteration only.
72
				 */
73
			} finally {
74
				input.close();
75
			}
5711 mandeep.dh 76
 
77
 
78
 
79
 
10689 manish.sha 80
			response.setContentType("application/vnd.ms-excel");
81
			response.setHeader("Content-disposition", "inline; filename="
82
					+ file.getName());
5711 mandeep.dh 83
 
10689 manish.sha 84
			ServletOutputStream sos = response.getOutputStream();
85
			sos.write(buffer);
86
			sos.flush();      
5711 mandeep.dh 87
 
10689 manish.sha 88
		}
89
		catch (Exception e) {
90
		}
91
 
92
		return null;
93
	}
94
 
95
	/**
96
	 * @param inventoryAge
97
	 * @return
98
	 */
99
	private File createFile(List<InventoryAge> inventoryAge, List<InventoryAge> inventoryAgeAmazon) {
100
		Map<Long,InventoryAge> inventoryAgeMap = new HashMap<Long,InventoryAge>();
11639 anikendra 101
 
10689 manish.sha 102
		for(InventoryAge invAge : inventoryAge){
103
			inventoryAgeMap.put(invAge.getItemId(), invAge);
104
		}
11639 anikendra 105
 
10689 manish.sha 106
		for(InventoryAge invAge : inventoryAgeAmazon){
107
			if(inventoryAgeMap.containsKey(invAge.getItemId())){
108
				InventoryAge invAgeObj = inventoryAgeMap.get(invAge.getItemId());
109
				invAgeObj.setFreshCount(invAgeObj.getFreshCount()+ invAge.getFreshCount());
110
				invAgeObj.setOneToTwoCount(invAgeObj.getOneToTwoCount() + invAge.getOneToTwoCount());
111
				invAgeObj.setTwoToThreeCount(invAgeObj.getTwoToThreeCount() + invAge.getTwoToThreeCount());
11639 anikendra 112
 
10689 manish.sha 113
				invAgeObj.setThreeToFourCount(invAgeObj.getThreeToFourCount() + invAge.getThreeToFourCount());
114
				invAgeObj.setFourPlusCount(invAgeObj.getFourPlusCount() + invAge.getFourPlusCount());
115
				invAgeObj.setThreeMonthPlusCount(invAgeObj.getThreeMonthPlusCount() + invAge.getThreeMonthPlusCount());
116
				invAgeObj.setSixMonthPlusCount(invAgeObj.getSixMonthPlusCount() + invAge.getSixMonthPlusCount());
11219 manish.sha 117
				invAgeObj.setZeroToThreeMonthCount(invAgeObj.getZeroToThreeMonthCount() + invAge.getZeroToThreeMonthCount());
118
				invAgeObj.setThreeToSixMonthCount(invAgeObj.getThreeToSixMonthCount() + invAge.getThreeToSixMonthCount());
119
				invAgeObj.setSixToTwelveMonthCount(invAgeObj.getSixToTwelveMonthCount() + invAge.getSixToTwelveMonthCount());
120
				invAgeObj.setTwelveMonthsPlusCount(invAgeObj.getTwelveMonthsPlusCount() + invAge.getTwelveMonthsPlusCount());
10689 manish.sha 121
				invAgeObj.setZeroPlusCount(invAgeObj.getZeroPlusCount() + invAge.getZeroPlusCount());
122
				invAgeObj.setOnePlusCount(invAgeObj.getOnePlusCount() + invAge.getOnePlusCount());
123
				invAgeObj.setZeroPlusCost(invAgeObj.getZeroPlusCost() + invAge.getZeroPlusCost());
124
				invAgeObj.setOnePlusCost(invAgeObj.getOnePlusCost() + invAge.getOnePlusCost());
11639 anikendra 125
 
10689 manish.sha 126
				inventoryAgeMap.put(invAge.getItemId(), invAgeObj);
11639 anikendra 127
 
10689 manish.sha 128
			}
129
			else{
130
				inventoryAgeMap.put(invAge.getItemId(), invAge);
131
			}
132
		}
133
		List<InventoryAge> finalInventoryAge = new ArrayList<InventoryAge>();
134
		for(Long itemId : inventoryAgeMap.keySet()){
135
			finalInventoryAge.add(inventoryAgeMap.get(itemId));
136
		}
137
		try {
138
			File file = new File("/tmp/InventoryAge.xls");
139
			BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));
140
			bufferedWriter.write(StringUtils.join(new String[] {
141
					"Item Id",
142
					"Category",
143
					"Brand",
144
					"Model Name",
145
					"Model Number",
146
					"Color",
147
					"Fresh",
148
					"1-2 week",
149
					"2-3 week",
150
					"3-4 week",
151
					"4+ week",
152
					"3+ month",
153
					"6+ month",
11219 manish.sha 154
					"0-3 month",
155
					"3-6 month",
156
					"6-12 month",
157
					"12+ month",
10689 manish.sha 158
					"1+ week",
159
					"1+ week cost",
160
					"All",
161
			"All cost" }, '\t'));
162
 
163
			for (InventoryAge item : finalInventoryAge) {
164
				bufferedWriter.newLine();
165
 
166
				bufferedWriter.write(StringUtils.join(
167
						new String[] {
168
								String.valueOf(item.getItemId()),
169
								item.getCategory(),
170
								item.getBrand(),
171
								item.getModelName(),
172
								item.getModelNumber(),
173
								item.getColor(),
174
								String.valueOf(item.getFreshCount()),
175
								String.valueOf(item.getOneToTwoCount()),
176
								String.valueOf(item.getTwoToThreeCount()),
177
								String.valueOf(item.getThreeToFourCount()),
178
								String.valueOf(item.getFourPlusCount()),
179
								String.valueOf(item.getThreeMonthPlusCount()),
180
								String.valueOf(item.getSixMonthPlusCount()),
11219 manish.sha 181
								String.valueOf(item.getZeroToThreeMonthCount()),
182
								String.valueOf(item.getThreeToSixMonthCount()),
183
								String.valueOf(item.getSixToTwelveMonthCount()),
184
								String.valueOf(item.getTwelveMonthsPlusCount()),
10689 manish.sha 185
								String.valueOf(item.getOnePlusCount()),
186
								String.valueOf(item.getOnePlusCost()),
187
								String.valueOf(item.getZeroPlusCount()),
188
								String.valueOf(item.getZeroPlusCost())}, '\t'));
189
			}
190
 
191
			bufferedWriter.close();
192
			return file;
193
		} catch (Exception e) {
194
			return null;
195
		}
196
	}
197
 
198
 
199
	public List<InventoryAge> getAmazonInventoryAge(){
200
		Long currentTimestamp = System.currentTimeMillis();
201
 
202
		List<InventoryAge> amazonInventoryAge = new ArrayList<InventoryAge>();
203
		try{
204
			InventoryService.Client inventoryClient = new InventoryClient().getClient();
205
			List<AmazonFbaInventorySnapshot> amazonFbaInventorySnapshot = inventoryClient.getAllAmazonFbaItemInventory();
11639 anikendra 206
 
10689 manish.sha 207
			List<Long> itemIds = new ArrayList<Long>();
11639 anikendra 208
 
209
			for(AmazonFbaInventorySnapshot invSnapShot : amazonFbaInventorySnapshot){
11643 vikram.rag 210
				//logger.info("AmazonFbaInventorySnapshot entry " + invSnapShot.getItem_id());
11640 vikram.rag 211
				itemIds.add(invSnapShot.getItem_id());
11639 anikendra 212
			}
213
 
10689 manish.sha 214
			Client client = new WarehouseClient().getClient();
11639 anikendra 215
 
10689 manish.sha 216
			List<AmazonTransferredSkuDetail> amazonTransferredSkuDetails = client.getAmazonTransferredSkuDetails(itemIds);
11582 manish.sha 217
			Map<Long, AmazonFbaInventorySnapshot> amazonFbaSnapshotMap = new HashMap<Long, AmazonFbaInventorySnapshot> ();
11639 anikendra 218
 
10689 manish.sha 219
			Map<Long, List<AmazonTransferredSkuDetail>> skuDetailsMap = new HashMap<Long, List<AmazonTransferredSkuDetail>>();
11639 anikendra 220
 
10689 manish.sha 221
			for(AmazonFbaInventorySnapshot invSnapShot : amazonFbaInventorySnapshot){
11642 vikram.rag 222
				Long itemId = invSnapShot.getItem_id();
11582 manish.sha 223
				if(!amazonFbaSnapshotMap.containsKey(itemId)){
224
					amazonFbaSnapshotMap.put(itemId, invSnapShot);
11643 vikram.rag 225
					//logger.info("Adding Availabity " + itemId + " Availability " +invSnapShot.getAvailability());
11582 manish.sha 226
				} else {
227
					AmazonFbaInventorySnapshot invSS = amazonFbaSnapshotMap.get(itemId);
228
					invSnapShot.setAvailability(invSnapShot.getAvailability() + invSS.getAvailability());
229
					amazonFbaSnapshotMap.put(itemId, invSnapShot);
11643 vikram.rag 230
					//logger.info("Updating Availabity " + itemId + " Availability " +invSnapShot.getAvailability());
11582 manish.sha 231
				}
11639 anikendra 232
 
10689 manish.sha 233
				List<AmazonTransferredSkuDetail> mappedList = new ArrayList<AmazonTransferredSkuDetail>();
234
				for(AmazonTransferredSkuDetail detail: amazonTransferredSkuDetails){
11641 vikram.rag 235
					if(itemId.longValue() == detail.getItemId()){
11642 vikram.rag 236
						logger.info("Amazon Transferred Sku Details Detail found for ITEM ID  " + itemId.longValue()+" " + itemId);
10689 manish.sha 237
						mappedList.add(detail);
238
					}
11639 anikendra 239
					else{
240
					}
10689 manish.sha 241
				}
11641 vikram.rag 242
				skuDetailsMap.put(itemId, mappedList);
10689 manish.sha 243
			}
244
 
245
			//CatalogService.Client catalogClient = new CatalogClient().getClient();
11639 anikendra 246
 
11582 manish.sha 247
			for(AmazonFbaInventorySnapshot invSnapShot : amazonFbaSnapshotMap.values()){
10689 manish.sha 248
				try{
249
 
250
					Long item_id = invSnapShot.getItem_id();
251
					List<AmazonTransferredSkuDetail> amazonTranSkuDetails = skuDetailsMap.get(item_id);
252
					long amazonFbaInvAvailability = invSnapShot.getAvailability();
253
					List<AmazonTransferredSkuDetail> toBeIncludeList = new ArrayList<AmazonTransferredSkuDetail>();
254
 
255
					long freshCount = 0;
256
					long oneToTwoCount = 0;
257
					long twoToThreeCount = 0;
258
					long threeToFourCount = 0;
259
					long fourPlusCount = 0;
260
					long onePlusCount = 0;
261
					long threeMonthPlusCount = 0;
262
					long sixMonthPlusCount = 0;
11219 manish.sha 263
					long zeroToThreeMonthCount = 0;
264
					long threeToSixMonthsCount = 0;
265
					long sixToTwelveMonthsCount = 0;
266
					long twelveMonthsPlusCount = 0;					
10689 manish.sha 267
					long onePlusCost = 0;
268
					long zeroPlusCount = 0;
269
					long zeroPlusCost = 0;
270
					String brand ="";
271
					String modelName ="";
272
					String modelNumber ="";
273
					String color ="";
274
					String category ="";
275
 
276
					if(amazonTranSkuDetails!=null && amazonTranSkuDetails.size()>0){
277
						brand = amazonTranSkuDetails.get(0).getBrand();
278
						modelName = amazonTranSkuDetails.get(0).getModelName();
279
						modelNumber = amazonTranSkuDetails.get(0).getModelNumber();
280
						color = amazonTranSkuDetails.get(0).getColor();
281
						category = amazonTranSkuDetails.get(0).getCategory();
11639 anikendra 282
					}else{	
283
						logger.info("Amazon Sku Transfer details  skipped " + item_id);
10689 manish.sha 284
						continue;
285
					}
286
					double invAge = 0;
287
 
288
					for(AmazonTransferredSkuDetail amazonSkuDetail : amazonTranSkuDetails){
289
						if(amazonFbaInvAvailability == amazonSkuDetail.getQuantity()){
290
							toBeIncludeList.add(amazonSkuDetail);
291
							break;
292
						}
293
						if(amazonFbaInvAvailability > amazonSkuDetail.getQuantity()){
294
							toBeIncludeList.add(amazonSkuDetail);
295
							amazonFbaInvAvailability = amazonFbaInvAvailability- amazonSkuDetail.getQuantity();
296
							continue;
297
						}
298
						if(amazonFbaInvAvailability < amazonSkuDetail.getQuantity()){
299
							amazonSkuDetail.setQuantity(amazonFbaInvAvailability);
300
							toBeIncludeList.add(amazonSkuDetail);
301
							break;
302
						}
303
					}
304
 
305
					for(AmazonTransferredSkuDetail amazonSkuInfo : toBeIncludeList){
306
						if(!amazonSkuInfo.isSetPurchaseDate() || amazonSkuInfo.getPurchaseDate() == 0){
307
							if(!client.isAlive()){
308
								client = new WarehouseClient().getClient();
309
							}
310
							List<Scan> purchaseScans = client.getScansforPurchase(amazonSkuInfo.getPurchaseId(), ScanType.PURCHASE);
311
							amazonSkuInfo.setPurchaseDate(purchaseScans.get(0).getScannedAt());
312
						}
313
						invAge = (double)(currentTimestamp - amazonSkuInfo.getPurchaseDate())/ (24 * 60 * 60 * 1000 * 7);
314
						if(invAge < 1){
315
							freshCount = freshCount + amazonSkuInfo.getQuantity();
316
						}
317
						if(invAge >= 1 && invAge < 2){
318
							oneToTwoCount = oneToTwoCount + amazonSkuInfo.getQuantity();
319
						}
320
						if(invAge >= 2 && invAge < 3){
321
							twoToThreeCount = twoToThreeCount + amazonSkuInfo.getQuantity();
322
						}
323
						if(invAge >= 3 && invAge < 4){
324
							threeToFourCount = threeToFourCount + amazonSkuInfo.getQuantity();
325
						}
326
						if(invAge >= 4){
327
							fourPlusCount = fourPlusCount + amazonSkuInfo.getQuantity();
328
						}
329
						if(invAge >= 1){
330
							onePlusCount = onePlusCount + amazonSkuInfo.getQuantity();
331
							onePlusCost = (long)(onePlusCost + ( amazonSkuInfo.getQuantity() * amazonSkuInfo.getUnitPrice() ));
332
						}
333
						if(invAge >= 13){
334
							threeMonthPlusCount = threeMonthPlusCount + amazonSkuInfo.getQuantity();
335
						}
336
						if(invAge >= 26){
337
							sixMonthPlusCount = sixMonthPlusCount + amazonSkuInfo.getQuantity();
338
						}
11639 anikendra 339
 
11219 manish.sha 340
						if(invAge >0 && invAge <=13){
341
							zeroToThreeMonthCount = zeroToThreeMonthCount + amazonSkuInfo.getQuantity();
342
						}
11639 anikendra 343
 
11219 manish.sha 344
						if(invAge >13 && invAge <=26){
345
							threeToSixMonthsCount = threeToSixMonthsCount + amazonSkuInfo.getQuantity();
346
						}
11639 anikendra 347
 
11219 manish.sha 348
						if(invAge >26 && invAge <=52){
349
							sixToTwelveMonthsCount = sixToTwelveMonthsCount + amazonSkuInfo.getQuantity();
350
						}
11639 anikendra 351
 
11219 manish.sha 352
						if(invAge > 52){
353
							twelveMonthsPlusCount = twelveMonthsPlusCount + amazonSkuInfo.getQuantity();
354
						}
10689 manish.sha 355
 
356
						zeroPlusCount = zeroPlusCount + amazonSkuInfo.getQuantity(); 
11639 anikendra 357
 
10689 manish.sha 358
						zeroPlusCost = (long)(zeroPlusCost + ( amazonSkuInfo.getQuantity() * amazonSkuInfo.getUnitPrice() ));
359
					}
360
 
11639 anikendra 361
 
10689 manish.sha 362
					InventoryAge inventAge = new InventoryAge();
363
					inventAge.setItemId(item_id);
364
					inventAge.setBrand(brand);
365
					inventAge.setModelName(modelName);
366
					inventAge.setModelNumber(modelNumber);
367
					inventAge.setColor(color);
368
					inventAge.setFreshCount(freshCount);
369
					inventAge.setOneToTwoCount(oneToTwoCount);
370
					inventAge.setTwoToThreeCount(twoToThreeCount);
371
					inventAge.setThreeToFourCount(threeToFourCount);
372
					inventAge.setFourPlusCount(fourPlusCount);
373
					inventAge.setThreeMonthPlusCount(threeMonthPlusCount);
374
					inventAge.setSixMonthPlusCount(sixMonthPlusCount);
11219 manish.sha 375
					inventAge.setZeroToThreeMonthCount(zeroToThreeMonthCount);
376
					inventAge.setThreeToSixMonthCount(threeToSixMonthsCount);
377
					inventAge.setSixToTwelveMonthCount(sixToTwelveMonthsCount);
378
					inventAge.setTwelveMonthsPlusCount(twelveMonthsPlusCount);
10689 manish.sha 379
					inventAge.setZeroPlusCount(zeroPlusCount);
380
					inventAge.setOnePlusCount(onePlusCount);
381
					inventAge.setZeroPlusCost(zeroPlusCost);
382
					inventAge.setOnePlusCost(onePlusCost);
383
					inventAge.setCategory(category);
384
 
385
					amazonInventoryAge.add(inventAge);
386
				}
387
				catch(Exception e){
388
					e.printStackTrace();				
389
				}
390
			}
391
 
392
		}
393
		catch(Exception e){
394
			e.printStackTrace();				
395
		}
396
		return amazonInventoryAge;
397
	}
11639 anikendra 398
 
10689 manish.sha 399
	public File createFile(List<InventoryAge> inventoryAge, String name){
400
		try {
401
			File file = new File(name);
402
			BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));
403
			bufferedWriter.write(StringUtils.join(new String[] {
404
					"Item Id",
405
					"Category",
406
					"Brand",
407
					"Model Name",
408
					"Model Number",
409
					"Color",
410
					"Fresh",
411
					"1-2 week",
412
					"2-3 week",
413
					"3-4 week",
414
					"4+ week",
415
					"3+ month",
416
					"6+ month",
11219 manish.sha 417
					"0-3 month",
418
					"3-6 month",
419
					"6-12 month",
420
					"12+ month",
10689 manish.sha 421
					"1+ week",
422
					"1+ week cost",
423
					"All",
424
			"All cost" }, '\t'));
425
 
426
			for (InventoryAge item : inventoryAge) {
427
				bufferedWriter.newLine();
428
 
429
				bufferedWriter.write(StringUtils.join(
430
						new String[] {
431
								String.valueOf(item.getItemId()),
432
								item.getCategory(),
433
								item.getBrand(),
434
								item.getModelName(),
435
								item.getModelNumber(),
436
								item.getColor(),
437
								String.valueOf(item.getFreshCount()),
438
								String.valueOf(item.getOneToTwoCount()),
439
								String.valueOf(item.getTwoToThreeCount()),
440
								String.valueOf(item.getThreeToFourCount()),
441
								String.valueOf(item.getFourPlusCount()),
442
								String.valueOf(item.getThreeMonthPlusCount()),
443
								String.valueOf(item.getSixMonthPlusCount()),
11219 manish.sha 444
								String.valueOf(item.getZeroToThreeMonthCount()),
445
								String.valueOf(item.getThreeToSixMonthCount()),
446
								String.valueOf(item.getSixToTwelveMonthCount()),
447
								String.valueOf(item.getTwelveMonthsPlusCount()),
10689 manish.sha 448
								String.valueOf(item.getOnePlusCount()),
449
								String.valueOf(item.getOnePlusCost()),
450
								String.valueOf(item.getZeroPlusCount()),
451
								String.valueOf(item.getZeroPlusCost())}, '\t'));
452
			}
453
 
454
			bufferedWriter.close();
455
			return file;
456
		} catch (Exception e) {
457
			return null;
458
		}
11639 anikendra 459
 
10689 manish.sha 460
	}
11639 anikendra 461
 
10689 manish.sha 462
	public void downloadAmazonInventoryAge(){
463
		try {
464
			List<InventoryAge> inventoryAgeAmazon = getAmazonInventoryAge();
465
			byte[] buffer = null;
466
			File file = createFile(inventoryAgeAmazon,"/tmp/AmazonInventoryAge.xls");
467
			Thread.sleep(10000);
468
			buffer = new byte[(int) file.length()];
469
			InputStream input = null;
470
			try {
471
				int totalBytesRead = 0;
472
				input = new BufferedInputStream(new FileInputStream(file));
473
				while (totalBytesRead < buffer.length) {
474
					int bytesRemaining = buffer.length - totalBytesRead;
475
					// input.read() returns -1, 0, or more :
476
					int bytesRead = input.read(buffer, totalBytesRead,
477
							bytesRemaining);
478
					if (bytesRead > 0) {
479
						totalBytesRead = totalBytesRead + bytesRead;
480
					}
481
				}
482
				/*
483
				 * the above style is a bit tricky: it places bytes into the
484
				 * 'buffer' array; 'buffer' is an output parameter; the while
485
				 * loop usually has a single iteration only.
486
				 */
487
			} finally {
488
				input.close();
489
			}
490
 
491
 
492
 
493
 
494
			response.setContentType("application/vnd.ms-excel");
495
			response.setHeader("Content-disposition", "inline; filename="
496
					+ file.getName());
497
 
498
			ServletOutputStream sos = response.getOutputStream();
499
			sos.write(buffer);
500
			sos.flush();      
501
 
502
		}
503
		catch (Exception e) {
504
		}
505
 
506
	}
11639 anikendra 507
 
10689 manish.sha 508
	public void downloadSaholicInventoryAge(){
509
		try {
510
			Client client = new WarehouseClient().getClient();
511
			List<InventoryAge> inventoryAge = client.getInventoryAge();
512
			byte[] buffer = null;
513
			File file = createFile(inventoryAge,"/tmp/SaholicInventoryAge.xls");
514
			Thread.sleep(10000);
515
			buffer = new byte[(int) file.length()];
516
			InputStream input = null;
517
			try {
518
				int totalBytesRead = 0;
519
				input = new BufferedInputStream(new FileInputStream(file));
520
				while (totalBytesRead < buffer.length) {
521
					int bytesRemaining = buffer.length - totalBytesRead;
522
					// input.read() returns -1, 0, or more :
523
					int bytesRead = input.read(buffer, totalBytesRead,
524
							bytesRemaining);
525
					if (bytesRead > 0) {
526
						totalBytesRead = totalBytesRead + bytesRead;
527
					}
528
				}
529
				/*
530
				 * the above style is a bit tricky: it places bytes into the
531
				 * 'buffer' array; 'buffer' is an output parameter; the while
532
				 * loop usually has a single iteration only.
533
				 */
534
			} finally {
535
				input.close();
536
			}
537
 
538
 
539
 
540
 
541
			response.setContentType("application/vnd.ms-excel");
542
			response.setHeader("Content-disposition", "inline; filename="
543
					+ file.getName());
544
 
545
			ServletOutputStream sos = response.getOutputStream();
546
			sos.write(buffer);
547
			sos.flush();      
548
 
549
		}
550
		catch (Exception e) {
551
		}
552
 
553
	}
554
 
555
	/*public static void main(String[] args) throws Exception{
11639 anikendra 556
 
10689 manish.sha 557
	}*/
5711 mandeep.dh 558
}