From c489ebbf9149da82f7ab1364b52c883131c02c24 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 25 Apr 2019 17:12:39 +0400 Subject: [PATCH 01/37] #70 added create notification for all users about new conference --- .../ru/ulstu/conference/model/Conference.java | 20 +++++ .../ConferenceNotificationService.java | 73 +++++++++++++++++++ .../conference/service/ConferenceService.java | 6 +- .../conferenceCreateNotification.html | 30 ++++++++ .../templates/conferences/conference.html | 5 +- 5 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 src/main/resources/mail_templates/conferenceCreateNotification.html diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index 3f77699..126c1bc 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -21,8 +21,10 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import java.util.ArrayList; +import java.util.Comparator; import java.util.Date; import java.util.List; +import java.util.Optional; @Entity @Table(name = "conference") @@ -135,4 +137,22 @@ public class Conference extends BaseEntity { public void setUsers(List users) { this.users = users; } + + public Optional getNextDeadline() { + return deadlines + .stream() + .filter(deadline -> deadline.getDate() != null) + .sorted(Comparator.comparing(Deadline::getDate)) + .filter(d -> d.getDate().after(new Date())) + .findFirst(); + } + + public boolean lastDeadlineFailed() { + return !deadlines + .stream() + .filter(deadline -> deadline.getDate() != null) + .filter(d -> d.getDate().after(new Date())) + .findAny() + .isPresent(); + } } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java b/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java index ff9f69a..c69d862 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java @@ -1,7 +1,80 @@ package ru.ulstu.conference.service; +import com.google.common.collect.ImmutableMap; import org.springframework.stereotype.Service; +import ru.ulstu.conference.model.Conference; +import ru.ulstu.core.util.DateUtils; +import ru.ulstu.user.service.MailService; +import ru.ulstu.user.service.UserService; + +import java.util.Date; +import java.util.List; +import java.util.Map; @Service public class ConferenceNotificationService { + + private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7; + private final static String TEMPLATE_DEADLINE = "conferenceDeadlineNotification"; + private final static String TEMPLATE_CREATE_CONFERENCE = "conferenceCreateNotification"; + private final static String TEMPLATE_STATUS_CHANGED = "conferenceChangeNotification"; + private final static String TEMPLATE_FAILED = "conferenceFailedNotification"; + + private final static String TITLE_DEADLINE = "Приближается дедлайн конференции"; + private final static String TITLE_CREATE = "Создана новая конференция: %s"; + private final static String TITLE_STATUS_CHANGED = "Изменения в конференции"; + private final static String TITLE_FAILED = "Статья провалена"; + + + private final MailService mailService; + private final UserService userService; + + public ConferenceNotificationService(MailService mailService, + UserService userService) { + this.mailService = mailService; + this.userService = userService; + } + + public void sendDeadlineNotifications(List conferences, boolean isDeadlineBeforeWeek) { + Date now = DateUtils.addDays(new Date(), DAYS_TO_DEADLINE_NOTIFICATION); + conferences + .stream() + .filter(conference -> needToSendDeadlineNotification(conference, now, isDeadlineBeforeWeek)) + .forEach(conference -> sendMessageDeadline(conference)); + } + + private boolean needToSendDeadlineNotification(Conference conference, Date compareDate, boolean isDeadlineBeforeWeek) { + return (conference.getNextDeadline().isPresent()) + && (compareDate.before(conference.getNextDeadline().get().getDate()) && isDeadlineBeforeWeek + || compareDate.after(conference.getNextDeadline().get().getDate()) && !isDeadlineBeforeWeek) + && conference.getNextDeadline().get().getDate().after(new Date()); + } + + private void sendMessageDeadline(Conference conference) { + Map variables = ImmutableMap.of("conference", conference); + sendForAllParticipals(variables, conference, TEMPLATE_DEADLINE, TITLE_DEADLINE); + } + + public void sendCreateNotification(Conference conference) { + Map variables = ImmutableMap.of("conference", conference); + sendForAllUsers(variables, TEMPLATE_CREATE_CONFERENCE, String.format(TITLE_CREATE, conference.getTitle())); + } + + // public void statusChangeNotification(Paper paper, Paper.PaperStatus oldStatus) { +// Map variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus); +// sendForAllParticipals(variables, paper, TEMPLATE_STATUS_CHANGED, TITLE_STATUS_CHANGED); +// } +// +// public void sendFailedNotification(Paper paper, Paper.PaperStatus oldStatus) { +// Map variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus); +// sendForAllParticipals(variables, paper, TEMPLATE_FAILED, TITLE_FAILED); +// } + + private void sendForAllUsers(Map variables, String template, String title) { + userService.findAll().forEach(user -> mailService.sendEmailFromTemplate(variables, user, template, title)); + } + + private void sendForAllParticipals(Map variables, Conference conference, String template, String title) { + conference.getUsers().forEach(conferenceUser -> mailService.sendEmailFromTemplate(variables, conferenceUser.getUser(), template, title)); + } } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 905c208..bed0deb 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -36,19 +36,22 @@ public class ConferenceService { private final PaperService paperService; private final UserService userService; private final PingService pingService; + private final ConferenceNotificationService conferenceNotificationService; public ConferenceService(ConferenceRepository conferenceRepository, ConferenceUserService conferenceUserService, DeadlineService deadlineService, PaperService paperService, UserService userService, - PingService pingService) { + PingService pingService, + ConferenceNotificationService conferenceNotificationService) { this.conferenceRepository = conferenceRepository; this.conferenceUserService = conferenceUserService; this.deadlineService = deadlineService; this.paperService = paperService; this.userService = userService; this.pingService = pingService; + this.conferenceNotificationService = conferenceNotificationService; } public ConferenceDto getExistConferenceById(Integer id) { @@ -91,6 +94,7 @@ public class ConferenceService { public Integer create(ConferenceDto conferenceDto) throws IOException { Conference newConference = copyFromDto(new Conference(), conferenceDto); newConference = conferenceRepository.save(newConference); + conferenceNotificationService.sendCreateNotification(newConference); return newConference.getId(); } diff --git a/src/main/resources/mail_templates/conferenceCreateNotification.html b/src/main/resources/mail_templates/conferenceCreateNotification.html new file mode 100644 index 0000000..055e85d --- /dev/null +++ b/src/main/resources/mail_templates/conferenceCreateNotification.html @@ -0,0 +1,30 @@ + + + + Уведомление о создании конференции + + + + +

+ Уважаемый(ая) Ivan Ivanov +

+

+ Была создана новая конференция: " + Title". +
+ Спешите принять участие! +

+

+ Даты проведения: + + - + . +

+

+ Regards, +
+ NG-tracker. +

+ + \ No newline at end of file diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 2d93a5e..69c754a 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -1,7 +1,7 @@ + layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html"> @@ -135,7 +135,6 @@
-
@@ -148,8 +147,6 @@ Имя статьи - - From 16e9bf1fb56c092e6a57fc7afa45306f18a6f406 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 25 Apr 2019 19:15:19 +0400 Subject: [PATCH 02/37] #70 added update notification for all participants --- .../ConferenceNotificationService.java | 25 ++++++++---- .../conference/service/ConferenceService.java | 40 +++++++++++++++++++ .../conferenceUpdateDatesNotification.html | 31 ++++++++++++++ ...conferenceUpdateDeadlinesNotification.html | 24 +++++++++++ 4 files changed, 113 insertions(+), 7 deletions(-) create mode 100644 src/main/resources/mail_templates/conferenceUpdateDatesNotification.html create mode 100644 src/main/resources/mail_templates/conferenceUpdateDeadlinesNotification.html diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java b/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java index c69d862..39472aa 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java @@ -16,15 +16,14 @@ public class ConferenceNotificationService { private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7; private final static String TEMPLATE_DEADLINE = "conferenceDeadlineNotification"; - private final static String TEMPLATE_CREATE_CONFERENCE = "conferenceCreateNotification"; - private final static String TEMPLATE_STATUS_CHANGED = "conferenceChangeNotification"; - private final static String TEMPLATE_FAILED = "conferenceFailedNotification"; + private final static String TEMPLATE_CREATE = "conferenceCreateNotification"; + private final static String TEMPLATE_UPDATE_DEADLINES = "conferenceUpdateDeadlinesNotification"; + private final static String TEMPLATE_UPDATE_DATES = "conferenceUpdateDatesNotification"; private final static String TITLE_DEADLINE = "Приближается дедлайн конференции"; private final static String TITLE_CREATE = "Создана новая конференция: %s"; - private final static String TITLE_STATUS_CHANGED = "Изменения в конференции"; - private final static String TITLE_FAILED = "Статья провалена"; - + private final static String TITLE_UPDATE_DEADLINES = "Изменения дедлайнов в конференции: %s"; + private final static String TITLE_UPDATE_DATES = "Изменение дат проведения конференции: %s"; private final MailService mailService; private final UserService userService; @@ -57,7 +56,17 @@ public class ConferenceNotificationService { public void sendCreateNotification(Conference conference) { Map 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 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 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) { @@ -77,4 +86,6 @@ public class ConferenceNotificationService { private void sendForAllParticipals(Map variables, Conference conference, String template, String title) { conference.getUsers().forEach(conferenceUser -> mailService.sendEmailFromTemplate(variables, conferenceUser.getUser(), template, title)); } + + } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index bed0deb..af43ae9 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -10,6 +10,7 @@ import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.model.ConferenceFilterDto; import ru.ulstu.conference.model.ConferenceUser; import ru.ulstu.conference.repository.ConferenceRepository; +import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.service.PaperService; @@ -22,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; +import java.util.stream.Collectors; import static org.springframework.util.ObjectUtils.isEmpty; import static ru.ulstu.core.util.StreamApiUtils.convert; @@ -101,7 +103,13 @@ public class ConferenceService { @Transactional public Integer update(ConferenceDto conferenceDto) throws IOException { Conference conference = conferenceRepository.findOne(conferenceDto.getId()); + List oldDeadlines = conference.getDeadlines().stream() + .map(this::copyDeadline) + .collect(Collectors.toList()); + Date oldBeginDate = conference.getBeginDate(); + Date oldEndDate = conference.getEndDate(); conferenceRepository.save(copyFromDto(conference, conferenceDto)); + sendNotificationAfterUpdate(conference, oldDeadlines, oldBeginDate, oldEndDate); conferenceDto.getRemovedDeadlineIds().forEach(deadlineService::remove); return conference.getId(); } @@ -228,4 +236,36 @@ public class ConferenceService { modelMap.addAttribute("nearshoreSales", nearshoreSales); modelMap.addAttribute("offshoreSales", offshoreSales); } + + public void sendNotificationAfterUpdate(Conference conference, List 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; + } } diff --git a/src/main/resources/mail_templates/conferenceUpdateDatesNotification.html b/src/main/resources/mail_templates/conferenceUpdateDatesNotification.html new file mode 100644 index 0000000..479336f --- /dev/null +++ b/src/main/resources/mail_templates/conferenceUpdateDatesNotification.html @@ -0,0 +1,31 @@ + + + + Уведомление об изменении дат проведения конференции + + + + +

+ Уважаемый(ая) Ivan Ivanov +

+

+ Даты проведения конференции " + Title" изменились с
+ "oldBeginDate" + - + "oldEndDate" +
+ + на
+ "" + - + "". +

+

+ Regards, +
+ NG-tracker. +

+ + \ No newline at end of file diff --git a/src/main/resources/mail_templates/conferenceUpdateDeadlinesNotification.html b/src/main/resources/mail_templates/conferenceUpdateDeadlinesNotification.html new file mode 100644 index 0000000..f010fb8 --- /dev/null +++ b/src/main/resources/mail_templates/conferenceUpdateDeadlinesNotification.html @@ -0,0 +1,24 @@ + + + + Уведомление об изменении дедлайнов конференции + + + + +

+ Уважаемый(ая) Ivan Ivanov +

+

+ Дедлайны конференции " + Title" притерпели изменения. +
+ Ознакомтесь с изменениями. +

+

+ Regards, +
+ NG-tracker. +

+ + \ No newline at end of file From 34925b81ffc1fc03cbfa7ca5c798921483447b7d Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 25 Apr 2019 21:17:48 +0400 Subject: [PATCH 03/37] #70 added schedule for deadline of conference --- .../ConferenceNotificationService.java | 12 +----- .../service/ConferenceScheduler.java | 37 +++++++++++++++++++ .../conferenceDeadlineNotification.html | 29 +++++++++++++++ 3 files changed, 67 insertions(+), 11 deletions(-) create mode 100644 src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java create mode 100644 src/main/resources/mail_templates/conferenceDeadlineNotification.html diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java b/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java index 39472aa..54faa49 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java @@ -39,7 +39,7 @@ public class ConferenceNotificationService { conferences .stream() .filter(conference -> needToSendDeadlineNotification(conference, now, isDeadlineBeforeWeek)) - .forEach(conference -> sendMessageDeadline(conference)); + .forEach(this::sendMessageDeadline); } private boolean needToSendDeadlineNotification(Conference conference, Date compareDate, boolean isDeadlineBeforeWeek) { @@ -69,16 +69,6 @@ public class ConferenceNotificationService { sendForAllParticipals(variables, conference, TEMPLATE_UPDATE_DATES, String.format(TITLE_UPDATE_DATES, conference.getTitle())); } - // public void statusChangeNotification(Paper paper, Paper.PaperStatus oldStatus) { -// Map variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus); -// sendForAllParticipals(variables, paper, TEMPLATE_STATUS_CHANGED, TITLE_STATUS_CHANGED); -// } -// -// public void sendFailedNotification(Paper paper, Paper.PaperStatus oldStatus) { -// Map variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus); -// sendForAllParticipals(variables, paper, TEMPLATE_FAILED, TITLE_FAILED); -// } - private void sendForAllUsers(Map variables, String template, String title) { userService.findAll().forEach(user -> mailService.sendEmailFromTemplate(variables, user, template, title)); } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java b/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java new file mode 100644 index 0000000..ead2913 --- /dev/null +++ b/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java @@ -0,0 +1,37 @@ +package ru.ulstu.conference.service; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +@Service +public class ConferenceScheduler { + private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true; + + private final Logger log = LoggerFactory.getLogger(ConferenceScheduler.class); + + private final ConferenceNotificationService conferenceNotificationService; + private final ConferenceService conferenceService; + + public ConferenceScheduler(ConferenceNotificationService conferenceNotificationService, + ConferenceService conferenceService) { + this.conferenceNotificationService = conferenceNotificationService; + this.conferenceService = conferenceService; + } + + + @Scheduled(cron = "0 0 21-22 * * *", zone = "Europe/Samara") + public void checkDeadlineBeforeWeek() { + log.debug("ConferenceScheduler.checkDeadlineBeforeWeek started"); + conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); + log.debug("ConferenceScheduler.checkDeadlineBeforeWeek finished"); + } + + @Scheduled(cron = "0 0 21-22 * * ?", zone = "Europe/Samara") + public void checkDeadlineAfterWeek() { + log.debug("ConferenceScheduler.checkDeadlineAfterWeek started"); + conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll(), !IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); + log.debug("ConferenceScheduler.checkDeadlineAfterWeek finished"); + } +} diff --git a/src/main/resources/mail_templates/conferenceDeadlineNotification.html b/src/main/resources/mail_templates/conferenceDeadlineNotification.html new file mode 100644 index 0000000..77c89b1 --- /dev/null +++ b/src/main/resources/mail_templates/conferenceDeadlineNotification.html @@ -0,0 +1,29 @@ + + + + Уведомление о дедлайне конференции + + + + +

+ Уважаемый(ая) Ivan Ivanov +

+

+ Приближается дедлайн конференции " + Title". +

+

+ Срок исполнения: . +

+ +

+ Примечание: . +

+

+ Regards, +
+ NG-tracker. +

+ + From 51e121ae249325615a3f378fe61595f9c25edcb6 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Fri, 26 Apr 2019 00:29:20 +0400 Subject: [PATCH 04/37] #117 add BAK papers filter --- .../java/ru/ulstu/grant/model/GrantDto.java | 18 +++++++++++ .../ru/ulstu/grant/service/GrantService.java | 32 +++++++++++++++++-- .../paper/repository/PaperRepository.java | 2 ++ .../ru/ulstu/paper/service/PaperService.java | 7 ++++ .../resources/templates/grants/grant.html | 9 ++++-- 5 files changed, 62 insertions(+), 6 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/model/GrantDto.java b/src/main/java/ru/ulstu/grant/model/GrantDto.java index 3fb77c5..b60aec0 100644 --- a/src/main/java/ru/ulstu/grant/model/GrantDto.java +++ b/src/main/java/ru/ulstu/grant/model/GrantDto.java @@ -33,6 +33,8 @@ public class GrantDto { private boolean wasLeader; private boolean hasAge; private boolean hasDegree; + private boolean hasBAKPapers; + private boolean hasScopusPapers; private List paperIds = new ArrayList<>(); private List papers = new ArrayList<>(); private List removedDeadlineIds = new ArrayList<>(); @@ -224,4 +226,20 @@ public class GrantDto { public void setRemovedDeadlineIds(List removedDeadlineIds) { this.removedDeadlineIds = removedDeadlineIds; } + + public boolean isHasBAKPapers() { + return hasBAKPapers; + } + + public void setHasBAKPapers(boolean hasBAKPapers) { + this.hasBAKPapers = hasBAKPapers; + } + + public boolean isHasScopusPapers() { + return hasScopusPapers; + } + + public void setHasScopusPapers(boolean hasScopusPapers) { + this.hasScopusPapers = hasScopusPapers; + } } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index cabed80..ba6e1e9 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -18,11 +18,12 @@ import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; -import java.util.stream.Collectors; +import static java.util.stream.Collectors.toList; import static org.springframework.util.ObjectUtils.isEmpty; import static ru.ulstu.core.util.StreamApiUtils.convert; import static ru.ulstu.grant.model.Grant.GrantStatus.APPLICATION; @@ -156,8 +157,15 @@ public class GrantService { filteredUsers = filteredUsers .stream() .filter(getCompletedGrantLeaders()::contains) - .collect(Collectors.toList()); + .collect(toList()); } + if (grantDto.isHasBAKPapers()) { + filteredUsers = filteredUsers + .stream() + .filter(getCompletedBAKPapersAuthors()::contains) + .collect(toList()); + } + return filteredUsers; } @@ -165,7 +173,7 @@ public class GrantService { return grantRepository.findByStatus(Grant.GrantStatus.COMPLETED) .stream() .map(Grant::getLeader) - .collect(Collectors.toList()); + .collect(toList()); } public List getGrantPapers(List paperIds) { @@ -193,4 +201,22 @@ public class GrantService { grantDto.getDeadlines().remove((int) deadlineId); } + private List getCompletedBAKPapersAuthors() { + List papers = paperService.findCompletedVAKPapers() + .stream() + .filter(paper -> paper.getAuthors() != null) + .collect(toList()); + + List users = new ArrayList<>(); + for (Paper p : papers) { + p.getAuthors() + .stream() + .forEach(users::add); + } + + return users + .stream() + .distinct() + .collect(toList()); + } } diff --git a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java index cab9b1a..8bc59ce 100644 --- a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java +++ b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java @@ -16,4 +16,6 @@ public interface PaperRepository extends JpaRepository { List findByIdNotIn(List paperIds); List findAllByIdIn(List paperIds); + + List findByType(Paper.PaperType type); } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 325e377..648dbc9 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -272,4 +272,11 @@ public class PaperService { .map(User::getUserAbbreviate) .collect(Collectors.joining(", ")); } + + public List findCompletedVAKPapers() { + return paperRepository.findByType(Paper.PaperType.VAK) + .stream() + .filter(findAllCompleted()::contains) + .collect(toList()); + } } diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index 9c0736d..da59248 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -90,7 +90,8 @@ aria-expanded="false" aria-controls="collapse-filter">Фильтр рабочей группы -
@@ -111,14 +112,16 @@
- +
- +
From 51877023d122a5ea98198ce254ef57af5d4f245f Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 26 Apr 2019 09:28:20 +0400 Subject: [PATCH 05/37] #70 added new column to event --- .../ru/ulstu/conference/model/Conference.java | 9 ------- .../service/ConferenceScheduler.java | 4 +-- .../conference/service/ConferenceService.java | 7 +++++- .../ulstu/timeline/service/EventService.java | 25 +++++++++++++++++++ .../db/changelog-20190426_000000-schema.xml | 13 ++++++++++ src/main/resources/db/changelog-master.xml | 1 + 6 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 src/main/resources/db/changelog-20190426_000000-schema.xml diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index 126c1bc..9c91a7e 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -146,13 +146,4 @@ public class Conference extends BaseEntity { .filter(d -> d.getDate().after(new Date())) .findFirst(); } - - public boolean lastDeadlineFailed() { - return !deadlines - .stream() - .filter(deadline -> deadline.getDate() != null) - .filter(d -> d.getDate().after(new Date())) - .findAny() - .isPresent(); - } } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java b/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java index ead2913..863abb5 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java @@ -21,14 +21,14 @@ public class ConferenceScheduler { } - @Scheduled(cron = "0 0 21-22 * * *", zone = "Europe/Samara") + @Scheduled(cron = "0 0 8 * * *", zone = "Europe/Samara") public void checkDeadlineBeforeWeek() { log.debug("ConferenceScheduler.checkDeadlineBeforeWeek started"); conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); log.debug("ConferenceScheduler.checkDeadlineBeforeWeek finished"); } - @Scheduled(cron = "0 0 21-22 * * ?", zone = "Europe/Samara") + @Scheduled(cron = "0 0 8 * * ?", zone = "Europe/Samara") public void checkDeadlineAfterWeek() { log.debug("ConferenceScheduler.checkDeadlineAfterWeek started"); conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll(), !IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index af43ae9..6550814 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -15,6 +15,7 @@ import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.service.PaperService; import ru.ulstu.ping.service.PingService; +import ru.ulstu.timeline.service.EventService; import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; @@ -39,6 +40,7 @@ public class ConferenceService { private final UserService userService; private final PingService pingService; private final ConferenceNotificationService conferenceNotificationService; + private final EventService eventService; public ConferenceService(ConferenceRepository conferenceRepository, ConferenceUserService conferenceUserService, @@ -46,7 +48,8 @@ public class ConferenceService { PaperService paperService, UserService userService, PingService pingService, - ConferenceNotificationService conferenceNotificationService) { + ConferenceNotificationService conferenceNotificationService, + EventService eventService) { this.conferenceRepository = conferenceRepository; this.conferenceUserService = conferenceUserService; this.deadlineService = deadlineService; @@ -54,6 +57,7 @@ public class ConferenceService { this.userService = userService; this.pingService = pingService; this.conferenceNotificationService = conferenceNotificationService; + this.eventService = eventService; } public ConferenceDto getExistConferenceById(Integer id) { @@ -97,6 +101,7 @@ public class ConferenceService { Conference newConference = copyFromDto(new Conference(), conferenceDto); newConference = conferenceRepository.save(newConference); conferenceNotificationService.sendCreateNotification(newConference); + eventService.createFromConference(newConference); return newConference.getId(); } diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index 2d2b83d..d0e50a9 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -4,6 +4,7 @@ import org.apache.commons.lang3.time.DateUtils; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import ru.ulstu.conference.model.Conference; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.paper.model.Paper; import ru.ulstu.timeline.model.Event; @@ -140,4 +141,28 @@ public class EventService { public List findAllFutureDto() { return convert(findAllFuture(), EventDto::new); } + + public void createFromConference(Conference newConference) { + List timelines = timelineService.findAll(); + Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0); + + for (Deadline deadline : newConference.getDeadlines() + .stream() + .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) + .collect(Collectors.toList())) { + Event newEvent = new Event(); + newEvent.setTitle("Дедлайн статьи"); + newEvent.setStatus(Event.EventStatus.NEW); + newEvent.setExecuteDate(deadline.getDate()); + newEvent.setCreateDate(new Date()); + newEvent.setUpdateDate(new Date()); +// newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' cтатьи '" + newPaper.getTitle() + "'"); +// newEvent.setRecipients(new ArrayList(newPaper.getAuthors())); +// newEvent.setConference(newConference); + eventRepository.save(newEvent); + + timeline.getEvents().add(newEvent); + timelineService.save(timeline); + } + } } diff --git a/src/main/resources/db/changelog-20190426_000000-schema.xml b/src/main/resources/db/changelog-20190426_000000-schema.xml new file mode 100644 index 0000000..5304032 --- /dev/null +++ b/src/main/resources/db/changelog-20190426_000000-schema.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 68b294a..f5a1451 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -34,4 +34,5 @@ + \ No newline at end of file From dbcdb96dbf066655ebe4ff30048a7c38321902cc Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 26 Apr 2019 15:12:34 +0400 Subject: [PATCH 06/37] #70 added event method, don't work, because trying to find null entity --- .../ru/ulstu/conference/model/Conference.java | 1 + .../conference/service/ConferenceService.java | 1 + src/main/java/ru/ulstu/timeline/model/Event.java | 13 +++++++++++++ .../java/ru/ulstu/timeline/model/EventDto.java | 15 ++++++++++++++- .../timeline/repository/EventRepository.java | 3 +++ .../ru/ulstu/timeline/service/EventService.java | 13 +++++++++---- 6 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index 9c91a7e..7e18ac0 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -59,6 +59,7 @@ public class Conference extends BaseEntity { @JoinTable(name = "paper_conference", joinColumns = {@JoinColumn(name = "conference_id")}, inverseJoinColumns = {@JoinColumn(name = "paper_id")}) + @Fetch(FetchMode.SUBSELECT) private List papers = new ArrayList<>(); @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 6550814..0c1d37d 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -114,6 +114,7 @@ public class ConferenceService { Date oldBeginDate = conference.getBeginDate(); Date oldEndDate = conference.getEndDate(); conferenceRepository.save(copyFromDto(conference, conferenceDto)); + eventService.updateConferenceDeadlines(conference); sendNotificationAfterUpdate(conference, oldDeadlines, oldBeginDate, oldEndDate); conferenceDto.getRemovedDeadlineIds().forEach(deadlineService::remove); return conference.getId(); diff --git a/src/main/java/ru/ulstu/timeline/model/Event.java b/src/main/java/ru/ulstu/timeline/model/Event.java index ef0a4b8..f53a52d 100644 --- a/src/main/java/ru/ulstu/timeline/model/Event.java +++ b/src/main/java/ru/ulstu/timeline/model/Event.java @@ -1,6 +1,7 @@ package ru.ulstu.timeline.model; import org.hibernate.validator.constraints.NotBlank; +import ru.ulstu.conference.model.Conference; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.paper.model.Paper; import ru.ulstu.user.model.User; @@ -76,6 +77,10 @@ public class Event extends BaseEntity { @JoinColumn(name = "paper_id") private Paper paper; + @ManyToOne + @JoinColumn(name = "conference_id") + private Conference conference; + public String getTitle() { return title; } @@ -163,4 +168,12 @@ public class Event extends BaseEntity { public void setPaper(Paper paper) { this.paper = paper; } + + public Conference getConference() { + return conference; + } + + public void setConference(Conference conference) { + this.conference = conference; + } } diff --git a/src/main/java/ru/ulstu/timeline/model/EventDto.java b/src/main/java/ru/ulstu/timeline/model/EventDto.java index 6a4a90b..1d2a29a 100644 --- a/src/main/java/ru/ulstu/timeline/model/EventDto.java +++ b/src/main/java/ru/ulstu/timeline/model/EventDto.java @@ -3,6 +3,7 @@ package ru.ulstu.timeline.model; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import org.hibernate.validator.constraints.NotBlank; +import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.user.model.UserDto; @@ -25,6 +26,7 @@ public class EventDto { private final String description; private final List recipients; private PaperDto paperDto; + private ConferenceDto conferenceDto; @JsonCreator public EventDto(@JsonProperty("id") Integer id, @@ -36,7 +38,8 @@ public class EventDto { @JsonProperty("updateDate") Date updateDate, @JsonProperty("description") String description, @JsonProperty("paperDto") PaperDto paperDto, - @JsonProperty("recipients") List recipients) { + @JsonProperty("recipients") List recipients, + @JsonProperty("paperDto") ConferenceDto conferenceDto) { this.id = id; this.title = title; this.period = period; @@ -47,6 +50,7 @@ public class EventDto { this.description = description; this.recipients = recipients; this.paperDto = paperDto; + this.conferenceDto = conferenceDto; } public EventDto(Event event) { @@ -60,6 +64,7 @@ public class EventDto { this.description = event.getDescription(); this.paperDto = new PaperDto(event.getPaper()); this.recipients = convert(event.getRecipients(), UserDto::new); + this.conferenceDto = new ConferenceDto(event.getConference()); } public Integer getId() { @@ -105,4 +110,12 @@ public class EventDto { public void setPaperDto(PaperDto paperDto) { this.paperDto = paperDto; } + + public ConferenceDto getConferenceDto() { + return conferenceDto; + } + + public void setConferenceDto(ConferenceDto conferenceDto) { + this.conferenceDto = conferenceDto; + } } diff --git a/src/main/java/ru/ulstu/timeline/repository/EventRepository.java b/src/main/java/ru/ulstu/timeline/repository/EventRepository.java index eb5c08b..a4b1e47 100644 --- a/src/main/java/ru/ulstu/timeline/repository/EventRepository.java +++ b/src/main/java/ru/ulstu/timeline/repository/EventRepository.java @@ -2,6 +2,7 @@ package ru.ulstu.timeline.repository; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import ru.ulstu.conference.model.Conference; import ru.ulstu.paper.model.Paper; import ru.ulstu.timeline.model.Event; @@ -15,4 +16,6 @@ public interface EventRepository extends JpaRepository { List findAllFuture(); List findAllByPaper(Paper paper); + + List findAllByConference(Conference conference); } diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index d0e50a9..f4e2873 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -151,18 +151,23 @@ public class EventService { .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) .collect(Collectors.toList())) { Event newEvent = new Event(); - newEvent.setTitle("Дедлайн статьи"); + newEvent.setTitle("Дедлайн конференции"); newEvent.setStatus(Event.EventStatus.NEW); newEvent.setExecuteDate(deadline.getDate()); newEvent.setCreateDate(new Date()); newEvent.setUpdateDate(new Date()); -// newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' cтатьи '" + newPaper.getTitle() + "'"); -// newEvent.setRecipients(new ArrayList(newPaper.getAuthors())); -// newEvent.setConference(newConference); + newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' конференции '" + newConference.getTitle() + "'"); + newConference.getUsers().forEach(conferenceUser -> newEvent.getRecipients().add(conferenceUser.getUser())); + newEvent.setConference(newConference); eventRepository.save(newEvent); timeline.getEvents().add(newEvent); timelineService.save(timeline); } } + + public void updateConferenceDeadlines(Conference conference) { + eventRepository.delete(eventRepository.findAllByConference(conference)); + createFromConference(conference); + } } From 39f3c6947925f9999e2d58ec16ff1e698b971f6c Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Fri, 26 Apr 2019 15:16:04 +0400 Subject: [PATCH 07/37] #117 add scopus papers filter --- .../ru/ulstu/grant/service/GrantService.java | 34 +++++++++++++++---- .../ru/ulstu/paper/service/PaperService.java | 4 +-- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index ba6e1e9..dbf9972 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -20,6 +20,7 @@ import ru.ulstu.user.service.UserService; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Date; import java.util.List; @@ -162,10 +163,15 @@ public class GrantService { if (grantDto.isHasBAKPapers()) { filteredUsers = filteredUsers .stream() - .filter(getCompletedBAKPapersAuthors()::contains) + .filter(getBAKAuthors()::contains) + .collect(toList()); + } + if (grantDto.isHasScopusPapers()) { + filteredUsers = filteredUsers + .stream() + .filter(getScopusAuthors()::contains) .collect(toList()); } - return filteredUsers; } @@ -201,22 +207,36 @@ public class GrantService { grantDto.getDeadlines().remove((int) deadlineId); } - private List getCompletedBAKPapersAuthors() { - List papers = paperService.findCompletedVAKPapers() - .stream() + private List getCompletedPapersAuthors(Paper.PaperType type) { + List papers = paperService.findAllCompletedByType(type); + papers.stream() .filter(paper -> paper.getAuthors() != null) .collect(toList()); - List users = new ArrayList<>(); for (Paper p : papers) { p.getAuthors() .stream() .forEach(users::add); } + return users; + } - return users + private List getBAKAuthors() { + return getCompletedPapersAuthors(Paper.PaperType.VAK) .stream() .distinct() .collect(toList()); } + + private List getScopusAuthors() { + List oldAuthors = getCompletedPapersAuthors(Paper.PaperType.SCOPUS); + List newAuthors = new ArrayList<>(); + oldAuthors.forEach(author -> { + int count = Collections.frequency(oldAuthors, author); + if (count > 3) { + newAuthors.add(author); + } + }); + return newAuthors; + } } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 648dbc9..ae9056b 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -273,8 +273,8 @@ public class PaperService { .collect(Collectors.joining(", ")); } - public List findCompletedVAKPapers() { - return paperRepository.findByType(Paper.PaperType.VAK) + public List findAllCompletedByType(Paper.PaperType type) { + return paperRepository.findByType(type) .stream() .filter(findAllCompleted()::contains) .collect(toList()); From e178cd163909119693001cf225a96dc8eee71bc3 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sat, 27 Apr 2019 09:45:47 +0400 Subject: [PATCH 08/37] #70 added checking empty fields of deadline, fix bug on EventDto --- .../ulstu/conference/controller/ConferenceController.java | 6 ++++++ src/main/java/ru/ulstu/timeline/model/EventDto.java | 8 ++++++-- src/main/resources/templates/conferences/conference.html | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 4c5ea91..d324eb4 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -78,6 +78,12 @@ public class ConferenceController { @PostMapping(value = "/conference", params = "save") public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { filterEmptyDeadlines(conferenceDto); + for (Deadline deadline : conferenceDto.getDeadlines()) { + if (deadline.getDate() == null || deadline.getDescription().isEmpty()) { + errors.rejectValue("deadlines", "errorCode", "Все поля дедлайна должны быть заполнены"); + return CONFERENCE_PAGE; + } + } if (errors.hasErrors()) { return CONFERENCE_PAGE; } diff --git a/src/main/java/ru/ulstu/timeline/model/EventDto.java b/src/main/java/ru/ulstu/timeline/model/EventDto.java index 1d2a29a..e92d2cb 100644 --- a/src/main/java/ru/ulstu/timeline/model/EventDto.java +++ b/src/main/java/ru/ulstu/timeline/model/EventDto.java @@ -62,9 +62,13 @@ public class EventDto { this.createDate = event.getCreateDate(); this.updateDate = event.getUpdateDate(); this.description = event.getDescription(); - this.paperDto = new PaperDto(event.getPaper()); this.recipients = convert(event.getRecipients(), UserDto::new); - this.conferenceDto = new ConferenceDto(event.getConference()); + if (paperDto != null) { + this.paperDto = new PaperDto(event.getPaper()); + } + if (conferenceDto != null) { + this.conferenceDto = new ConferenceDto(event.getConference()); + } } public Integer getId() { diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 69c754a..d5906b6 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -150,10 +150,10 @@ + Имя статьи - From 0e8752e4607dbf4b2561668b8e657be57df37495 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sat, 27 Apr 2019 20:34:49 +0400 Subject: [PATCH 09/37] #70 style fixes --- .../java/ru/ulstu/timeline/model/EventDto.java | 2 +- src/main/resources/public/css/conference.css | 18 ++++++++++++++++-- .../fragments/confLineFragment.html | 6 +----- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/ru/ulstu/timeline/model/EventDto.java b/src/main/java/ru/ulstu/timeline/model/EventDto.java index e92d2cb..ccce25a 100644 --- a/src/main/java/ru/ulstu/timeline/model/EventDto.java +++ b/src/main/java/ru/ulstu/timeline/model/EventDto.java @@ -39,7 +39,7 @@ public class EventDto { @JsonProperty("description") String description, @JsonProperty("paperDto") PaperDto paperDto, @JsonProperty("recipients") List recipients, - @JsonProperty("paperDto") ConferenceDto conferenceDto) { + @JsonProperty("conferenceDto") ConferenceDto conferenceDto) { this.id = id; this.title = title; this.period = period; diff --git a/src/main/resources/public/css/conference.css b/src/main/resources/public/css/conference.css index 6018b9c..73a96ae 100644 --- a/src/main/resources/public/css/conference.css +++ b/src/main/resources/public/css/conference.css @@ -7,6 +7,10 @@ body { border-radius: .25rem; } +.conference-row .d-flex:hover .icon-delete { + visibility: visible; +} + .filter-option-inner-inner { color: white; } @@ -17,10 +21,20 @@ body { .conference-row .d-flex .text-decoration { text-decoration: none; + margin: 0; } .conference-row .d-flex .text-decoration:nth-child(1) { - margin-left: 10px; + margin-left: 5px; +} + +.conference-row .d-flex .icon-delete { + width: 29px; + height: 29px; + margin: auto; + border: none; + visibility: hidden; + background-color: transparent; } @@ -159,7 +173,7 @@ body { } .icon-delete:hover { - background-color: #ff0000; + background-color: #ff0000 !important; transition: background-color .15s ease-in-out; } diff --git a/src/main/resources/templates/conferences/fragments/confLineFragment.html b/src/main/resources/templates/conferences/fragments/confLineFragment.html index ecd166d..21b4191 100644 --- a/src/main/resources/templates/conferences/fragments/confLineFragment.html +++ b/src/main/resources/templates/conferences/fragments/confLineFragment.html @@ -7,17 +7,13 @@
- + - - - -
From 5c677a975c29d024a326b459e093440b6e88268c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BD=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD?= Date: Tue, 30 Apr 2019 01:01:30 +0300 Subject: [PATCH 10/37] #114 changelog edited --- .../resources/db/changelog-20190428_000000-schema.xml | 10 ++++++++++ src/main/resources/db/changelog-master.xml | 1 + 2 files changed, 11 insertions(+) create mode 100644 src/main/resources/db/changelog-20190428_000000-schema.xml diff --git a/src/main/resources/db/changelog-20190428_000000-schema.xml b/src/main/resources/db/changelog-20190428_000000-schema.xml new file mode 100644 index 0000000..b44691d --- /dev/null +++ b/src/main/resources/db/changelog-20190428_000000-schema.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 68b294a..07b0ca2 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -34,4 +34,5 @@ + \ No newline at end of file From 9edcf353389d453389dcc5e897564a822fb2cbb5 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Tue, 30 Apr 2019 10:43:36 +0400 Subject: [PATCH 11/37] #70 added ping notification --- .../ConferenceNotificationService.java | 34 +++++++++++++++++-- .../service/ConferenceScheduler.java | 9 ++++- .../ulstu/ping/repository/PingRepository.java | 6 ++++ .../ru/ulstu/ping/service/PingService.java | 8 +++++ .../conferencePingNotification.html | 25 ++++++++++++++ 5 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 src/main/resources/mail_templates/conferencePingNotification.html diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java b/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java index 54faa49..9449b12 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java @@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableMap; import org.springframework.stereotype.Service; import ru.ulstu.conference.model.Conference; import ru.ulstu.core.util.DateUtils; +import ru.ulstu.ping.service.PingService; import ru.ulstu.user.service.MailService; import ru.ulstu.user.service.UserService; @@ -14,24 +15,30 @@ import java.util.Map; @Service public class ConferenceNotificationService { + private final static int YESTERDAY = 0; private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7; + private final static String TEMPLATE_PING = "conferencePingNotification"; private final static String TEMPLATE_DEADLINE = "conferenceDeadlineNotification"; private final static String TEMPLATE_CREATE = "conferenceCreateNotification"; private final static String TEMPLATE_UPDATE_DEADLINES = "conferenceUpdateDeadlinesNotification"; private final static String TEMPLATE_UPDATE_DATES = "conferenceUpdateDatesNotification"; - private final static String TITLE_DEADLINE = "Приближается дедлайн конференции"; + private final static String TITLE_PING = "Обратите внимание на конференцию: %s"; + private final static String TITLE_DEADLINE = "Приближается дедлайн конференции: %s"; private final static String TITLE_CREATE = "Создана новая конференция: %s"; private final static String TITLE_UPDATE_DEADLINES = "Изменения дедлайнов в конференции: %s"; private final static String TITLE_UPDATE_DATES = "Изменение дат проведения конференции: %s"; private final MailService mailService; private final UserService userService; + private final PingService pingService; public ConferenceNotificationService(MailService mailService, - UserService userService) { + UserService userService, + PingService pingService) { this.mailService = mailService; this.userService = userService; + this.pingService = pingService; } public void sendDeadlineNotifications(List conferences, boolean isDeadlineBeforeWeek) { @@ -78,4 +85,27 @@ public class ConferenceNotificationService { } + public void sendPingNotifications(List conferences) { + Date yesterday = DateUtils.addDays(new Date(), YESTERDAY); + conferences + .stream() + .filter(conference -> { + Integer pingCount = pingService.countPingYesterday(conference, yesterday); + return needToSendPingNotification(conference, pingCount); + }) + .forEach(this::sendMessagePing); + } + + private boolean needToSendPingNotification(Conference conference, Integer pingCount) { + if (pingCount > 0) { + conference.setPing((Integer) pingCount); + return true; + } + return false; + } + + private void sendMessagePing(Conference conference) { + Map variables = ImmutableMap.of("conference", conference); + sendForAllParticipals(variables, conference, TEMPLATE_PING, String.format(TITLE_PING, conference.getTitle())); + } } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java b/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java index 863abb5..f55f885 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java @@ -21,7 +21,7 @@ public class ConferenceScheduler { } - @Scheduled(cron = "0 0 8 * * *", zone = "Europe/Samara") + @Scheduled(cron = "0 0 8 * * MON", zone = "Europe/Samara") public void checkDeadlineBeforeWeek() { log.debug("ConferenceScheduler.checkDeadlineBeforeWeek started"); conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); @@ -34,4 +34,11 @@ public class ConferenceScheduler { conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll(), !IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); log.debug("ConferenceScheduler.checkDeadlineAfterWeek finished"); } + + @Scheduled(cron = "0 0 8 * * *", zone = "Europe/Samara") + public void checkNewPing() { + log.debug("ConferenceScheduler.checkPing started"); + conferenceNotificationService.sendPingNotifications(conferenceService.findAll()); + log.debug("ConferenceScheduler.checkPing finished"); + } } diff --git a/src/main/java/ru/ulstu/ping/repository/PingRepository.java b/src/main/java/ru/ulstu/ping/repository/PingRepository.java index ebafc0c..8e69111 100644 --- a/src/main/java/ru/ulstu/ping/repository/PingRepository.java +++ b/src/main/java/ru/ulstu/ping/repository/PingRepository.java @@ -1,7 +1,13 @@ package ru.ulstu.ping.repository; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import ru.ulstu.conference.model.Conference; import ru.ulstu.ping.model.Ping; public interface PingRepository extends JpaRepository { + + @Query("SELECT count(*) FROM Ping p WHERE (DAY(p.date) = :day) AND (MONTH(p.date) = :month) AND (p.conference = :conference)") + long countByConferenceAndDate(@Param("conference") Conference conference, @Param("day") Integer day, @Param("month") Integer month); } diff --git a/src/main/java/ru/ulstu/ping/service/PingService.java b/src/main/java/ru/ulstu/ping/service/PingService.java index ff0d249..3152e5a 100644 --- a/src/main/java/ru/ulstu/ping/service/PingService.java +++ b/src/main/java/ru/ulstu/ping/service/PingService.java @@ -8,6 +8,7 @@ import ru.ulstu.ping.repository.PingRepository; import ru.ulstu.user.service.UserService; import java.io.IOException; +import java.util.Calendar; import java.util.Date; @Service @@ -27,4 +28,11 @@ public class PingService { newPing.setConference(conference); pingRepository.save(newPing); } + + public Integer countPingYesterday(Conference conference, Date yesterday) { + Calendar cal = Calendar.getInstance(); + cal.setTime(yesterday); + + return Math.toIntExact(pingRepository.countByConferenceAndDate(conference, cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1)); + } } diff --git a/src/main/resources/mail_templates/conferencePingNotification.html b/src/main/resources/mail_templates/conferencePingNotification.html new file mode 100644 index 0000000..a80a3f2 --- /dev/null +++ b/src/main/resources/mail_templates/conferencePingNotification.html @@ -0,0 +1,25 @@ + + + + Обратите внимание на конференциию + + + + +

+ Уважаемый(ая) Ivan Ivanov +

+

+ Конференция " + Title" была пропингована + раз. +
+ Обратите внимание. +

+

+ Regards, +
+ NG-tracker. +

+ + \ No newline at end of file From 0e062f133707716faa6843f73164f415adf8d34e Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Tue, 30 Apr 2019 11:41:36 +0400 Subject: [PATCH 12/37] #70 fast fix --- src/main/java/ru/ulstu/ping/repository/PingRepository.java | 4 ++-- src/main/java/ru/ulstu/ping/service/PingService.java | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/ru/ulstu/ping/repository/PingRepository.java b/src/main/java/ru/ulstu/ping/repository/PingRepository.java index 8e69111..de79dd7 100644 --- a/src/main/java/ru/ulstu/ping/repository/PingRepository.java +++ b/src/main/java/ru/ulstu/ping/repository/PingRepository.java @@ -8,6 +8,6 @@ import ru.ulstu.ping.model.Ping; public interface PingRepository extends JpaRepository { - @Query("SELECT count(*) FROM Ping p WHERE (DAY(p.date) = :day) AND (MONTH(p.date) = :month) AND (p.conference = :conference)") - long countByConferenceAndDate(@Param("conference") Conference conference, @Param("day") Integer day, @Param("month") Integer month); + @Query("SELECT count(*) FROM Ping p WHERE (DAY(p.date) = :day) AND (MONTH(p.date) = :month) AND (YEAR(p.date) = :year) AND (p.conference = :conference)") + long countByConferenceAndDate(@Param("conference") Conference conference, @Param("day") Integer day, @Param("month") Integer month, @Param("year") Integer year); } diff --git a/src/main/java/ru/ulstu/ping/service/PingService.java b/src/main/java/ru/ulstu/ping/service/PingService.java index 3152e5a..f24ed9d 100644 --- a/src/main/java/ru/ulstu/ping/service/PingService.java +++ b/src/main/java/ru/ulstu/ping/service/PingService.java @@ -33,6 +33,7 @@ public class PingService { Calendar cal = Calendar.getInstance(); cal.setTime(yesterday); - return Math.toIntExact(pingRepository.countByConferenceAndDate(conference, cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1)); + return Math.toIntExact(pingRepository.countByConferenceAndDate(conference, cal.get(Calendar.DAY_OF_MONTH), + cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR))); } } From 2ebd61016d1b6ea4216726aa2f57f0abd81c1edd Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Tue, 30 Apr 2019 23:40:40 +0400 Subject: [PATCH 13/37] #38 add variable "files" --- src/main/java/ru/ulstu/grant/model/Grant.java | 19 ++++++++------ .../java/ru/ulstu/grant/model/GrantDto.java | 25 ++++++++++-------- .../ru/ulstu/grant/service/GrantService.java | 26 +++++++++---------- 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java index abd61ac..d6f9f0c 100644 --- a/src/main/java/ru/ulstu/grant/model/Grant.java +++ b/src/main/java/ru/ulstu/grant/model/Grant.java @@ -1,5 +1,7 @@ package ru.ulstu.grant.model; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.UserContainer; @@ -66,10 +68,11 @@ public class Grant extends BaseEntity implements UserContainer { private String comment; - //Заявка на грант - @ManyToOne - @JoinColumn(name = "file_id") - private FileData application; + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @JoinColumn(name = "grant_id", unique = true) + @Fetch(FetchMode.SUBSELECT) + private List files = new ArrayList<>(); + @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "project_id") @@ -113,12 +116,12 @@ public class Grant extends BaseEntity implements UserContainer { this.comment = comment; } - public FileData getApplication() { - return application; + public List getFiles() { + return files; } - public void setApplication(FileData application) { - this.application = application; + public void setFiles(List files) { + this.files = files; } public String getTitle() { diff --git a/src/main/java/ru/ulstu/grant/model/GrantDto.java b/src/main/java/ru/ulstu/grant/model/GrantDto.java index 3fb77c5..6866f41 100644 --- a/src/main/java/ru/ulstu/grant/model/GrantDto.java +++ b/src/main/java/ru/ulstu/grant/model/GrantDto.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.commons.lang3.StringUtils; import org.hibernate.validator.constraints.NotEmpty; import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.file.model.FileDataDto; import ru.ulstu.paper.model.Paper; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.user.model.UserDto; @@ -25,7 +26,7 @@ public class GrantDto { private Grant.GrantStatus status; private List deadlines = new ArrayList<>(); private String comment; - private String applicationFileName; + private List files = new ArrayList<>(); private ProjectDto project; private Set authorIds; private Set authors; @@ -47,6 +48,7 @@ public class GrantDto { @JsonProperty("status") Grant.GrantStatus status, @JsonProperty("deadlines") List deadlines, @JsonProperty("comment") String comment, + @JsonProperty("files") List files, @JsonProperty("project") ProjectDto project, @JsonProperty("authorIds") Set authorIds, @JsonProperty("authors") Set authors, @@ -61,8 +63,9 @@ public class GrantDto { this.status = status; this.deadlines = deadlines; this.comment = comment; - this.applicationFileName = null; + this.files = files; this.project = project; + this.authorIds = authorIds; this.authors = authors; this.leaderId = leaderId; this.wasLeader = wasLeader; @@ -78,8 +81,8 @@ public class GrantDto { this.status = grant.getStatus(); this.deadlines = grant.getDeadlines(); this.comment = grant.getComment(); + this.files = convert(grant.getFiles(), FileDataDto::new); this.project = grant.getProject() == null ? null : new ProjectDto(grant.getProject()); - this.applicationFileName = grant.getApplication() == null ? null : grant.getApplication().getName(); this.authorIds = convert(grant.getAuthors(), user -> user.getId()); this.authors = convert(grant.getAuthors(), UserDto::new); this.leaderId = grant.getLeader().getId(); @@ -130,20 +133,20 @@ public class GrantDto { this.comment = comment; } - public ProjectDto getProject() { - return project; + public List getFiles() { + return files; } - public void setProject(ProjectDto project) { - this.project = project; + public void setFiles(List files) { + this.files = files; } - public String getApplicationFileName() { - return applicationFileName; + public ProjectDto getProject() { + return project; } - public void setApplicationFileName(String applicationFileName) { - this.applicationFileName = applicationFileName; + public void setProject(ProjectDto project) { + this.project = project; } public Set getAuthorIds() { diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index cabed80..0c1d68e 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -5,6 +5,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; +import ru.ulstu.file.model.FileDataDto; import ru.ulstu.file.service.FileService; import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.GrantDto; @@ -21,8 +22,8 @@ import java.io.IOException; import java.util.Arrays; import java.util.Date; import java.util.List; -import java.util.stream.Collectors; +import static java.util.stream.Collectors.toList; import static org.springframework.util.ObjectUtils.isEmpty; import static ru.ulstu.core.util.StreamApiUtils.convert; import static ru.ulstu.grant.model.Grant.GrantStatus.APPLICATION; @@ -81,9 +82,10 @@ public class GrantService { grant.setProject(projectService.findById(grantDto.getProject().getId())); } grant.setDeadlines(deadlineService.saveOrCreate(grantDto.getDeadlines())); - if (grantDto.getApplicationFileName() != null) { - grant.setApplication(fileService.createFileFromTmp(grantDto.getApplicationFileName())); - } + + grant.setFiles(fileService.saveOrCreate(grantDto.getFiles().stream() + .filter(f -> !f.isDeleted()) + .collect(toList()))); grant.getAuthors().clear(); if (grantDto.getAuthorIds() != null && !grantDto.getAuthorIds().isEmpty()) { grantDto.getAuthorIds().forEach(authorIds -> grant.getAuthors().add(userService.findById(authorIds))); @@ -106,8 +108,11 @@ public class GrantService { @Transactional public Integer update(GrantDto grantDto) throws IOException { Grant grant = grantRepository.findOne(grantDto.getId()); - if (grantDto.getApplicationFileName() != null && grant.getApplication() != null) { - fileService.deleteFile(grant.getApplication()); + + for (FileDataDto file : grantDto.getFiles().stream() + .filter(f -> f.isDeleted() && f.getId() != null) + .collect(toList())) { + fileService.delete(file.getId()); } grantDto.getRemovedDeadlineIds().forEach(deadlineService::remove); grantRepository.save(copyFromDto(grant, grantDto)); @@ -117,9 +122,6 @@ public class GrantService { @Transactional public void delete(Integer grantId) throws IOException { Grant grant = grantRepository.findOne(grantId); - if (grant.getApplication() != null) { - fileService.deleteFile(grant.getApplication()); - } grantRepository.delete(grant); } @@ -156,7 +158,7 @@ public class GrantService { filteredUsers = filteredUsers .stream() .filter(getCompletedGrantLeaders()::contains) - .collect(Collectors.toList()); + .collect(toList()); } return filteredUsers; } @@ -165,12 +167,11 @@ public class GrantService { return grantRepository.findByStatus(Grant.GrantStatus.COMPLETED) .stream() .map(Grant::getLeader) - .collect(Collectors.toList()); + .collect(toList()); } public List getGrantPapers(List paperIds) { return paperService.findAllSelect(paperIds); - } public List getAllPapers() { @@ -192,5 +193,4 @@ public class GrantService { } grantDto.getDeadlines().remove((int) deadlineId); } - } From 6442a67ff108ca538aeb742f09002478e9df6b15 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Tue, 30 Apr 2019 23:41:51 +0400 Subject: [PATCH 14/37] #38 update view --- .../fragments/grantFilesListFragment.html | 37 ++++++ .../resources/templates/grants/grant.html | 111 ++++++++++++++---- 2 files changed, 125 insertions(+), 23 deletions(-) create mode 100644 src/main/resources/templates/grants/fragments/grantFilesListFragment.html diff --git a/src/main/resources/templates/grants/fragments/grantFilesListFragment.html b/src/main/resources/templates/grants/fragments/grantFilesListFragment.html new file mode 100644 index 0000000..2547c80 --- /dev/null +++ b/src/main/resources/templates/grants/fragments/grantFilesListFragment.html @@ -0,0 +1,37 @@ + + + + + + +
+ + +
+ + + + +
+ + +
+
+ + + +
+
+
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index 9c0736d..d33015c 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -61,7 +61,7 @@
-
- +
+
-
+
+
+
From 2d9fd0506079bb27016c07416c64977aadb2b616 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 8 May 2019 23:32:37 +0400 Subject: [PATCH 33/37] #119 create grantCreateNotification mail template --- .../grantCreateNotification.html | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/main/resources/mail_templates/grantCreateNotification.html diff --git a/src/main/resources/mail_templates/grantCreateNotification.html b/src/main/resources/mail_templates/grantCreateNotification.html new file mode 100644 index 0000000..69736cd --- /dev/null +++ b/src/main/resources/mail_templates/grantCreateNotification.html @@ -0,0 +1,28 @@ + + + + Уведомление о создании гранта + + + + +

+ Уважаемый(ая) Ivan Ivanov +

+

+ Был добавлен новый грант: " + Title". +
+

+

+ Руководитель гранта: + + Leader. +

+

+ Regards, +
+ NG-tracker. +

+ + \ No newline at end of file From b640dea99a47521352214b6e00f1800adea2a7c2 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Thu, 9 May 2019 00:45:54 +0400 Subject: [PATCH 34/37] #119 create scheduler --- .../ulstu/grant/service/GrantScheduler.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/main/java/ru/ulstu/grant/service/GrantScheduler.java diff --git a/src/main/java/ru/ulstu/grant/service/GrantScheduler.java b/src/main/java/ru/ulstu/grant/service/GrantScheduler.java new file mode 100644 index 0000000..1c38c4a --- /dev/null +++ b/src/main/java/ru/ulstu/grant/service/GrantScheduler.java @@ -0,0 +1,30 @@ +package ru.ulstu.grant.service; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +@Service +public class GrantScheduler { + private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true; + + private final Logger log = LoggerFactory.getLogger(GrantScheduler.class); + + private final GrantNotificationService grantNotificationService; + private final GrantService grantService; + + public GrantScheduler(GrantNotificationService grantNotificationService, + GrantService grantService) { + this.grantNotificationService = grantNotificationService; + this.grantService = grantService; + } + + + @Scheduled(cron = "0 0 8 * * MON", zone = "Europe/Samara") + public void checkDeadlineBeforeWeek() { + log.debug("GrantScheduler.checkDeadlineBeforeWeek started"); + grantNotificationService.sendDeadlineNotifications(grantService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); + log.debug("GrantScheduler.checkDeadlineBeforeWeek finished"); + } +} From 4262446aef8147b06e3b5b535076d7cfc519e24c Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Thu, 9 May 2019 01:21:56 +0400 Subject: [PATCH 35/37] #119 create all mail templates --- .../grantAuthorsChangeNotification.html | 24 ++++++++++++++++ .../grantDeadlineNotification.html | 28 +++++++++++++++++++ .../grantLeaderChangeNotification.html | 24 ++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 src/main/resources/mail_templates/grantAuthorsChangeNotification.html create mode 100644 src/main/resources/mail_templates/grantDeadlineNotification.html create mode 100644 src/main/resources/mail_templates/grantLeaderChangeNotification.html diff --git a/src/main/resources/mail_templates/grantAuthorsChangeNotification.html b/src/main/resources/mail_templates/grantAuthorsChangeNotification.html new file mode 100644 index 0000000..2bae4fe --- /dev/null +++ b/src/main/resources/mail_templates/grantAuthorsChangeNotification.html @@ -0,0 +1,24 @@ + + + + Уведомление об изменении состава рабочей группы + + + + +

+ Уважаемый(ая) Ivan Ivanov +

+

+ Состав рабочей группы гранта "Title" сменился с + " oldAuthors" + на " newAuthors". +

+

+ Regards, +
+ NG-tracker. +

+ + diff --git a/src/main/resources/mail_templates/grantDeadlineNotification.html b/src/main/resources/mail_templates/grantDeadlineNotification.html new file mode 100644 index 0000000..190ef67 --- /dev/null +++ b/src/main/resources/mail_templates/grantDeadlineNotification.html @@ -0,0 +1,28 @@ + + + + Уведомление о дедлайне гранта + + + + +

+ Уважаемый(ая) Ivan Ivanov +

+

+ Приближается дедлайн гранта "Title". +

+

+ Срок исполнения: Date. +

+

+ Примечание: Description. +

+

+ Regards, +
+ NG-tracker. +

+ + diff --git a/src/main/resources/mail_templates/grantLeaderChangeNotification.html b/src/main/resources/mail_templates/grantLeaderChangeNotification.html new file mode 100644 index 0000000..c6a37e0 --- /dev/null +++ b/src/main/resources/mail_templates/grantLeaderChangeNotification.html @@ -0,0 +1,24 @@ + + + + Уведомление об изменении руководителя гранта + + + + +

+ Уважаемый(ая) Ivan Ivanov +

+

+ Руководитель гранта "Title" сменился с + "oldLeader" + на "newLeader". +

+

+ Regards, +
+ NG-tracker. +

+ + From 74a8dcbd8ab22de90e4318da464254aa624cc0f6 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Thu, 9 May 2019 01:23:17 +0400 Subject: [PATCH 36/37] #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); } } From 77e2ad06516d4da9d80b7c8d8c62a51d4397d5d3 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Thu, 9 May 2019 01:24:55 +0400 Subject: [PATCH 37/37] #119 add send notification functions --- .../ru/ulstu/grant/service/GrantService.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index ae11850..83ef49e 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -23,7 +23,9 @@ import java.io.IOException; import java.util.Arrays; import java.util.Collections; import java.util.Date; +import java.util.HashSet; import java.util.List; +import java.util.Set; import static java.util.stream.Collectors.toList; import static org.springframework.util.ObjectUtils.isEmpty; @@ -41,6 +43,7 @@ public class GrantService { private final UserService userService; private final PaperService paperService; private final EventService eventService; + private final GrantNotificationService grantNotificationService; public GrantService(GrantRepository grantRepository, FileService fileService, @@ -48,7 +51,8 @@ public class GrantService { ProjectService projectService, UserService userService, PaperService paperService, - EventService eventService) { + EventService eventService, + GrantNotificationService grantNotificationService) { this.grantRepository = grantRepository; this.fileService = fileService; this.deadlineService = deadlineService; @@ -56,6 +60,7 @@ public class GrantService { this.userService = userService; this.paperService = paperService; this.eventService = eventService; + this.grantNotificationService = grantNotificationService; } public List findAll() { @@ -77,6 +82,7 @@ public class GrantService { Grant newGrant = copyFromDto(new Grant(), grantDto); newGrant = grantRepository.save(newGrant); eventService.createFromGrant(newGrant); + grantNotificationService.sendCreateNotification(newGrant); return newGrant.getId(); } @@ -113,6 +119,8 @@ public class GrantService { @Transactional public Integer update(GrantDto grantDto) throws IOException { Grant grant = grantRepository.findOne(grantDto.getId()); + Set oldAuthors = new HashSet<>(grant.getAuthors()); + User oldLeader = grant.getLeader(); for (FileDataDto file : grantDto.getFiles().stream() .filter(f -> f.isDeleted() && f.getId() != null) .collect(toList())) { @@ -120,6 +128,20 @@ public class GrantService { } grantDto.getRemovedDeadlineIds().forEach(deadlineService::remove); grantRepository.save(copyFromDto(grant, grantDto)); + + grant.getAuthors().forEach(author -> { + if (!oldAuthors.contains(author)) { + grantNotificationService.sendAuthorsChangeNotification(grant, oldAuthors); + } + }); + oldAuthors.forEach(oldAuthor -> { + if (!grant.getAuthors().contains(oldAuthor)) { + grantNotificationService.sendAuthorsChangeNotification(grant, oldAuthors); + } + }); + if (grant.getLeader() != oldLeader) { + grantNotificationService.sendLeaderChangeNotification(grant, oldLeader); + } eventService.updateGrantDeadlines(grant); return grant.getId(); } @@ -148,6 +170,7 @@ public class GrantService { grant = grantRepository.save(grant); eventService.createFromGrant(grant); + grantNotificationService.sendCreateNotification(grant); return grant; } @@ -222,7 +245,6 @@ public class GrantService { .filter(paper -> paper.getAuthors() != null) .flatMap(paper -> paper.getAuthors().stream()) .collect(toList()); - } private List getBAKAuthors() {