Subversion Repositories SmartDukaan

Rev

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

Rev 2427 Rev 2489
Line 179... Line 179...
179
        }catch(Exception e){
179
        }catch(Exception e){
180
            e.printStackTrace();
180
            e.printStackTrace();
181
        }
181
        }
182
        return null;
182
        return null;
183
    }
183
    }
184
 
184
    
-
 
185
    /**
-
 
186
     * Creates a new Item object and populates its attributes from thrift item passed as parameter.
-
 
187
     * Also creates a Map each for VendorItemPricing and VendorItemMapping and adds these maps to the
-
 
188
     * new Item object.
-
 
189
     * @param thriftItem
-
 
190
     * @param tVendorPricings
-
 
191
     * @param tVendorMappings
-
 
192
     * @return item object with attributes copied from thrift item object.
-
 
193
     */
185
    private Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem, 
194
    private Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem, 
186
            List<in.shop2020.model.v1.catalog.VendorItemPricing> tVendorPricings, 
195
            List<in.shop2020.model.v1.catalog.VendorItemPricing> tVendorPricings, 
187
            List<in.shop2020.model.v1.catalog.VendorItemMapping> tVendorMappings){
196
            List<in.shop2020.model.v1.catalog.VendorItemMapping> tVendorMappings){
188
 
197
 
189
        Map<String, VendorItemMapping> vItemMap = new HashMap<String, VendorItemMapping>();
198
        Map<String, VendorItemMapping> vItemMap = new HashMap<String, VendorItemMapping>();
Line 216... Line 225...
216
                vendorPricingMap.put(vPricings.getVendorId(), vPricings);
225
                vendorPricingMap.put(vPricings.getVendorId(), vPricings);
217
            }
226
            }
218
        }
227
        }
219
 
228
 
220
        Item item = new Item(thriftItem.getId(),
229
        Item item = new Item(thriftItem.getId(),
-
 
230
                thriftItem.getHotspotCategory(),
221
                thriftItem.getProductGroup(),
231
                thriftItem.getProductGroup(),
222
                thriftItem.getBrand(),
232
                thriftItem.getBrand(),
223
                thriftItem.getModelNumber(),
233
                thriftItem.getModelNumber(),
224
                thriftItem.getModelName(),
234
                thriftItem.getModelName(),
225
                thriftItem.getColor(),
235
                thriftItem.getColor(),
Line 227... Line 237...
227
                thriftItem.getCategory(),
237
                thriftItem.getCategory(),
228
                thriftItem.getComments(),
238
                thriftItem.getComments(),
229
                thriftItem.getCatalogItemId(),
239
                thriftItem.getCatalogItemId(),
230
                thriftItem.getFeatureId(),
240
                thriftItem.getFeatureId(),
231
                thriftItem.getFeatureDescription(),
241
                thriftItem.getFeatureDescription(),
232
                thriftItem.isSetMrp() ? thriftItem.getMrp() : -1,
242
                thriftItem.isSetMrp() ? thriftItem.getMrp() : null,
233
                thriftItem.getMop(),
243
                thriftItem.getMop(),
234
                thriftItem.isSetSellingPrice() ? thriftItem.getSellingPrice() : -1,
244
                thriftItem.isSetSellingPrice() ? thriftItem.getSellingPrice() : null,
235
                thriftItem.getDealerPrice(),
245
                thriftItem.getDealerPrice(),
236
                thriftItem.isSetWeight() ? thriftItem.getWeight() : -1,
246
                thriftItem.isSetWeight() ? thriftItem.getWeight() : null,
237
                thriftItem.getAddedOn(),
247
                thriftItem.getAddedOn(),
238
                thriftItem.getStartDate(),
248
                thriftItem.getStartDate(),
239
                thriftItem.getRetireDate(),
249
                thriftItem.getRetireDate(),
240
                thriftItem.getUpdatedOn(),
250
                thriftItem.getUpdatedOn(),
241
                thriftItem.getItemStatus().name(),
251
                thriftItem.getItemStatus().name(),
242
                thriftItem.getItemStatus().getValue(),
252
                thriftItem.getItemStatus().getValue(),
243
                thriftItem.getStatus_description(),
253
                thriftItem.getStatus_description(),
244
                thriftItem.getOtherInfo(),
254
                thriftItem.getOtherInfo(),
245
                thriftItem.getBestDealText(),
255
                thriftItem.getBestDealText(),
246
                thriftItem.isSetBestDealValue() ? thriftItem.getBestDealValue() : -1,
256
                thriftItem.isSetBestDealValue() ? thriftItem.getBestDealValue() : null,
247
                thriftItem.isSetBestSellingRank() ? thriftItem.getBestSellingRank() : -1,
257
                thriftItem.isSetBestSellingRank() ? thriftItem.getBestSellingRank() : null,
248
                thriftItem.isDefaultForEntity(),
258
                thriftItem.isDefaultForEntity(),
249
                thriftItem.isRisky(),
259
                thriftItem.isRisky(),
250
                (thriftItem.getItemInventory() != null ? thriftItem.getItemInventory().getAvailability() : null),
260
                (thriftItem.getItemInventory() != null ? thriftItem.getItemInventory().getAvailability() : null),
251
                vendorPricingMap,
261
                vendorPricingMap,
252
                vItemMap);
262
                vItemMap);
Line 414... Line 424...
414
        tItem.setColor(item.getColor());
424
        tItem.setColor(item.getColor());
415
 
425
 
416
        tItem.setStatus_description(item.getItemStatusDesc());
426
        tItem.setStatus_description(item.getItemStatusDesc());
417
        tItem.setComments(item.getComments());
427
        tItem.setComments(item.getComments());
418
 
428
 
419
        if(item.getMrp() != -1) {
429
        if(item.getMrp() != null) {
420
            tItem.setMrp(item.getMrp());
430
            tItem.setMrp(item.getMrp());
421
        } else {
431
        } else {
422
            tItem.setMrpIsSet(false);
432
            tItem.setMrpIsSet(false);
423
        }
433
        }
424
        if(item.getSellingPrice() != -1) {
434
        if(item.getSellingPrice() != null) {
425
            tItem.setSellingPrice(item.getSellingPrice());
435
            tItem.setSellingPrice(item.getSellingPrice());
426
        } else {
436
        } else {
427
            tItem.setSellingPriceIsSet(false);
437
            tItem.setSellingPriceIsSet(false);
428
        }
438
        }
429
        if(item.getWeight() != -1) {
439
        if(item.getWeight() != null) {
430
            tItem.setWeight(item.getWeight());
440
            tItem.setWeight(item.getWeight());
431
        } else {
441
        } else {
432
            tItem.setWeightIsSet(false);
442
            tItem.setWeightIsSet(false);
433
        }
443
        }
434
 
-
 
-
 
444
        if(item.getMop() != null) {
435
        tItem.setMop(item.getMop());
445
            tItem.setMop(item.getMop());
-
 
446
        } else {
-
 
447
            tItem.setMopIsSet(false);
-
 
448
        }
-
 
449
        if(item.getDealerPrice() != null) {
436
        tItem.setDealerPrice(item.getDealerPrice());
450
            tItem.setDealerPrice(item.getDealerPrice());
-
 
451
        } else {
-
 
452
            tItem.setTransferPriceIsSet(false);
-
 
453
        }
-
 
454
        if(item.getTransferPrice() != null) {
437
        tItem.setTransferPrice(item.getTransferPrice());
455
            tItem.setTransferPrice(item.getTransferPrice());
-
 
456
        } else {
-
 
457
            tItem.setTransferPriceIsSet(false);
438
 
458
        }
439
        tItem.setBestDealText(item.getBestDealsText());
459
        tItem.setBestDealText(item.getBestDealsText());
440
        if(item.getBestDealsValue() != -1) {
460
        if(item.getBestDealsValue() != null) {
441
            tItem.setBestDealValue(item.getBestDealsValue());
461
            tItem.setBestDealValue(item.getBestDealsValue());
442
        } else {
462
        } else {
443
            tItem.setBestDealValueIsSet(false);
463
            tItem.setBestDealValueIsSet(false);
444
        }
464
        }
445
        if(item.getBestSellingRank() != -1) {
465
        if(item.getBestSellingRank() != null) {
446
            tItem.setBestSellingRank(item.getBestSellingRank());
466
            tItem.setBestSellingRank(item.getBestSellingRank());
447
        } else {
467
        } else {
448
            tItem.setBestSellingRankIsSet(false);
468
            tItem.setBestSellingRankIsSet(false);
449
        }
469
        }
450
        tItem.setDefaultForEntity(item.isDefaultForEntity());
470
        tItem.setDefaultForEntity(item.isDefaultForEntity());
451
        tItem.setRisky(item.isRisky());
471
        tItem.setRisky(item.isRisky());
452
 
472
 
-
 
473
        if(item.getStartDate() != null) {
453
        tItem.setStartDate(item.getStartDate());
474
            tItem.setStartDate(item.getStartDate());
-
 
475
        } else {
-
 
476
            tItem.setStartDateIsSet(false);
-
 
477
        }
-
 
478
        if(item.getRetireDate() != null) {
-
 
479
            tItem.setRetireDate(item.getRetireDate());
-
 
480
        } else {
-
 
481
            tItem.setRetireDateIsSet(false);
-
 
482
        }
454
        tItem.setUpdatedOn(Calendar.getInstance().getTimeInMillis());
483
        tItem.setUpdatedOn(Calendar.getInstance().getTimeInMillis());
455
        tItem.setRetireDate(item.getRetireDate());
484
        
456
        tItem.setHotspotCategory(item.getVendorCategory());
485
        tItem.setHotspotCategory(item.getVendorCategory());
457
    }
486
    }
458
 
487
 
459
    @Override
488
    @Override
460
    public void pauseItem(long itemId) {
489
    public void pauseItem(long itemId) {
Line 592... Line 621...
592
        // If errMsg is not null, then return that message to user
621
        // If errMsg is not null, then return that message to user
593
        // else move forward with update.
622
        // else move forward with update.
594
        if(errMsg != null) {
623
        if(errMsg != null) {
595
            return errMsg;
624
            return errMsg;
596
        }
625
        }
597
        log(item);
-
 
598
        try{
626
        try{
599
            /*CatalogServiceClient catalogServiceClient_Prod = new CatalogServiceClient(CatalogServiceClient.class.getSimpleName(), 
627
            /*CatalogServiceClient catalogServiceClient_Prod = new CatalogServiceClient(CatalogServiceClient.class.getSimpleName(), 
600
                    ConfigClientKeys.catalog_service_server_host_prod.toString(),
628
                    ConfigClientKeys.catalog_service_server_host_prod.toString(),
601
                    ConfigClientKeys.catalog_service_server_port.toString());*/
629
                    ConfigClientKeys.catalog_service_server_port.toString());*/
602
            
630
            
Line 606... Line 634...
606
            
634
            
607
            InventoryService.Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
635
            InventoryService.Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
608
 
636
 
609
            in.shop2020.model.v1.catalog.Item tItem = catalogClient_Prod.getItem(item.getId());
637
            in.shop2020.model.v1.catalog.Item tItem = catalogClient_Prod.getItem(item.getId());
610
            
638
            
611
            // -1 is used to signify that the corresponding double/float/long/int field is NULL
-
 
612
            // It is done so because these fields cannot be set as null in Item bean and thrift object item.
-
 
613
            if(item.getMrp() != -1) {
639
            if(item.getMrp() != null) {
614
                tItem.setMrp(item.getMrp());
640
                tItem.setMrp(item.getMrp());
615
            } else {
641
            } else {
616
                tItem.setMrpIsSet(false);
642
                tItem.setMrpIsSet(false);
617
            }
643
            }
618
            if(item.getSellingPrice() != -1) {
644
            if(item.getSellingPrice() != null) {
619
                tItem.setSellingPrice(item.getSellingPrice());
645
                tItem.setSellingPrice(item.getSellingPrice());
620
            } else {
646
            } else {
621
                tItem.setSellingPriceIsSet(false);
647
                tItem.setSellingPriceIsSet(false);
622
            }
648
            }
623
            if(item.getMop() != -1) {
649
            if(item.getMop() != null) {
624
                tItem.setMop(item.getMop());
650
                tItem.setMop(item.getMop());
625
            } else {
651
            } else {
626
                tItem.setMopIsSet(false);
652
                tItem.setMopIsSet(false);
627
            }
653
            }
628
            if(item.getDealerPrice() != -1) {
654
            if(item.getDealerPrice() != null) {
629
                tItem.setDealerPrice(item.getDealerPrice());
655
                tItem.setDealerPrice(item.getDealerPrice());
630
            } else {
656
            } else {
631
                tItem.setDealerPriceIsSet(false);
657
                tItem.setDealerPriceIsSet(false);
632
            }
658
            }
633
            if(item.getTransferPrice() != -1) {
659
            if(item.getTransferPrice() != null) {
634
                tItem.setTransferPrice(item.getTransferPrice());
660
                tItem.setTransferPrice(item.getTransferPrice());
635
            } else {
661
            } else {
636
                tItem.setTransferPriceIsSet(false);
662
                tItem.setTransferPriceIsSet(false);
637
            }
663
            }
638
 
-
 
639
            long rItemId;
664
            long rItemId;
640
            if((rItemId = catalogClient_Prod.updateItem(tItem)) != item.getId()) {
665
            if((rItemId = catalogClient_Prod.updateItem(tItem)) != item.getId()) {
641
                GWT.log("Error updating item, returned Item Id: " + rItemId);
666
                GWT.log("Error updating item, returned Item Id: " + rItemId);
642
                return "Error updating item prices on production";
667
                return "Error updating item prices on production";
643
            }
668
            }
644
            GWT.log("Item updated successfully, Item Id: " + item.getId());
669
            GWT.log("Item updated successfully, Item Id: " + item.getId());
645
 
670
 
646
            Map<Long, VendorPricings> vendorPricings = item.getVendorPricesMap();
671
            Map<Long, VendorPricings> vendorPricings = item.getVendorPricesMap();
-
 
672
            StringBuilder sb = new StringBuilder();
647
            if(vendorPricings != null && !vendorPricings.isEmpty()) {
673
            if(vendorPricings != null && !vendorPricings.isEmpty()) {
648
                in.shop2020.model.v1.catalog.VendorItemPricing tVendorPricing;
674
                in.shop2020.model.v1.catalog.VendorItemPricing tVendorPricing;
649
                for(VendorPricings v : vendorPricings.values()) {
675
                for(VendorPricings v : vendorPricings.values()) {
650
                    tVendorPricing = new in.shop2020.model.v1.catalog.VendorItemPricing();
676
                    tVendorPricing = new in.shop2020.model.v1.catalog.VendorItemPricing();
651
                    tVendorPricing.setVendorId(v.getVendorId());
677
                    tVendorPricing.setVendorId(v.getVendorId());
Line 654... Line 680...
654
                    tVendorPricing.setTransferPrice(v.getTransferPrice());
680
                    tVendorPricing.setTransferPrice(v.getTransferPrice());
655
                    tVendorPricing.setDealerPrice(v.getDealerPrice());
681
                    tVendorPricing.setDealerPrice(v.getDealerPrice());
656
                    catalogClient_Prod.addVendorItemPricing(tVendorPricing);
682
                    catalogClient_Prod.addVendorItemPricing(tVendorPricing);
657
                    GWT.log("VendorItemPricing updated. " + tVendorPricing.getVendorId() + ", " + tVendorPricing.getItemId() + ", " +
683
                    GWT.log("VendorItemPricing updated. " + tVendorPricing.getVendorId() + ", " + tVendorPricing.getItemId() + ", " +
658
                            tVendorPricing.getMop() + ", " + tVendorPricing.getTransferPrice() + ", " + tVendorPricing.getDealerPrice());
684
                            tVendorPricing.getMop() + ", " + tVendorPricing.getTransferPrice() + ", " + tVendorPricing.getDealerPrice());
-
 
685
                    sb.append("[VId:" + v.getVendorId() + ",MOP=" + v.getMop() + ",TP=" + v.getTransferPrice() + ",DP=" + v.getDealerPrice() + "], ");
659
                }
686
                }
660
            }
687
            }
-
 
688
            logItemDetails("Id=" + item.getId() + ",MRP=" + item.getMrp() + ",SP=" + " " + item.getSellingPrice() + sb.toString());
661
        } catch (Exception e) {
689
        } catch (Exception e) {
662
            e.printStackTrace();
690
            e.printStackTrace();
663
            return "Error while updating all prices on production. Some of the prices may have been  updated";
691
            return "Error while updating all prices on production. Some of the prices may have been  updated";
664
        }
692
        }
-
 
693
        
665
        /*
694
        /*
666
        // Push the content of one item to production 
695
        // Push the content of one item to production 
667
        Process p;
696
        Process p;
668
		try {
697
		try {
669
		    String scriptPath = ConfigClient.getClient().get(ConfigClientKeys.PUSH_PRICES_TO_PROD_SCRIPT_PATH.toString());
698
		    String scriptPath = ConfigClient.getClient().get(ConfigClientKeys.PUSH_PRICES_TO_PROD_SCRIPT_PATH.toString());
Line 683... Line 712...
683
            return "Error getting content script path";
712
            return "Error getting content script path";
684
        }*/
713
        }*/
685
        return "Prices updated and content generated successfully";
714
        return "Prices updated and content generated successfully";
686
    }
715
    }
687
    
716
    
-
 
717
    /**
-
 
718
     * 
-
 
719
     * @return null if push to production count is less than maximum allowed.
-
 
720
     *   <br>otherwise error message to be passed to the client side for showing to the user
-
 
721
     */
688
    private String checkPushToProdCount() {
722
    private String checkPushToProdCount() {
689
        int count = 0, maxCount;
723
        int count = 0, maxCount;
690
        try {
724
        try {
691
            //logfile = ConfigClient.getClient().get(ConfigClientKeys.push_prices_to_prod_log_file.toString());
725
            //logfile = ConfigClient.getClient().get(ConfigClientKeys.push_prices_to_prod_log_file.toString());
692
            maxCount = Integer.parseInt(ConfigClient.getClient().get(ConfigClientKeys.push_prices_to_prod_max_count.toString()));
726
            maxCount = Integer.parseInt(ConfigClient.getClient().get(ConfigClientKeys.push_prices_to_prod_max_count.toString()));
Line 699... Line 733...
699
            return "Error getting push to production parameters";
733
            return "Error getting push to production parameters";
700
        }
734
        }
701
        return null;
735
        return null;
702
    }
736
    }
703
    
737
    
-
 
738
    /**
-
 
739
     * Log push to production details
-
 
740
     * @param str
-
 
741
     */
704
    private void log(Item item) {
742
    private void logItemDetails(String str) {
705
        Logger log = Logger.getLogger(CatalogServiceImpl.class);
743
        Logger log = Logger.getLogger(CatalogServiceImpl.class);
706
        log.info("MRP: " + item.getMrp() + ", SP: " + item.getSellingPrice());
744
        log.info(str);
707
    }
745
    }
708
    
746
    
-
 
747
    /**
-
 
748
     * If this is the first attempt to push to production for current date, returns 0
-
 
749
     * else reads number of lines from daily rolling log file to get the count.
-
 
750
     * @return push to production count for current date
-
 
751
     */
709
    private int getPushToProdCount() {
752
    private int getPushToProdCount() {
710
        int lineCount = 0;
753
        int lineCount = 0;
711
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm");
754
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm");
712
        Date currentDate = Calendar.getInstance().getTime();
755
        Date currentDate = Calendar.getInstance().getTime();
713
        if(pushToProdDate == null ||  !dateFormat.format(pushToProdDate).equals(dateFormat.format(currentDate))) {
756
        if(pushToProdDate == null ||  !dateFormat.format(pushToProdDate).equals(dateFormat.format(currentDate))) {