|
2 | 2 |
|
3 | 3 | import it.aboutbits.springboot.emailservice.lib.AttachmentDataSource; |
4 | 4 | import it.aboutbits.springboot.emailservice.lib.EmailSchedulerCallback; |
| 5 | +import it.aboutbits.springboot.emailservice.lib.application.EmailAttachmentMapper; |
| 6 | +import it.aboutbits.springboot.emailservice.lib.application.EmailAttachmentMapperImpl; |
| 7 | +import it.aboutbits.springboot.emailservice.lib.application.EmailMapper; |
| 8 | +import it.aboutbits.springboot.emailservice.lib.application.EmailMapperImpl; |
5 | 9 | import it.aboutbits.springboot.emailservice.lib.application.ManageEmail; |
6 | 10 | import it.aboutbits.springboot.emailservice.lib.application.QueryEmail; |
7 | 11 | import it.aboutbits.springboot.emailservice.lib.application.SendScheduledEmails; |
8 | 12 | import it.aboutbits.springboot.emailservice.lib.application.UnavailableAttachmentDataSource; |
9 | 13 | import it.aboutbits.springboot.emailservice.lib.jpa.EmailRepository; |
10 | 14 | import jakarta.persistence.EntityManager; |
11 | 15 | import liquibase.integration.spring.SpringLiquibase; |
| 16 | +import org.springframework.boot.autoconfigure.AutoConfigurationPackage; |
12 | 17 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
13 | 18 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
14 | 19 | import org.springframework.context.annotation.Bean; |
15 | | -import org.springframework.context.annotation.Configuration; |
16 | | -import org.springframework.data.jpa.repository.support.JpaRepositoryFactory; |
17 | 20 | import org.springframework.mail.javamail.JavaMailSender; |
18 | 21 |
|
19 | 22 | import javax.sql.DataSource; |
20 | 23 | import java.util.List; |
21 | 24 |
|
22 | | -@Configuration |
23 | | -public class EmailServiceAutoConfiguration { |
24 | | - @Bean(name = "emailServiceLiquibase") |
25 | | - public SpringLiquibase emailServiceLiquibase(DataSource dataSource) { |
| 25 | +@AutoConfigurationPackage |
| 26 | +public class EmailServiceConfiguration { |
| 27 | + @Bean |
| 28 | + @ConditionalOnProperty(value = "lib.emailservice.liquibase.enabled", matchIfMissing = true) |
| 29 | + public SpringLiquibase springLiquibase(DataSource dataSource) { |
26 | 30 | var liquibase = new SpringLiquibase(); |
27 | 31 | liquibase.setDataSource(dataSource); |
28 | | - liquibase.setChangeLog("classpath:/db/changelog/emailservice/main.xml"); |
| 32 | + liquibase.setChangeLog("classpath:/db/changelog/emailservice/main.yml"); |
29 | 33 | liquibase.setShouldRun(true); |
30 | 34 | return liquibase; |
31 | 35 | } |
32 | 36 |
|
33 | 37 | @Bean |
34 | | - public EmailRepository emailRepository(EntityManager entityManager) { |
35 | | - var factory = new JpaRepositoryFactory(entityManager); |
36 | | - return factory.getRepository(EmailRepository.class); |
| 38 | + public EmailAttachmentMapper emailAttachmentMapper() { |
| 39 | + return new EmailAttachmentMapperImpl(); |
| 40 | + } |
| 41 | + |
| 42 | + @Bean |
| 43 | + public EmailMapper emailMapper() { |
| 44 | + return new EmailMapperImpl(); |
37 | 45 | } |
38 | 46 |
|
39 | 47 | @Bean |
40 | | - public QueryEmail queryEmail(EmailRepository emailRepository) { |
41 | | - return new QueryEmail(emailRepository); |
| 48 | + public QueryEmail queryEmail(EmailRepository emailRepository, EmailMapper emailMapper, EntityManager entityManager) { |
| 49 | + return new QueryEmail(emailRepository, emailMapper, entityManager); |
42 | 50 | } |
43 | 51 |
|
44 | 52 | @Bean |
45 | | - public ManageEmail manageEmail(EmailRepository emailRepository, JavaMailSender javaMailSender, AttachmentDataSource attachmentDataSource) { |
46 | | - return new ManageEmail(emailRepository, javaMailSender, attachmentDataSource); |
| 53 | + public ManageEmail manageEmail(EmailRepository emailRepository, JavaMailSender javaMailSender, AttachmentDataSource attachmentDataSource, EmailMapper emailMapper) { |
| 54 | + return new ManageEmail(emailRepository, javaMailSender, attachmentDataSource, emailMapper); |
47 | 55 | } |
48 | 56 |
|
49 | 57 | @Bean |
|
0 commit comments