Subversion Repositories SmartDukaan

Rev

Rev 24005 | Rev 24086 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.smartdukaan.cron;

import java.util.Properties;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Primary;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.io.ClassPathResource;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.scheduling.annotation.EnableScheduling;

import com.smartdukaan.cron.migrations.RunOnceTasks;
import com.smartdukaan.cron.scheduled.ScheduledTasks;


@SpringBootApplication
@EnableCaching
@EnableScheduling
@ComponentScan("com.smartdukaan.cron.*, com.spice.profitmandi.common.*")
public class Application implements ApplicationRunner{
        
        private static final Logger LOGGER=LogManager.getLogger(Application.class);
        
        public static void main(String[] args) throws Throwable {
                new SpringApplicationBuilder(Application.class).web(WebApplicationType.NONE).run(args);
        }
        
        @Bean
        public static PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
                LOGGER.info("Called Configuration");
                PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer =  new PropertySourcesPlaceholderConfigurer();
                propertySourcesPlaceholderConfigurer.setLocation(new ClassPathResource("/META-INF/env.properties"));
                return propertySourcesPlaceholderConfigurer;
        }
        
        @Bean(name="mailSender")
        @Primary
    public JavaMailSender sendGridMailSender(){
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
         
        //Using gmail
        mailSender.setHost("smtp.sendgrid.net");
        mailSender.setPort(587);
        mailSender.setUsername("shop2020");
        mailSender.setPassword("U2/=fP,t");
         
        Properties javaMailProperties = new Properties();
        javaMailProperties.put("mail.smtp.starttls.enable", "false");
        javaMailProperties.put("mail.smtp.auth", "true");
        javaMailProperties.put("mail.transport.protocol", "smtp");
        javaMailProperties.put("mail.debug", "true");//Prints out everything on screen
         
        mailSender.setJavaMailProperties(javaMailProperties);
        return mailSender;
    }

        @Bean
        public JavaMailSender googleMailSender(){
                JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
                //Using gmail
                mailSender.setHost("smtp.gmail.com");
                mailSender.setPort(587);
                mailSender.setUsername("build@shop2020.in");
                mailSender.setPassword("cafe@nes");
                
                Properties javaMailProperties = new Properties();
                javaMailProperties.put("mail.smtp.starttls.enable", "true");
                javaMailProperties.put("mail.smtp.auth", "true");
                javaMailProperties.put("mail.transport.protocol", "smtp");
                javaMailProperties.put("mail.debug", "true");//Prints out everything on screen
                mailSender.setJavaMailProperties(javaMailProperties);
                return mailSender;
        }

        @Autowired 
        private RunOnceTasks runOnceTasks;
        
        @Autowired 
        private ScheduledTasks scheduledTasks;
        @Override
        public void run(ApplicationArguments args) throws Exception {
                LOGGER.info("Called run method");
                if(args.containsOption("once")) {
                        //runOnceTasks.dropCorrection();
                        System.exit(0);
                }
                
        }

}