From 74a8dcbd8ab22de90e4318da464254aa624cc0f6 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Thu, 9 May 2019 01:23:17 +0400 Subject: [PATCH] #119 add leader changed notification --- .../ulstu/grant/service/GrantNotificationService.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/service/GrantNotificationService.java b/src/main/java/ru/ulstu/grant/service/GrantNotificationService.java index c234290..40c045b 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantNotificationService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantNotificationService.java @@ -18,10 +18,12 @@ public class GrantNotificationService { private final static String TEMPLATE_DEADLINE = "grantDeadlineNotification"; private final static String TEMPLATE_CREATE = "grantCreateNotification"; private final static String TEMPLATE_AUTHORS_CHANGED = "grantAuthorsChangeNotification"; + private final static String TEMPLATE_LEADER_CHANGED = "grantLeaderChangeNotification"; private final static String TITLE_DEADLINE = "Приближается дедлайн гранта: %s"; private final static String TITLE_CREATE = "Создан грант: %s"; private final static String TITLE_AUTHORS_CHANGED = "Изменился состав рабочей группы гранта: %s"; + private final static String TITLE_LEADER_CHANGED = "Изменился руководитель гранта: %s"; private final MailService mailService; @@ -53,14 +55,18 @@ public class GrantNotificationService { sendForAllAuthors(variables, grant, TEMPLATE_CREATE, String.format(TITLE_CREATE, grant.getTitle())); } - public void authorsChangeNotification(Grant grant, List oldAuthors) { + public void sendAuthorsChangeNotification(Grant grant, Set oldAuthors) { Map variables = ImmutableMap.of("grant", grant, "oldAuthors", oldAuthors); sendForAllAuthors(variables, grant, TEMPLATE_AUTHORS_CHANGED, String.format(TITLE_AUTHORS_CHANGED, grant.getTitle())); } + public void sendLeaderChangeNotification(Grant grant, User oldLeader) { + Map variables = ImmutableMap.of("grant", grant, "oldLeader", oldLeader); + sendForAllAuthors(variables, grant, TEMPLATE_LEADER_CHANGED, String.format(TITLE_LEADER_CHANGED, grant.getTitle())); + } private void sendForAllAuthors(Map variables, Grant grant, String template, String title) { Set allAuthors = grant.getAuthors(); - allAuthors.add(grant.getLeader()); allAuthors.forEach(author -> mailService.sendEmailFromTemplate(variables, author, template, title)); + mailService.sendEmailFromTemplate(variables, grant.getLeader(), template, title); } }