#70 added update notification for all participants

This commit is contained in:
Nightblade73 2019-04-25 19:15:19 +04:00
parent c489ebbf91
commit 16e9bf1fb5
4 changed files with 113 additions and 7 deletions

View File

@ -16,15 +16,14 @@ public class ConferenceNotificationService {
private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7; private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7;
private final static String TEMPLATE_DEADLINE = "conferenceDeadlineNotification"; private final static String TEMPLATE_DEADLINE = "conferenceDeadlineNotification";
private final static String TEMPLATE_CREATE_CONFERENCE = "conferenceCreateNotification"; private final static String TEMPLATE_CREATE = "conferenceCreateNotification";
private final static String TEMPLATE_STATUS_CHANGED = "conferenceChangeNotification"; private final static String TEMPLATE_UPDATE_DEADLINES = "conferenceUpdateDeadlinesNotification";
private final static String TEMPLATE_FAILED = "conferenceFailedNotification"; private final static String TEMPLATE_UPDATE_DATES = "conferenceUpdateDatesNotification";
private final static String TITLE_DEADLINE = "Приближается дедлайн конференции"; private final static String TITLE_DEADLINE = "Приближается дедлайн конференции";
private final static String TITLE_CREATE = "Создана новая конференция: %s"; private final static String TITLE_CREATE = "Создана новая конференция: %s";
private final static String TITLE_STATUS_CHANGED = "Изменения в конференции"; private final static String TITLE_UPDATE_DEADLINES = "Изменения дедлайнов в конференции: %s";
private final static String TITLE_FAILED = "Статья провалена"; private final static String TITLE_UPDATE_DATES = "Изменение дат проведения конференции: %s";
private final MailService mailService; private final MailService mailService;
private final UserService userService; private final UserService userService;
@ -57,7 +56,17 @@ public class ConferenceNotificationService {
public void sendCreateNotification(Conference conference) { public void sendCreateNotification(Conference conference) {
Map<String, Object> variables = ImmutableMap.of("conference", conference); Map<String, Object> 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<String, Object> 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<String, Object> 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) { // public void statusChangeNotification(Paper paper, Paper.PaperStatus oldStatus) {
@ -77,4 +86,6 @@ public class ConferenceNotificationService {
private void sendForAllParticipals(Map<String, Object> variables, Conference conference, String template, String title) { private void sendForAllParticipals(Map<String, Object> variables, Conference conference, String template, String title) {
conference.getUsers().forEach(conferenceUser -> mailService.sendEmailFromTemplate(variables, conferenceUser.getUser(), template, title)); conference.getUsers().forEach(conferenceUser -> mailService.sendEmailFromTemplate(variables, conferenceUser.getUser(), template, title));
} }
} }

View File

@ -10,6 +10,7 @@ import ru.ulstu.conference.model.ConferenceDto;
import ru.ulstu.conference.model.ConferenceFilterDto; import ru.ulstu.conference.model.ConferenceFilterDto;
import ru.ulstu.conference.model.ConferenceUser; import ru.ulstu.conference.model.ConferenceUser;
import ru.ulstu.conference.repository.ConferenceRepository; import ru.ulstu.conference.repository.ConferenceRepository;
import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.deadline.service.DeadlineService;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.service.PaperService; import ru.ulstu.paper.service.PaperService;
@ -22,6 +23,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import static org.springframework.util.ObjectUtils.isEmpty; import static org.springframework.util.ObjectUtils.isEmpty;
import static ru.ulstu.core.util.StreamApiUtils.convert; import static ru.ulstu.core.util.StreamApiUtils.convert;
@ -101,7 +103,13 @@ public class ConferenceService {
@Transactional @Transactional
public Integer update(ConferenceDto conferenceDto) throws IOException { public Integer update(ConferenceDto conferenceDto) throws IOException {
Conference conference = conferenceRepository.findOne(conferenceDto.getId()); Conference conference = conferenceRepository.findOne(conferenceDto.getId());
List<Deadline> oldDeadlines = conference.getDeadlines().stream()
.map(this::copyDeadline)
.collect(Collectors.toList());
Date oldBeginDate = conference.getBeginDate();
Date oldEndDate = conference.getEndDate();
conferenceRepository.save(copyFromDto(conference, conferenceDto)); conferenceRepository.save(copyFromDto(conference, conferenceDto));
sendNotificationAfterUpdate(conference, oldDeadlines, oldBeginDate, oldEndDate);
conferenceDto.getRemovedDeadlineIds().forEach(deadlineService::remove); conferenceDto.getRemovedDeadlineIds().forEach(deadlineService::remove);
return conference.getId(); return conference.getId();
} }
@ -228,4 +236,36 @@ public class ConferenceService {
modelMap.addAttribute("nearshoreSales", nearshoreSales); modelMap.addAttribute("nearshoreSales", nearshoreSales);
modelMap.addAttribute("offshoreSales", offshoreSales); modelMap.addAttribute("offshoreSales", offshoreSales);
} }
public void sendNotificationAfterUpdate(Conference conference, List<Deadline> 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;
}
} }

View File

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Уведомление об изменении дат проведения конференции</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
</head>
<body>
<p>
Уважаемый(ая) <span th:text="${user.firstName + ' ' + user.lastName}">Ivan Ivanov</span>
</p>
<p>
Даты проведения конференции "<a th:href="@{|${baseUrl}/conferences/conference?id=${conference.id}|}">
<span th:text="${conference.title}">Title</span></a>" изменились с <br/>
"<span th:text="${#dates.format(oldBeginDate, 'dd.MM.yyyy')}">oldBeginDate</span>"
-
"<span th:text="${#dates.format(oldEndDate, 'dd.MM.yyyy')}">oldEndDate</span>"
<br/>
на <br/>
"<span th:text="${#dates.format(conference.beginDate, 'dd.MM.yyyy')}"></span>"
-
"<span th:text="${#dates.format(conference.endDate, 'dd.MM.yyyy')}"></span>".
</p>
<p>
Regards,
<br/>
<em>NG-tracker.</em>
</p>
</body>
</html>

View File

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Уведомление об изменении дедлайнов конференции</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
</head>
<body>
<p>
Уважаемый(ая) <span th:text="${user.firstName + ' ' + user.lastName}">Ivan Ivanov</span>
</p>
<p>
Дедлайны конференции "<a th:href="@{|${baseUrl}/conferences/conference?id=${conference.id}|}">
<span th:text="${conference.title}">Title</span></a>" притерпели изменения.
<br/>
Ознакомтесь с изменениями.
</p>
<p>
Regards,
<br/>
<em>NG-tracker.</em>
</p>
</body>
</html>