Subversion Repositories SmartDukaan

Rev

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

Rev 3911 Rev 3922
Line 42... Line 42...
42
@SuppressWarnings("serial")
42
@SuppressWarnings("serial")
43
public class CatalogServiceImpl extends RemoteServiceServlet implements CatalogService {
43
public class CatalogServiceImpl extends RemoteServiceServlet implements CatalogService {
44
 
44
 
45
    private static Logger logger = Logger.getLogger(CatalogServiceImpl.class);
45
    private static Logger logger = Logger.getLogger(CatalogServiceImpl.class);
46
    
46
    
-
 
47
    private static Logger pushToProdLogger = Logger.getLogger("pushToProdLogger");
-
 
48
    
47
    private static Date pushToProdDate;
49
    private static Date pushToProdDate;
48
    
50
    
-
 
51
    private static String logFile;
-
 
52
    
-
 
53
    private static int maxCount;
-
 
54
    
-
 
55
    static {
-
 
56
        try {
-
 
57
            logFile = ConfigClient.getClient().get(ConfigClientKeys.push_prices_to_prod_log_file.toString());
-
 
58
            maxCount = Integer.parseInt(ConfigClient.getClient().get(ConfigClientKeys.push_prices_to_prod_max_count.toString()));    
-
 
59
        } catch(ConfigException ce) {
-
 
60
            logger.error("Unable to connect to the config server. Setting sensible defaults.", ce);
-
 
61
            logFile = "/var/log/services/pushToProductionCount/pushToProd.log";
-
 
62
            maxCount = 5;
-
 
63
        }
-
 
64
                
-
 
65
    }
-
 
66
    
49
    @Override
67
    @Override
50
    public int getItemCountByStatus(boolean useStatus, ItemStatus itemStatus){
68
    public int getItemCountByStatus(boolean useStatus, ItemStatus itemStatus){
51
        int count = 0;
69
        int count = 0;
52
        try{
70
        try{
53
            CatalogClient catalogServiceClient = new CatalogClient();
71
            CatalogClient catalogServiceClient = new CatalogClient();
Line 569... Line 587...
569
 
587
 
570
    @Override
588
    @Override
571
    public String updateItemOnProduction(Item item) {
589
    public String updateItemOnProduction(Item item) {
572
        logger.info("Update item on production call, Item Id: " + item.getId());
590
        logger.info("Update item on production call, Item Id: " + item.getId());
573
        
591
        
574
        String errMsg = checkPushToProdCount();
592
        if(!canPushToProduction()) {
575
        // If errMsg is not null, then return that message to user
593
            // If we can't push to production, then return that message to user
576
        // else move forward with update.
594
            // else move forward with update.
577
        if(errMsg != null) {
-
 
578
            return errMsg;
595
            return "Maximum push to production count reached for today";
579
        }
596
        }
580
        try{
597
        try{
581
            CatalogClient catalogServiceClient_Prod = new CatalogClient( 
598
            CatalogClient catalogServiceClient_Prod = new CatalogClient( 
582
                    ConfigClientKeys.catalog_service_server_host_prod.toString(),
599
                    ConfigClientKeys.catalog_service_server_host_prod.toString(),
583
                    ConfigClientKeys.catalog_service_server_port.toString());
600
                    ConfigClientKeys.catalog_service_server_port.toString());
584
            
601
            
585
            //for testing, put catalog_service_server_port_test in shop2020.cfg
-
 
586
            /*CatalogServiceClient catalogServiceClient_Prod = new CatalogServiceClient(CatalogServiceClient.class.getSimpleName(), 
-
 
587
                    ConfigClientKeys.catalog_service_server_host.toString(), "catalog_service_server_port_test");*/
-
 
588
            
-
 
589
            InventoryService.Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
602
            InventoryService.Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
590
 
603
 
591
            in.shop2020.model.v1.catalog.Item tItem = catalogClient_Prod.getItem(item.getId());
604
            in.shop2020.model.v1.catalog.Item tItem = catalogClient_Prod.getItem(item.getId());
592
            
605
            
593
            if(item.getMrp() != null) {
606
            if(item.getMrp() != null) {
Line 636... Line 649...
636
                    logger.info("SourceItemPricing updated. " + tSourcePricing.toString());
649
                    logger.info("SourceItemPricing updated. " + tSourcePricing.toString());
637
                    sb.append("[SId:" + s.getSourceId() + ",MRP=" + s.getMrp() + ",SP=" + s.getSellingPrice() + "], ");
650
                    sb.append("[SId:" + s.getSourceId() + ",MRP=" + s.getMrp() + ",SP=" + s.getSellingPrice() + "], ");
638
                }
651
                }
639
            }
652
            }
640
            
653
            
641
            logItemDetails("Id=" + item.getId() + ",MRP=" + item.getMrp() + ",SP=" + " " + item.getSellingPrice() + sb.toString());
654
            pushToProdLogger.info("Id=" + item.getId() + ",MRP=" + item.getMrp() + ",SP=" + " " + item.getSellingPrice() + sb.toString());
642
        } catch (Exception e) {
655
        } catch (Exception e) {
643
            logger.error("Error while updating prices on production", e);
656
            logger.error("Error while updating prices on production", e);
644
            return "Error while updating all prices on production. Some of the prices may have been  updated";
657
            return "Error while updating all prices on production. Some of the prices may have been  updated";
645
        }
658
        }
646
        
659
        
Line 773... Line 786...
773
        return item;
786
        return item;
774
    }
787
    }
775
    
788
    
776
    /**
789
    /**
777
     * 
790
     * 
778
     * @return null if push to production count is less than maximum allowed.
791
     * @return True if push to production count is less than maximum allowed.
779
     *   <br>otherwise error message to be passed to the client side for showing to the user
-
 
780
     */
792
     */
781
    private String checkPushToProdCount() {
793
    private boolean canPushToProduction() {
782
        int count = 0, maxCount;
-
 
783
        try {
-
 
784
            //String logFile = ConfigClient.getClient().get(ConfigClientKeys.push_prices_to_prod_log_file.toString());
-
 
785
            maxCount = Integer.parseInt(ConfigClient.getClient().get(ConfigClientKeys.push_prices_to_prod_max_count.toString()));
-
 
786
            //count = getPushToProdCount(logFile);
794
        int count = getPushToProdCount(logFile);
787
            if(count >= maxCount) {
795
        return count < maxCount;
788
                return "Maximum push to production count reached for today";
-
 
789
            }
-
 
790
        } catch (ConfigException e) {
-
 
791
            logger.error("Error while getting the max count from the config server", e);
-
 
792
            return "Error getting push to production parameters";
-
 
793
        }
-
 
794
        return null;
-
 
795
    }
-
 
796
    
-
 
797
    /**
-
 
798
     * Log push to production details
-
 
799
     * @param str
-
 
800
     */
-
 
801
    private void logItemDetails(String str) {
-
 
802
        logger.info(str);
-
 
803
    }
796
    }
804
    
797
      
805
    /**
798
    /**
806
     * If this is the first attempt to push to production for current date, returns 0
799
     * If this is the first attempt to push to production for current date, returns 0
807
     * else reads number of lines from daily rolling log file to get the count.
800
     * else reads number of lines from daily rolling log file to get the count.
808
     * @return push to production count for current date
801
     * @return push to production count for current date
809
     */
802
     */