|
|
@ -8,6 +8,7 @@ import ru.ulstu.ping.service.PingService;
|
|
|
|
import ru.ulstu.user.service.MailService;
|
|
|
|
import ru.ulstu.user.service.MailService;
|
|
|
|
import ru.ulstu.user.service.UserService;
|
|
|
|
import ru.ulstu.user.service.UserService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
@ -15,7 +16,7 @@ import java.util.Map;
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
public class ConferenceNotificationService {
|
|
|
|
public class ConferenceNotificationService {
|
|
|
|
|
|
|
|
|
|
|
|
private final static int YESTERDAY = 0;
|
|
|
|
private final static int YESTERDAY = -1;
|
|
|
|
private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7;
|
|
|
|
private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7;
|
|
|
|
private final static String TEMPLATE_PING = "conferencePingNotification";
|
|
|
|
private final static String TEMPLATE_PING = "conferencePingNotification";
|
|
|
|
private final static String TEMPLATE_DEADLINE = "conferenceDeadlineNotification";
|
|
|
|
private final static String TEMPLATE_DEADLINE = "conferenceDeadlineNotification";
|
|
|
@ -41,24 +42,23 @@ public class ConferenceNotificationService {
|
|
|
|
this.pingService = pingService;
|
|
|
|
this.pingService = pingService;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void sendDeadlineNotifications(List<Conference> conferences, boolean isDeadlineBeforeWeek) {
|
|
|
|
public void sendDeadlineNotifications(List<Conference> conferences) {
|
|
|
|
Date now = DateUtils.addDays(new Date(), DAYS_TO_DEADLINE_NOTIFICATION);
|
|
|
|
Date now = DateUtils.addDays(new Date(), DAYS_TO_DEADLINE_NOTIFICATION);
|
|
|
|
conferences
|
|
|
|
conferences
|
|
|
|
.stream()
|
|
|
|
.stream()
|
|
|
|
.filter(conference -> needToSendDeadlineNotification(conference, now, isDeadlineBeforeWeek))
|
|
|
|
.filter(conference -> needToSendDeadlineNotification(conference, now))
|
|
|
|
.forEach(this::sendMessageDeadline);
|
|
|
|
.forEach(this::sendMessageDeadline);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean needToSendDeadlineNotification(Conference conference, Date compareDate, boolean isDeadlineBeforeWeek) {
|
|
|
|
private boolean needToSendDeadlineNotification(Conference conference, Date compareDate) {
|
|
|
|
return (conference.getNextDeadline().isPresent())
|
|
|
|
return (conference.getNextDeadline().isPresent())
|
|
|
|
&& (compareDate.before(conference.getNextDeadline().get().getDate()) && isDeadlineBeforeWeek
|
|
|
|
&& conference.getNextDeadline().get().getDate().after(new Date())
|
|
|
|
|| compareDate.after(conference.getNextDeadline().get().getDate()) && !isDeadlineBeforeWeek)
|
|
|
|
&& conference.getNextDeadline().get().getDate().before(compareDate);
|
|
|
|
&& conference.getNextDeadline().get().getDate().after(new Date());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void sendMessageDeadline(Conference conference) {
|
|
|
|
private void sendMessageDeadline(Conference conference) {
|
|
|
|
Map<String, Object> variables = ImmutableMap.of("conference", conference);
|
|
|
|
Map<String, Object> variables = ImmutableMap.of("conference", conference);
|
|
|
|
sendForAllParticipals(variables, conference, TEMPLATE_DEADLINE, TITLE_DEADLINE);
|
|
|
|
sendForAllParticipants(variables, conference, TEMPLATE_DEADLINE, String.format(TITLE_DEADLINE, conference.getTitle()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void sendCreateNotification(Conference conference) {
|
|
|
|
public void sendCreateNotification(Conference conference) {
|
|
|
@ -68,29 +68,31 @@ public class ConferenceNotificationService {
|
|
|
|
|
|
|
|
|
|
|
|
public void updateDeadlineNotification(Conference conference) {
|
|
|
|
public void updateDeadlineNotification(Conference conference) {
|
|
|
|
Map<String, Object> variables = ImmutableMap.of("conference", conference);
|
|
|
|
Map<String, Object> variables = ImmutableMap.of("conference", conference);
|
|
|
|
sendForAllParticipals(variables, conference, TEMPLATE_UPDATE_DEADLINES, String.format(TITLE_UPDATE_DEADLINES, conference.getTitle()));
|
|
|
|
sendForAllParticipants(variables, conference, TEMPLATE_UPDATE_DEADLINES, String.format(TITLE_UPDATE_DEADLINES, conference.getTitle()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void updateConferencesDatesNotification(Conference conference, Date oldBeginDate, Date oldEndDate) {
|
|
|
|
public void updateConferencesDatesNotification(Conference conference, Date oldBeginDate, Date oldEndDate) {
|
|
|
|
Map<String, Object> variables = ImmutableMap.of("conference", conference, "oldBeginDate", oldBeginDate, "oldEndDate", 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()));
|
|
|
|
sendForAllParticipants(variables, conference, TEMPLATE_UPDATE_DATES, String.format(TITLE_UPDATE_DATES, conference.getTitle()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void sendForAllUsers(Map<String, Object> variables, String template, String title) {
|
|
|
|
private void sendForAllUsers(Map<String, Object> variables, String template, String title) {
|
|
|
|
userService.findAll().forEach(user -> mailService.sendEmailFromTemplate(variables, user, template, title));
|
|
|
|
userService.findAll().forEach(user -> mailService.sendEmailFromTemplate(variables, user, template, title));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void sendForAllParticipals(Map<String, Object> variables, Conference conference, String template, String title) {
|
|
|
|
private void sendForAllParticipants(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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void sendPingNotifications(List<Conference> conferences) {
|
|
|
|
public void sendPingNotifications(List<Conference> conferences) {
|
|
|
|
Date yesterday = DateUtils.addDays(new Date(), YESTERDAY);
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
|
|
|
|
calendar.setTime(new Date());
|
|
|
|
|
|
|
|
calendar.add(Calendar.DAY_OF_MONTH, YESTERDAY);
|
|
|
|
conferences
|
|
|
|
conferences
|
|
|
|
.stream()
|
|
|
|
.stream()
|
|
|
|
.filter(conference -> {
|
|
|
|
.filter(conference -> {
|
|
|
|
Integer pingCount = pingService.countPingYesterday(conference, yesterday);
|
|
|
|
Integer pingCount = pingService.countPingYesterday(conference, calendar);
|
|
|
|
return needToSendPingNotification(conference, pingCount);
|
|
|
|
return needToSendPingNotification(conference, pingCount);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.forEach(this::sendMessagePing);
|
|
|
|
.forEach(this::sendMessagePing);
|
|
|
@ -106,6 +108,6 @@ public class ConferenceNotificationService {
|
|
|
|
|
|
|
|
|
|
|
|
private void sendMessagePing(Conference conference) {
|
|
|
|
private void sendMessagePing(Conference conference) {
|
|
|
|
Map<String, Object> variables = ImmutableMap.of("conference", conference);
|
|
|
|
Map<String, Object> variables = ImmutableMap.of("conference", conference);
|
|
|
|
sendForAllParticipals(variables, conference, TEMPLATE_PING, String.format(TITLE_PING, conference.getTitle()));
|
|
|
|
sendForAllParticipants(variables, conference, TEMPLATE_PING, String.format(TITLE_PING, conference.getTitle()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|