RED-3584 / RED-3581 - notification issues - preferences validation test
This commit is contained in:
parent
37a84d9049
commit
ec29d583f5
@ -11,6 +11,7 @@ import java.util.List;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@SuppressWarnings("PMD")
|
||||||
public class NotificationEmailService {
|
public class NotificationEmailService {
|
||||||
|
|
||||||
public void sendNotificationEmail(String userId, EmailNotificationType emailNotificationType, List<NotificationEntity> notifications) {
|
public void sendNotificationEmail(String userId, EmailNotificationType emailNotificationType, List<NotificationEntity> notifications) {
|
||||||
|
|||||||
@ -30,28 +30,23 @@ public class SendNotificationEmailJob implements Job {
|
|||||||
|
|
||||||
var allConfiguredPreferences = notificationPreferencesPersistenceService.findAll();
|
var allConfiguredPreferences = notificationPreferencesPersistenceService.findAll();
|
||||||
allConfiguredPreferences.forEach(preference -> {
|
allConfiguredPreferences.forEach(preference -> {
|
||||||
if (preference.isEmailNotificationsEnabled()) {
|
if (preference.isEmailNotificationsEnabled() && preference.getEmailNotificationType() == EmailNotificationType.WEEKLY_SUMMARY || preference.getEmailNotificationType() == EmailNotificationType.DAILY_SUMMARY) {
|
||||||
|
|
||||||
// summary emails only
|
var now = OffsetDateTime.now().truncatedTo(ChronoUnit.HOURS);
|
||||||
if (preference.getEmailNotificationType() == EmailNotificationType.WEEKLY_SUMMARY || preference.getEmailNotificationType() == EmailNotificationType.DAILY_SUMMARY) {
|
|
||||||
|
|
||||||
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
|
notificationEmailService.sendNotificationEmail(preference.getUserId(), EmailNotificationType.WEEKLY_SUMMARY, notifications);
|
||||||
if (now.getDayOfWeek() == DayOfWeek.MONDAY && preference.getEmailNotificationType() == EmailNotificationType.WEEKLY_SUMMARY) {
|
} else {
|
||||||
var from = OffsetDateTime.now().minusDays(7).truncatedTo(ChronoUnit.HOURS).withHour(0);
|
var from = OffsetDateTime.now().minusDays(1).withHour(0).truncatedTo(ChronoUnit.HOURS);
|
||||||
var to = OffsetDateTime.now().truncatedTo(ChronoUnit.HOURS).withHour(0);
|
var to = OffsetDateTime.now().minusDays(1).withHour(23).truncatedTo(ChronoUnit.HOURS);
|
||||||
var notifications = notificationPersistenceService.getNotificationsForEmailSummary(preference.getUserId(), from, to);
|
var notifications = notificationPersistenceService.getNotificationsForEmailSummary(preference.getUserId(), from, to);
|
||||||
|
|
||||||
notificationEmailService.sendNotificationEmail(preference.getUserId(), EmailNotificationType.WEEKLY_SUMMARY, notifications);
|
notificationEmailService.sendNotificationEmail(preference.getUserId(), EmailNotificationType.DAILY_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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,5 +55,4 @@ public class SendNotificationEmailJob implements Job {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user