From 43740981f2b7335ff76aa6450957bf40d6bce4e2 Mon Sep 17 00:00:00 2001 From: Alyona Date: Sat, 27 Oct 2018 22:24:10 +0400 Subject: [PATCH 1/8] add deadlineDate to models --- src/main/java/ru/ulstu/paper/model/Paper.java | 11 +++++++++++ src/main/java/ru/ulstu/paper/model/PaperDto.java | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index ad6950a..77b8e0c 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -37,6 +37,9 @@ public class Paper extends BaseEntity { @Column(name = "update_date") private Date updateDate; + @Column(name = "deadline_date") + private Date deadlineDate; + private String comment; private Boolean locked; @@ -72,6 +75,14 @@ public class Paper extends BaseEntity { this.updateDate = updateDate; } + public Date getDeadlineDate() { + return deadlineDate; + } + + public void setDeadlineDate(Date deadlineDate) { + this.deadlineDate = deadlineDate; + } + public String getComment() { return comment; } diff --git a/src/main/java/ru/ulstu/paper/model/PaperDto.java b/src/main/java/ru/ulstu/paper/model/PaperDto.java index d7fb8f2..aeb4e3f 100644 --- a/src/main/java/ru/ulstu/paper/model/PaperDto.java +++ b/src/main/java/ru/ulstu/paper/model/PaperDto.java @@ -15,6 +15,7 @@ public class PaperDto { private final Paper.PaperStatus status; private final Date createDate; private final Date updateDate; + private final Date deadlineDate; private final String comment; private final Boolean locked; private final String tmpFileName; @@ -29,6 +30,7 @@ public class PaperDto { @JsonProperty("status") Paper.PaperStatus status, @JsonProperty("createDate") Date createDate, @JsonProperty("updateDate") Date updateDate, + @JsonProperty("deadlineDate") Date deadlineDate, @JsonProperty("comment") String comment, @JsonProperty("locked") Boolean locked, @JsonProperty("tmpFileName") String tmpFileName, @@ -38,6 +40,7 @@ public class PaperDto { this.status = status; this.createDate = createDate; this.updateDate = updateDate; + this.deadlineDate = deadlineDate; this.comment = comment; this.locked = locked; this.tmpFileName = tmpFileName; @@ -53,6 +56,7 @@ public class PaperDto { this.status = paper.getStatus(); this.createDate = paper.getCreateDate(); this.updateDate = paper.getUpdateDate(); + this.deadlineDate = paper.getDeadlineDate(); this.comment = paper.getComment(); this.locked = paper.getLocked(); this.tmpFileName = null; @@ -82,6 +86,8 @@ public class PaperDto { return updateDate; } + public Date getDeadlineDate() {return deadlineDate;} + public String getComment() { return comment; } From 61c19e5b87d6919f4bdd04d4db78468a366e954c Mon Sep 17 00:00:00 2001 From: Alyona Date: Sat, 27 Oct 2018 22:32:51 +0400 Subject: [PATCH 2/8] =?UTF-8?q?add=20deadlineS=D1=81heduler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../paper/service/DeadlineSсheduler.java | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/main/java/ru/ulstu/paper/service/DeadlineSсheduler.java diff --git a/src/main/java/ru/ulstu/paper/service/DeadlineSсheduler.java b/src/main/java/ru/ulstu/paper/service/DeadlineSсheduler.java new file mode 100644 index 0000000..d1810f4 --- /dev/null +++ b/src/main/java/ru/ulstu/paper/service/DeadlineSсheduler.java @@ -0,0 +1,70 @@ +package ru.ulstu.paper.service; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.Scheduled; +import ru.ulstu.core.util.DateUtils; +import ru.ulstu.paper.model.PaperDto; +import ru.ulstu.paper.repository.PaperRepository; +import ru.ulstu.paper.service.PaperService; +import ru.ulstu.paper.model.Paper; +import ru.ulstu.user.model.User; +import ru.ulstu.user.model.UserDto; +import ru.ulstu.user.repository.UserRepository; +import ru.ulstu.user.scheduler.UserScheduler; +import ru.ulstu.user.service.MailService; + +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; +import java.util.Calendar; +import java.util.List; + +public class DeadlineSсheduler { + + private final Logger log = LoggerFactory.getLogger(UserScheduler.class); + + private final PaperRepository paperRepository; + private final MailService mailService; + + public DeadlineSсheduler(PaperRepository paperRepository, MailService mailService) { + this.paperRepository = paperRepository; + this.mailService = mailService; + } + + @Scheduled(cron = "0 0 8 * 1 ?") + public void sendMessageDeadlineBeforeWeek() { + log.debug("DeadlineSсheduler.sendMessageDeadlineBeforeWeek started"); + List allPapers = paperRepository.findAll(); + for (Paper element: allPapers) { + Calendar c = Calendar.getInstance(); + c.add(Calendar.DAY_OF_YEAR, 7); + if(c.getTime().compareTo(element.getDeadlineDate()) < 0 ) { + List users = element.getAuthors(); + for (User user : users) { + mailService.sendEmail(user.getEmail(), "Приближается срок сдачи статьи", + "Срок сдачи статьи " + element.getTitle() + " " + element.getDeadlineDate().toString()); + } + } + } + log.debug("DeadlineSсheduler.sendMessageDeadlineBeforeWeek finished"); + } + @Scheduled(cron = "0 0 8 * * ?") + public void sendMessageDeadlineAfterWeek() { + log.debug("DeadlineSсheduler.sendMessageDeadlineAfterWeek started"); + List allPapers = paperRepository.findAll(); + for (Paper element: allPapers) { + Calendar c = Calendar.getInstance(); + c.add(Calendar.DAY_OF_YEAR, 7); + if(c.getTime().compareTo(element.getDeadlineDate()) >= 0 ) { + List users = element.getAuthors(); + for (User user : users) { + mailService.sendEmail(user.getEmail(), "Приближается срок сдачи статьи", + "Срок сдачи статьи " + element.getTitle() + " " + element.getDeadlineDate().toString()); + } + } + } + log.debug("DeadlineSсheduler.sendMessageDeadlineAfterWeek finished"); + } +} From 7388b2cb274a95ca878038dc72f52423775b35a6 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 27 Oct 2018 23:16:14 +0400 Subject: [PATCH 3/8] add database column --- .../db/changelog-20181027_000000-schema.xml | 13 +++++++++++++ src/main/resources/db/changelog-master.xml | 1 + 2 files changed, 14 insertions(+) create mode 100644 src/main/resources/db/changelog-20181027_000000-schema.xml diff --git a/src/main/resources/db/changelog-20181027_000000-schema.xml b/src/main/resources/db/changelog-20181027_000000-schema.xml new file mode 100644 index 0000000..99c50e4 --- /dev/null +++ b/src/main/resources/db/changelog-20181027_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 4faae2e..776b2bb 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -11,4 +11,5 @@ + \ No newline at end of file From afd854e0cb68f614bf6a945b3190693440b9fe79 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 27 Oct 2018 23:25:27 +0400 Subject: [PATCH 4/8] - make scheduler as a service - reformat code - fix cyrillic letter --- ...Sсheduler.java => DeadlineScheduler.java} | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) rename src/main/java/ru/ulstu/paper/service/{DeadlineSсheduler.java => DeadlineScheduler.java} (71%) diff --git a/src/main/java/ru/ulstu/paper/service/DeadlineSсheduler.java b/src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java similarity index 71% rename from src/main/java/ru/ulstu/paper/service/DeadlineSсheduler.java rename to src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java index d1810f4..e1e15c0 100644 --- a/src/main/java/ru/ulstu/paper/service/DeadlineSсheduler.java +++ b/src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java @@ -3,32 +3,25 @@ package ru.ulstu.paper.service; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.scheduling.annotation.Scheduled; -import ru.ulstu.core.util.DateUtils; -import ru.ulstu.paper.model.PaperDto; -import ru.ulstu.paper.repository.PaperRepository; -import ru.ulstu.paper.service.PaperService; +import org.springframework.stereotype.Service; import ru.ulstu.paper.model.Paper; +import ru.ulstu.paper.repository.PaperRepository; import ru.ulstu.user.model.User; -import ru.ulstu.user.model.UserDto; -import ru.ulstu.user.repository.UserRepository; import ru.ulstu.user.scheduler.UserScheduler; import ru.ulstu.user.service.MailService; -import java.time.Instant; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.time.temporal.ChronoUnit; import java.util.Calendar; import java.util.List; -public class DeadlineSсheduler { +@Service +public class DeadlineScheduler { private final Logger log = LoggerFactory.getLogger(UserScheduler.class); private final PaperRepository paperRepository; private final MailService mailService; - public DeadlineSсheduler(PaperRepository paperRepository, MailService mailService) { + public DeadlineScheduler(PaperRepository paperRepository, MailService mailService) { this.paperRepository = paperRepository; this.mailService = mailService; } @@ -37,31 +30,32 @@ public class DeadlineSсheduler { public void sendMessageDeadlineBeforeWeek() { log.debug("DeadlineSсheduler.sendMessageDeadlineBeforeWeek started"); List allPapers = paperRepository.findAll(); - for (Paper element: allPapers) { + for (Paper element : allPapers) { Calendar c = Calendar.getInstance(); c.add(Calendar.DAY_OF_YEAR, 7); - if(c.getTime().compareTo(element.getDeadlineDate()) < 0 ) { + if (c.getTime().compareTo(element.getDeadlineDate()) < 0) { List users = element.getAuthors(); for (User user : users) { mailService.sendEmail(user.getEmail(), "Приближается срок сдачи статьи", - "Срок сдачи статьи " + element.getTitle() + " " + element.getDeadlineDate().toString()); + "Срок сдачи статьи " + element.getTitle() + " " + element.getDeadlineDate().toString()); } } } log.debug("DeadlineSсheduler.sendMessageDeadlineBeforeWeek finished"); } + @Scheduled(cron = "0 0 8 * * ?") public void sendMessageDeadlineAfterWeek() { log.debug("DeadlineSсheduler.sendMessageDeadlineAfterWeek started"); List allPapers = paperRepository.findAll(); - for (Paper element: allPapers) { + for (Paper element : allPapers) { Calendar c = Calendar.getInstance(); c.add(Calendar.DAY_OF_YEAR, 7); - if(c.getTime().compareTo(element.getDeadlineDate()) >= 0 ) { + if (c.getTime().compareTo(element.getDeadlineDate()) >= 0) { List users = element.getAuthors(); for (User user : users) { mailService.sendEmail(user.getEmail(), "Приближается срок сдачи статьи", - "Срок сдачи статьи " + element.getTitle() + " " + element.getDeadlineDate().toString()); + "Срок сдачи статьи " + element.getTitle() + " " + element.getDeadlineDate().toString()); } } } From 92f86e70c9e15e43ccb091e454c44d2a709f91d1 Mon Sep 17 00:00:00 2001 From: Alyona Date: Sat, 27 Oct 2018 23:46:49 +0400 Subject: [PATCH 5/8] fix --- .../paper/service/DeadlineScheduler.java | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java b/src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java index e1e15c0..139dc74 100644 --- a/src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java +++ b/src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java @@ -27,38 +27,37 @@ public class DeadlineScheduler { } @Scheduled(cron = "0 0 8 * 1 ?") - public void sendMessageDeadlineBeforeWeek() { - log.debug("DeadlineSсheduler.sendMessageDeadlineBeforeWeek started"); + public void checkDeadlineBeforeWeek() { + log.debug("DeadlineScheduler.checkDeadlineBeforeWeek started"); List allPapers = paperRepository.findAll(); - for (Paper element : allPapers) { + for (Paper paper : allPapers) { Calendar c = Calendar.getInstance(); c.add(Calendar.DAY_OF_YEAR, 7); - if (c.getTime().compareTo(element.getDeadlineDate()) < 0) { - List users = element.getAuthors(); - for (User user : users) { - mailService.sendEmail(user.getEmail(), "Приближается срок сдачи статьи", - "Срок сдачи статьи " + element.getTitle() + " " + element.getDeadlineDate().toString()); - } + if (c.getTime().compareTo(paper.getDeadlineDate()) < 0) { + sendMessageDeadline(paper); } } - log.debug("DeadlineSсheduler.sendMessageDeadlineBeforeWeek finished"); + log.debug("DeadlineScheduler.checkDeadlineBeforeWeek finished"); } @Scheduled(cron = "0 0 8 * * ?") - public void sendMessageDeadlineAfterWeek() { - log.debug("DeadlineSсheduler.sendMessageDeadlineAfterWeek started"); + public void checkDeadlineAfterWeek() { + log.debug("DeadlineScheduler.checkDeadlineAfterWeek started"); List allPapers = paperRepository.findAll(); - for (Paper element : allPapers) { + for (Paper paper : allPapers) { Calendar c = Calendar.getInstance(); c.add(Calendar.DAY_OF_YEAR, 7); - if (c.getTime().compareTo(element.getDeadlineDate()) >= 0) { - List users = element.getAuthors(); - for (User user : users) { - mailService.sendEmail(user.getEmail(), "Приближается срок сдачи статьи", - "Срок сдачи статьи " + element.getTitle() + " " + element.getDeadlineDate().toString()); - } + if (c.getTime().compareTo(paper.getDeadlineDate()) >= 0) { + sendMessageDeadline(paper); } } - log.debug("DeadlineSсheduler.sendMessageDeadlineAfterWeek finished"); + log.debug("DeadlineScheduler.checkDeadlineAfterWeek finished"); + } + + private void sendMessageDeadline(Paper paper){ + for (User user : paper.getAuthors()) { + mailService.sendEmail(user.getEmail(), "Приближается срок сдачи статьи", + "Срок сдачи статьи " + paper.getTitle() + " " + paper.getDeadlineDate().toString()); + } } } From d0f40da30ea20be028ac5af4ba8737dea34f65f6 Mon Sep 17 00:00:00 2001 From: Alyona Date: Sat, 27 Oct 2018 23:50:12 +0400 Subject: [PATCH 6/8] fix --- src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java b/src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java index 139dc74..45260cc 100644 --- a/src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java +++ b/src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java @@ -16,7 +16,7 @@ import java.util.List; @Service public class DeadlineScheduler { - private final Logger log = LoggerFactory.getLogger(UserScheduler.class); + private final Logger log = LoggerFactory.getLogger(DeadlineScheduler.class); private final PaperRepository paperRepository; private final MailService mailService; From 450cb92d012b0d10325a8d660aef7c38fc071577 Mon Sep 17 00:00:00 2001 From: Alyona Date: Sun, 28 Oct 2018 00:15:42 +0400 Subject: [PATCH 7/8] fix --- .../paper/service/DeadlineScheduler.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java b/src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java index 45260cc..63b1fa0 100644 --- a/src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java +++ b/src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java @@ -25,33 +25,32 @@ public class DeadlineScheduler { this.paperRepository = paperRepository; this.mailService = mailService; } + private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true; @Scheduled(cron = "0 0 8 * 1 ?") public void checkDeadlineBeforeWeek() { log.debug("DeadlineScheduler.checkDeadlineBeforeWeek started"); - List allPapers = paperRepository.findAll(); - for (Paper paper : allPapers) { - Calendar c = Calendar.getInstance(); - c.add(Calendar.DAY_OF_YEAR, 7); - if (c.getTime().compareTo(paper.getDeadlineDate()) < 0) { - sendMessageDeadline(paper); - } - } + sendNotifications(IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); log.debug("DeadlineScheduler.checkDeadlineBeforeWeek finished"); } @Scheduled(cron = "0 0 8 * * ?") public void checkDeadlineAfterWeek() { log.debug("DeadlineScheduler.checkDeadlineAfterWeek started"); + sendNotifications(!IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); + log.debug("DeadlineScheduler.checkDeadlineAfterWeek finished"); + } + + private void sendNotifications(boolean isDeadlineBeforeWeek) { List allPapers = paperRepository.findAll(); for (Paper paper : allPapers) { Calendar c = Calendar.getInstance(); c.add(Calendar.DAY_OF_YEAR, 7); - if (c.getTime().compareTo(paper.getDeadlineDate()) >= 0) { - sendMessageDeadline(paper); + if (((c.getTime().compareTo(paper.getDeadlineDate()) < 0) && isDeadlineBeforeWeek) || + (c.getTime().compareTo(paper.getDeadlineDate()) >= 0) && !isDeadlineBeforeWeek) { + sendMessageDeadline(paper); } } - log.debug("DeadlineScheduler.checkDeadlineAfterWeek finished"); } private void sendMessageDeadline(Paper paper){ From d1e6e80f87fd552bec17274cab30cdc3363ad01e Mon Sep 17 00:00:00 2001 From: Alyona Date: Sun, 28 Oct 2018 00:17:16 +0400 Subject: [PATCH 8/8] fix --- src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java b/src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java index 63b1fa0..da1f2bf 100644 --- a/src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java +++ b/src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java @@ -19,13 +19,16 @@ public class DeadlineScheduler { private final Logger log = LoggerFactory.getLogger(DeadlineScheduler.class); private final PaperRepository paperRepository; + private final MailService mailService; + private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true; + public DeadlineScheduler(PaperRepository paperRepository, MailService mailService) { this.paperRepository = paperRepository; this.mailService = mailService; } - private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true; + @Scheduled(cron = "0 0 8 * 1 ?") public void checkDeadlineBeforeWeek() {