|
4 | 4 | import java.util.Properties; |
5 | 5 |
|
6 | 6 | import io.shiftleft.model.Patient; |
| 7 | + |
7 | 8 | import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; |
8 | 9 | import org.jasypt.properties.EncryptableProperties; |
| 10 | +import org.slf4j.Logger; |
| 11 | +import org.slf4j.LoggerFactory; |
9 | 12 | import org.springframework.beans.factory.annotation.Autowired; |
10 | 13 | import org.springframework.boot.CommandLineRunner; |
11 | 14 | import org.springframework.context.annotation.Configuration; |
|
20 | 23 | import io.shiftleft.repository.CustomerRepository; |
21 | 24 | import io.shiftleft.repository.PatientRepository; |
22 | 25 |
|
23 | | - |
24 | | -import lombok.extern.slf4j.Slf4j; |
25 | | - |
26 | | -@Slf4j |
27 | 26 | @Component |
28 | 27 | @Configuration |
29 | 28 | @EnableEncryptableProperties |
30 | 29 | @PropertySource({ "classpath:config/application-aws.properties", "classpath:config/application-mysql.properties", |
31 | | - "classpath:config/application-sfdc.properties" }) |
| 30 | + "classpath:config/application-sfdc.properties" }) |
32 | 31 | public class DataLoader implements CommandLineRunner { |
33 | 32 |
|
34 | | - @Autowired |
35 | | - private DataBuilder dataBuilder; |
| 33 | + private static Logger log = LoggerFactory.getLogger(DataLoader.class); |
| 34 | + |
| 35 | + @Autowired |
| 36 | + private DataBuilder dataBuilder; |
36 | 37 |
|
37 | | - @Autowired |
38 | | - Environment env; |
| 38 | + @Autowired |
| 39 | + Environment env; |
39 | 40 |
|
40 | | - @Autowired |
41 | | - private CustomerRepository customerRepository; |
| 41 | + @Autowired |
| 42 | + private CustomerRepository customerRepository; |
42 | 43 |
|
43 | | - @Autowired |
44 | | - private PatientRepository patientRepository; |
| 44 | + @Autowired |
| 45 | + private PatientRepository patientRepository; |
45 | 46 |
|
46 | | - /* |
47 | | - * Internal workings of @EnableEncryptableProperties annotation |
48 | | - */ |
49 | | - private String getSecurePassword(String masterPassword) throws IOException { |
50 | | - StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor(); |
51 | | - encryptor.setPassword(masterPassword); |
52 | | - Properties props = new EncryptableProperties(encryptor); |
53 | | - props.load(this.getClass().getClassLoader().getResourceAsStream("config/application-mysql.properties")); |
54 | | - return props.getProperty("db.password"); |
55 | | - } |
| 47 | + /* |
| 48 | + * Internal workings of @EnableEncryptableProperties annotation |
| 49 | + */ |
| 50 | + private String getSecurePassword(String masterPassword) throws IOException { |
| 51 | + StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor(); |
| 52 | + encryptor.setPassword(masterPassword); |
| 53 | + Properties props = new EncryptableProperties(encryptor); |
| 54 | + props.load(this.getClass().getClassLoader().getResourceAsStream("config/application-mysql.properties")); |
| 55 | + return props.getProperty("db.password"); |
| 56 | + } |
56 | 57 |
|
57 | | - private boolean connectToAws() { |
| 58 | + private boolean connectToAws() { |
58 | 59 |
|
59 | | - log.info("Start Loading AWS Properties"); |
60 | | - log.info("AWS AccessKey is {} and SecretKey is {}", env.getProperty("aws.accesskey"), |
61 | | - env.getProperty("aws.secretkey")); |
62 | | - log.info("AWS Bucket is {}", env.getProperty("aws.bucket")); |
63 | | - log.info("End Loading AWS Properties"); |
| 60 | + log.info("Start Loading AWS Properties"); |
| 61 | + log.info("AWS AccessKey is {} and SecretKey is {}", env.getProperty("aws.accesskey"), |
| 62 | + env.getProperty("aws.secretkey")); |
| 63 | + log.info("AWS Bucket is {}", env.getProperty("aws.bucket")); |
| 64 | + log.info("End Loading AWS Properties"); |
64 | 65 |
|
65 | | - // Connect to AWS resources and do something |
| 66 | + // Connect to AWS resources and do something |
66 | 67 |
|
67 | | - return true; |
68 | | - } |
| 68 | + return true; |
| 69 | + } |
69 | 70 |
|
70 | | - private boolean connectToMySQL() { |
| 71 | + private boolean connectToMySQL() { |
71 | 72 |
|
72 | | - log.info("Start Loading MySQL Properties"); |
73 | | - log.info("Url is {}", env.getProperty("db.url")); |
74 | | - log.info("UserName is {}", env.getProperty("db.username")); |
75 | | - log.info("Password is {}", env.getProperty("db.password")); |
76 | | - log.info("End Loading MySQL Properties"); |
| 73 | + log.info("Start Loading MySQL Properties"); |
| 74 | + log.info("Url is {}", env.getProperty("db.url")); |
| 75 | + log.info("UserName is {}", env.getProperty("db.username")); |
| 76 | + log.info("Password is {}", env.getProperty("db.password")); |
| 77 | + log.info("End Loading MySQL Properties"); |
77 | 78 |
|
78 | | - // Connect to DB MySQL resources and do something |
| 79 | + // Connect to DB MySQL resources and do something |
79 | 80 |
|
80 | | - return true; |
81 | | - } |
| 81 | + return true; |
| 82 | + } |
82 | 83 |
|
83 | | - @Override |
84 | | - public void run(String... arg0) throws Exception { |
| 84 | + @Override |
| 85 | + public void run(String... arg0) throws Exception { |
85 | 86 |
|
86 | | - SimpleCommandLinePropertySource ps = new SimpleCommandLinePropertySource(arg0); |
| 87 | + SimpleCommandLinePropertySource ps = new SimpleCommandLinePropertySource(arg0); |
87 | 88 | String encryptor = (String) ps.getProperty("jasypt.encryptor.password"); |
88 | | - log.info("JASP Master Creds is {}", encryptor); |
| 89 | + log.info("JASP Master Creds is {}", encryptor); |
89 | 90 |
|
90 | | - connectToMySQL(); |
| 91 | + connectToMySQL(); |
91 | 92 |
|
92 | | - connectToAws(); |
| 93 | + connectToAws(); |
93 | 94 |
|
94 | | - log.debug("Loading test data..."); |
95 | | - for(Customer customer : dataBuilder.createCustomers()) { |
96 | | - customerRepository.save(customer); |
97 | | - } |
98 | | - for (Patient patient : dataBuilder.createPatients()) { |
99 | | - patientRepository.save(patient); |
100 | | - } |
101 | | - log.debug("Test data loaded..."); |
102 | | - } |
| 95 | + log.debug("Loading test data..."); |
| 96 | + for (Customer customer : dataBuilder.createCustomers()) { |
| 97 | + customerRepository.save(customer); |
| 98 | + } |
| 99 | + for (Patient patient : dataBuilder.createPatients()) { |
| 100 | + patientRepository.save(patient); |
| 101 | + } |
| 102 | + log.debug("Test data loaded..."); |
| 103 | + } |
103 | 104 | } |
0 commit comments