Subversion Repositories SmartDukaan

Rev

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

Rev 5257 Rev 5279
Line 74... Line 74...
74
    private Map<Long, Entity>     entities;
74
    private Map<Long, Entity>     entities;
75
    private List<Item>            items;
75
    private List<Item>            items;
76
    private List<Source>          sources;
76
    private List<Source>          sources;
77
    private CatalogClient         csc;
77
    private CatalogClient         csc;
78
    private Client                client;
78
    private Client                client;
79
 
-
 
-
 
79
    private List<Item>			  alertItems;	
80
    private long                  newLastGenerationTime;
80
    private long                  newLastGenerationTime;
81
 
81
 
82
    static {
82
    static {
83
        options = new Options();
83
        options = new Options();
84
        options.addOption(GENERATION_TYPE_OPTION, true, "Generation type");
84
        options.addOption(GENERATION_TYPE_OPTION, true, "Generation type");
Line 92... Line 92...
92
 
92
 
93
    public ContentGenerationUtility() throws Exception {
93
    public ContentGenerationUtility() throws Exception {
94
        csc = new CatalogClient();
94
        csc = new CatalogClient();
95
        client = csc.getClient();
95
        client = csc.getClient();
96
        sources = client.getAllSources();
96
        sources = client.getAllSources();
-
 
97
        alertItems = new ArrayList<Item>();	
97
    }
98
    }
98
 
99
 
99
    /**
100
    /**
100
     * @param args
101
     * @param args
101
     * @throws Exception
102
     * @throws Exception
Line 484... Line 485...
484
                		String statusDescription = productName + " is coming soon.";
485
                		String statusDescription = productName + " is coming soon.";
485
                		if(item.getExpectedArrivalDate()>new Date().getTime() + ONE_DAY){
486
                		if(item.getExpectedArrivalDate()>new Date().getTime() + ONE_DAY){
486
                			statusDescription = productName + " will be available by " 
487
                			statusDescription = productName + " will be available by " 
487
                			+ new SimpleDateFormat("dd/MM/yy").format(new Date(item.getExpectedArrivalDate()));
488
                			+ new SimpleDateFormat("dd/MM/yy").format(new Date(item.getExpectedArrivalDate()));
488
                		}
489
                		}
-
 
490
                		//Send alert to Category team one day before expected arrival date
-
 
491
                		//So they may change the expected arrival date if they want to.
-
 
492
                		if(item.getExpectedArrivalDate() < new Date().getTime() + 2*ONE_DAY && 
-
 
493
                				item.getExpectedArrivalDate() > new Date().getTime() + ONE_DAY) {
-
 
494
                				alertItems.add(item);
-
 
495
                		}
489
                		item.setStatus_description(statusDescription);
496
                		item.setStatus_description(statusDescription);
490
                	}
497
                	}
491
                    client.updateItem(item);
498
                    client.updateItem(item);
492
                }
499
            	}
493
            }
500
            }
494
        }
501
        }
-
 
502
        sendAlertToCategoryTeam(alertItems);
495
        try {
503
        try {
496
            //generate products list that is to be uploaded in Amazon.
504
            //generate products list that is to be uploaded in Amazon.
497
        	AmazonSCDataGenerator ascdGenerator = new AmazonSCDataGenerator();
505
        	AmazonSCDataGenerator ascdGenerator = new AmazonSCDataGenerator();
498
            ascdGenerator.generateSCProdData(validEntities, GENERATION_TYPE);
506
            ascdGenerator.generateSCProdData(validEntities, GENERATION_TYPE);
499
        } catch (Exception e) {
507
        } catch (Exception e) {
500
        	e.printStackTrace();
508
        	e.printStackTrace();
501
            log.info("Could not generate Amazon data", e);
509
            log.info("Could not generate Amazon data", e);
502
        }
510
        }
503
    }
511
    }
504
 
512
 
-
 
513
    private void sendAlertToCategoryTeam(List<Item> items) {
-
 
514
    	if(items!=null && items.size()!=0){
-
 
515
			GmailUtils util = new GmailUtils();
-
 
516
			String[] recipients = {"amit.gupta@shop2020.in"};
-
 
517
			String from = "build@shop2020.in";
-
 
518
			String password = "cafe@nes";
-
 
519
			String subject = Utils.EXPECTED_ARRIVAL_ACHIEVED_TEMPLATE;
-
 
520
			StringBuffer message = new StringBuffer("Please check the following items:\n");
-
 
521
			List<File> emptyList = new ArrayList<File>();
-
 
522
			for( Item item : items){
-
 
523
				message.append("\t" + getProductName(item));
-
 
524
			}
-
 
525
			try {
-
 
526
				util.sendSSLMessage(recipients, subject, message.toString(), from, password, emptyList);
-
 
527
			} catch (Exception e){
-
 
528
				log.info("Could not send alert" + e);
-
 
529
			}
-
 
530
    	}
-
 
531
	}
-
 
532
 
505
    private String getProductName(Item item) {
533
	private String getProductName(Item item) {
506
    	String brand = item.getBrand();
534
    	String brand = item.getBrand();
507
		String modelName = item.getModelName();
535
		String modelName = item.getModelName();
508
		String modelNumber = item.getModelNumber();
536
		String modelNumber = item.getModelNumber();
509
		String product = "";
537
		String product = "";
510
		if(StringUtils.isEmpty(modelName)){
538
		if(StringUtils.isEmpty(modelName)){