Subversion Repositories SmartDukaan

Rev

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

Rev 24086 Rev 24122
Line 1... Line 1...
1
package com.smartdukaan.cron;
1
package com.smartdukaan.cron;
2
 
2
 
-
 
3
import java.text.MessageFormat;
-
 
4
import java.time.LocalDate;
3
import java.util.Properties;
5
import java.util.Properties;
4
 
6
 
5
import org.apache.logging.log4j.LogManager;
7
import org.apache.logging.log4j.LogManager;
6
import org.apache.logging.log4j.Logger;
8
import org.apache.logging.log4j.Logger;
7
import org.springframework.beans.factory.annotation.Autowired;
9
import org.springframework.beans.factory.annotation.Autowired;
Line 21... Line 23...
21
import org.springframework.scheduling.annotation.EnableScheduling;
23
import org.springframework.scheduling.annotation.EnableScheduling;
22
 
24
 
23
import com.smartdukaan.cron.migrations.RunOnceTasks;
25
import com.smartdukaan.cron.migrations.RunOnceTasks;
24
import com.smartdukaan.cron.scheduled.ScheduledTasks;
26
import com.smartdukaan.cron.scheduled.ScheduledTasks;
25
 
27
 
26
 
-
 
27
@SpringBootApplication
28
@SpringBootApplication
28
@EnableCaching
29
@EnableCaching
29
@EnableScheduling
30
@EnableScheduling
30
@ComponentScan("com.smartdukaan.cron.*, com.spice.profitmandi.common.*")
31
@ComponentScan("com.smartdukaan.cron.*, com.spice.profitmandi.common.*")
31
public class Application implements ApplicationRunner{
32
public class Application implements ApplicationRunner {
32
	
33
 
33
	private static final Logger LOGGER=LogManager.getLogger(Application.class);
34
	private static final Logger LOGGER = LogManager.getLogger(Application.class);
34
	
35
 
35
	public static void main(String[] args) throws Throwable {
36
	public static void main(String[] args) throws Throwable {
36
		new SpringApplicationBuilder(Application.class).web(WebApplicationType.NONE).run(args);
37
		new SpringApplicationBuilder(Application.class).web(WebApplicationType.NONE).run(args);
37
	}
38
	}
38
	
39
 
39
	@Bean
40
	@Bean
40
	public static PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
41
	public static PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
41
		LOGGER.info("Called Configuration");
42
		LOGGER.info("Called Configuration");
42
		PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer =  new PropertySourcesPlaceholderConfigurer();
43
		PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
43
		propertySourcesPlaceholderConfigurer.setLocation(new ClassPathResource("/META-INF/env.properties"));
44
		propertySourcesPlaceholderConfigurer.setLocation(new ClassPathResource("/META-INF/env.properties"));
44
		return propertySourcesPlaceholderConfigurer;
45
		return propertySourcesPlaceholderConfigurer;
45
	}
46
	}
46
	
47
 
47
	@Bean(name="mailSender")
48
	@Bean(name = "mailSender")
48
	@Primary
49
	@Primary
49
    public JavaMailSender sendGridMailSender(){
50
	public JavaMailSender sendGridMailSender() {
50
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
51
		JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
51
         
52
 
52
        //Using gmail
53
		// Using gmail
53
        mailSender.setHost("smtp.sendgrid.net");
54
		mailSender.setHost("smtp.sendgrid.net");
54
        mailSender.setPort(587);
55
		mailSender.setPort(587);
55
        mailSender.setUsername("shop2020");
56
		mailSender.setUsername("shop2020");
56
        mailSender.setPassword("U2/=fP,t");
57
		mailSender.setPassword("U2/=fP,t");
57
         
58
 
58
        Properties javaMailProperties = new Properties();
59
		Properties javaMailProperties = new Properties();
59
        javaMailProperties.put("mail.smtp.starttls.enable", "false");
60
		javaMailProperties.put("mail.smtp.starttls.enable", "false");
60
        javaMailProperties.put("mail.smtp.auth", "true");
61
		javaMailProperties.put("mail.smtp.auth", "true");
61
        javaMailProperties.put("mail.transport.protocol", "smtp");
62
		javaMailProperties.put("mail.transport.protocol", "smtp");
62
        javaMailProperties.put("mail.debug", "true");//Prints out everything on screen
63
		javaMailProperties.put("mail.debug", "true");// Prints out everything on screen
63
         
64
 
64
        mailSender.setJavaMailProperties(javaMailProperties);
65
		mailSender.setJavaMailProperties(javaMailProperties);
65
        return mailSender;
66
		return mailSender;
66
    }
67
	}
67
 
68
 
68
	@Bean
69
	@Bean
69
	public JavaMailSender googleMailSender(){
70
	public JavaMailSender googleMailSender() {
70
		JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
71
		JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
71
		//Using gmail
72
		// Using gmail
72
		mailSender.setHost("smtp.gmail.com");
73
		mailSender.setHost("smtp.gmail.com");
73
		mailSender.setPort(587);
74
		mailSender.setPort(587);
74
		mailSender.setUsername("build@shop2020.in");
75
		mailSender.setUsername("build@shop2020.in");
75
		mailSender.setPassword("cafe@nes");
76
		mailSender.setPassword("cafe@nes");
76
		
77
 
77
		Properties javaMailProperties = new Properties();
78
		Properties javaMailProperties = new Properties();
78
		javaMailProperties.put("mail.smtp.starttls.enable", "true");
79
		javaMailProperties.put("mail.smtp.starttls.enable", "true");
79
		javaMailProperties.put("mail.smtp.auth", "true");
80
		javaMailProperties.put("mail.smtp.auth", "true");
80
		javaMailProperties.put("mail.transport.protocol", "smtp");
81
		javaMailProperties.put("mail.transport.protocol", "smtp");
81
		javaMailProperties.put("mail.debug", "true");//Prints out everything on screen
82
		javaMailProperties.put("mail.debug", "true");// Prints out everything on screen
82
		mailSender.setJavaMailProperties(javaMailProperties);
83
		mailSender.setJavaMailProperties(javaMailProperties);
83
		return mailSender;
84
		return mailSender;
84
	}
85
	}
85
 
86
 
86
	@Autowired 
87
	@Autowired
87
	private RunOnceTasks runOnceTasks;
88
	private RunOnceTasks runOnceTasks;
88
	
89
 
89
	@Autowired 
90
	@Autowired
90
	private ScheduledTasks scheduledTasks;
91
	private ScheduledTasks scheduledTasks;
-
 
92
 
91
	@Override
93
	@Override
92
	public void run(ApplicationArguments args) throws Exception {
94
	public void run(ApplicationArguments args) throws Exception {
93
		LOGGER.info("Called run method");
95
		LOGGER.info("Called run method");
94
		if(args.containsOption("once")) {
96
		if (args.containsOption("once")) {
-
 
97
			if (args.containsOption("1")) {
95
			if(args.containsOption("1")) scheduledTasks.sendPartnerInvestmentDetails();
98
				scheduledTasks.sendPartnerInvestmentDetails();
96
			System.exit(0);
99
				System.exit(0);
-
 
100
			}
-
 
101
			if (args.containsOption("2")) {
-
 
102
				String message = MessageFormat.format("Sale Target summary for {1}", LocalDate.now());
-
 
103
				scheduledTasks.sendMailWithAttachments("adeel.yazdani@smartdukaan.com", "Daily Sale Report", message);
-
 
104
				System.exit(0);
-
 
105
			}
-
 
106
 
97
		}
107
		}
98
		
108
 
99
	}
109
	}
100
 
110
 
101
}
111
}