From 6d3a80bbf2cd8f808e31007fca4244b46ae12354 Mon Sep 17 00:00:00 2001 From: Danilo Date: Tue, 12 Mar 2024 21:26:47 -0300 Subject: [PATCH] replacing .properties file to yaml and adding fixed cc --- README.md | 2 +- .../service/impl/EmailServiceImpl.java | 11 ++++---- .../resources/application-local.properties | 17 ------------ src/main/resources/application-local.yml | 25 ++++++++++++++++++ .../resources/application-prod.properties | 17 ------------ src/main/resources/application-prod.yml | 26 +++++++++++++++++++ .../resources/application-test.properties | 10 ------- src/main/resources/application-test.yml | 15 +++++++++++ src/main/resources/application.properties | 4 --- src/main/resources/application.yml | 5 ++++ .../service/WrtSanityCheckServiceTest.java | 4 +-- 11 files changed, 80 insertions(+), 56 deletions(-) delete mode 100644 src/main/resources/application-local.properties create mode 100644 src/main/resources/application-local.yml delete mode 100644 src/main/resources/application-prod.properties create mode 100644 src/main/resources/application-prod.yml delete mode 100644 src/main/resources/application-test.properties create mode 100644 src/main/resources/application-test.yml delete mode 100644 src/main/resources/application.properties create mode 100644 src/main/resources/application.yml diff --git a/README.md b/README.md index 74251dd..5a0e271 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ''; create database wca_development; ``` -The database `wca_development` will be populated with WCA data. If you want to change password, username or others, make sure to also change on `application-local.properties`. +The database `wca_development` will be populated with WCA data. If you want to change password, username or others, make sure to also change on `application-local.yml`. ## Before you run this diff --git a/src/main/java/org/worldcubeassociation/dbsanitycheck/service/impl/EmailServiceImpl.java b/src/main/java/org/worldcubeassociation/dbsanitycheck/service/impl/EmailServiceImpl.java index 33fc830..547d298 100644 --- a/src/main/java/org/worldcubeassociation/dbsanitycheck/service/impl/EmailServiceImpl.java +++ b/src/main/java/org/worldcubeassociation/dbsanitycheck/service/impl/EmailServiceImpl.java @@ -3,6 +3,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.core.io.ByteArrayResource; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mail.javamail.MimeMessageHelper; @@ -34,6 +35,9 @@ public class EmailServiceImpl implements EmailService { @Value("${service.mail.subject}") private String subject; + @Value("${service.mail.cc}") + private String[] cc; + @Autowired private JavaMailSender emailSender; @@ -46,7 +50,7 @@ public class EmailServiceImpl implements EmailService { public void sendEmail(String emailTo, List analysisResult, List queriesWithError) throws MessagingException { - if (sendMail && emailTo.length() > 0) { + if (sendMail && emailTo != null && !emailTo.isEmpty()) { log.info("Sending email with the analysis"); MimeMessage message = emailSender.createMimeMessage(); @@ -86,10 +90,7 @@ private void handleRecipients(String mailTo, MimeMessageHelper helper) throws Me var mailSplit = List.of(mailTo.split(",")); helper.setTo(InternetAddress.parse(mailTo)); helper.setReplyTo(mailSplit.get(0)); - if (mailSplit.size() > 1) { - helper.setCc(InternetAddress.parse( - String.join(",", mailSplit.subList(1, mailSplit.size())))); - } + helper.setCc(cc); } private String getText(List analysisResult, List queriesWithError) { diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties deleted file mode 100644 index f3041fa..0000000 --- a/src/main/resources/application-local.properties +++ /dev/null @@ -1,17 +0,0 @@ -spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver -spring.datasource.url=jdbc:mysql://localhost:3306/wca_development -spring.datasource.username=root -spring.datasource.password= - -spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect - -service.mail.send=false -service.mail.from=@mail.from@ -service.mail.subject=Sanity Check - -spring.mail.host=@mail.host@ -spring.mail.port=587 -spring.mail.username=@mail.username@ -spring.mail.password=@mail.password@ -spring.mail.properties.mail.smtp.auth=true -spring.mail.properties.mail.smtp.starttls.enable=true diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml new file mode 100644 index 0000000..f6ae9fb --- /dev/null +++ b/src/main/resources/application-local.yml @@ -0,0 +1,25 @@ +spring: + datasource: + driverClassName: com.mysql.cj.jdbc.Driver + password: '' + username: root + url: jdbc:mysql://localhost:3306/wca_development + jpa: + database-platform: org.hibernate.dialect.MySQL5InnoDBDialect + mail: + host: ${mail.host} + username: ${mail.username} + port: '587' + properties: + mail: + smtp: + starttls: + enable: 'true' + auth: 'true' + password: ${mail.password} + +service: + mail: + send: 'false' + from: ${mail.from} + subject: Sanity Check diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties deleted file mode 100644 index 60318ba..0000000 --- a/src/main/resources/application-prod.properties +++ /dev/null @@ -1,17 +0,0 @@ -spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver -spring.datasource.url=@connectopm.dbwca@ -spring.datasource.username=@user.dbwca@ -spring.datasource.password=@connectopm.dbwca@ - -spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect - -service.mail.send=true -service.mail.from=@mail.from@ -service.mail.subject=Sanity Check - -spring.mail.host=@mail.host@ -spring.mail.port=587 -spring.mail.username=@mail.username@ -spring.mail.password=@mail.password@ -spring.mail.properties.mail.smtp.auth=true -spring.mail.properties.mail.smtp.starttls.enable=true diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml new file mode 100644 index 0000000..6bf4915 --- /dev/null +++ b/src/main/resources/application-prod.yml @@ -0,0 +1,26 @@ +spring: + datasource: + driverClassName: com.mysql.cj.jdbc.Driver + password: ${connectopm.dbwca} + username: ${user.dbwca} + url: ${connectopm.dbwca} + jpa: + database-platform: org.hibernate.dialect.MySQL5InnoDBDialect + mail: + host: ${mail.host} + username: ${mail.username} + port: '587' + properties: + mail: + smtp: + starttls: + enable: 'true' + auth: 'true' + password: ${mail.password} + +service: + mail: + send: 'true' + from: ${mail.from} + subject: Sanity Check + cc: wst@worldcubeassociation.org \ No newline at end of file diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties deleted file mode 100644 index 3b54193..0000000 --- a/src/main/resources/application-test.properties +++ /dev/null @@ -1,10 +0,0 @@ -spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver -spring.datasource.url=jdbc:mysql://localhost:8306/wca_development -spring.datasource.username=root -spring.datasource.password= - -spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect - -service.mail.send=true -service.mail.from=email@wca.com -service.mail.subject=Sanity Check diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml new file mode 100644 index 0000000..6139c2d --- /dev/null +++ b/src/main/resources/application-test.yml @@ -0,0 +1,15 @@ +spring: + datasource: + username: root + url: jdbc:mysql://localhost:8306/wca_development + driverClassName: com.mysql.cj.jdbc.Driver + password: '' + jpa: + database-platform: org.hibernate.dialect.MySQL5InnoDBDialect + +service: + mail: + send: 'true' + from: email@wca.com + subject: Sanity Check + cc: wst@wca.org, wst-north@wca.org, wst-east@wca.org \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 7fb4f45..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1,4 +0,0 @@ -spring.application.name=WCA Sanity Check - -# Default profile -spring.profiles.active=local diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..f5cf218 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,5 @@ +spring: + application: + name: WCA Sanity Check + profiles: + active: local # Default profile \ No newline at end of file diff --git a/src/test/java/org/worldcubeassociation/dbsanitycheck/integration/service/WrtSanityCheckServiceTest.java b/src/test/java/org/worldcubeassociation/dbsanitycheck/integration/service/WrtSanityCheckServiceTest.java index 02009dc..378f241 100644 --- a/src/test/java/org/worldcubeassociation/dbsanitycheck/integration/service/WrtSanityCheckServiceTest.java +++ b/src/test/java/org/worldcubeassociation/dbsanitycheck/integration/service/WrtSanityCheckServiceTest.java @@ -30,7 +30,7 @@ @Slf4j @SpringBootTest @ActiveProfiles("test") -@TestPropertySource(locations = "classpath:application-test.properties") +@TestPropertySource(locations = "classpath:application-test.yml") public class WrtSanityCheckServiceTest extends AbstractTest { @Autowired @@ -43,7 +43,7 @@ public class WrtSanityCheckServiceTest extends AbstractTest { private ArgumentCaptor messageCaptor; @BeforeEach - private void setup() { + public void setup() { MimeMessage mimeMessage = new MimeMessage((Session) null); when(emailSender.createMimeMessage()).thenReturn(mimeMessage); }