Skip to content

Commit

Permalink
Merge pull request #44 from ddiasss/feature/parameterized-email-list
Browse files Browse the repository at this point in the history
Closes #43 replacing .properties file to yaml and adding fixed cc
  • Loading branch information
campos20 authored Mar 13, 2024
2 parents bbb2bc6 + 6d3a80b commit 0c88517
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 56 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -46,7 +50,7 @@ public class EmailServiceImpl implements EmailService {
public void sendEmail(String emailTo, List<AnalysisBean> analysisResult,
List<SanityCheckWithErrorBean> 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();
Expand Down Expand Up @@ -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<AnalysisBean> analysisResult, List<SanityCheckWithErrorBean> queriesWithError) {
Expand Down
17 changes: 0 additions & 17 deletions src/main/resources/application-local.properties

This file was deleted.

25 changes: 25 additions & 0 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 0 additions & 17 deletions src/main/resources/application-prod.properties

This file was deleted.

26 changes: 26 additions & 0 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
@@ -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: [email protected]
10 changes: 0 additions & 10 deletions src/main/resources/application-test.properties

This file was deleted.

15 changes: 15 additions & 0 deletions src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -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 protected]
subject: Sanity Check
cc: [email protected], [email protected], [email protected]
4 changes: 0 additions & 4 deletions src/main/resources/application.properties

This file was deleted.

5 changes: 5 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
spring:
application:
name: WCA Sanity Check
profiles:
active: local # Default profile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -43,7 +43,7 @@ public class WrtSanityCheckServiceTest extends AbstractTest {
private ArgumentCaptor<MimeMessage> messageCaptor;

@BeforeEach
private void setup() {
public void setup() {
MimeMessage mimeMessage = new MimeMessage((Session) null);
when(emailSender.createMimeMessage()).thenReturn(mimeMessage);
}
Expand Down

0 comments on commit 0c88517

Please sign in to comment.