Skip to content

Commit

Permalink
Sonar: Call async methods via an injected dependency instead of direc…
Browse files Browse the repository at this point in the history
…tly via 'this'
  • Loading branch information
qmonmert committed Oct 28, 2023
1 parent 739c75a commit ec85d7e
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ public class MailService {

private final SpringTemplateEngine templateEngine;

private final MailService self;

public MailService(JHipsterProperties jHipsterProperties, JavaMailSender javaMailSender,
MessageSource messageSource, SpringTemplateEngine templateEngine) {

this.jHipsterProperties = jHipsterProperties;
this.javaMailSender = javaMailSender;
this.messageSource = messageSource;
this.templateEngine = templateEngine;
this.self = this;
}

@Async
Expand Down Expand Up @@ -101,26 +104,26 @@ public class MailService {
context.setVariable(BASE_URL, jHipsterProperties.getMail().getBaseUrl());
String content = templateEngine.process(templateName, context);
String subject = messageSource.getMessage(titleKey, null, locale);
sendEmail(user.getEmail(), subject, content, false, true);
self.sendEmail(user.getEmail(), subject, content, false, true);
}
<%_ if (!authenticationTypeOauth2) { _%>

@Async
public void sendActivationEmail(<%= user.persistClass %> user) {
log.debug("Sending activation email to '{}'", user.getEmail());
sendEmailFromTemplate(user, "mail/activationEmail", "email.activation.title");
self.sendEmailFromTemplate(user, "mail/activationEmail", "email.activation.title");
}

@Async
public void sendCreationEmail(<%= user.persistClass %> user) {
log.debug("Sending creation email to '{}'", user.getEmail());
sendEmailFromTemplate(user, "mail/creationEmail", "email.activation.title");
self.sendEmailFromTemplate(user, "mail/creationEmail", "email.activation.title");
}

@Async
public void sendPasswordResetMail(<%= user.persistClass %> user) {
log.debug("Sending password reset email to '{}'", user.getEmail());
sendEmailFromTemplate(user, "mail/passwordResetEmail", "email.reset.title");
self.sendEmailFromTemplate(user, "mail/passwordResetEmail", "email.reset.title");
}
<%_ } _%>
}

0 comments on commit ec85d7e

Please sign in to comment.