-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Event handlers for new comment (#63)
- Loading branch information
1 parent
c126e00
commit 52b3662
Showing
20 changed files
with
330 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
.../main/java/io/flowinquiry/modules/teams/service/listener/NewTeamCreatedEventListener.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...lowinquiry/modules/teams/service/listener/TeamRequestCommentCreatedMailEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package io.flowinquiry.modules.teams.service.listener; | ||
|
||
import io.flowinquiry.modules.collab.EmailContext; | ||
import io.flowinquiry.modules.collab.service.CommentService; | ||
import io.flowinquiry.modules.collab.service.MailService; | ||
import io.flowinquiry.modules.collab.service.dto.CommentDTO; | ||
import io.flowinquiry.modules.teams.repository.TeamRequestWatcherRepository; | ||
import io.flowinquiry.modules.teams.service.TeamRequestService; | ||
import io.flowinquiry.modules.teams.service.dto.TeamRequestDTO; | ||
import io.flowinquiry.modules.teams.service.dto.WatcherDTO; | ||
import io.flowinquiry.modules.teams.service.event.TeamRequestCommentCreatedEvent; | ||
import io.flowinquiry.modules.teams.service.mapper.WatcherMapper; | ||
import io.flowinquiry.utils.Obfuscator; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Component | ||
public class TeamRequestCommentCreatedMailEventListener { | ||
private final CommentService commentService; | ||
private final WatcherMapper watcherMapper; | ||
private final TeamRequestWatcherRepository teamRequestWatcherRepository; | ||
private final TeamRequestService teamRequestService; | ||
private final MailService mailService; | ||
|
||
public TeamRequestCommentCreatedMailEventListener( | ||
CommentService commentService, | ||
WatcherMapper watcherMapper, | ||
TeamRequestWatcherRepository teamRequestWatcherRepository, | ||
TeamRequestService teamRequestService, | ||
MailService mailService) { | ||
this.commentService = commentService; | ||
this.watcherMapper = watcherMapper; | ||
this.teamRequestWatcherRepository = teamRequestWatcherRepository; | ||
this.teamRequestService = teamRequestService; | ||
this.mailService = mailService; | ||
} | ||
|
||
@Async("asyncTaskExecutor") | ||
@Transactional | ||
@EventListener | ||
public void onTeamRequestCommentCreated(TeamRequestCommentCreatedEvent event) { | ||
CommentDTO commentDTO = commentService.getCommentById(event.getCommentDTO().getId()); | ||
List<WatcherDTO> watchers = | ||
teamRequestWatcherRepository.findWatchersByRequestId(commentDTO.getEntityId()); | ||
|
||
TeamRequestDTO teamRequestDTO = | ||
teamRequestService.getTeamRequestById(commentDTO.getEntityId()); | ||
|
||
if (!watchers.isEmpty()) { | ||
for (WatcherDTO watcher : watchers) { | ||
// Skip sending email if the watcher is the comment creator | ||
if (watcher.getId().equals(commentDTO.getCreatedById())) { | ||
continue; | ||
} | ||
|
||
EmailContext emailContext = | ||
new EmailContext(Locale.forLanguageTag("en")) | ||
.setToUser(watcherMapper.toUserDto(watcher)) | ||
.setSubject( | ||
"email.new.ticket.comment.subject", | ||
teamRequestDTO.getRequestTitle()) | ||
.addVariable("ticket", teamRequestDTO) | ||
.addVariable("comment", commentDTO) | ||
.addVariable( | ||
"obfuscatedTeamId", | ||
Obfuscator.obfuscate(teamRequestDTO.getTeamId())) | ||
.addVariable( | ||
"obfuscatedTicketId", | ||
Obfuscator.obfuscate(teamRequestDTO.getId())) | ||
.setTemplate("mail/newTicketCommentEmail"); | ||
|
||
mailService.sendEmail(emailContext); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.