Subversion Repositories SmartDukaan

Rev

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

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