Skip to content

Commit

Permalink
email event listeners and update names of data files (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
haiphucnguyen authored Jan 2, 2025
1 parent 74bb92b commit 59804ca
Show file tree
Hide file tree
Showing 21 changed files with 124 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.flowinquiry.modules.teams.repository.TeamRepository;
import io.flowinquiry.modules.teams.repository.TeamRoleRepository;
import io.flowinquiry.modules.teams.service.dto.TeamDTO;
import io.flowinquiry.modules.teams.service.event.NewTeamCreatedEvent;
import io.flowinquiry.modules.teams.service.event.NewUsersAddedIntoTeamEvent;
import io.flowinquiry.modules.teams.service.event.RemoveUserOutOfTeamEvent;
import io.flowinquiry.modules.teams.service.mapper.TeamMapper;
Expand Down Expand Up @@ -67,7 +68,9 @@ public TeamService(

public TeamDTO createTeam(TeamDTO teamDTO) {
Team team = teamMapper.toEntity(teamDTO);
return teamMapper.toDto(teamRepository.save(team));
TeamDTO savedTeam = teamMapper.toDto(teamRepository.save(team));
eventPublisher.publishEvent(new NewTeamCreatedEvent(this, savedTeam));
return savedTeam;
}

public TeamDTO updateTeam(TeamDTO updatedTeam) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.flowinquiry.modules.teams.service.event;

import io.flowinquiry.modules.teams.service.dto.TeamDTO;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;

@Getter
public class NewTeamCreatedEvent extends ApplicationEvent {
private final TeamDTO team;

public NewTeamCreatedEvent(Object source, TeamDTO team) {
super(source);
this.team = team;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@Getter
public class NewTeamRequestCreatedEvent extends ApplicationEvent {
private TeamRequestDTO teamRequest;
private final TeamRequestDTO teamRequest;

public NewTeamRequestCreatedEvent(Object source, TeamRequestDTO teamRequest) {
super(source);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.flowinquiry.modules.teams.service.listener;

import io.flowinquiry.modules.teams.service.event.NewTeamRequestCreatedEvent;
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 NewTeamCreatedEventListener {

@Async("auditLogExecutor")
@Transactional
@EventListener
public void onNewTeamCreated(NewTeamRequestCreatedEvent event) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.flowinquiry.modules.teams.service.listener;

import io.flowinquiry.config.FlowInquiryProperties;
import io.flowinquiry.modules.collab.service.MailService;
import io.flowinquiry.modules.teams.service.dto.TeamRequestDTO;
import io.flowinquiry.modules.teams.service.event.NewTeamRequestCreatedEvent;
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 NewTeamRequestCreatedMailEventListener {

private final MailService mailService;
private final FlowInquiryProperties flowInquiryProperties;

public NewTeamRequestCreatedMailEventListener(MailService mailService, FlowInquiryProperties flowInquiryProperties) {
this.mailService = mailService;
this.flowInquiryProperties = flowInquiryProperties;
}

@Async("auditLogExecutor")
@Transactional
@EventListener
public void onNewTeamRequestCreated(NewTeamRequestCreatedEvent event) {
TeamRequestDTO teamRequestDTO = event.getTeamRequest();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
import static j2html.TagCreator.text;

@Component
public class NewTeamRequestCreatedEventListener {
public class NewTeamRequestCreatedNotificationEventListener {
private final NotificationRepository notificationRepository;
private final TeamRepository teamRepository;
private final ActivityLogRepository activityLogRepository;

public NewTeamRequestCreatedEventListener(

public NewTeamRequestCreatedNotificationEventListener(
NotificationRepository notificationRepository,
TeamRepository teamRepository,
ActivityLogRepository activityLogRepository) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.flowinquiry.modules.teams.service.listener;

import io.flowinquiry.modules.teams.service.event.NewUsersAddedIntoTeamEvent;
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 NewUserAddedIntoTeamEmailEventListener {

@Async("auditLogExecutor")
@EventListener
@Transactional
public void onNewUsersAddedIntoTeam(NewUsersAddedIntoTeamEvent event) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
import static j2html.TagCreator.ul;

@Component
public class NewUserAddedIntoTeamEventListener {
public class NewUserAddedIntoTeamNotificationEventListener {

private ActivityLogRepository activityLogRepository;
private TeamRepository teamRepository;
private UserRepository userRepository;
private final ActivityLogRepository activityLogRepository;
private final TeamRepository teamRepository;
private final UserRepository userRepository;

public NewUserAddedIntoTeamEventListener(
public NewUserAddedIntoTeamNotificationEventListener(
ActivityLogRepository activityLogRepository,
TeamRepository teamRepository,
UserRepository userRepository) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.flowinquiry.modules.teams.service.listener;

import io.flowinquiry.modules.teams.service.event.RemoveUserOutOfTeamEvent;
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 RemoveUserOutOfTeamEmailEventListener {

@Async("auditLogExecutor")
@EventListener
@Transactional
public void onRemoveUserOutOfTeam(RemoveUserOutOfTeamEvent event) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
import org.springframework.transaction.annotation.Transactional;

@Component
public class RemoveUserOutOfTeamEventListener {
public class RemoveUserOutOfTeamNotificationEventListener {

private final TeamRepository teamRepository;

private final UserRepository userRepository;

private final ActivityLogRepository activityLogRepository;

public RemoveUserOutOfTeamEventListener(
public RemoveUserOutOfTeamNotificationEventListener(
TeamRepository teamRepository,
UserRepository userRepository,
ActivityLogRepository activityLogRepository) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@
public class TeamRequestWorkStateTransitionEventListener {

private final ActivityLogRepository activityLogRepository;

private final TeamRequestRepository teamRequestRepository;

private final WorkflowStateRepository workflowStateRepository;

private final WorkflowTransitionHistoryService workflowTransitionHistoryService;

public TeamRequestWorkStateTransitionEventListener(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,13 @@
<changeSet author="flowinquiry"
id="000:05-insert-default-user-authority-data" context="dev,test">
<loadData
file="config/liquibase/tenant/data/fw_user_authority.csv"
file="config/liquibase/tenant/data/fw_user_authority_dev.csv"
separator=";" tableName="fw_user_authority"
usePreparedStatements="true">
<column name="user_id" type="numeric" />
</loadData>
<loadData
file="config/liquibase/tenant/data/fw_organization.csv"
file="config/liquibase/tenant/data/fw_organization_dev.csv"
tableName="fw_organization" usePreparedStatements="true"
separator=";">
<column name="id" type="NUMERIC" />
Expand All @@ -383,22 +383,10 @@
usePreparedStatements="true">
<column name="user_id" type="numeric" />
</loadData>
<loadData
file="config/liquibase/tenant/data/fw_organization.csv"
tableName="fw_organization" usePreparedStatements="true"
separator=";">
<column name="id" type="NUMERIC" />
<column name="name" type="STRING" />
<column name="logo_url" type="STRING" />
<column name="slogan" type="STRING" />
<column name="description" type="STRING" />
</loadData>
<sql>SELECT setval('fw_organization_id_seq', (SELECT MAX(id) FROM
fw_organization));</sql>
</changeSet>
<changeSet author="flowinquiry"
id="000:06-insert-default-fw-team-data" context="dev,test">
<loadData file="config/liquibase/tenant/data/fw_team.csv"
<loadData file="config/liquibase/tenant/data/fw_team_dev.csv"
tableName="fw_team" separator=";">
<column name="id" type="NUMERIC" />
<column name="name" type="STRING" />
Expand All @@ -421,7 +409,7 @@
<changeSet author="flowinquiry"
id="000:08-insert-default-fw-user-team-data" context="dev,test">
<loadData
file="config/liquibase/tenant/data/fw_user_team.csv"
file="config/liquibase/tenant/data/fw_user_team_dev.csv"
tableName="fw_user_team" separator=";">
<column name="user_id" type="NUMERIC" />
<column name="team_id" type="NUMERIC" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,9 @@
</changeSet>
<changeSet author="flowinquiry"
id="001:01-insert-workflow-data" context="dev,test">
<loadData file="config/liquibase/tenant/data/fw_workflow.csv"
separator=";" tableName="fw_workflow" usePreparedStatements="true">
<loadData
file="config/liquibase/tenant/data/fw_workflow_dev.csv" separator=";"
tableName="fw_workflow" usePreparedStatements="true">
<column name="id" type="numeric" />
<column name="name" type="string" />
<column name="description" type="string" />
Expand All @@ -368,7 +369,7 @@
<changeSet author="flowinquiry"
id="001:02-insert-workflow-state-data" context="dev,test">
<loadData
file="config/liquibase/tenant/data/fw_workflow_state.csv"
file="config/liquibase/tenant/data/fw_workflow_state_dev.csv"
separator=";" tableName="fw_workflow_state"

usePreparedStatements="true">
Expand All @@ -384,7 +385,7 @@
<changeSet author="flowinquiry"
id="001:03-insert-workflow-transition-data" context="dev,test">
<loadData
file="config/liquibase/tenant/data/fw_workflow_transition.csv"
file="config/liquibase/tenant/data/fw_workflow_transition_dev.csv"
separator=";" tableName="fw_workflow_transition"
usePreparedStatements="true">
<column name="id" type="numeric" />
Expand All @@ -400,7 +401,7 @@
<changeSet author="flowinquiry"
id="001:04-insert-team-workflow-usage-data" context="dev,test">
<loadData
file="config/liquibase/tenant/data/fw_team_workflow_selection.csv"
file="config/liquibase/tenant/data/fw_team_workflow_selection_dev.csv"
separator=";" tableName="fw_team_workflow_selection"
usePreparedStatements="true">
<column name="id" type="numeric" />
Expand Down

0 comments on commit 59804ca

Please sign in to comment.