Subversion Repositories SmartDukaan

Rev

Rev 15462 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7283 kshitij.so 1
package in.shop2020.support.controllers;
2
 
8362 kshitij.so 3
import java.io.BufferedInputStream;
12449 kshitij.so 4
import java.io.BufferedReader;
7524 kshitij.so 5
import java.io.File;
7741 kshitij.so 6
import java.io.FileInputStream;
12449 kshitij.so 7
import java.io.FileNotFoundException;
8
import java.io.FileReader;
8362 kshitij.so 9
import java.io.FileWriter;
7524 kshitij.so 10
import java.io.IOException;
8362 kshitij.so 11
import java.io.InputStream;
12449 kshitij.so 12
import java.text.ParseException;
13
import java.util.ArrayList;
8620 kshitij.so 14
import java.util.Arrays;
12449 kshitij.so 15
import java.util.Calendar;
16
import java.util.Date;
17
import java.util.GregorianCalendar;
7365 kshitij.so 18
import java.util.HashMap;
7283 kshitij.so 19
import java.util.List;
20
import java.util.Map;
21
 
7591 kshitij.so 22
import javax.servlet.ServletContext;
8362 kshitij.so 23
import javax.servlet.ServletOutputStream;
7283 kshitij.so 24
import javax.servlet.ServletRequest;
25
import javax.servlet.http.HttpServletRequest;
8168 kshitij.so 26
import javax.servlet.http.HttpServletResponse;
7591 kshitij.so 27
import javax.servlet.http.HttpSession;
7283 kshitij.so 28
 
12449 kshitij.so 29
import in.shop2020.model.v1.catalog.AmazonPromotionType;
7283 kshitij.so 30
import in.shop2020.model.v1.catalog.Amazonlisted;
31
import in.shop2020.model.v1.catalog.CatalogServiceException;
32
import in.shop2020.model.v1.catalog.Item;
11197 kshitij.so 33
import in.shop2020.model.v1.inventory.AmazonFbaInventorySnapshot;
7283 kshitij.so 34
import in.shop2020.model.v1.inventory.AmazonInventorySnapshot;
12449 kshitij.so 35
import in.shop2020.model.v1.catalog.AmazonPromotion;
7283 kshitij.so 36
import in.shop2020.model.v1.catalog.CatalogService.Client;
37
import in.shop2020.model.v1.inventory.InventoryServiceException;
7741 kshitij.so 38
import in.shop2020.model.v1.order.AmazonOrder;
7591 kshitij.so 39
import in.shop2020.support.utils.ReportsUtils;
12449 kshitij.so 40
import in.shop2020.support.utils.PromotionFeed;
7283 kshitij.so 41
import in.shop2020.thrift.clients.CatalogClient;
42
import in.shop2020.thrift.clients.InventoryClient;
7365 kshitij.so 43
import in.shop2020.thrift.clients.LogisticsClient;
7741 kshitij.so 44
import in.shop2020.thrift.clients.TransactionClient;
7365 kshitij.so 45
import in.shop2020.logistics.DeliveryType;
46
import in.shop2020.logistics.LogisticsInfo;
47
import in.shop2020.logistics.LogisticsServiceException;
48
import in.shop2020.logistics.PickUpType;
7283 kshitij.so 49
 
7524 kshitij.so 50
import org.apache.commons.io.FileUtils;
7365 kshitij.so 51
import org.apache.commons.lang.xwork.StringUtils;
7741 kshitij.so 52
import org.apache.poi.hssf.usermodel.HSSFSheet;
53
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
8168 kshitij.so 54
import org.apache.poi.ss.usermodel.Cell;
7591 kshitij.so 55
import org.apache.struts2.convention.annotation.InterceptorRef;
56
import org.apache.struts2.convention.annotation.InterceptorRefs;
7283 kshitij.so 57
import org.apache.struts2.convention.annotation.Result;
58
import org.apache.struts2.convention.annotation.Results;
59
import org.apache.struts2.interceptor.ServletRequestAware;
8168 kshitij.so 60
import org.apache.struts2.interceptor.ServletResponseAware;
61
import org.apache.struts2.util.ServletContextAware;
7283 kshitij.so 62
import org.apache.thrift.TException;
7741 kshitij.so 63
import org.apache.thrift.transport.TTransportException;
7283 kshitij.so 64
import org.slf4j.Logger;
65
import org.slf4j.LoggerFactory;
66
 
12449 kshitij.so 67
import com.amazonaws.mws.MarketplaceWebServiceException;
68
import com.ibm.icu.text.SimpleDateFormat;
7283 kshitij.so 69
import com.opensymphony.xwork2.ValidationAwareSupport;
70
 
71
@SuppressWarnings("serial")
8620 kshitij.so 72
 
7591 kshitij.so 73
@InterceptorRefs({
12449 kshitij.so 74
    @InterceptorRef("defaultStack"),
75
    @InterceptorRef("login")
7591 kshitij.so 76
})
7283 kshitij.so 77
@Results({
12449 kshitij.so 78
    @Result(name = "redirect", location = "${url}", type = "redirect"),
79
    @Result(name="authsuccess", type="redirectAction", params = {"actionName" , "reports"})
7524 kshitij.so 80
})
8168 kshitij.so 81
public class AmazonListController extends ValidationAwareSupport implements ServletRequestAware ,ServletResponseAware, ServletContextAware{
7283 kshitij.so 82
 
12449 kshitij.so 83
    private static Logger logger = LoggerFactory.getLogger(AmazonListController.class);
7283 kshitij.so 84
 
12449 kshitij.so 85
    private HttpServletRequest request;
86
    private HttpSession session;
87
    private ServletContext context;
88
    private HttpServletResponse response;
89
    private String url;
90
    private String id;
91
    private String itemId;
92
    private String isFba;
93
    private String isNonFba;
94
    private String isInventoryOverride;
95
    private String fbaPrice;
96
    private String sellingPrice;
97
    private String saholicPrice;
98
    private String isTime;
99
    private String handlingTime;
100
    private String customHandlingTime;
101
    private String holdInventory;
102
    private String defaultInventory;
103
    private String fileUploadFileName;
104
    private String fileUploadContentType;
105
    private String suppressMfnPriceUpdate;
106
    private String suppressFbaPriceUpdate;
107
    private File file;
108
    private String errMsg;
109
    private String next;
110
    private List<Amazonlisted> amazonItems;
111
    private String searchText;
112
    private long searchCount;
113
    private long totalCount;
114
    private String taxCode;
115
    private String fbbTaxCode;
116
    private String isFbb;
117
    private String fbbPrice;
118
    private String suppressFbbPriceUpdate;
119
    private String startDate;
120
    private String endDate;
121
    private List<AmazonPromotion> promotionResult;
122
    private String promotionType;
123
    private String overrrideWanlc;
124
    private String exceptionalWanlc;
125
    private String autoDecrement;
126
    private String autoIncrement;
127
    private String autoFavourite;
128
    private String manualFavourite;
129
    private String otherCost;
12673 kshitij.so 130
    private String isFbaPromotionActive;
131
    private String isFbbPromotionActive;
12661 kshitij.so 132
    private String fbaPromoPrice;
133
    private String fbbPromoPrice;
134
    private String promoItemId;
12889 kshitij.so 135
    private String fbgTaxCode;
136
    private String isFbg;
137
    private String fbgPrice;
138
    private String suppressFbgPriceUpdate;
139
    private String fbgPromoPrice;
140
    private String isFbgPromotionActive;
15703 kshitij.so 141
    private String fbdTaxCode;
142
    private String isFbd;
143
    private String fbdPrice;
144
    private String suppressFbdPriceUpdate;
145
    private String fbdPromoPrice;
146
    private String isFbdPromotionActive;
12948 kshitij.so 147
 
12449 kshitij.so 148
    public String getOtherCost() {
149
        return otherCost;
150
    }
7283 kshitij.so 151
 
12449 kshitij.so 152
    public void setOtherCost(String otherCost) {
153
        this.otherCost = otherCost;
154
    }
7283 kshitij.so 155
 
12449 kshitij.so 156
    public String getAutoDecrement() {
157
        return autoDecrement;
158
    }
7283 kshitij.so 159
 
12449 kshitij.so 160
    public void setAutoDecrement(String autoDecrement) {
161
        this.autoDecrement = autoDecrement;
162
    }
8620 kshitij.so 163
 
12449 kshitij.so 164
    public String getAutoIncrement() {
165
        return autoIncrement;
166
    }
7283 kshitij.so 167
 
12449 kshitij.so 168
    public void setAutoIncrement(String autoIncrement) {
169
        this.autoIncrement = autoIncrement;
170
    }
7365 kshitij.so 171
 
12449 kshitij.so 172
    public String getAutoFavourite() {
173
        return autoFavourite;
174
    }
7365 kshitij.so 175
 
12449 kshitij.so 176
    public void setAutoFavourite(String autoFavourite) {
177
        this.autoFavourite = autoFavourite;
178
    }
7365 kshitij.so 179
 
12449 kshitij.so 180
    public String getManualFavourite() {
181
        return manualFavourite;
182
    }
8620 kshitij.so 183
 
12449 kshitij.so 184
    public void setManualFavourite(String manualFavourite) {
185
        this.manualFavourite = manualFavourite;
186
    }
187
 
188
 
189
    public String index() {
190
        if (!ReportsUtils.canAccessReport((Long) session.getAttribute(ReportsUtils.ROLE),request.getServletPath())) {
191
            return "authfail";
192
        }
193
        return "index";
194
    }
195
 
196
    public String fetchItems() throws TException {
197
        Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
198
        if (searchText.length() == 0) {
199
            amazonItems = CatalogClient.getAmazonListedItems(Long.valueOf(next), 10);
200
            totalCount = CatalogClient.getCountForAmazonlistedItems();
201
            setSearchCount(totalCount);
202
        } else {
203
            List<String> subString = Arrays.asList(searchText.split(" "));
204
            amazonItems = CatalogClient.searchAmazonItems(subString,Long.valueOf(next), 10);
205
            totalCount = CatalogClient.getCountForAmazonlistedItems();
206
            searchCount = CatalogClient.getAmazonSearchResultCount(subString);
207
        }
208
        return "amazon-item-table";
209
    }
210
 
211
 
212
    public Amazonlisted fetchItemDetail() throws NumberFormatException, TException {
213
        Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
12661 kshitij.so 214
        long now = getTimeInMilliseconds();
215
        Amazonlisted amazonItemDetails = CatalogClient.getAmazonItemDetails(Long.valueOf(id));
216
        return amazonItemDetails;
12449 kshitij.so 217
    }
218
 
219
    public Item getSaholicItem(String id) throws NumberFormatException, CatalogServiceException, TException {
220
        Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
221
        return CatalogClient.getItem(Long.valueOf(id));
222
    }
223
 
224
 
225
 
226
    public String update() throws NumberFormatException, TException{
227
        Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
228
        boolean flag=false;
229
        boolean commit=false;
230
        long delay = Long.valueOf(customHandlingTime);
231
        if ( Boolean.valueOf(isTime)) {
232
            flag = true;
233
        }
234
        changeItemInventory();
235
        Amazonlisted amazonlisted = CatalogClient.getAmazonItemDetails(Long.valueOf(itemId));
236
        if (amazonlisted.getSellingPrice()!=Double.valueOf(sellingPrice)){
237
            amazonlisted.setSellingPrice(Double.valueOf(sellingPrice));
238
            commit=true;
239
        }
240
        if (amazonlisted.getFbaPrice()!=Double.valueOf(fbaPrice)){
241
            amazonlisted.setFbaPrice(Double.valueOf(fbaPrice));
242
            commit=true;
243
        }
244
        if (amazonlisted.isIsFba()!=Boolean.valueOf(isFba)){
245
            amazonlisted.setIsFba(Boolean.valueOf(isFba));
246
            commit=true;
247
        }
248
        if (amazonlisted.isIsNonFba()!=Boolean.valueOf(isNonFba)){
249
            amazonlisted.setIsNonFba(Boolean.valueOf(isNonFba));
250
            commit=true;
251
        }
252
        if (amazonlisted.isIsCustomTime()!=flag){
253
            amazonlisted.setIsCustomTime(flag);
254
            commit=true;
255
        }
256
        if (amazonlisted.getHandlingTime()!=delay){
257
            amazonlisted.setHandlingTime(delay);
258
            commit=true;
259
        }
260
        if(amazonlisted.isIsInventoryOverride()!=Boolean.valueOf(isInventoryOverride)){
261
            amazonlisted.setIsInventoryOverride(Boolean.valueOf(isInventoryOverride));
262
            commit=true;
263
        }
264
        if(amazonlisted.isSuppressMfnPriceUpdate()!=Boolean.valueOf(suppressMfnPriceUpdate)){
265
            amazonlisted.setSuppressMfnPriceUpdate(Boolean.valueOf(suppressMfnPriceUpdate));
266
            commit=true;
267
        }
268
        if(amazonlisted.isSuppressFbaPriceUpdate()!=Boolean.valueOf(suppressFbaPriceUpdate)){
269
            amazonlisted.setSuppressFbaPriceUpdate(Boolean.valueOf(suppressFbaPriceUpdate));
270
            commit=true;
271
        }
272
 
273
        if(!StringUtils.equals(amazonlisted.getTaxCode(), taxCode)){
274
            amazonlisted.setTaxCode(taxCode);
275
            commit=true;
276
        }
277
 
278
        if(!StringUtils.equals(amazonlisted.getFbbtaxCode(), fbbTaxCode)){
10922 kshitij.so 279
            amazonlisted.setFbbtaxCode(fbbTaxCode);
280
            commit=true;
281
        }
12449 kshitij.so 282
 
283
        if(amazonlisted.isSuppressFbbPriceUpdate()!=Boolean.valueOf(suppressFbbPriceUpdate)){
10922 kshitij.so 284
            amazonlisted.setSuppressFbbPriceUpdate(Boolean.valueOf(suppressFbbPriceUpdate));
285
            commit=true;
286
        }
12449 kshitij.so 287
 
288
        if (amazonlisted.getFbbPrice()!=Double.valueOf(fbbPrice)){
10922 kshitij.so 289
            amazonlisted.setFbbPrice(Double.valueOf(fbbPrice));
290
            commit=true;
291
        }
12449 kshitij.so 292
 
293
        if (amazonlisted.isIsFbb()!=Boolean.valueOf(isFbb)){
10922 kshitij.so 294
            amazonlisted.setIsFbb(Boolean.valueOf(isFbb));
295
            commit=true;
296
        }
8620 kshitij.so 297
 
12449 kshitij.so 298
        if (amazonlisted.isAutoDecrement()!=Boolean.valueOf(autoDecrement)){
299
            amazonlisted.setAutoDecrement(Boolean.valueOf(autoDecrement));
300
            commit=true;
301
        }
12948 kshitij.so 302
 
12449 kshitij.so 303
        if (amazonlisted.isAutoIncrement()!=Boolean.valueOf(autoIncrement)){
304
            amazonlisted.setAutoIncrement(Boolean.valueOf(autoIncrement));
305
            commit=true;
306
        }
12948 kshitij.so 307
 
12449 kshitij.so 308
        if (amazonlisted.isManualFavourite()!=Boolean.valueOf(manualFavourite)){
309
            amazonlisted.setManualFavourite(Boolean.valueOf(manualFavourite));
310
            commit=true;
311
        }
7283 kshitij.so 312
 
313
 
12449 kshitij.so 314
        if (amazonlisted.isOverrrideWanlc()!=Boolean.valueOf(overrrideWanlc)){
315
            amazonlisted.setOverrrideWanlc(Boolean.valueOf(overrrideWanlc));
316
            commit=true;
317
        }
7524 kshitij.so 318
 
12449 kshitij.so 319
        if (amazonlisted.getExceptionalWanlc()!=Double.valueOf(exceptionalWanlc)){
320
            amazonlisted.setExceptionalWanlc(Double.valueOf(exceptionalWanlc));
321
            commit=true;
322
        }
12948 kshitij.so 323
 
12449 kshitij.so 324
        if (amazonlisted.getOtherCost()!=Double.valueOf(otherCost)){
325
            amazonlisted.setOtherCost(Double.valueOf(otherCost));
326
            commit=true;
327
        }
12948 kshitij.so 328
 
12889 kshitij.so 329
        if(!StringUtils.equals(amazonlisted.getFbgtaxCode(), fbgTaxCode)){
330
            amazonlisted.setFbgtaxCode(fbgTaxCode);
331
            commit=true;
332
        }
8620 kshitij.so 333
 
12889 kshitij.so 334
        if(amazonlisted.isSuppressFbgPriceUpdate()!=Boolean.valueOf(suppressFbgPriceUpdate)){
335
            amazonlisted.setSuppressFbgPriceUpdate(Boolean.valueOf(suppressFbgPriceUpdate));
336
            commit=true;
337
        }
338
 
339
        if (amazonlisted.getFbgPrice()!=Double.valueOf(fbgPrice)){
340
            amazonlisted.setFbgPrice(Double.valueOf(fbgPrice));
341
            commit=true;
342
        }
343
 
344
        if (amazonlisted.isIsFbg()!=Boolean.valueOf(isFbg)){
345
            amazonlisted.setIsFbg(Boolean.valueOf(isFbg));
346
            commit=true;
347
        }
15703 kshitij.so 348
 
349
        if(!StringUtils.equals(amazonlisted.getFbdtaxCode(), fbdTaxCode)){
350
            amazonlisted.setFbdtaxCode(fbdTaxCode);
351
            commit=true;
352
        }
12889 kshitij.so 353
 
15703 kshitij.so 354
        if(amazonlisted.isSuppressFbdPriceUpdate()!=Boolean.valueOf(suppressFbdPriceUpdate)){
355
            amazonlisted.setSuppressFbdPriceUpdate(Boolean.valueOf(suppressFbdPriceUpdate));
356
            commit=true;
357
        }
358
 
359
        if (amazonlisted.getFbdPrice()!=Double.valueOf(fbdPrice)){
360
            amazonlisted.setFbdPrice(Double.valueOf(fbdPrice));
361
            commit=true;
362
        }
363
 
364
        if (amazonlisted.isIsFbd()!=Boolean.valueOf(isFbd)){
365
            amazonlisted.setIsFbd(Boolean.valueOf(isFbd));
366
            commit=true;
367
        }
368
 
369
 
12449 kshitij.so 370
        if(commit){
371
            CatalogClient.updateAmazonItemDetails(amazonlisted);
372
        }
373
        else{
374
            logger.info("Nothing new to commit");
375
        }
376
        return "index";
8620 kshitij.so 377
 
12449 kshitij.so 378
    }
12948 kshitij.so 379
 
12661 kshitij.so 380
    public String updatePromo() throws NumberFormatException, TException{
12948 kshitij.so 381
 
12661 kshitij.so 382
        Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
383
        Amazonlisted amazonlisted = catalogClient.getAmazonItemDetails(Long.valueOf(promoItemId));
12948 kshitij.so 384
 
385
 
12661 kshitij.so 386
        if(Boolean.valueOf(isFbaPromotionActive)){
387
            amazonlisted.setFbaPromoPrice(Double.valueOf(fbaPromoPrice));
388
        }
12948 kshitij.so 389
 
12661 kshitij.so 390
        if(Boolean.valueOf(isFbbPromotionActive)){
391
            amazonlisted.setFbbPromoPrice(Double.valueOf(fbbPromoPrice));
392
        }
12948 kshitij.so 393
 
12889 kshitij.so 394
        if(Boolean.valueOf(isFbgPromotionActive)){
395
            amazonlisted.setFbgPromoPrice(Double.valueOf(fbgPromoPrice));
396
        }
15703 kshitij.so 397
 
398
        if(Boolean.valueOf(isFbdPromotionActive)){
399
            amazonlisted.setFbdPromoPrice(Double.valueOf(fbdPromoPrice));
400
        }
12948 kshitij.so 401
 
12661 kshitij.so 402
        catalogClient.updateAmazonItemDetails(amazonlisted);
403
        return "index";
404
    }
7524 kshitij.so 405
 
12449 kshitij.so 406
    public void upload() throws IOException, TException {
407
        File fileToCreate = new File("/tmp/", "Amazon-shipping.xls");
408
        FileUtils.copyFile(this.file, fileToCreate);
409
        FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
410
        HSSFWorkbook workbook = new HSSFWorkbook(iFile);
411
        HSSFSheet sheet = workbook.getSheetAt(0);
412
        Map<Long,Map<String,String>> amazonOrderMap = new HashMap<Long,Map<String,String>>();
413
        for (int iterator=sheet.getFirstRowNum();iterator<=sheet.getLastRowNum();iterator++){
414
            TransactionClient tcl = new TransactionClient();
415
            List<AmazonOrder> orders = tcl.getClient().getAmazonOrderByAmazonOrderId(sheet.getRow(iterator).getCell(0).getStringCellValue());
416
            for (AmazonOrder order : orders){
417
                if (StringUtils.equals(order.getStatus(), "Order-Payment-Success")){
418
                    Map<String,String> dateMap = new HashMap<String,String>();
419
                    dateMap.put(sheet.getRow(iterator).getCell(1).getStringCellValue(), sheet.getRow(iterator).getCell(2).getStringCellValue());
420
                    amazonOrderMap.put(order.getOrderId(), dateMap);
421
                }
422
            }
423
        }
424
        TransactionClient tcl = new TransactionClient();
425
        tcl.getClient().updateTimestampForAmazonOrder(amazonOrderMap);
426
    }
7461 kshitij.so 427
 
12661 kshitij.so 428
    public void uploadPromotionSheet() throws IOException, ParseException, TException, CatalogServiceException, InterruptedException{
12449 kshitij.so 429
        Map<String,AmazonPromotion> amazonPromoMap = new HashMap<String,AmazonPromotion>();
430
        SimpleDateFormat dateFormatter;
12661 kshitij.so 431
        long timeNow = Long.valueOf(getTimeInMilliseconds());
12449 kshitij.so 432
        if (promotionType.equalsIgnoreCase("SHORTTERM")){
12586 kshitij.so 433
            dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
12449 kshitij.so 434
        }
435
        else{
436
            dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
437
        }
12661 kshitij.so 438
        File fileToCreate = new File("/tmp/", "Amazon-Promotion-"+String.valueOf(getTimeInMilliseconds()));
12449 kshitij.so 439
        FileUtils.copyFile(this.file, fileToCreate);
440
        BufferedReader reader = null;
441
        try {
442
            reader = new BufferedReader(new FileReader(file.getAbsolutePath()));
443
        } catch (FileNotFoundException e1) {
444
            // TODO Auto-generated catch block
445
            e1.printStackTrace();
446
        }
447
        String str;
448
        int lineNumber = 0;
449
        while ((str = reader.readLine()) != null) {
450
            lineNumber++;
12504 kshitij.so 451
            if (str.trim().length() == 0 || lineNumber<2) {
12449 kshitij.so 452
                continue;
453
            }
12661 kshitij.so 454
            timeNow +=1500;
12449 kshitij.so 455
            String[] values = str.split("\t");
456
            AmazonPromotion amazonPromotion = new AmazonPromotion();
457
            amazonPromotion.setSku(values[0]);
12460 kshitij.so 458
            amazonPromotion.setStandardPrice(Double.valueOf(values[1]));
459
            amazonPromotion.setSalePrice(Double.valueOf(values[2]));
460
            amazonPromotion.setSubsidyAmount(Double.valueOf(values[3]));
461
            Date startDate = dateFormatter.parse(values[4]);
462
            Date endDate = dateFormatter.parse(values[5]);
12449 kshitij.so 463
            amazonPromotion.setStartDate(startDate.getTime());
464
            amazonPromotion.setEndDate(endDate.getTime());
12661 kshitij.so 465
            amazonPromotion.setAddedOn(timeNow);
12449 kshitij.so 466
            amazonPromotion.setPromotionType(AmazonPromotionType.valueOf(promotionType));
467
            amazonPromoMap.put(amazonPromotion.getSku(), amazonPromotion);
468
        }
469
        Client cc = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
12948 kshitij.so 470
        List<String> notAddedItems = cc.addAmazonPromotion(amazonPromoMap);
471
 
472
        StringBuilder sb = new StringBuilder();
473
 
474
        if (notAddedItems.size() > 0){
475
            sb.append("Following Items were not added : \n");
476
            for (String notAddedItem:notAddedItems){
477
                amazonPromoMap.remove(notAddedItem);
478
                sb.append("Amazon Sku "+notAddedItem+"\n");
479
            }
12449 kshitij.so 480
        }
12948 kshitij.so 481
        else{
482
            sb.append("All Items Uploaded Successfully");
483
        }
12661 kshitij.so 484
 
485
        if (promotionType.equalsIgnoreCase("LONGTERM")){
486
            List<AmazonPromotion> list = new ArrayList<AmazonPromotion>(amazonPromoMap.values());
487
            PromotionFeed pm = new PromotionFeed(list);
488
            pm.start();
489
        }
12948 kshitij.so 490
 
491
        File file = new File("/tmp/amazon-promo");
492
        FileWriter writer = new FileWriter(file);
493
        writer.append(sb.toString());
494
        writer.close();
495
        byte[] buffer = new byte[(int)file.length()];
496
        InputStream input = null;
497
        try {
498
            int totalBytesRead = 0;
499
            input = new BufferedInputStream(new FileInputStream(file));
500
            while(totalBytesRead < buffer.length){
501
                int bytesRemaining = buffer.length - totalBytesRead;
502
                int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
503
                if (bytesRead > 0){
504
                    totalBytesRead = totalBytesRead + bytesRead;
505
                }
506
            }
507
        }
508
        finally {
509
            input.close();
510
            file.delete();
511
        }
512
 
513
        response.setHeader("Content-Type", "text/javascript");
514
 
515
        ServletOutputStream sos;
516
        try {
517
            sos = response.getOutputStream();
518
            sos.write(buffer);
519
            sos.flush();
520
        } catch (IOException e) {
521
            System.out.println("Unable to stream the manifest file");
522
        }   
12449 kshitij.so 523
    }
7283 kshitij.so 524
 
12449 kshitij.so 525
    private void changeItemInventory() throws NumberFormatException, TException {
526
        Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
7283 kshitij.so 527
 
12449 kshitij.so 528
        if (StringUtils.isEmpty(holdInventory)) {
529
            holdInventory = "0";
530
        }
531
        if (StringUtils.isEmpty(defaultInventory)) {
532
            defaultInventory = "0";
533
        }
534
        CatalogClient.updateItemInventory(Long.valueOf(itemId),Long.valueOf(holdInventory),Long.valueOf(defaultInventory));
535
    }
7283 kshitij.so 536
 
537
 
12449 kshitij.so 538
    public Map<Long, Long> getAvailableItemInventory(String itemId) throws NumberFormatException, InventoryServiceException, TException{
539
        InventoryClient inventoryServiceClient = new InventoryClient();
540
        in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
541
        in.shop2020.model.v1.inventory.ItemInventory thriftItemInventory = inventoryClient.getItemInventoryByItemId(Long.valueOf(itemId));
542
        return thriftItemInventory.getAvailability();
8620 kshitij.so 543
 
12449 kshitij.so 544
    }
7365 kshitij.so 545
 
12449 kshitij.so 546
    public Map<Long, Long> getReservedItemInventory(String itemId) throws NumberFormatException, InventoryServiceException, TException{
547
        InventoryClient inventoryServiceClient = new InventoryClient();
548
        in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
549
        in.shop2020.model.v1.inventory.ItemInventory thriftItemInventory = inventoryClient.getItemInventoryByItemId(Long.valueOf(itemId));
550
        return thriftItemInventory.getReserved();
7365 kshitij.so 551
 
12449 kshitij.so 552
    }
8070 kshitij.so 553
 
12449 kshitij.so 554
    public String getWarehouseName(String warehouseId) throws NumberFormatException, TException { 
555
        InventoryClient inventoryServiceClient = new InventoryClient();
556
        return inventoryServiceClient.getClient().getWarehouseName(Long.valueOf(warehouseId));
557
    }
558
 
559
    public AmazonInventorySnapshot getInventoryForAmazonItem(String itemId) throws NumberFormatException, TException {
560
        InventoryClient inventoryServiceClient = new InventoryClient();
561
        try { 
562
            return inventoryServiceClient.getClient().getAmazonInventoryForItem(Long.valueOf(itemId));
563
        }
564
        catch (Exception e){
565
            return null;
566
        }
567
    }
568
 
569
    public List<AmazonFbaInventorySnapshot> getFbaInventoryForAmazonItem(String itemId) throws NumberFormatException, TException {
570
        InventoryClient inventoryServiceClient = new InventoryClient();
571
        try { 
572
            return inventoryServiceClient.getClient().getAmazonFbaItemInventory(Long.valueOf(itemId));
573
        }
574
        catch (Exception e){
575
            return null;
576
        }
577
    }
578
 
12453 kshitij.so 579
    public Long getTimetoShip(String itemId) throws LogisticsServiceException, TException{
15462 kshitij.so 580
//        LogisticsClient logisticsClient = new LogisticsClient();
581
//        return logisticsClient.getClient().getLogisticsInfo("110001", Long.valueOf(itemId), DeliveryType.COD, PickUpType.COURIER).getShippingTime();
582
        return 0L;
12453 kshitij.so 583
    }
12948 kshitij.so 584
 
585
 
12449 kshitij.so 586
    public double getWanlcForItem(String itemId){
587
        InventoryClient inventoryServiceClient;
588
        try {
589
            inventoryServiceClient = new InventoryClient();
590
        } catch (TTransportException e1) {
591
            // TODO Auto-generated catch block
592
            return 0.0;
593
        }
594
        try { 
595
            return inventoryServiceClient.getClient().getWanNlcForSource(Long.valueOf(itemId), 3);
596
        }
597
        catch (Exception e){
598
            return 0.0;
599
        }
600
    }
601
 
602
    public long getTimeInMilliseconds(){
603
        Calendar cal=GregorianCalendar.getInstance();
604
        return cal.getTimeInMillis();
605
    }
606
 
607
    public String runAsinJob() throws IOException, InterruptedException {
10925 kshitij.so 608
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
609
            logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
610
            return "authfail";
611
        }
612
        ProcessBuilder testProcess = new ProcessBuilder("/bin/bash");
12449 kshitij.so 613
        String[] command = {"/bin/bash", "-c", "sudo /root/code/trunk/AmazonFeeds/RunAsinJob.sh"};
614
        testProcess.command(command);
615
        logger.info(testProcess.command().toString());
616
        Process process = testProcess.start();
617
        process.waitFor();
618
        logger.info(String.valueOf(process.exitValue()));
619
        return "asinjob";
620
 
621
    }
622
 
623
    public String runFbbListingJob() throws IOException, InterruptedException {
624
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
625
            logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
626
            return "authfail";
627
        }
628
        ProcessBuilder testProcess = new ProcessBuilder("/bin/bash");
10925 kshitij.so 629
        String[] command = {"/bin/bash", "-c", "sudo /root/code/trunk/AmazonFeeds/RunFbbListingJob.sh"};
630
        testProcess.command(command);
631
        logger.info(testProcess.command().toString());
632
        Process process = testProcess.start();
633
        process.waitFor();
634
        logger.info(String.valueOf(process.exitValue()));
635
        return "asinjob";
636
    }
12948 kshitij.so 637
 
12920 kshitij.so 638
    public String runFbgListingJob() throws IOException, InterruptedException {
639
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
640
            logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
641
            return "authfail";
642
        }
643
        ProcessBuilder testProcess = new ProcessBuilder("/bin/bash");
644
        String[] command = {"/bin/bash", "-c", "sudo /root/code/trunk/AmazonFeeds/RunFbgListingJob.sh"};
645
        testProcess.command(command);
646
        logger.info(testProcess.command().toString());
647
        Process process = testProcess.start();
648
        process.waitFor();
649
        logger.info(String.valueOf(process.exitValue()));
650
        return "asinjob";
651
    }
15703 kshitij.so 652
 
653
    public String runFbdListingJob() throws IOException, InterruptedException {
654
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
655
            logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
656
            return "authfail";
657
        }
658
        ProcessBuilder testProcess = new ProcessBuilder("/bin/bash");
659
        String[] command = {"/bin/bash", "-c", "sudo /root/code/trunk/AmazonFeeds/RunFbdListingJob.sh"};
660
        testProcess.command(command);
661
        logger.info(testProcess.command().toString());
662
        Process process = testProcess.start();
663
        process.waitFor();
664
        logger.info(String.valueOf(process.exitValue()));
665
        return "asinjob";
666
    }
8620 kshitij.so 667
 
668
 
15703 kshitij.so 669
 
12449 kshitij.so 670
    public String runFbaListingJob() throws IOException, InterruptedException {
671
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
672
            logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
673
            return "authfail";
674
        }
675
        ProcessBuilder testProcess = new ProcessBuilder("/bin/bash");
676
        String[] command = {"/bin/bash", "-c", "sudo /root/code/trunk/AmazonFeeds/RunFbaListingJob.sh"};
677
        testProcess.command(command);
678
        logger.info(testProcess.command().toString());
679
        Process process = testProcess.start();
680
        process.waitFor();
681
        logger.info(String.valueOf(process.exitValue()));
682
        return "asinjob";
683
    }
8073 kshitij.so 684
 
12449 kshitij.so 685
    public String runNonFbaListingJob() throws IOException, InterruptedException {
686
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
687
            logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
688
            return "authfail";
689
        }
690
        ProcessBuilder testProcess = new ProcessBuilder("/bin/bash");
691
        String[] command = {"/bin/bash", "-c", "sudo /root/code/trunk/AmazonFeeds/RunNonFbaListingJob.sh"};
692
        testProcess.command(command);
693
        logger.info(testProcess.command().toString());
694
        Process process = testProcess.start();
695
        process.waitFor();
696
        logger.info(String.valueOf(process.exitValue()));
697
        return "asinjob";
698
    }
8620 kshitij.so 699
 
12449 kshitij.so 700
    public void runFbaInventoryJob() throws IOException, InterruptedException {
701
        ProcessBuilder testProcess = new ProcessBuilder("/bin/bash");
702
        String[] command = {"/bin/bash", "-c", "sudo /root/code/trunk/AmazonFeeds/SubmitFBAInventoryFeed.sh"};
703
        testProcess.command(command);
704
        logger.info(testProcess.command().toString());
705
        Process process = testProcess.start();
706
        process.waitFor();
707
        logger.info(String.valueOf(process.exitValue()));
708
    }
8620 kshitij.so 709
 
12449 kshitij.so 710
    public void uploadAsinFile() throws IOException, TException{
711
        File fileToCreate = new File("/tmp/", "Amazon-asin-upload.xls");
712
        FileUtils.copyFile(this.file, fileToCreate);
713
        FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
714
        HSSFWorkbook workbook = new HSSFWorkbook(iFile);
715
        HSSFSheet sheet = workbook.getSheetAt(0);
716
        Map<Long,Item> amazonAsin = new HashMap<Long,Item>();
717
        StringBuilder sb =new StringBuilder();
718
        Client CatalogClient=null;
719
        try {
720
            CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
721
        } catch (TTransportException e) {
722
            e.printStackTrace();
723
        }
724
        for (int iterator=(sheet.getFirstRowNum()+1);iterator<=sheet.getLastRowNum();iterator++){
725
            Item item=null;
726
            Long sku;
727
            String asin;
728
            if (checkEmptyString(sheet.getRow(iterator).getCell(0))){
729
                continue;
730
            }
731
            else {
732
                sku=(long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
733
                try {
734
                    item = CatalogClient.getItem(sku);
735
                } catch (Exception e) {
736
                    logger.info("Unable to fetch item details ID= "+sku);
737
                    logger.info("Unable to fetch item. "+e);
738
                    sb.append("Service exception ItemId not updated Id= "+sku+"\n");
739
                    continue;
740
                } 
741
            }
8620 kshitij.so 742
 
12449 kshitij.so 743
            if(item.getId() == 0){
744
                logger.info("Item Id doesn't exist in catalog Id= "+sku);
745
                sb.append("Item Id doesn't exist in catalog Id= "+sku+"\n");
746
                continue;
747
            }
8620 kshitij.so 748
 
12449 kshitij.so 749
            if (!checkEmptyString(sheet.getRow(iterator).getCell(1))){
750
                asin = sheet.getRow(iterator).getCell(1).getStringCellValue();
751
                item.setAsin(asin);
752
            }
8620 kshitij.so 753
 
12449 kshitij.so 754
            if (!checkEmptyString(sheet.getRow(iterator).getCell(2))){
755
                long virtualInventory =(long) sheet.getRow(iterator).getCell(2).getNumericCellValue();
756
                item.setDefaultInventory(virtualInventory);
757
            }
8620 kshitij.so 758
 
12449 kshitij.so 759
            if (!checkEmptyString(sheet.getRow(iterator).getCell(3))){
760
                long riskyInventory =(long) sheet.getRow(iterator).getCell(3).getNumericCellValue();
761
                item.setHoldInventory(riskyInventory);
762
            }
8620 kshitij.so 763
 
12449 kshitij.so 764
            amazonAsin.put(sku, item);
765
        }
766
        CatalogClient.updateAsin(amazonAsin);
8620 kshitij.so 767
 
12449 kshitij.so 768
        logger.info("Amazon Asin Map "+amazonAsin.toString());
769
        CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
770
        CatalogClient.updateAsin(amazonAsin);
771
        File file = new File("/tmp/asinfile");
772
        FileWriter writer = new FileWriter(file);
773
        writer.append(sb.toString());
774
        writer.close();
775
        byte[] buffer = new byte[(int)file.length()];
776
        InputStream input = null;
777
        try {
778
            int totalBytesRead = 0;
779
            input = new BufferedInputStream(new FileInputStream(file));
780
            while(totalBytesRead < buffer.length){
781
                int bytesRemaining = buffer.length - totalBytesRead;
782
                int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
783
                if (bytesRead > 0){
784
                    totalBytesRead = totalBytesRead + bytesRead;
785
                }
786
            }
787
        }
788
        finally {
789
            input.close();
790
            file.delete();
791
        }
8620 kshitij.so 792
 
12449 kshitij.so 793
        response.setHeader("Content-Type", "text/javascript");
8168 kshitij.so 794
 
12449 kshitij.so 795
        ServletOutputStream sos;
796
        try {
797
            sos = response.getOutputStream();
798
            sos.write(buffer);
799
            sos.flush();
800
        } catch (IOException e) {
801
            System.out.println("Unable to stream the manifest file");
802
        }   
803
    }
8168 kshitij.so 804
 
12449 kshitij.so 805
    public void uploadBulkFile() throws IOException, TException{
806
        File fileToCreate = new File("/tmp/", "Amazon-bulk-upload.xls");
807
        FileUtils.copyFile(this.file, fileToCreate);
808
        FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
809
        HSSFWorkbook workbook = new HSSFWorkbook(iFile);
810
 
811
        HSSFSheet sheet = workbook.getSheetAt(0);
812
        Map<Long,Amazonlisted> amazonBulkUpdate = new HashMap<Long,Amazonlisted>();
813
        Client CatalogClient=null;
814
        StringBuilder sb = new StringBuilder();
815
        try {
816
            CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
817
        } catch (TTransportException e) {
818
            // TODO Auto-generated catch block
819
            e.printStackTrace();
820
        }
821
        for (int iterator=(sheet.getFirstRowNum()+1);iterator<=sheet.getLastRowNum();iterator++){
822
            Amazonlisted amazonlisted =null;
823
            Long sku;
824
            if (checkEmptyString(sheet.getRow(iterator).getCell(0))){
825
                continue;
826
            }
827
            else {
828
                sku=(long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
829
                try {
830
                    amazonlisted = CatalogClient.getAmazonItemDetails(sku);
831
                } catch (TException e) {
832
                    logger.info("Unable to fetch item details ID= "+sku);
833
                    sb.append("Service exception ItemId not updated Id= "+sku+"\n");
834
                    continue;
835
                }
836
            }
837
 
838
            if(amazonlisted.getItemid() == 0){
839
                logger.info("Item Id doesn't exist in amazonlisted Id= "+sku);
840
                sb.append("Item Id doesn't exist in amazonlisted Id= "+sku+"\n");
841
                continue;
842
            }
843
 
844
            if (!checkEmptyString(sheet.getRow(iterator).getCell(1))){
845
                double mfnPrice = sheet.getRow(iterator).getCell(1).getNumericCellValue();
846
                amazonlisted.setSellingPrice(mfnPrice);
847
            }
848
 
849
            if (!checkEmptyString(sheet.getRow(iterator).getCell(2))){
850
                double fbaSellingPrice = sheet.getRow(iterator).getCell(2).getNumericCellValue();
851
                amazonlisted.setFbaPrice(fbaSellingPrice);
852
            }
853
 
854
            if (!checkEmptyString(sheet.getRow(iterator).getCell(3))){
10922 kshitij.so 855
                double fbbSellingPrice = sheet.getRow(iterator).getCell(3).getNumericCellValue();
856
                amazonlisted.setFbbPrice(fbbSellingPrice);
857
            }
8168 kshitij.so 858
 
12449 kshitij.so 859
            if (!checkEmptyString(sheet.getRow(iterator).getCell(4))){
860
                if ((long)sheet.getRow(iterator).getCell(4).getNumericCellValue()==1){
861
                    amazonlisted.setIsNonFba(true);
862
                }
863
                if ((long)sheet.getRow(iterator).getCell(4).getNumericCellValue()==0){
864
                    amazonlisted.setIsNonFba(false);
865
                }
866
            }
8168 kshitij.so 867
 
12449 kshitij.so 868
            if (!checkEmptyString(sheet.getRow(iterator).getCell(5))){
869
                if ((long)sheet.getRow(iterator).getCell(5).getNumericCellValue()==1){
870
                    amazonlisted.setIsFba(true);
871
                }
872
                if ((long)sheet.getRow(iterator).getCell(5).getNumericCellValue()==0){
873
                    amazonlisted.setIsFba(false);
874
                }
875
            }
876
 
877
            if (!checkEmptyString(sheet.getRow(iterator).getCell(6))){
10922 kshitij.so 878
                if ((long)sheet.getRow(iterator).getCell(6).getNumericCellValue()==1){
879
                    amazonlisted.setIsFbb(true);
880
                }
881
                if ((long)sheet.getRow(iterator).getCell(6).getNumericCellValue()==0){
882
                    amazonlisted.setIsFbb(false);
883
                }
884
            }
8168 kshitij.so 885
 
12449 kshitij.so 886
            if (!checkEmptyString(sheet.getRow(iterator).getCell(7))){
887
                if ((long)sheet.getRow(iterator).getCell(7).getNumericCellValue()==1){
888
                    amazonlisted.setIsInventoryOverride(true);
889
                }
890
                if ((long)sheet.getRow(iterator).getCell(7).getNumericCellValue()==0){
891
                    amazonlisted.setIsInventoryOverride(false);
892
                }
893
            }
894
            if (!checkEmptyString(sheet.getRow(iterator).getCell(8))){
895
                if ((long)sheet.getRow(iterator).getCell(8).getNumericCellValue()==1){
896
                    amazonlisted.setSuppressMfnPriceUpdate(true);
897
                }
898
                if ((long)sheet.getRow(iterator).getCell(8).getNumericCellValue()==0){
899
                    amazonlisted.setSuppressMfnPriceUpdate(false);
900
                }
901
            }
902
 
903
            if (!checkEmptyString(sheet.getRow(iterator).getCell(9))){
904
                if ((long)sheet.getRow(iterator).getCell(9).getNumericCellValue()==1){
905
                    amazonlisted.setSuppressFbaPriceUpdate(true);
906
                }
907
                if ((long)sheet.getRow(iterator).getCell(9).getNumericCellValue()==0){
908
                    amazonlisted.setSuppressFbaPriceUpdate(false);
909
                }
910
            }
911
 
912
            if (!checkEmptyString(sheet.getRow(iterator).getCell(10))){
10922 kshitij.so 913
                if ((long)sheet.getRow(iterator).getCell(10).getNumericCellValue()==1){
914
                    amazonlisted.setSuppressFbbPriceUpdate(true);
915
                }
916
                if ((long)sheet.getRow(iterator).getCell(10).getNumericCellValue()==0){
917
                    amazonlisted.setSuppressFbbPriceUpdate(false);
918
                }
919
            }
8620 kshitij.so 920
 
12449 kshitij.so 921
            if (!checkEmptyString(sheet.getRow(iterator).getCell(11))){
922
                String taxCode = sheet.getRow(iterator).getCell(11).getStringCellValue();
923
                amazonlisted.setTaxCode(taxCode);
924
            }
925
 
926
            if (!checkEmptyString(sheet.getRow(iterator).getCell(12))){
10922 kshitij.so 927
                String fbbTaxCode = sheet.getRow(iterator).getCell(12).getStringCellValue();
928
                amazonlisted.setFbbtaxCode(fbbTaxCode);
929
            }
12948 kshitij.so 930
 
12504 kshitij.so 931
            if (!checkEmptyString(sheet.getRow(iterator).getCell(13))){
932
                double otherCost = sheet.getRow(iterator).getCell(13).getNumericCellValue();
933
                amazonlisted.setOtherCost(otherCost);
934
            }
8362 kshitij.so 935
 
12449 kshitij.so 936
            amazonBulkUpdate.put(sku, amazonlisted);
937
        }
938
        logger.info("Amazon Bulk Map "+amazonBulkUpdate.toString());
939
        CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
940
        boolean result = CatalogClient.updateAmazonAttributesInBulk(amazonBulkUpdate);
941
        if (!result){
942
            sb = new StringBuilder();
943
            sb.append("Error : Unable to update");
944
        }
945
        File file = new File("/tmp/amazonbulk");
946
        FileWriter writer = new FileWriter(file);
947
        writer.append(sb.toString());
948
        writer.close();
949
        byte[] buffer = new byte[(int)file.length()];
950
        InputStream input = null;
951
        try {
952
            int totalBytesRead = 0;
953
            input = new BufferedInputStream(new FileInputStream(file));
954
            while(totalBytesRead < buffer.length){
955
                int bytesRemaining = buffer.length - totalBytesRead;
956
                int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
957
                if (bytesRead > 0){
958
                    totalBytesRead = totalBytesRead + bytesRead;
959
                }
960
            }
961
        }
962
        finally {
963
            input.close();
964
            file.delete();
965
        }
8362 kshitij.so 966
 
12449 kshitij.so 967
        response.setHeader("Content-Type", "text/javascript");
8168 kshitij.so 968
 
12449 kshitij.so 969
        ServletOutputStream sos;
970
        try {
971
            sos = response.getOutputStream();
972
            sos.write(buffer);
973
            sos.flush();
974
        } catch (IOException e) {
975
            System.out.println("Unable to stream the manifest file");
976
        }   
977
    }
8168 kshitij.so 978
 
12449 kshitij.so 979
    public boolean checkEmptyString(Cell cell){
980
        if (cell==null){
981
            return true;
982
        }
983
        return false;
984
    }
8168 kshitij.so 985
 
12449 kshitij.so 986
    public String uploadSheet(){
987
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
988
            logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
989
            return "authfail";
990
        }
991
        return "amazon-shipping-upload";
992
    }
8620 kshitij.so 993
 
12449 kshitij.so 994
    public String uploadPromotion(){
995
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
996
            logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
997
            return "authfail";
998
        }
999
        return "amazon-promotion-upload";
1000
    }
8168 kshitij.so 1001
 
12449 kshitij.so 1002
    public String uploadAsin(){
1003
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
1004
            logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
1005
            return "authfail";
1006
        }
1007
        return "amazon-asin-upload";
1008
    }
8168 kshitij.so 1009
 
12449 kshitij.so 1010
    public String uploadBulkSheet(){
1011
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
1012
            logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
1013
            return "authfail";
1014
        }
1015
        return "amazon-bulk-upload";
1016
    }
7283 kshitij.so 1017
 
8168 kshitij.so 1018
 
12449 kshitij.so 1019
    public String edit() {
1020
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1])) {
1021
            return "authfail";
1022
        }
1023
        return "edit";
1024
    }
8620 kshitij.so 1025
 
12449 kshitij.so 1026
    public String viewPromotionDetails() throws ParseException, TException{
1027
        logger.info(startDate);
1028
        logger.info(endDate);
1029
        SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
1030
        Date start = dateFormatter.parse(startDate);
1031
        Date end = dateFormatter.parse(endDate);
1032
        logger.info(start.getTime()+"");
1033
        logger.info(end.getTime()+"");
1034
        Client cc = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
1035
        setPromotionResult(cc.getAmazonPromotion(start.getTime(),end.getTime()));
1036
        return "amazon-promotion-result";
1037
    }
8620 kshitij.so 1038
 
12449 kshitij.so 1039
    public String getDate(long timestamp){
1040
        return new java.util.Date(timestamp).toLocaleString();
1041
    }
7283 kshitij.so 1042
 
12449 kshitij.so 1043
    public String show() {
1044
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1])) {
1045
            logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1]);
1046
            return "authfail";
1047
        }
7283 kshitij.so 1048
 
12449 kshitij.so 1049
        if (StringUtils.equals(id, "options")){
1050
            return "options";
1051
        }
7283 kshitij.so 1052
 
12449 kshitij.so 1053
        if (StringUtils.equals(id, "item-table")){
1054
            return "amazon-item-table";
1055
        }
7283 kshitij.so 1056
 
12449 kshitij.so 1057
        if (StringUtils.equals(id, "promotion")){
1058
            return "amazon-promotion";
1059
        }
7283 kshitij.so 1060
 
12449 kshitij.so 1061
        return "id";
1062
    }
7283 kshitij.so 1063
 
12449 kshitij.so 1064
    public String editNew() {
1065
        return "editNew";
1066
    }	
7283 kshitij.so 1067
 
12449 kshitij.so 1068
    public void setId(String id) {
1069
        logger.info(id);
1070
        this.id = id;
1071
    }
7283 kshitij.so 1072
 
12449 kshitij.so 1073
    public void setUrl(String url) {
1074
        this.url = url;
1075
    }
7283 kshitij.so 1076
 
12449 kshitij.so 1077
    public String getUrl() {
1078
        return url;
1079
    }
7283 kshitij.so 1080
 
12449 kshitij.so 1081
    public String getId() {
1082
        return id;
1083
    }
7283 kshitij.so 1084
 
12449 kshitij.so 1085
    public void setItemId(String itemId) {
1086
        this.itemId = itemId;
1087
    }
7283 kshitij.so 1088
 
12449 kshitij.so 1089
    public String getItemId() {
1090
        return itemId;
1091
    }
7283 kshitij.so 1092
 
12449 kshitij.so 1093
    public void setIsFba(String isFba) {
1094
        this.isFba = isFba;
1095
    }
7283 kshitij.so 1096
 
12449 kshitij.so 1097
    public String getIsFba() {
1098
        return isFba;
1099
    }
7283 kshitij.so 1100
 
12449 kshitij.so 1101
    public void setIsNonFba(String isNonFba) {
1102
        this.isNonFba = isNonFba;
1103
    }
7283 kshitij.so 1104
 
12449 kshitij.so 1105
    public String getIsNonFba() {
1106
        return isNonFba;
1107
    }
7283 kshitij.so 1108
 
12449 kshitij.so 1109
    public void setIsInventoryOverride(String isInventoryOverride) {
1110
        this.isInventoryOverride = isInventoryOverride;
1111
    }
7365 kshitij.so 1112
 
12449 kshitij.so 1113
    public String getIsInventoryOverride() {
1114
        return isInventoryOverride;
1115
    }
7283 kshitij.so 1116
 
12449 kshitij.so 1117
    public void setSellingPrice(String sellingPrice) {
1118
        this.sellingPrice = sellingPrice;
1119
    }
7283 kshitij.so 1120
 
12449 kshitij.so 1121
    public String getSellingPrice() {
1122
        return sellingPrice;
1123
    }
7365 kshitij.so 1124
 
12449 kshitij.so 1125
    public void setFbaPrice(String fbaPrice) {
1126
        this.fbaPrice = fbaPrice;
1127
    }
7365 kshitij.so 1128
 
12449 kshitij.so 1129
    public String getFbaPrice() {
1130
        return fbaPrice;
1131
    }
7365 kshitij.so 1132
 
12449 kshitij.so 1133
    public void setSaholicPrice(String saholicPrice) {
1134
        this.saholicPrice = saholicPrice;
1135
    }
8168 kshitij.so 1136
 
12449 kshitij.so 1137
    public String getSaholicPrice() {
1138
        return saholicPrice;
1139
    }
7365 kshitij.so 1140
 
12449 kshitij.so 1141
    public void setIsTime(String isTime){
1142
        logger.info("set istime"+isTime);
1143
        this.isTime = isTime;
1144
    }
7524 kshitij.so 1145
 
12449 kshitij.so 1146
    public String getIsTime(){
1147
        return isTime;
1148
    }
7365 kshitij.so 1149
 
12449 kshitij.so 1150
    public void setHandlingTime(String handlingTime){
1151
        this.handlingTime = handlingTime;
1152
    }
7524 kshitij.so 1153
 
12449 kshitij.so 1154
    public String getHandlingTime(){
1155
        return handlingTime;
1156
    }
7461 kshitij.so 1157
 
12449 kshitij.so 1158
    public void setCustomHandlingTime(String customHandlingTime){
1159
        logger.info("set custom handling time"+customHandlingTime);
1160
        this.customHandlingTime = customHandlingTime;
1161
    }
7461 kshitij.so 1162
 
12449 kshitij.so 1163
    public String getCustomHandlingTime(){
1164
        return customHandlingTime;
1165
    }
7524 kshitij.so 1166
 
12449 kshitij.so 1167
    public void setHoldInventory(String holdInventory){
1168
        this.holdInventory = holdInventory;
1169
    }
7524 kshitij.so 1170
 
12449 kshitij.so 1171
    public String getHoldInventory(){
1172
        return holdInventory;
1173
    }
7524 kshitij.so 1174
 
12449 kshitij.so 1175
    public void setDefaultInventory(String defaultInventory){
1176
        this.defaultInventory = defaultInventory;
1177
    }
7524 kshitij.so 1178
 
12449 kshitij.so 1179
    public String getDefaultInventory(){
1180
        return defaultInventory;
1181
    }
7524 kshitij.so 1182
 
12449 kshitij.so 1183
    public File getFile() {
1184
        return file;
1185
    }
7524 kshitij.so 1186
 
12449 kshitij.so 1187
    public void setFile(File file) {
1188
        this.file = file;
1189
    }
7283 kshitij.so 1190
 
12449 kshitij.so 1191
    public String getFileUploadContentType() {
1192
        return fileUploadContentType;
1193
    }
8168 kshitij.so 1194
 
12449 kshitij.so 1195
    public void setFileUploadContentType(String fileUploadContentType) {
1196
        this.fileUploadContentType = fileUploadContentType;
1197
    }
8168 kshitij.so 1198
 
12449 kshitij.so 1199
    public String getFileUploadFileName() {
1200
        return fileUploadFileName;
1201
    }
8168 kshitij.so 1202
 
12449 kshitij.so 1203
    public void setFileUploadFileName(String fileUploadFileName) {
1204
        this.fileUploadFileName = fileUploadFileName;
1205
    }
8168 kshitij.so 1206
 
12449 kshitij.so 1207
    public void setServletRequest(HttpServletRequest req) {
1208
        this.request = req;
1209
        this.session = req.getSession();        
1210
    }
8168 kshitij.so 1211
 
12449 kshitij.so 1212
    @Override
1213
    public void setServletContext(ServletContext arg0) {
1214
        // TODO Auto-generated method stub
8168 kshitij.so 1215
 
12449 kshitij.so 1216
    }
8362 kshitij.so 1217
 
1218
 
12449 kshitij.so 1219
    public void setSuppressMfnPriceUpdate(String suppressMfnPriceUpdate) {
1220
        this.suppressMfnPriceUpdate = suppressMfnPriceUpdate;
1221
    }
8620 kshitij.so 1222
 
12449 kshitij.so 1223
    public String getSuppressMfnPriceUpdate() {
1224
        return suppressMfnPriceUpdate;
1225
    }
8362 kshitij.so 1226
 
12449 kshitij.so 1227
    public void setSuppressFbaPriceUpdate(String suppressFbaPriceUpdate) {
1228
        this.suppressFbaPriceUpdate = suppressFbaPriceUpdate;
1229
    }
8620 kshitij.so 1230
 
12449 kshitij.so 1231
    public String getSuppressFbaPriceUpdate() {
1232
        return suppressFbaPriceUpdate;
1233
    }
8620 kshitij.so 1234
 
12449 kshitij.so 1235
    public void setErrMsg(String errMsg) {
1236
        this.errMsg = errMsg;
1237
    }
8620 kshitij.so 1238
 
12449 kshitij.so 1239
    public String getErrMsg() {
1240
        return errMsg;
1241
    }
8620 kshitij.so 1242
 
12449 kshitij.so 1243
    public void setServletResponse(HttpServletResponse response) {
1244
        this.response = response;
1245
    }
8620 kshitij.so 1246
 
12449 kshitij.so 1247
    public void setNext(String next) {
1248
        logger.info("next is"+next);
1249
        this.next = next;
1250
    }
8620 kshitij.so 1251
 
12449 kshitij.so 1252
    public String getNext() {
1253
        return next;
1254
    }
8620 kshitij.so 1255
 
12449 kshitij.so 1256
    public void setAmazonItems(List<Amazonlisted> amazonItems) {
1257
        this.amazonItems = amazonItems;
1258
    }
8620 kshitij.so 1259
 
12449 kshitij.so 1260
    public List<Amazonlisted> getAmazonItems() {
1261
        return amazonItems;
1262
    }
8620 kshitij.so 1263
 
12449 kshitij.so 1264
    public void setSearchText(String searchText) {
1265
        this.searchText = searchText;
1266
    }
8620 kshitij.so 1267
 
12449 kshitij.so 1268
    public String getSearchText() {
1269
        return searchText;
1270
    }
8620 kshitij.so 1271
 
12449 kshitij.so 1272
    public long getSearchCount() {
1273
        return searchCount;
1274
    }
1275
 
1276
    public long getTotalCount() {
1277
        return totalCount;
1278
    }
1279
 
1280
    public void setSearchCount(long count) {
1281
        this.searchCount = count;
1282
    }
1283
 
1284
    public void setTaxCode(String taxCode) {
1285
        this.taxCode = taxCode;
1286
    }
1287
 
1288
    public String getTaxCode() {
1289
        return taxCode;
1290
    }
1291
 
10922 kshitij.so 1292
    public void setFbbTaxCode(String fbbTaxCode) {
1293
        this.fbbTaxCode = fbbTaxCode;
1294
    }
1295
 
1296
    public String get() {
1297
        return fbbTaxCode;
1298
    }
1299
 
1300
    public void setIsFbb(String isFbb) {
1301
        this.isFbb = isFbb;
1302
    }
1303
 
1304
    public String getIsFbb() {
1305
        return isFbb;
1306
    }
1307
 
1308
    public void setFbbPrice(String fbbPrice) {
1309
        this.fbbPrice = fbbPrice;
1310
    }
1311
 
1312
    public String getFbbPrice() {
1313
        return fbbPrice;
1314
    }
1315
 
1316
    public void setSuppressFbbPriceUpdate(String suppressFbbPriceUpdate) {
1317
        this.suppressFbbPriceUpdate = suppressFbbPriceUpdate;
1318
    }
1319
 
1320
    public String getSuppressFbbPriceUpdate() {
1321
        return suppressFbbPriceUpdate;
1322
    }
1323
 
12449 kshitij.so 1324
    public String getStartDate() {
1325
        return startDate;
1326
    }
1327
 
1328
    public void setStartDate(String startDate) {
1329
        this.startDate = startDate;
1330
    }
1331
 
1332
    public String getEndDate() {
1333
        return endDate;
1334
    }
1335
 
1336
    public void setEndDate(String endDate) {
1337
        this.endDate = endDate;
1338
    }
1339
 
1340
    public void setPromotionResult(List<AmazonPromotion> promotionResult) {
1341
        this.promotionResult = promotionResult;
1342
    }
1343
 
1344
    public List<AmazonPromotion> getPromotionResult() {
1345
        return promotionResult;
1346
    }
1347
 
1348
    public String getPromotionType() {
1349
        return promotionType;
1350
    }
1351
 
1352
    public void setPromotionType(String promotionType) {
1353
        this.promotionType = promotionType;
1354
    }
1355
 
1356
    public String getOverrrideWanlc() {
1357
        return overrrideWanlc;
1358
    }
1359
 
1360
    public void setOverrrideWanlc(String overrrideWanlc) {
1361
        this.overrrideWanlc = overrrideWanlc;
1362
    }
1363
 
1364
    public String getExceptionalWanlc() {
1365
        return exceptionalWanlc;
1366
    }
1367
 
1368
    public void setExceptionalWanlc(String exceptionalWanlc) {
1369
        this.exceptionalWanlc = exceptionalWanlc;
1370
    }
1371
 
12661 kshitij.so 1372
    public void setFbaPromoPrice(String fbaPromoPrice) {
1373
        this.fbaPromoPrice = fbaPromoPrice;
1374
    }
1375
 
1376
    public String getFbaPromoPrice() {
1377
        return fbaPromoPrice;
1378
    }
1379
 
1380
    public void setFbbPromoPrice(String fbbPromoPrice) {
1381
        this.fbbPromoPrice = fbbPromoPrice;
1382
    }
1383
 
1384
    public String getFbbPromoPrice() {
1385
        return fbbPromoPrice;
1386
    }
1387
 
1388
    public void setPromoItemId(String promoItemId) {
1389
        this.promoItemId = promoItemId;
1390
    }
1391
 
1392
    public String getPromoItemId() {
1393
        return promoItemId;
1394
    }
12948 kshitij.so 1395
 
12675 kshitij.so 1396
    public String getIsFbaPromotionActive() {
1397
        return isFbaPromotionActive;
1398
    }
12661 kshitij.so 1399
 
12675 kshitij.so 1400
    public void setIsFbaPromotionActive(String isFbaPromotionActive) {
1401
        this.isFbaPromotionActive = isFbaPromotionActive;
1402
    }
1403
 
1404
    public String getIsFbbPromotionActive() {
1405
        return isFbbPromotionActive;
1406
    }
1407
 
1408
    public void setIsFbbPromotionActive(String isFbbPromotionActive) {
1409
        this.isFbbPromotionActive = isFbbPromotionActive;
1410
    }
1411
 
12889 kshitij.so 1412
    public void setFbgTaxCode(String fbgTaxCode) {
1413
        this.fbgTaxCode = fbgTaxCode;
1414
    }
1415
 
1416
    public String getFbgTaxCode() {
1417
        return fbgTaxCode;
1418
    }
1419
 
1420
    public void setIsFbg(String isFbg) {
1421
        this.isFbg = isFbg;
1422
    }
1423
 
1424
    public String getIsFbg() {
1425
        return isFbg;
1426
    }
1427
 
1428
    public void setFbgPrice(String fbgPrice) {
1429
        this.fbgPrice = fbgPrice;
1430
    }
1431
 
1432
    public String getFbgPrice() {
1433
        return fbgPrice;
1434
    }
1435
 
1436
    public void setSuppressFbgPriceUpdate(String suppressFbgPriceUpdate) {
1437
        this.suppressFbgPriceUpdate = suppressFbgPriceUpdate;
1438
    }
1439
 
1440
    public String getSuppressFbgPriceUpdate() {
1441
        return suppressFbgPriceUpdate;
1442
    }
1443
 
1444
    public void setFbgPromoPrice(String fbgPromoPrice) {
1445
        this.fbgPromoPrice = fbgPromoPrice;
1446
    }
1447
 
1448
    public String getFbgPromoPrice() {
1449
        return fbgPromoPrice;
1450
    }
1451
 
1452
    public void setIsFbgPromotionActive(String isFbgPromotionActive) {
1453
        this.isFbgPromotionActive = isFbgPromotionActive;
1454
    }
1455
 
1456
    public String getIsFbgPromotionActive() {
1457
        return isFbgPromotionActive;
1458
    }
1459
 
15703 kshitij.so 1460
	public void setFbdTaxCode(String fbdTaxCode) {
1461
		this.fbdTaxCode = fbdTaxCode;
1462
	}
1463
 
1464
	public String getFbdTaxCode() {
1465
		return fbdTaxCode;
1466
	}
1467
 
1468
	public void setIsFbd(String isFbd) {
1469
		this.isFbd = isFbd;
1470
	}
1471
 
1472
	public String getIsFbd() {
1473
		return isFbd;
1474
	}
1475
 
1476
	public void setFbdPrice(String fbdPrice) {
1477
		this.fbdPrice = fbdPrice;
1478
	}
1479
 
1480
	public String getFbdPrice() {
1481
		return fbdPrice;
1482
	}
1483
 
1484
	public void setSuppressFbdPriceUpdate(String suppressFbdPriceUpdate) {
1485
		this.suppressFbdPriceUpdate = suppressFbdPriceUpdate;
1486
	}
1487
 
1488
	public String getSuppressFbdPriceUpdate() {
1489
		return suppressFbdPriceUpdate;
1490
	}
1491
 
1492
	public void setFbdPromoPrice(String fbdPromoPrice) {
1493
		this.fbdPromoPrice = fbdPromoPrice;
1494
	}
1495
 
1496
	public String getFbdPromoPrice() {
1497
		return fbdPromoPrice;
1498
	}
1499
 
1500
	public void setIsFbdPromotionActive(String isFbdPromotionActive) {
1501
		this.isFbdPromotionActive = isFbdPromotionActive;
1502
	}
1503
 
1504
	public String getIsFbdPromotionActive() {
1505
		return isFbdPromotionActive;
1506
	}
1507
 
7283 kshitij.so 1508
}