From 34925b81ffc1fc03cbfa7ca5c798921483447b7d Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 25 Apr 2019 21:17:48 +0400 Subject: [PATCH] #70 added schedule for deadline of conference --- .../ConferenceNotificationService.java | 12 +----- .../service/ConferenceScheduler.java | 37 +++++++++++++++++++ .../conferenceDeadlineNotification.html | 29 +++++++++++++++ 3 files changed, 67 insertions(+), 11 deletions(-) create mode 100644 src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java create mode 100644 src/main/resources/mail_templates/conferenceDeadlineNotification.html diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java b/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java index 39472aa..54faa49 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java @@ -39,7 +39,7 @@ public class ConferenceNotificationService { conferences .stream() .filter(conference -> needToSendDeadlineNotification(conference, now, isDeadlineBeforeWeek)) - .forEach(conference -> sendMessageDeadline(conference)); + .forEach(this::sendMessageDeadline); } private boolean needToSendDeadlineNotification(Conference conference, Date compareDate, boolean isDeadlineBeforeWeek) { @@ -69,16 +69,6 @@ public class ConferenceNotificationService { sendForAllParticipals(variables, conference, TEMPLATE_UPDATE_DATES, String.format(TITLE_UPDATE_DATES, conference.getTitle())); } - // public void statusChangeNotification(Paper paper, Paper.PaperStatus oldStatus) { -// Map variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus); -// sendForAllParticipals(variables, paper, TEMPLATE_STATUS_CHANGED, TITLE_STATUS_CHANGED); -// } -// -// public void sendFailedNotification(Paper paper, Paper.PaperStatus oldStatus) { -// Map variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus); -// sendForAllParticipals(variables, paper, TEMPLATE_FAILED, TITLE_FAILED); -// } - private void sendForAllUsers(Map variables, String template, String title) { userService.findAll().forEach(user -> mailService.sendEmailFromTemplate(variables, user, template, title)); } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java b/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java new file mode 100644 index 0000000..ead2913 --- /dev/null +++ b/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java @@ -0,0 +1,37 @@ +package ru.ulstu.conference.service; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +@Service +public class ConferenceScheduler { + private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true; + + private final Logger log = LoggerFactory.getLogger(ConferenceScheduler.class); + + private final ConferenceNotificationService conferenceNotificationService; + private final ConferenceService conferenceService; + + public ConferenceScheduler(ConferenceNotificationService conferenceNotificationService, + ConferenceService conferenceService) { + this.conferenceNotificationService = conferenceNotificationService; + this.conferenceService = conferenceService; + } + + + @Scheduled(cron = "0 0 21-22 * * *", zone = "Europe/Samara") + public void checkDeadlineBeforeWeek() { + log.debug("ConferenceScheduler.checkDeadlineBeforeWeek started"); + conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); + log.debug("ConferenceScheduler.checkDeadlineBeforeWeek finished"); + } + + @Scheduled(cron = "0 0 21-22 * * ?", zone = "Europe/Samara") + public void checkDeadlineAfterWeek() { + log.debug("ConferenceScheduler.checkDeadlineAfterWeek started"); + conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll(), !IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); + log.debug("ConferenceScheduler.checkDeadlineAfterWeek finished"); + } +} diff --git a/src/main/resources/mail_templates/conferenceDeadlineNotification.html b/src/main/resources/mail_templates/conferenceDeadlineNotification.html new file mode 100644 index 0000000..77c89b1 --- /dev/null +++ b/src/main/resources/mail_templates/conferenceDeadlineNotification.html @@ -0,0 +1,29 @@ + + + + Уведомление о дедлайне конференции + + + + +

+ Уважаемый(ая) Ivan Ivanov +

+

+ Приближается дедлайн конференции " + Title". +

+

+ Срок исполнения: . +

+ +

+ Примечание: . +

+

+ Regards, +
+ NG-tracker. +

+ +