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