diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java b/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java index c69d862..39472aa 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java @@ -16,15 +16,14 @@ public class ConferenceNotificationService { private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7; private final static String TEMPLATE_DEADLINE = "conferenceDeadlineNotification"; - private final static String TEMPLATE_CREATE_CONFERENCE = "conferenceCreateNotification"; - private final static String TEMPLATE_STATUS_CHANGED = "conferenceChangeNotification"; - private final static String TEMPLATE_FAILED = "conferenceFailedNotification"; + private final static String TEMPLATE_CREATE = "conferenceCreateNotification"; + private final static String TEMPLATE_UPDATE_DEADLINES = "conferenceUpdateDeadlinesNotification"; + private final static String TEMPLATE_UPDATE_DATES = "conferenceUpdateDatesNotification"; private final static String TITLE_DEADLINE = "Приближается дедлайн конференции"; private final static String TITLE_CREATE = "Создана новая конференция: %s"; - private final static String TITLE_STATUS_CHANGED = "Изменения в конференции"; - private final static String TITLE_FAILED = "Статья провалена"; - + private final static String TITLE_UPDATE_DEADLINES = "Изменения дедлайнов в конференции: %s"; + private final static String TITLE_UPDATE_DATES = "Изменение дат проведения конференции: %s"; private final MailService mailService; private final UserService userService; @@ -57,7 +56,17 @@ public class ConferenceNotificationService { public void sendCreateNotification(Conference conference) { Map variables = ImmutableMap.of("conference", conference); - sendForAllUsers(variables, TEMPLATE_CREATE_CONFERENCE, String.format(TITLE_CREATE, conference.getTitle())); + sendForAllUsers(variables, TEMPLATE_CREATE, String.format(TITLE_CREATE, conference.getTitle())); + } + + public void updateDeadlineNotification(Conference conference) { + Map variables = ImmutableMap.of("conference", conference); + sendForAllParticipals(variables, conference, TEMPLATE_UPDATE_DEADLINES, String.format(TITLE_UPDATE_DEADLINES, conference.getTitle())); + } + + public void updateConferencesDatesNotification(Conference conference, Date oldBeginDate, Date oldEndDate) { + Map variables = ImmutableMap.of("conference", conference, "oldBeginDate", oldBeginDate, "oldEndDate", oldEndDate); + sendForAllParticipals(variables, conference, TEMPLATE_UPDATE_DATES, String.format(TITLE_UPDATE_DATES, conference.getTitle())); } // public void statusChangeNotification(Paper paper, Paper.PaperStatus oldStatus) { @@ -77,4 +86,6 @@ public class ConferenceNotificationService { private void sendForAllParticipals(Map variables, Conference conference, String template, String title) { conference.getUsers().forEach(conferenceUser -> mailService.sendEmailFromTemplate(variables, conferenceUser.getUser(), template, title)); } + + } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index bed0deb..af43ae9 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -10,6 +10,7 @@ import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.model.ConferenceFilterDto; import ru.ulstu.conference.model.ConferenceUser; import ru.ulstu.conference.repository.ConferenceRepository; +import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.service.PaperService; @@ -22,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; +import java.util.stream.Collectors; import static org.springframework.util.ObjectUtils.isEmpty; import static ru.ulstu.core.util.StreamApiUtils.convert; @@ -101,7 +103,13 @@ public class ConferenceService { @Transactional public Integer update(ConferenceDto conferenceDto) throws IOException { Conference conference = conferenceRepository.findOne(conferenceDto.getId()); + List oldDeadlines = conference.getDeadlines().stream() + .map(this::copyDeadline) + .collect(Collectors.toList()); + Date oldBeginDate = conference.getBeginDate(); + Date oldEndDate = conference.getEndDate(); conferenceRepository.save(copyFromDto(conference, conferenceDto)); + sendNotificationAfterUpdate(conference, oldDeadlines, oldBeginDate, oldEndDate); conferenceDto.getRemovedDeadlineIds().forEach(deadlineService::remove); return conference.getId(); } @@ -228,4 +236,36 @@ public class ConferenceService { modelMap.addAttribute("nearshoreSales", nearshoreSales); modelMap.addAttribute("offshoreSales", offshoreSales); } + + public void sendNotificationAfterUpdate(Conference conference, List oldDeadlines, Date oldBeginDate, Date oldEndDate) { + boolean isSendNotificationAboutDeadlines = false; + if (oldDeadlines.size() != conference.getDeadlines().size()) { + isSendNotificationAboutDeadlines = true; + } + for (Deadline deadline : conference.getDeadlines()) { + if (isSendNotificationAboutDeadlines) { + break; + } + for (Deadline oldDeadline : oldDeadlines) { + if (deadline.getId().equals(oldDeadline.getId())) { + if (!deadline.getDescription().equals(oldDeadline.getDescription()) || !deadline.getDate().equals(oldDeadline.getDate())) { + isSendNotificationAboutDeadlines = true; + break; + } + } + } + } + if (isSendNotificationAboutDeadlines) { + conferenceNotificationService.updateDeadlineNotification(conference); + } + if (!conference.getBeginDate().equals(oldBeginDate) || !conference.getEndDate().equals(oldEndDate)) { + conferenceNotificationService.updateConferencesDatesNotification(conference, oldBeginDate, oldEndDate); + } + } + + public Deadline copyDeadline(Deadline oldDeadline) { + Deadline newDeadline = new Deadline(oldDeadline.getDate(), oldDeadline.getDescription()); + newDeadline.setId(oldDeadline.getId()); + return newDeadline; + } } diff --git a/src/main/resources/mail_templates/conferenceUpdateDatesNotification.html b/src/main/resources/mail_templates/conferenceUpdateDatesNotification.html new file mode 100644 index 0000000..479336f --- /dev/null +++ b/src/main/resources/mail_templates/conferenceUpdateDatesNotification.html @@ -0,0 +1,31 @@ + + + + Уведомление об изменении дат проведения конференции + + + + +

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

+

+ Даты проведения конференции " + Title" изменились с
+ "oldBeginDate" + - + "oldEndDate" +
+ + на
+ "" + - + "". +

+

+ Regards, +
+ NG-tracker. +

+ + \ No newline at end of file diff --git a/src/main/resources/mail_templates/conferenceUpdateDeadlinesNotification.html b/src/main/resources/mail_templates/conferenceUpdateDeadlinesNotification.html new file mode 100644 index 0000000..f010fb8 --- /dev/null +++ b/src/main/resources/mail_templates/conferenceUpdateDeadlinesNotification.html @@ -0,0 +1,24 @@ + + + + Уведомление об изменении дедлайнов конференции + + + + +

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

+

+ Дедлайны конференции " + Title" притерпели изменения. +
+ Ознакомтесь с изменениями. +

+

+ Regards, +
+ NG-tracker. +

+ + \ No newline at end of file