Subversion Repositories SmartDukaan

Rev

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