RED-3584 / RED-3581 - notification issues - preferences validation test

This commit is contained in:
Timo Bejan 2022-06-03 10:11:12 +03:00
parent 37a84d9049
commit ec29d583f5
2 changed files with 14 additions and 19 deletions

View File

@ -11,6 +11,7 @@ import java.util.List;
@Slf4j
@Service
@RequiredArgsConstructor
@SuppressWarnings("PMD")
public class NotificationEmailService {
public void sendNotificationEmail(String userId, EmailNotificationType emailNotificationType, List<NotificationEntity> notifications) {

View File

@ -30,28 +30,23 @@ public class SendNotificationEmailJob implements Job {
var allConfiguredPreferences = notificationPreferencesPersistenceService.findAll();
allConfiguredPreferences.forEach(preference -> {
if (preference.isEmailNotificationsEnabled()) {
if (preference.isEmailNotificationsEnabled() && preference.getEmailNotificationType() == EmailNotificationType.WEEKLY_SUMMARY || preference.getEmailNotificationType() == EmailNotificationType.DAILY_SUMMARY) {
// summary emails only
if (preference.getEmailNotificationType() == EmailNotificationType.WEEKLY_SUMMARY || preference.getEmailNotificationType() == EmailNotificationType.DAILY_SUMMARY) {
var now = OffsetDateTime.now().truncatedTo(ChronoUnit.HOURS);
var now = OffsetDateTime.now().truncatedTo(ChronoUnit.HOURS);
// Weekly summary is sent monday night
if (now.getDayOfWeek() == DayOfWeek.MONDAY && preference.getEmailNotificationType() == EmailNotificationType.WEEKLY_SUMMARY) {
var from = OffsetDateTime.now().minusDays(7).truncatedTo(ChronoUnit.HOURS).withHour(0);
var to = OffsetDateTime.now().truncatedTo(ChronoUnit.HOURS).withHour(0);
var notifications = notificationPersistenceService.getNotificationsForEmailSummary(preference.getUserId(), from, to);
// Weekly summary is sent monday night
if (now.getDayOfWeek() == DayOfWeek.MONDAY && preference.getEmailNotificationType() == EmailNotificationType.WEEKLY_SUMMARY) {
var from = OffsetDateTime.now().minusDays(7).truncatedTo(ChronoUnit.HOURS).withHour(0);
var to = OffsetDateTime.now().truncatedTo(ChronoUnit.HOURS).withHour(0);
var notifications = notificationPersistenceService.getNotificationsForEmailSummary(preference.getUserId(), from, to);
notificationEmailService.sendNotificationEmail(preference.getUserId(), EmailNotificationType.WEEKLY_SUMMARY, notifications);
} else {
var from = OffsetDateTime.now().minusDays(1).withHour(0).truncatedTo(ChronoUnit.HOURS);
var to = OffsetDateTime.now().minusDays(1).withHour(23).truncatedTo(ChronoUnit.HOURS);
var notifications = notificationPersistenceService.getNotificationsForEmailSummary(preference.getUserId(), from, to);
notificationEmailService.sendNotificationEmail(preference.getUserId(), EmailNotificationType.WEEKLY_SUMMARY, notifications);
} else {
var from = OffsetDateTime.now().minusDays(1).withHour(0).truncatedTo(ChronoUnit.HOURS);
var to = OffsetDateTime.now().minusDays(1).withHour(23).truncatedTo(ChronoUnit.HOURS);
var notifications = notificationPersistenceService.getNotificationsForEmailSummary(preference.getUserId(), from, to);
notificationEmailService.sendNotificationEmail(preference.getUserId(), EmailNotificationType.DAILY_SUMMARY, notifications);
}
notificationEmailService.sendNotificationEmail(preference.getUserId(), EmailNotificationType.DAILY_SUMMARY, notifications);
}
@ -60,5 +55,4 @@ public class SendNotificationEmailJob implements Job {
}
}