|
|
@ -13,6 +13,16 @@ import java.util.Map;
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
public class PaperNotificationService {
|
|
|
|
public class PaperNotificationService {
|
|
|
|
private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7;
|
|
|
|
private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7;
|
|
|
|
|
|
|
|
private final static String TEMPLATE_DEADLINE = "paperDeadlineNotification";
|
|
|
|
|
|
|
|
private final static String TEMPLATE_CREATE = "paperCreateNotification";
|
|
|
|
|
|
|
|
private final static String TEMPLATE_STATUS_CHANGED = "paperStatusChangeNotification";
|
|
|
|
|
|
|
|
private final static String TEMPLATE_FAILED = "paperFailedNotification";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final static String TITLE_DEADLINE = "Приближается дедлайн статьи";
|
|
|
|
|
|
|
|
private final static String TITLE_CREATE = "Создана статья";
|
|
|
|
|
|
|
|
private final static String TITLE_STATUS_CHANGED = "Изменился статус статьи";
|
|
|
|
|
|
|
|
private final static String TITLE_FAILED = "Статья провалена";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final MailService mailService;
|
|
|
|
private final MailService mailService;
|
|
|
|
|
|
|
|
|
|
|
@ -36,30 +46,26 @@ public class PaperNotificationService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void sendMessageDeadline(Paper paper) {
|
|
|
|
private void sendMessageDeadline(Paper paper) {
|
|
|
|
paper.getAuthors().forEach(user -> {
|
|
|
|
Map<String, Object> variables = ImmutableMap.of("paper", paper);
|
|
|
|
mailService.sendEmail(user.getEmail(), "Приближается дедлайн статьи",
|
|
|
|
sendForAllAuhtors(variables, paper, TEMPLATE_DEADLINE, TITLE_DEADLINE);
|
|
|
|
"Срок сдачи статьи " + paper.getTitle() + " " + paper.getNextDeadline().get().getDate().toString());
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void sendCreateNotification(Paper paper) {
|
|
|
|
public void sendCreateNotification(Paper paper) {
|
|
|
|
Map<String, Object> variables = ImmutableMap.of("paper", paper);
|
|
|
|
Map<String, Object> variables = ImmutableMap.of("paper", paper);
|
|
|
|
paper.getAuthors().forEach(author -> {
|
|
|
|
sendForAllAuhtors(variables, paper, TEMPLATE_CREATE, TITLE_CREATE);
|
|
|
|
mailService.sendEmailFromTemplate(variables, author, "paperCreateNotification", "Создана статья");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void statusChangeNotification(Paper paper, Paper.PaperStatus oldStatus) {
|
|
|
|
public void statusChangeNotification(Paper paper, Paper.PaperStatus oldStatus) {
|
|
|
|
Map<String, Object> variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus);
|
|
|
|
Map<String, Object> variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus);
|
|
|
|
paper.getAuthors().forEach(author -> {
|
|
|
|
sendForAllAuhtors(variables, paper, TEMPLATE_STATUS_CHANGED, TITLE_STATUS_CHANGED);
|
|
|
|
mailService.sendEmailFromTemplate(variables, author, "paperStatusChangeNotification", "Изменился статус статьи");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void sendFailedNotification(Paper paper, Paper.PaperStatus oldStatus) {
|
|
|
|
public void sendFailedNotification(Paper paper, Paper.PaperStatus oldStatus) {
|
|
|
|
Map<String, Object> variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus);
|
|
|
|
Map<String, Object> variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus);
|
|
|
|
paper.getAuthors().forEach(author -> {
|
|
|
|
sendForAllAuhtors(variables, paper, TEMPLATE_FAILED, TITLE_FAILED);
|
|
|
|
mailService.sendEmailFromTemplate(variables, author, "paperFailedNotification", "Статья провалена");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
private void sendForAllAuhtors(Map<String, Object> variables, Paper paper, String template, String title) {
|
|
|
|
|
|
|
|
paper.getAuthors().forEach(author -> mailService.sendEmailFromTemplate(variables, author, template, title));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|