task notifications

pull/244/head
Anton Romanov 5 years ago
parent 0f9f591c6b
commit 5b4dbac481

@ -1,8 +1,25 @@
package ru.ulstu.activity.common.service;
import ru.ulstu.activity.common.model.AbstractActivity;
import ru.ulstu.user.model.User;
import ru.ulstu.user.service.MailService;
import java.util.Map;
public abstract class ActivityNotificationService<T extends AbstractActivity> {
private final MailService mailService;
protected ActivityNotificationService(MailService mailService) {
this.mailService = mailService;
}
public abstract void sendCreateNotification(T entity);
protected void sendForAuthor(Map<String, Object> variables, User author, String template, String title) {
mailService.sendEmailFromTemplate(variables, author, template, title);
}
protected void sendForAllAuthors(Map<String, Object> variables, T entity, String template, String title) {
entity.getActivityMembers().forEach(author -> sendForAuthor(variables, author, template, title));
}
}

@ -38,6 +38,7 @@ public class ConferenceNotificationService extends ActivityNotificationService<C
public ConferenceNotificationService(MailService mailService,
UserService userService,
PingService pingService) {
super(mailService);
this.mailService = mailService;
this.userService = userService;
this.pingService = pingService;

@ -26,10 +26,8 @@ public class GrantNotificationService extends ActivityNotificationService<Grant>
private final static String TITLE_AUTHORS_CHANGED = "Изменился состав рабочей группы гранта: %s";
private final static String TITLE_LEADER_CHANGED = "Изменился руководитель гранта: %s";
private final MailService mailService;
public GrantNotificationService(MailService mailService) {
this.mailService = mailService;
super(mailService);
}
public void sendDeadlineNotifications(List<Grant> grants, boolean isDeadlineBeforeWeek) {
@ -65,10 +63,4 @@ public class GrantNotificationService extends ActivityNotificationService<Grant>
Map<String, Object> variables = ImmutableMap.of("grant", grant, "oldLeader", oldLeader);
sendForAllAuthors(variables, grant, TEMPLATE_LEADER_CHANGED, String.format(TITLE_LEADER_CHANGED, grant.getTitle()));
}
private void sendForAllAuthors(Map<String, Object> variables, Grant grant, String template, String title) {
Set<User> allAuthors = grant.getAuthors();
allAuthors.forEach(author -> mailService.sendEmailFromTemplate(variables, author, template, title));
mailService.sendEmailFromTemplate(variables, grant.getLeader(), template, title);
}
}

@ -26,11 +26,8 @@ public class PaperNotificationService extends ActivityNotificationService<Paper>
private final static String TITLE_STATUS_CHANGED = "Изменился статус статьи";
private final static String TITLE_FAILED = "Статья провалена";
private final MailService mailService;
public PaperNotificationService(MailService mailService) {
this.mailService = mailService;
super(mailService);
}
public void sendDeadlineNotifications(PageableItems<Paper> papers, boolean isDeadlineBeforeWeek) {
@ -81,12 +78,4 @@ public class PaperNotificationService extends ActivityNotificationService<Paper>
Map<String, Object> variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus);
sendForAllAuthors(variables, paper, TEMPLATE_FAILED, TITLE_FAILED);
}
private void sendForAuthor(Map<String, Object> variables, User author, String template, String title) {
mailService.sendEmailFromTemplate(variables, author, template, title);
}
private void sendForAllAuthors(Map<String, Object> variables, Paper paper, String template, String title) {
paper.getAuthors().forEach(author -> sendForAuthor(variables, author, template, title));
}
}

@ -8,10 +8,8 @@ import ru.ulstu.user.service.MailService;
@Service
public class ProjectNotificationService extends ActivityNotificationService<Project> {
private final MailService mailService;
public ProjectNotificationService(MailService mailService) {
this.mailService = mailService;
super(mailService);
}
public void sendCreateNotification(Project project) {

@ -1,20 +1,24 @@
package ru.ulstu.activity.students.service;
import com.google.common.collect.ImmutableMap;
import org.springframework.stereotype.Service;
import ru.ulstu.activity.common.service.ActivityNotificationService;
import ru.ulstu.activity.students.model.Task;
import ru.ulstu.user.service.MailService;
import java.util.Map;
@Service
public class TaskNotificationService extends ActivityNotificationService<Task> {
private final MailService mailService;
private final static String TEMPLATE_CREATE = "taskCreateNotification";
private final static String TITLE_CREATE = "Создана задача";
public TaskNotificationService(MailService mailService) {
this.mailService = mailService;
super(mailService);
}
public void sendCreateNotification(Task task) {
throw new RuntimeException("not implemented yet");
Map<String, Object> variables = ImmutableMap.of("task", task);
sendForAllAuthors(variables, task, TEMPLATE_CREATE, TITLE_CREATE);
}
}

@ -0,0 +1,23 @@
<!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}/students/task?id=${paper.id}|}"><span
th:text="${task.title}">Title</span></a>".
</p>
<p>
Regards,
<br/>
<em>NG-tracker.</em>
</p>
</body>
</html>
Loading…
Cancel
Save