From 0892d5786f53f728c14faa23e33d3a47eee46a63 Mon Sep 17 00:00:00 2001 From: upagge Date: Sun, 20 Sep 2020 22:18:45 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=83=D0=B2=D0=B5=D0=B4=D0=BE=D0=BC=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v.2.0.0/2020-09-06-cumulative.xml | 1 + .../v.2.0.0/2020-09-20-setting-notify.xml | 18 ++++ bitbucket-app/src/main/resources/logback.xml | 2 +- .../vcs/core/domain/entity/NotifySetting.java | 39 +++++++ .../notify/GoodMorningNotify.java} | 96 ++++++++--------- .../bot/vcs/core/domain/notify/Notify.java | 17 +-- .../vcs/core/domain/notify/NotifyType.java | 17 --- .../core/domain/notify/SimpleTextNotify.java | 28 +++++ .../notify/comment/AnswerCommentNotify.java | 6 +- .../domain/notify/comment/CommentNotify.java | 6 +- .../notify/pullrequest/ConflictPrNotify.java | 6 +- .../notify/pullrequest/NewPrNotify.java | 6 +- .../domain/notify/pullrequest/PrNotify.java | 5 +- .../notify/pullrequest/ReviewersPrNotify.java | 6 +- .../notify/pullrequest/StatusPrNotify.java | 5 +- .../notify/pullrequest/UpdatePrNotify.java | 5 +- .../domain/notify/task/TaskCloseNotify.java | 5 +- .../domain/notify/task/TaskNewNotify.java | 5 +- .../core/domain/notify/task/TaskNotify.java | 6 +- .../vcs/core/repository/NotifyRepository.java | 16 --- .../repository/NotifySettingRepository.java | 20 ++++ .../repository/impl/NotifyRepositoryImpl.java | 35 ------ .../impl/NotifySettingRepositoryImpl.java | 38 +++++++ .../jpa/NotifySettingJpaRepository.java | 23 ++++ .../core/scheduler/NotificationScheduler.java | 67 +++++++----- .../scheduler/NotifyParsingScheduler.java | 49 --------- .../vcs/core/service/MessageSendService.java | 5 +- .../bot/vcs/core/service/NotifyService.java | 17 ++- .../core/service/impl/CommentServiceImpl.java | 21 ++-- .../core/service/impl/NotifyServiceImpl.java | 29 +++-- .../core/service/impl/PersonServiceImpl.java | 28 ++++- .../service/impl/PullRequestsServiceImpl.java | 67 ++++++------ .../core/service/impl/TaskServiceImpl.java | 43 +++----- .../bot/vcs/core/utils/MessageUtils.java | 47 ++++++++ .../service/MessageSendTelegramService.java | 15 ++- .../service/MessageSendTestService.java | 22 ---- .../service/unit/PullRequestProcessing.java | 33 ++---- .../vcs/telegram/unit/NotifySettingUnit.java | 101 ++++++++++++++++++ .../bot/vcs/telegram/unit/UnitConfig.java | 27 ++++- .../telegram/utils/GeneratorKeyBoards.java | 37 +++++++ 40 files changed, 622 insertions(+), 397 deletions(-) create mode 100644 bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-09-20-setting-notify.xml create mode 100644 bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/entity/NotifySetting.java rename bot-core/src/main/java/org/sadtech/bot/vcs/core/{utils/Message.java => domain/notify/GoodMorningNotify.java} (51%) delete mode 100644 bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/NotifyType.java create mode 100644 bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/SimpleTextNotify.java delete mode 100644 bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/NotifyRepository.java create mode 100644 bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/NotifySettingRepository.java delete mode 100644 bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/impl/NotifyRepositoryImpl.java create mode 100644 bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/impl/NotifySettingRepositoryImpl.java create mode 100644 bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/jpa/NotifySettingJpaRepository.java delete mode 100644 bot-core/src/main/java/org/sadtech/bot/vcs/core/scheduler/NotifyParsingScheduler.java create mode 100644 bot-core/src/main/java/org/sadtech/bot/vcs/core/utils/MessageUtils.java delete mode 100644 telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/MessageSendTestService.java create mode 100644 telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/unit/NotifySettingUnit.java create mode 100644 telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/utils/GeneratorKeyBoards.java diff --git a/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-09-06-cumulative.xml b/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-09-06-cumulative.xml index 2ff2041..bf73835 100644 --- a/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-09-06-cumulative.xml +++ b/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-09-06-cumulative.xml @@ -5,5 +5,6 @@ + \ No newline at end of file diff --git a/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-09-20-setting-notify.xml b/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-09-20-setting-notify.xml new file mode 100644 index 0000000..c58f977 --- /dev/null +++ b/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-09-20-setting-notify.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/bitbucket-app/src/main/resources/logback.xml b/bitbucket-app/src/main/resources/logback.xml index 0335154..e106cf3 100644 --- a/bitbucket-app/src/main/resources/logback.xml +++ b/bitbucket-app/src/main/resources/logback.xml @@ -18,7 +18,7 @@ - + \ No newline at end of file diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/entity/NotifySetting.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/entity/NotifySetting.java new file mode 100644 index 0000000..22c5cad --- /dev/null +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/entity/NotifySetting.java @@ -0,0 +1,39 @@ +package org.sadtech.bot.vcs.core.domain.entity; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import java.time.LocalDateTime; + +/** + * // TODO: 20.09.2020 Добавить описание. + * + * @author upagge 20.09.2020 + */ +@Getter +@Setter +@Entity +@Table(name = "setting_notify") +@EqualsAndHashCode(onlyExplicitlyIncluded = true) +public class NotifySetting { + + /** + * Логин пользователя, которому принадлежат настройки + */ + @Id + @Column(name = "login") + @EqualsAndHashCode.Include + private String login; + + /** + * Дата, после которой пользователю будут поступать уведомления. + */ + @Column(name = "start_receiving") + private LocalDateTime startReceiving; + +} diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/utils/Message.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/GoodMorningNotify.java similarity index 51% rename from bot-core/src/main/java/org/sadtech/bot/vcs/core/utils/Message.java rename to bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/GoodMorningNotify.java index 33d8527..7b1b662 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/utils/Message.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/GoodMorningNotify.java @@ -1,59 +1,39 @@ -package org.sadtech.bot.vcs.core.utils; +package org.sadtech.bot.vcs.core.domain.notify; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; +import lombok.Builder; +import lombok.Getter; import lombok.NonNull; import org.sadtech.bot.vcs.core.domain.entity.PullRequest; +import org.sadtech.bot.vcs.core.utils.MessageUtils; +import org.sadtech.bot.vcs.core.utils.Smile; +import org.sadtech.bot.vcs.core.utils.UpdateDataComparator; -import java.time.LocalDate; import java.util.List; -import java.util.stream.Collectors; +import java.util.Set; /** - * Генерирует сообщения для отправки. + * // TODO: 20.09.2020 Добавить описание. * - * @author upagge [07.02.2020] + * @author upagge 20.09.2020 */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class Message { +@Getter +public class GoodMorningNotify extends Notify { private static final UpdateDataComparator COMPARATOR = new UpdateDataComparator(); private static final Integer PR_COUNT = 4; - private static final String DONATION_LINK = "https://www.tinkoff.ru/sl/1T9s4esiMf"; - @NonNull - public static String goodMorningStatistic(List pullRequestsReviews, List pullRequestsNeedWork) { - StringBuilder message = new StringBuilder().append(Smile.SUN).append(" *Доброе утро* ").append(Smile.SUN).append(Smile.HR); - if (!pullRequestsReviews.isEmpty()) { - message.append("Необходимо проверить ").append(pullRequestsReviews.size()).append(" ПР!").append(Smile.TWO_BR) - .append("Самые старые:").append(Smile.BR); - List oldPr = pullRequestsReviews.stream() - .sorted(COMPARATOR) - .limit(PR_COUNT) - .collect(Collectors.toList()); - oldPr.forEach(pullRequest -> message.append(topPr(pullRequest))); - } else { - message.append("Ты либо самый лучший работник, либо тебе не доверяют проверку ПР ").append(Smile.MEGA_FUN).append(Smile.TWO_BR) - .append("Поздравляю, у тебя ни одного ПР на проверку!").append(Smile.BR); - } - if (!pullRequestsNeedWork.isEmpty()) { - message.append(Smile.BR).append(Smile.DANGEROUS).append("Требуется доработать ").append(pullRequestsNeedWork.size()).append(" ПР:").append(Smile.BR); - message.append(needWorkPr(pullRequestsNeedWork)).append(Smile.BR); - } - if (dayX()) { - message.append(Smile.BR).append(Smile.FUN).append(" Кстати, поздравляю, сегодня день З/П").append(Smile.BR) - .append(Smile.DANGEROUS).append("Хостинг оплачен до 5 октября! Прошу неравнодушных ").append(link("задонатить", DONATION_LINK)) - .append(Smile.BR); - } - message - .append(Smile.BR).append("Удачного дня ").append(Smile.FLOWER).append(Smile.TWO_BR); - return message.toString(); - } + private final List pullRequestsReviews; + private final List pullRequestsNeedWork; - @NonNull - public static String goodWeekEnd() { - return "Ну вот и все! Веселых выходных " + Smile.MIG + Smile.BR + - "До понедельника" + Smile.BUY + Smile.TWO_BR; + @Builder + protected GoodMorningNotify( + Set logins, + List pullRequestsReviews, + List pullRequestsNeedWork + ) { + super(logins); + this.pullRequestsReviews = pullRequestsReviews; + this.pullRequestsNeedWork = pullRequestsNeedWork; } private static String needWorkPr(@NonNull List pullRequestsNeedWork) { @@ -66,20 +46,28 @@ public final class Message { return message.toString(); } - private static String topPr(PullRequest pullRequest) { - return Smile.statusPr(pullRequest.getUpdateDate()) + " " + - link(pullRequest.getTitle(), pullRequest.getUrl()) + - Smile.BR; - } - - private static boolean dayX() { - int dayOfMonth = LocalDate.now().getDayOfMonth(); - return dayOfMonth == 20 || dayOfMonth == 5; - } - - @NonNull private static String link(String name, String url) { return "[" + name + "](" + url + ")"; } + @Override + public String generateMessage() { + StringBuilder message = new StringBuilder().append(Smile.SUN).append(" *Доброе утро* ").append(Smile.SUN).append(Smile.HR); + if (!pullRequestsReviews.isEmpty()) { + message.append("Необходимо проверить ").append(pullRequestsReviews.size()).append(" ПР!").append(Smile.TWO_BR) + .append("Самые старые:").append(Smile.BR) + .append(MessageUtils.pullRequestForReview(pullRequestsReviews)); + } else { + message.append("Ты либо самый лучший работник, либо тебе не доверяют проверку ПР ").append(Smile.MEGA_FUN).append(Smile.TWO_BR) + .append("Поздравляю, у тебя ни одного ПР на проверку!").append(Smile.BR); + } + if (!pullRequestsNeedWork.isEmpty()) { + message.append(Smile.BR).append(Smile.DANGEROUS).append("Требуется доработать ").append(pullRequestsNeedWork.size()).append(" ПР:").append(Smile.BR); + message.append(needWorkPr(pullRequestsNeedWork)).append(Smile.BR); + } + message + .append(Smile.BR).append("Удачного дня ").append(Smile.FLOWER).append(Smile.TWO_BR); + return message.toString(); + } + } diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/Notify.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/Notify.java index 24bcc56..4663f5c 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/Notify.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/Notify.java @@ -1,27 +1,18 @@ package org.sadtech.bot.vcs.core.domain.notify; -import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; -import java.time.LocalDateTime; import java.util.Set; @Getter -@EqualsAndHashCode(onlyExplicitlyIncluded = true) +@Setter public abstract class Notify { - protected final NotifyType type; - protected final LocalDateTime localDateTime = LocalDateTime.now(); - protected final Set telegramIds; + protected Set logins; - @Setter - @EqualsAndHashCode.Include - protected Long id; - - protected Notify(NotifyType type, Set telegramIds) { - this.type = type; - this.telegramIds = telegramIds; + protected Notify(Set logins) { + this.logins = logins; } public abstract String generateMessage(); diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/NotifyType.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/NotifyType.java deleted file mode 100644 index c34151a..0000000 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/NotifyType.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.sadtech.bot.vcs.core.domain.notify; - -public enum NotifyType { - - STATUS_PR, - UPDATE_PR, - REVIEWERS, - NEW_PR, - CONFLICT_PR, - NEW_COMMENT, - NEW_ANSWERS_COMMENT, - NEW_TASK, - DELETED_TASK, - RESOLVED_TASK, - OPEN_TASK; - -} diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/SimpleTextNotify.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/SimpleTextNotify.java new file mode 100644 index 0000000..52f73cc --- /dev/null +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/SimpleTextNotify.java @@ -0,0 +1,28 @@ +package org.sadtech.bot.vcs.core.domain.notify; + +import lombok.Builder; +import lombok.Getter; + +import java.util.Set; + +/** + * // TODO: 20.09.2020 Добавить описание. + * + * @author upagge 20.09.2020 + */ +@Getter +public class SimpleTextNotify extends Notify { + + private final String message; + + @Builder + private SimpleTextNotify(Set logins, String message) { + super(logins); + this.message = message; + } + + @Override + public String generateMessage() { + return message; + } +} diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/comment/AnswerCommentNotify.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/comment/AnswerCommentNotify.java index c80fd1a..8da6266 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/comment/AnswerCommentNotify.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/comment/AnswerCommentNotify.java @@ -5,7 +5,6 @@ import lombok.EqualsAndHashCode; import lombok.Getter; import org.sadtech.bot.vcs.core.domain.Answer; import org.sadtech.bot.vcs.core.domain.notify.Notify; -import org.sadtech.bot.vcs.core.domain.notify.NotifyType; import org.sadtech.bot.vcs.core.utils.Smile; import java.text.MessageFormat; @@ -23,12 +22,12 @@ public class AnswerCommentNotify extends Notify { @Builder protected AnswerCommentNotify( - Set telegramIds, + Set logins, String youMessage, String url, List answers ) { - super(NotifyType.NEW_ANSWERS_COMMENT, telegramIds); + super(logins); this.youMessage = youMessage; this.url = url; this.answers = answers; @@ -46,4 +45,5 @@ public class AnswerCommentNotify extends Notify { Smile.BELL, url, Smile.HR, youMessage.substring(0, Math.min(youMessage.length(), 180)), Smile.HR, answerText ); } + } diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/comment/CommentNotify.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/comment/CommentNotify.java index df08609..01abb51 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/comment/CommentNotify.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/comment/CommentNotify.java @@ -4,7 +4,6 @@ import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; import org.sadtech.bot.vcs.core.domain.notify.Notify; -import org.sadtech.bot.vcs.core.domain.notify.NotifyType; import org.sadtech.bot.vcs.core.utils.Smile; import java.text.MessageFormat; @@ -20,12 +19,12 @@ public class CommentNotify extends Notify { @Builder private CommentNotify( - Set telegramIds, + Set logins, String url, String authorName, String message ) { - super(NotifyType.NEW_COMMENT, telegramIds); + super(logins); this.authorName = authorName; this.message = message; this.url = url; @@ -39,6 +38,7 @@ public class CommentNotify extends Notify { Smile.BELL, url, Smile.HR, authorName, message.replaceAll("@[\\w]+", "") ); } + } diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/pullrequest/ConflictPrNotify.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/pullrequest/ConflictPrNotify.java index 39ffce0..4eb3dae 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/pullrequest/ConflictPrNotify.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/pullrequest/ConflictPrNotify.java @@ -2,7 +2,6 @@ package org.sadtech.bot.vcs.core.domain.notify.pullrequest; import lombok.Builder; import lombok.Getter; -import org.sadtech.bot.vcs.core.domain.notify.NotifyType; import org.sadtech.bot.vcs.core.utils.Smile; import java.text.MessageFormat; @@ -13,11 +12,11 @@ public class ConflictPrNotify extends PrNotify { @Builder private ConflictPrNotify( - Set telegramIds, + Set logins, String name, String url ) { - super(NotifyType.CONFLICT_PR, telegramIds, name, url); + super(logins, name, url); } @Override @@ -29,4 +28,5 @@ public class ConflictPrNotify extends PrNotify { Smile.DANGEROUS, Smile.HR, title, url ); } + } diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/pullrequest/NewPrNotify.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/pullrequest/NewPrNotify.java index 6b9374b..1d67a42 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/pullrequest/NewPrNotify.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/pullrequest/NewPrNotify.java @@ -3,7 +3,6 @@ package org.sadtech.bot.vcs.core.domain.notify.pullrequest; import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; -import org.sadtech.bot.vcs.core.domain.notify.NotifyType; import org.sadtech.bot.vcs.core.utils.Smile; import java.text.MessageFormat; @@ -18,12 +17,12 @@ public class NewPrNotify extends PrNotify { @Builder private NewPrNotify( - Set telegramIds, + Set logins, String title, String url, String description, String author) { - super(NotifyType.NEW_PR, telegramIds, title, url); + super(logins, title, url); this.description = description; this.author = author; } @@ -39,4 +38,5 @@ public class NewPrNotify extends PrNotify { Smile.AUTHOR, author ); } + } diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/pullrequest/PrNotify.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/pullrequest/PrNotify.java index c3f5f14..4bf3999 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/pullrequest/PrNotify.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/pullrequest/PrNotify.java @@ -3,7 +3,6 @@ package org.sadtech.bot.vcs.core.domain.notify.pullrequest; import lombok.EqualsAndHashCode; import lombok.Getter; import org.sadtech.bot.vcs.core.domain.notify.Notify; -import org.sadtech.bot.vcs.core.domain.notify.NotifyType; import java.util.Set; @@ -14,8 +13,8 @@ public abstract class PrNotify extends Notify { protected final String title; protected final String url; - protected PrNotify(NotifyType type, Set telegramIds, String title, String url) { - super(type, telegramIds); + protected PrNotify(Set logins, String title, String url) { + super(logins); this.title = title; this.url = url; } diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/pullrequest/ReviewersPrNotify.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/pullrequest/ReviewersPrNotify.java index 929645d..e456279 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/pullrequest/ReviewersPrNotify.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/pullrequest/ReviewersPrNotify.java @@ -3,7 +3,6 @@ package org.sadtech.bot.vcs.core.domain.notify.pullrequest; import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; -import org.sadtech.bot.vcs.core.domain.notify.NotifyType; import org.sadtech.bot.vcs.core.domain.util.ReviewerChange; import org.sadtech.bot.vcs.core.utils.Smile; @@ -24,11 +23,11 @@ public class ReviewersPrNotify extends PrNotify { @Builder private ReviewersPrNotify( - Set telegramIds, + Set logins, String title, String url, List reviewerChanges) { - super(NotifyType.REVIEWERS, telegramIds, title, url); + super(logins, title, url); this.reviewerChanges = reviewerChanges; } @@ -68,4 +67,5 @@ public class ReviewersPrNotify extends PrNotify { "[" + title + "](" + url + ")" + Smile.HR + createMessage; } + } diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/pullrequest/StatusPrNotify.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/pullrequest/StatusPrNotify.java index bda9414..03530a5 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/pullrequest/StatusPrNotify.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/pullrequest/StatusPrNotify.java @@ -4,7 +4,6 @@ import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; import org.sadtech.bot.vcs.core.domain.PullRequestStatus; -import org.sadtech.bot.vcs.core.domain.notify.NotifyType; import org.sadtech.bot.vcs.core.utils.Smile; import java.text.MessageFormat; @@ -19,12 +18,12 @@ public class StatusPrNotify extends PrNotify { @Builder private StatusPrNotify( - Set telegramIds, + Set logins, String name, String url, PullRequestStatus oldStatus, PullRequestStatus newStatus) { - super(NotifyType.STATUS_PR, telegramIds, name, url); + super(logins, name, url); this.oldStatus = oldStatus; this.newStatus = newStatus; } diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/pullrequest/UpdatePrNotify.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/pullrequest/UpdatePrNotify.java index faa4b42..85ace16 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/pullrequest/UpdatePrNotify.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/pullrequest/UpdatePrNotify.java @@ -3,7 +3,6 @@ package org.sadtech.bot.vcs.core.domain.notify.pullrequest; import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; -import org.sadtech.bot.vcs.core.domain.notify.NotifyType; import org.sadtech.bot.vcs.core.utils.Smile; import java.text.MessageFormat; @@ -17,10 +16,10 @@ public class UpdatePrNotify extends PrNotify { @Builder private UpdatePrNotify( - Set telegramIds, + Set logins, String name, String url, String author) { - super(NotifyType.UPDATE_PR, telegramIds, name, url); + super(logins, name, url); this.author = author; } diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/task/TaskCloseNotify.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/task/TaskCloseNotify.java index 84686ba..6ecef4b 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/task/TaskCloseNotify.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/task/TaskCloseNotify.java @@ -1,7 +1,6 @@ package org.sadtech.bot.vcs.core.domain.notify.task; import lombok.Builder; -import org.sadtech.bot.vcs.core.domain.notify.NotifyType; import org.sadtech.bot.vcs.core.utils.Smile; import java.text.MessageFormat; @@ -16,12 +15,12 @@ public class TaskCloseNotify extends TaskNotify { @Builder protected TaskCloseNotify( - Set telegramIds, + Set logins, String authorName, String url, String messageTask ) { - super(NotifyType.RESOLVED_TASK, telegramIds, authorName, url, messageTask); + super(logins, authorName, url, messageTask); } @Override diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/task/TaskNewNotify.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/task/TaskNewNotify.java index f7b1eec..472dab4 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/task/TaskNewNotify.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/task/TaskNewNotify.java @@ -2,7 +2,6 @@ package org.sadtech.bot.vcs.core.domain.notify.task; import lombok.Builder; import lombok.Getter; -import org.sadtech.bot.vcs.core.domain.notify.NotifyType; import org.sadtech.bot.vcs.core.utils.Smile; import java.text.MessageFormat; @@ -18,12 +17,12 @@ public class TaskNewNotify extends TaskNotify { @Builder protected TaskNewNotify( - Set telegramIds, + Set logins, String authorName, String url, String messageTask ) { - super(NotifyType.NEW_TASK, telegramIds, authorName, url, messageTask); + super(logins, authorName, url, messageTask); } @Override diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/task/TaskNotify.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/task/TaskNotify.java index 7564b7e..f6b7314 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/task/TaskNotify.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/task/TaskNotify.java @@ -3,7 +3,6 @@ package org.sadtech.bot.vcs.core.domain.notify.task; import lombok.EqualsAndHashCode; import lombok.Getter; import org.sadtech.bot.vcs.core.domain.notify.Notify; -import org.sadtech.bot.vcs.core.domain.notify.NotifyType; import java.util.Set; @@ -16,13 +15,12 @@ public abstract class TaskNotify extends Notify { protected final String messageTask; protected TaskNotify( - NotifyType type, - Set telegramIds, + Set logins, String authorName, String url, String messageTask ) { - super(type, telegramIds); + super(logins); this.authorName = authorName; this.url = url; this.messageTask = messageTask; diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/NotifyRepository.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/NotifyRepository.java deleted file mode 100644 index 90211ba..0000000 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/NotifyRepository.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sadtech.bot.vcs.core.repository; - -import lombok.NonNull; -import org.sadtech.bot.vcs.core.domain.notify.Notify; - -import java.util.List; - -public interface NotifyRepository { - - T add(@NonNull T notify); - - List getAll(); - - void deleteAll(@NonNull List notifies); - -} diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/NotifySettingRepository.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/NotifySettingRepository.java new file mode 100644 index 0000000..5d1aafc --- /dev/null +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/NotifySettingRepository.java @@ -0,0 +1,20 @@ +package org.sadtech.bot.vcs.core.repository; + +import lombok.NonNull; +import org.sadtech.basic.context.repository.SimpleManagerRepository; +import org.sadtech.bot.vcs.core.domain.entity.NotifySetting; + +import java.util.Set; + +/** + * // TODO: 20.09.2020 Добавить описание. + * + * @author upagge 20.09.2020 + */ +public interface NotifySettingRepository extends SimpleManagerRepository { + + boolean isNotification(@NonNull String login); + + Set isNotification(@NonNull Set logins); + +} diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/impl/NotifyRepositoryImpl.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/impl/NotifyRepositoryImpl.java deleted file mode 100644 index b4db0e0..0000000 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/impl/NotifyRepositoryImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.sadtech.bot.vcs.core.repository.impl; - -import lombok.NonNull; -import org.sadtech.bot.vcs.core.domain.notify.Notify; -import org.sadtech.bot.vcs.core.repository.NotifyRepository; -import org.springframework.stereotype.Repository; - -import java.util.ArrayList; -import java.util.List; - -@Repository -public class NotifyRepositoryImpl implements NotifyRepository { - - private final List list = new ArrayList<>(); - private long count = 0; - - @Override - public T add(@NonNull T notify) { - notify.setId(count++); - list.add(notify); - return notify; - } - - @Override - public List getAll() { - return new ArrayList<>(list); - } - - @Override - public void deleteAll(@NonNull List notifies) { - list.removeAll(notifies); - } - - -} diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/impl/NotifySettingRepositoryImpl.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/impl/NotifySettingRepositoryImpl.java new file mode 100644 index 0000000..610d67d --- /dev/null +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/impl/NotifySettingRepositoryImpl.java @@ -0,0 +1,38 @@ +package org.sadtech.bot.vcs.core.repository.impl; + +import lombok.NonNull; +import org.sadtech.basic.database.repository.manager.AbstractSimpleManagerRepository; +import org.sadtech.bot.vcs.core.domain.entity.NotifySetting; +import org.sadtech.bot.vcs.core.repository.NotifySettingRepository; +import org.sadtech.bot.vcs.core.repository.jpa.NotifySettingJpaRepository; +import org.springframework.stereotype.Repository; + +import java.time.LocalDateTime; +import java.util.Set; + +/** + * // TODO: 20.09.2020 Добавить описание. + * + * @author upagge 20.09.2020 + */ +@Repository +public class NotifySettingRepositoryImpl extends AbstractSimpleManagerRepository implements NotifySettingRepository { + + private final NotifySettingJpaRepository jpaRepository; + + public NotifySettingRepositoryImpl(NotifySettingJpaRepository jpaRepository) { + super(jpaRepository); + this.jpaRepository = jpaRepository; + } + + @Override + public boolean isNotification(@NonNull String login) { + return jpaRepository.findByLoginAndStartReceivingAfter(login, LocalDateTime.now()); + } + + @Override + public Set isNotification(@NonNull Set logins) { + return jpaRepository.findAllByLoginInAndStartReceivingAfter(logins, LocalDateTime.now()); + } + +} diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/jpa/NotifySettingJpaRepository.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/jpa/NotifySettingJpaRepository.java new file mode 100644 index 0000000..0c0b694 --- /dev/null +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/jpa/NotifySettingJpaRepository.java @@ -0,0 +1,23 @@ +package org.sadtech.bot.vcs.core.repository.jpa; + +import org.sadtech.bot.vcs.core.domain.entity.NotifySetting; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.time.LocalDateTime; +import java.util.Set; + +/** + * // TODO: 20.09.2020 Добавить описание. + * + * @author upagge 20.09.2020 + */ +public interface NotifySettingJpaRepository extends JpaRepository { + + boolean findByLoginAndStartReceivingAfter(String login, LocalDateTime date); + + @Query("SELECT n.login FROM NotifySetting n WHERE n.login IN :logins AND n.startReceiving < :date") + Set findAllByLoginInAndStartReceivingAfter(@Param("logins") Set logins, @Param("date") LocalDateTime date); + +} diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/scheduler/NotificationScheduler.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/scheduler/NotificationScheduler.java index b12bed1..b63db3a 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/scheduler/NotificationScheduler.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/scheduler/NotificationScheduler.java @@ -1,15 +1,15 @@ package org.sadtech.bot.vcs.core.scheduler; import lombok.RequiredArgsConstructor; -import org.sadtech.bot.vcs.core.domain.MessageSend; import org.sadtech.bot.vcs.core.domain.PullRequestStatus; import org.sadtech.bot.vcs.core.domain.ReviewerStatus; import org.sadtech.bot.vcs.core.domain.entity.Person; import org.sadtech.bot.vcs.core.domain.entity.PullRequest; -import org.sadtech.bot.vcs.core.service.MessageSendService; +import org.sadtech.bot.vcs.core.domain.notify.GoodMorningNotify; +import org.sadtech.bot.vcs.core.domain.notify.SimpleTextNotify; +import org.sadtech.bot.vcs.core.service.NotifyService; import org.sadtech.bot.vcs.core.service.PersonService; import org.sadtech.bot.vcs.core.service.PullRequestsService; -import org.sadtech.bot.vcs.core.utils.Message; import org.sadtech.bot.vcs.core.utils.Smile; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @@ -26,13 +26,13 @@ import java.util.stream.Collectors; public class NotificationScheduler { private static final Set tksLoginNotify = new HashSet<>(Arrays.asList( - "mstruchkov", "dganin", "emukhin", "ktorgaeva", "imescheryakov", "kkeglev" + "mstruchkov", "emukhin", "ktorgaeva", "imescheryakov", "kkeglev" )); - private static final Set statuses = Collections.singleton(PullRequestStatus.OPEN); private final PersonService personService; private final PullRequestsService pullRequestsService; - private final MessageSendService messageSendService; + + private final NotifyService notifyService; // Утреннее сообщение @Scheduled(cron = "0 15 8 * * MON-FRI") @@ -42,44 +42,53 @@ public class NotificationScheduler { List pullRequestsReviews = pullRequestsService.getAllByReviewerAndStatuses( user.getLogin(), ReviewerStatus.NEEDS_WORK, - statuses + Collections.singleton(PullRequestStatus.OPEN) ); List pullRequestsNeedWork = pullRequestsService.getAllByAuthorAndReviewerStatus(user.getLogin(), ReviewerStatus.UNAPPROVED); - messageSendService.add( - MessageSend.builder() - .telegramId(user.getTelegramId()) - .message(Message.goodMorningStatistic(pullRequestsReviews, pullRequestsNeedWork)) + notifyService.send( + GoodMorningNotify.builder() + .pullRequestsNeedWork(pullRequestsNeedWork) + .pullRequestsReviews(pullRequestsReviews) + .logins(Collections.singleton(user.getLogin())) .build() ); } } - @Scheduled(cron = "0 25 10 * * MON-FRI") + @Scheduled(cron = "0 29 10 * * MON-FRI") public void tks() { List usersTks = personService.getAllRegister().stream() .filter(user -> tksLoginNotify.contains(user.getLogin())) .collect(Collectors.toList()); - for (Person person : usersTks) { - messageSendService.add( - MessageSend.builder() - .telegramId(person.getTelegramId()) - .message("☎️ Скоро созвон" + Smile.HR + "https://meet.google.com/czs-vigu-mte") - .build() - ); - } + notifyService.send( + SimpleTextNotify + .builder() + .logins( + usersTks.stream() + .map(Person::getLogin) + .collect(Collectors.toSet()) + ) + .message("☎️ Внимание созвон" + Smile.HR + "https://meet.google.com/czs-vigu-mte") + .build() + ); + } @Scheduled(cron = "0 0 18 * * FRI") public void goodWeekEnd() { List allRegister = personService.getAllRegister(); - for (Person user : allRegister) { - messageSendService.add( - MessageSend.builder() - .telegramId(user.getTelegramId()) - .message(Message.goodWeekEnd()) - .build() - ); - } + notifyService.send( + SimpleTextNotify.builder() + .message("Ну вот и все! Веселых выходных " + Smile.MIG + Smile.BR + + "До понедельника" + Smile.BUY + Smile.TWO_BR) + .logins( + allRegister.stream() + .map(Person::getLogin) + .collect(Collectors.toSet()) + ) + .build() + ); } - } + + diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/scheduler/NotifyParsingScheduler.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/scheduler/NotifyParsingScheduler.java deleted file mode 100644 index 6199dd9..0000000 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/scheduler/NotifyParsingScheduler.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.sadtech.bot.vcs.core.scheduler; - -import lombok.RequiredArgsConstructor; -import org.sadtech.bot.vcs.core.domain.MessageSend; -import org.sadtech.bot.vcs.core.domain.notify.Notify; -import org.sadtech.bot.vcs.core.service.NotifyService; -import org.sadtech.bot.vcs.core.service.MessageSendService; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.stream.Collectors; - -/** - * Парсер изменений. Отслеживает изменения, которые были добавлены и добавляет событие на отправку уведомления - * пользователю. - * - * @author upagge - */ -@Service -@RequiredArgsConstructor -public class NotifyParsingScheduler { - - private final MessageSendService messageSendService; - private final NotifyService notifyService; - - /** - * Проверяет наличие новых изменений. Если изменения найдены, то создает новое сообщение и отправляет - * его в сервис отправки сообщений {@link MessageSendService} - */ - @Scheduled(cron = "*/15 * * * * *") - public void parsing() { - final List newNotify = notifyService.getNew().stream() - .filter(notify -> notify.getTelegramIds() != null && !notify.getTelegramIds().isEmpty()) - .collect(Collectors.toList()); - for (Notify notify : newNotify) { - final String message = notify.generateMessage(); - notify.getTelegramIds().forEach( - telegramId -> messageSendService.add( - MessageSend.builder() - .telegramId(telegramId) - .message(message) - .build() - ) - ); - } - } - -} diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/MessageSendService.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/MessageSendService.java index 810d8df..2495282 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/MessageSendService.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/MessageSendService.java @@ -1,10 +1,11 @@ package org.sadtech.bot.vcs.core.service; import lombok.NonNull; -import org.sadtech.bot.vcs.core.domain.MessageSend; +import org.sadtech.bot.vcs.core.domain.notify.Notify; +@FunctionalInterface public interface MessageSendService { - void add(@NonNull MessageSend messageSend); + void send(@NonNull Notify notify); } diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/NotifyService.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/NotifyService.java index 5403590..099ca0e 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/NotifyService.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/NotifyService.java @@ -1,8 +1,10 @@ package org.sadtech.bot.vcs.core.service; +import lombok.NonNull; +import org.sadtech.bot.vcs.core.domain.entity.NotifySetting; import org.sadtech.bot.vcs.core.domain.notify.Notify; -import java.util.List; +import java.util.Optional; /** * Сервис по работе с изменениями в битбакете. @@ -12,11 +14,18 @@ import java.util.List; */ public interface NotifyService { - void save(T notify); + void send(T notify); /** - * Позволяет получить новые изменения. + * Сохранить настройки уведомлений */ - List getNew(); + void saveSettings(@NonNull NotifySetting setting); + + /** + * Получить настройки уведомлений по логину. + * + * @param login Логин пользователя + */ + Optional getSetting(@NonNull String login); } diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/CommentServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/CommentServiceImpl.java index 781c7ee..5ffee01 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/CommentServiceImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/CommentServiceImpl.java @@ -3,15 +3,14 @@ package org.sadtech.bot.vcs.core.service.impl; import lombok.NonNull; import org.sadtech.basic.core.service.AbstractSimpleManagerService; import org.sadtech.bot.vcs.core.domain.Answer; -import org.sadtech.bot.vcs.core.domain.notify.comment.AnswerCommentNotify; -import org.sadtech.bot.vcs.core.domain.notify.comment.CommentNotify; import org.sadtech.bot.vcs.core.domain.entity.Comment; import org.sadtech.bot.vcs.core.domain.entity.Task; +import org.sadtech.bot.vcs.core.domain.notify.comment.AnswerCommentNotify; +import org.sadtech.bot.vcs.core.domain.notify.comment.CommentNotify; import org.sadtech.bot.vcs.core.exception.NotFoundException; import org.sadtech.bot.vcs.core.repository.CommentRepository; -import org.sadtech.bot.vcs.core.service.NotifyService; import org.sadtech.bot.vcs.core.service.CommentService; -import org.sadtech.bot.vcs.core.service.PersonService; +import org.sadtech.bot.vcs.core.service.NotifyService; import org.sadtech.bot.vcs.core.service.TaskService; import org.springframework.context.annotation.Lazy; import org.springframework.core.convert.ConversionService; @@ -32,7 +31,6 @@ public class CommentServiceImpl extends AbstractSimpleManagerService recipientsIds = personService.getAllTelegramIdByLogin(recipientsLogins); - notifyService.save( + notifyService.send( CommentNotify.builder() .authorName(comment.getAuthor()) .url(comment.getUrl()) - .telegramIds(recipientsIds) + .logins(recipientsLogins) .message(comment.getMessage()) .build() ); @@ -132,11 +127,9 @@ public class CommentServiceImpl extends AbstractSimpleManagerService void save(T notify) { - notifyRepository.add(notify); + public void send(T notify) { + final Set recipientLogins = settingRepository.isNotification(notify.getLogins()); + notify.setLogins(recipientLogins); + messageSendService.send(notify); } @Override - public List getNew() { - final List notifies = notifyRepository.getAll(); - notifyRepository.deleteAll(notifies); - return notifies; + public void saveSettings(@NonNull NotifySetting setting) { + settingRepository.save(setting); + } + + @Override + public Optional getSetting(@NonNull String login) { + return settingRepository.findById(login); } } diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/PersonServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/PersonServiceImpl.java index 368ec8e..94d7a51 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/PersonServiceImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/PersonServiceImpl.java @@ -1,17 +1,20 @@ package org.sadtech.bot.vcs.core.service.impl; import lombok.NonNull; -import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.sadtech.basic.core.util.Assert; import org.sadtech.bot.vcs.core.config.properties.BitbucketProperty; +import org.sadtech.bot.vcs.core.domain.entity.NotifySetting; import org.sadtech.bot.vcs.core.domain.entity.Person; import org.sadtech.bot.vcs.core.exception.RegException; import org.sadtech.bot.vcs.core.repository.PersonRepository; +import org.sadtech.bot.vcs.core.service.NotifyService; import org.sadtech.bot.vcs.core.service.PersonService; import org.sadtech.bot.vcs.core.service.Utils; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; +import java.time.LocalDateTime; import java.util.Collection; import java.util.List; import java.util.Optional; @@ -20,12 +23,23 @@ import java.util.stream.Collectors; @Slf4j @Service -@RequiredArgsConstructor public class PersonServiceImpl implements PersonService { private final PersonRepository personRepository; private final BitbucketProperty bitbucketProperty; + private final NotifyService notifyService; + + public PersonServiceImpl( + PersonRepository personRepository, + BitbucketProperty bitbucketProperty, + @Lazy NotifyService notifyService + ) { + this.personRepository = personRepository; + this.bitbucketProperty = bitbucketProperty; + this.notifyService = notifyService; + } + @Override public Optional getByLogin(String login) { return personRepository.findByLogin(login); @@ -52,6 +66,9 @@ public class PersonServiceImpl implements PersonService { Optional sheetJson = Utils.urlToJson(bitbucketProperty.getUrlPullRequestClose(), user.getToken(), Object.class); if (sheetJson.isPresent()) { oldUser.setTelegramId(user.getTelegramId()); + + defaultSettings(oldUser); + return personRepository.save(oldUser); } else { throw new RegException("Ваш токен не валиден"); @@ -63,6 +80,13 @@ public class PersonServiceImpl implements PersonService { throw new RegException("Пользователь не найден, подождите обновление базы пользователей!"); } + private void defaultSettings(Person person) { + final NotifySetting notifySetting = new NotifySetting(); + notifySetting.setLogin(person.getLogin()); + notifySetting.setStartReceiving(LocalDateTime.now()); + notifyService.saveSettings(notifySetting); + } + @Override public List getAllRegister() { return personRepository.findAllByTelegramIdNotNullAndTokenNotNull(); diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/PullRequestsServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/PullRequestsServiceImpl.java index 7a91934..fb929a9 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/PullRequestsServiceImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/PullRequestsServiceImpl.java @@ -11,21 +11,20 @@ import org.sadtech.basic.filter.criteria.CriteriaQuery; import org.sadtech.bot.vcs.core.domain.IdAndStatusPr; import org.sadtech.bot.vcs.core.domain.PullRequestStatus; import org.sadtech.bot.vcs.core.domain.ReviewerStatus; -import org.sadtech.bot.vcs.core.domain.notify.pullrequest.ConflictPrNotify; -import org.sadtech.bot.vcs.core.domain.notify.pullrequest.NewPrNotify; -import org.sadtech.bot.vcs.core.domain.notify.pullrequest.ReviewersPrNotify; -import org.sadtech.bot.vcs.core.domain.notify.pullrequest.StatusPrNotify; -import org.sadtech.bot.vcs.core.domain.notify.pullrequest.UpdatePrNotify; import org.sadtech.bot.vcs.core.domain.entity.PullRequest; import org.sadtech.bot.vcs.core.domain.entity.PullRequestMini; import org.sadtech.bot.vcs.core.domain.entity.PullRequest_; import org.sadtech.bot.vcs.core.domain.entity.Reviewer; import org.sadtech.bot.vcs.core.domain.filter.PullRequestFilter; +import org.sadtech.bot.vcs.core.domain.notify.pullrequest.ConflictPrNotify; +import org.sadtech.bot.vcs.core.domain.notify.pullrequest.NewPrNotify; +import org.sadtech.bot.vcs.core.domain.notify.pullrequest.ReviewersPrNotify; +import org.sadtech.bot.vcs.core.domain.notify.pullrequest.StatusPrNotify; +import org.sadtech.bot.vcs.core.domain.notify.pullrequest.UpdatePrNotify; import org.sadtech.bot.vcs.core.domain.util.ReviewerChange; import org.sadtech.bot.vcs.core.exception.UpdateException; import org.sadtech.bot.vcs.core.repository.PullRequestsRepository; import org.sadtech.bot.vcs.core.service.NotifyService; -import org.sadtech.bot.vcs.core.service.PersonService; import org.sadtech.bot.vcs.core.service.PullRequestsService; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; @@ -43,18 +42,16 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService filterService; protected PullRequestsServiceImpl( PullRequestsRepository pullRequestsRepository, NotifyService notifyService, - PersonService personService, @Qualifier("pullRequestFilterService") FilterService pullRequestsFilterService + @Qualifier("pullRequestFilterService") FilterService pullRequestsFilterService ) { super(pullRequestsRepository); this.notifyService = notifyService; this.pullRequestsRepository = pullRequestsRepository; - this.personService = personService; this.filterService = pullRequestsFilterService; } @@ -64,26 +61,30 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService getReviewerTelegrams(@NonNull List reviewers) { - return personService.getAllTelegramIdByLogin( - reviewers.stream() - .map(Reviewer::getPersonLogin) - .collect(Collectors.toSet()) - ); - } +// +// private Set getReviewerTelegrams(@NonNull List reviewers) { +// return personService.getAllTelegramIdByLogin( +// reviewers.stream() +// .map(Reviewer::getPersonLogin) +// .collect(Collectors.toSet()) +// ); +// } @Override public PullRequest update(@NonNull PullRequest pullRequest) { @@ -98,11 +99,15 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService oldIds.contains(reviewer.getPersonLogin())); if (!reviewerChanges.isEmpty()) { - notifyService.save( + notifyService.send( ReviewersPrNotify.builder() .title(newPullRequest.getTitle()) .url(newPullRequest.getUrl()) - .telegramIds( - personService.getAllTelegramIdByLogin(Collections.singleton(newPullRequest.getAuthorLogin())) - ) + .logins(Collections.singleton(newPullRequest.getAuthorLogin())) .reviewerChanges(reviewerChanges) .build() ); diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/TaskServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/TaskServiceImpl.java index 3810ff2..83e0bc2 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/TaskServiceImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/TaskServiceImpl.java @@ -5,18 +5,17 @@ import org.sadtech.basic.core.service.AbstractSimpleManagerService; import org.sadtech.basic.core.util.Assert; import org.sadtech.bot.vcs.core.domain.Answer; import org.sadtech.bot.vcs.core.domain.TaskStatus; +import org.sadtech.bot.vcs.core.domain.entity.Comment; +import org.sadtech.bot.vcs.core.domain.entity.PullRequest; +import org.sadtech.bot.vcs.core.domain.entity.Task; import org.sadtech.bot.vcs.core.domain.notify.comment.AnswerCommentNotify; import org.sadtech.bot.vcs.core.domain.notify.comment.CommentNotify; import org.sadtech.bot.vcs.core.domain.notify.task.TaskCloseNotify; import org.sadtech.bot.vcs.core.domain.notify.task.TaskNewNotify; -import org.sadtech.bot.vcs.core.domain.entity.Comment; -import org.sadtech.bot.vcs.core.domain.entity.PullRequest; -import org.sadtech.bot.vcs.core.domain.entity.Task; import org.sadtech.bot.vcs.core.exception.NotFoundException; import org.sadtech.bot.vcs.core.repository.TaskRepository; -import org.sadtech.bot.vcs.core.service.NotifyService; import org.sadtech.bot.vcs.core.service.CommentService; -import org.sadtech.bot.vcs.core.service.PersonService; +import org.sadtech.bot.vcs.core.service.NotifyService; import org.sadtech.bot.vcs.core.service.PullRequestsService; import org.sadtech.bot.vcs.core.service.TaskService; import org.springframework.core.convert.ConversionService; @@ -40,7 +39,6 @@ public class TaskServiceImpl extends AbstractSimpleManagerService im private final PullRequestsService pullRequestsService; private final NotifyService notifyService; - private final PersonService personService; private final CommentService commentService; private final ConversionService conversionService; @@ -49,7 +47,6 @@ public class TaskServiceImpl extends AbstractSimpleManagerService im TaskRepository taskRepository, PullRequestsService pullRequestsService, NotifyService notifyService, - PersonService personService, CommentService commentService, ConversionService conversionService ) { @@ -57,7 +54,6 @@ public class TaskServiceImpl extends AbstractSimpleManagerService im this.taskRepository = taskRepository; this.pullRequestsService = pullRequestsService; this.notifyService = notifyService; - this.personService = personService; this.commentService = commentService; this.conversionService = conversionService; } @@ -93,26 +89,22 @@ public class TaskServiceImpl extends AbstractSimpleManagerService im if (!oldStatus.equals(newStatus)) { switch (newStatus) { case OPEN: - notifyService.save( + notifyService.send( TaskNewNotify.builder() .messageTask(task.getDescription()) .authorName(oldTask.getAuthor()) .url(oldTask.getUrl()) - .telegramIds( - personService.getAllTelegramIdByLogin(Collections.singleton(oldTask.getResponsible())) - ) + .logins(Collections.singleton(oldTask.getResponsible())) .build() ); break; case RESOLVED: - notifyService.save( + notifyService.send( TaskCloseNotify.builder() .messageTask(oldTask.getDescription()) .authorName(oldTask.getAuthor()) .url(oldTask.getUrl()) - .telegramIds( - personService.getAllTelegramIdByLogin(Collections.singleton(oldTask.getAuthor())) - ) + .logins(Collections.singleton(oldTask.getAuthor())) .build() ); break; @@ -133,11 +125,9 @@ public class TaskServiceImpl extends AbstractSimpleManagerService im .collect(Collectors.toList()); oldTask.getAnswers().clear(); oldTask.setAnswers(existsNewAnswersIds); - notifyService.save( + notifyService.send( AnswerCommentNotify.builder() - .telegramIds( - personService.getAllTelegramIdByLogin(Collections.singleton(oldTask.getAuthor())) - ) + .logins(Collections.singleton(oldTask.getAuthor())) .url(task.getUrl()) .youMessage(oldTask.getDescription()) .answers( @@ -178,16 +168,12 @@ public class TaskServiceImpl extends AbstractSimpleManagerService im final PullRequest pullRequest = pullRequestsService.getById(task.getPullRequestId()) .orElseThrow(() -> new NotFoundException("ПР не найден")); - notifyService.save( + notifyService.send( TaskNewNotify.builder() .authorName(task.getAuthor()) .messageTask(task.getDescription()) .url(task.getUrl()) - .telegramIds( - personService.getAllTelegramIdByLogin( - Collections.singleton(pullRequest.getAuthorLogin()) - ) - ) + .logins(Collections.singleton(pullRequest.getAuthorLogin())) .build() ); } @@ -199,12 +185,11 @@ public class TaskServiceImpl extends AbstractSimpleManagerService im final String login = matcher.group(0).replace("@", ""); recipientsLogins.add(login); } - final Set recipientsIds = personService.getAllTelegramIdByLogin(recipientsLogins); - notifyService.save( + notifyService.send( CommentNotify.builder() .authorName(task.getAuthor()) .url(task.getUrl()) - .telegramIds(recipientsIds) + .logins(recipientsLogins) .message(task.getDescription()) .build() ); diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/utils/MessageUtils.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/utils/MessageUtils.java new file mode 100644 index 0000000..fbaa14d --- /dev/null +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/utils/MessageUtils.java @@ -0,0 +1,47 @@ +package org.sadtech.bot.vcs.core.utils; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import org.sadtech.bot.vcs.core.domain.entity.PullRequest; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * Генерирует сообщения для отправки. + * + * @author upagge [07.02.2020] + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class MessageUtils { + + private static final UpdateDataComparator COMPARATOR = new UpdateDataComparator(); + private static final Integer PR_COUNT = 4; + + public static Optional pullRequestForReview(@NonNull List pullRequestsReviews) { + if (!pullRequestsReviews.isEmpty()) { + return Optional.of( + pullRequestsReviews.stream() + .sorted(COMPARATOR) + .limit(PR_COUNT) + .map(MessageUtils::topPr) + .collect(Collectors.joining("\n")) + ); + } + return Optional.empty(); + } + + private static String topPr(PullRequest pullRequest) { + return Smile.statusPr(pullRequest.getUpdateDate()) + " " + + link(pullRequest.getTitle(), pullRequest.getUrl()) + + Smile.BR; + } + + @NonNull + private static String link(String name, String url) { + return "[" + name + "](" + url + ")"; + } + +} diff --git a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/MessageSendTelegramService.java b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/MessageSendTelegramService.java index 5ff127c..70cded2 100644 --- a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/MessageSendTelegramService.java +++ b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/MessageSendTelegramService.java @@ -2,27 +2,34 @@ package org.sadtech.bot.vcs.telegram.service; import lombok.NonNull; import lombok.RequiredArgsConstructor; -import org.sadtech.bot.vcs.core.domain.MessageSend; +import org.sadtech.bot.vcs.core.domain.notify.Notify; import org.sadtech.bot.vcs.core.service.MessageSendService; +import org.sadtech.bot.vcs.core.service.PersonService; import org.sadtech.social.core.domain.BoxAnswer; import org.sadtech.social.core.service.sender.Sending; import org.springframework.stereotype.Service; +import java.util.Set; + /** * // TODO: 17.09.2020 Добавить описание. * * @author upagge 17.09.2020 */ -//@Profile("prod") @Service @RequiredArgsConstructor public class MessageSendTelegramService implements MessageSendService { private final Sending sending; + private final PersonService personService; + @Override - public void add(@NonNull MessageSend messageSend) { - sending.send(messageSend.getTelegramId(), BoxAnswer.of(messageSend.getMessage())); + public void send(@NonNull Notify notify) { + final Set telegramIds = personService.getAllTelegramIdByLogin(notify.getLogins()); + telegramIds.forEach( + telegramId -> sending.send(telegramId, BoxAnswer.of(notify.generateMessage())) + ); } } diff --git a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/MessageSendTestService.java b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/MessageSendTestService.java deleted file mode 100644 index eff2258..0000000 --- a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/MessageSendTestService.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.sadtech.bot.vcs.telegram.service; - -import lombok.NonNull; -import org.sadtech.bot.vcs.core.domain.MessageSend; -import org.sadtech.bot.vcs.core.service.MessageSendService; -import org.springframework.context.annotation.Profile; - -/** - * // TODO: 17.09.2020 Добавить описание. - * - * @author upagge 17.09.2020 - */ -//@Service -@Profile("dev") -public class MessageSendTestService implements MessageSendService { - - @Override - public void add(@NonNull MessageSend messageSend) { - System.out.println(messageSend); - } - -} diff --git a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/unit/PullRequestProcessing.java b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/unit/PullRequestProcessing.java index 081286c..24a93bd 100644 --- a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/unit/PullRequestProcessing.java +++ b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/unit/PullRequestProcessing.java @@ -8,16 +8,14 @@ import org.sadtech.bot.vcs.core.domain.entity.PullRequest; import org.sadtech.bot.vcs.core.exception.NotFoundException; import org.sadtech.bot.vcs.core.service.PersonService; import org.sadtech.bot.vcs.core.service.PullRequestsService; -import org.sadtech.bot.vcs.core.utils.Smile; +import org.sadtech.bot.vcs.core.utils.MessageUtils; import org.sadtech.social.bot.service.usercode.ProcessingData; import org.sadtech.social.core.domain.BoxAnswer; import org.sadtech.social.core.domain.content.Message; import org.springframework.stereotype.Component; -import java.text.MessageFormat; import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; /** * // TODO: 17.09.2020 Добавить описание. @@ -35,27 +33,14 @@ public class PullRequestProcessing implements ProcessingData { public BoxAnswer processing(Message message) { final Person person = personService.getByTelegramId(message.getPersonId()) .orElseThrow(() -> new NotFoundException("Пользователь не найден")); - final List pullRequests = pullRequestsService.getAllByReviewerAndStatuses(person.getLogin(), ReviewerStatus.NEEDS_WORK, Collections.singleton(PullRequestStatus.OPEN)); - String messageAnswer; - if (pullRequests.isEmpty()) { - messageAnswer = "Все ПР проверены :)"; - } else { - final String prAnswer = pullRequests.stream() - .map(this::convert) - .collect(Collectors.joining("\n")); - messageAnswer = MessageFormat.format( - "Вам необходимо посмотреть следующие ПР:{0}{1}", - Smile.HR, prAnswer - ); - } - return BoxAnswer.of(messageAnswer); - } - - private String convert(PullRequest pullRequest) { - return MessageFormat.format( - "- [{0}]({1})", - pullRequest.getTitle(), - pullRequest.getUrl() + final List pullRequests = pullRequestsService.getAllByReviewerAndStatuses( + person.getLogin(), + ReviewerStatus.NEEDS_WORK, + Collections.singleton(PullRequestStatus.OPEN) + ); + return BoxAnswer.of( + MessageUtils.pullRequestForReview(pullRequests) + .orElse("Все ПР проверены :)") ); } diff --git a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/unit/NotifySettingUnit.java b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/unit/NotifySettingUnit.java new file mode 100644 index 0000000..1698ba3 --- /dev/null +++ b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/unit/NotifySettingUnit.java @@ -0,0 +1,101 @@ +package org.sadtech.bot.vcs.telegram.unit; + +import lombok.Getter; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.sadtech.bot.vcs.core.domain.entity.NotifySetting; +import org.sadtech.bot.vcs.core.domain.entity.Person; +import org.sadtech.bot.vcs.core.exception.NotFoundException; +import org.sadtech.bot.vcs.core.service.NotifyService; +import org.sadtech.bot.vcs.core.service.PersonService; +import org.sadtech.social.bot.domain.unit.AnswerProcessing; +import org.sadtech.social.bot.domain.unit.AnswerText; +import org.sadtech.social.core.domain.BoxAnswer; +import org.sadtech.social.core.domain.content.Message; +import org.sadtech.social.core.utils.KeyBoards; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.time.LocalDateTime; +import java.util.Arrays; +import java.util.stream.Collectors; + +/** + * // TODO: 20.09.2020 Добавить описание. + * + * @author upagge 20.09.2020 + */ +@Configuration +@RequiredArgsConstructor +public class NotifySettingUnit { + + private final PersonService personService; + private final NotifyService notifyService; + + @Bean + public AnswerText notifySetting( + AnswerProcessing disableNotifications + ) { + return AnswerText.builder() + .boxAnswer( + BoxAnswer.builder() + .message("Вы можете полностью остановить уведомления от бота") + .keyBoard( + KeyBoards.verticalDuoMenuString( + Arrays.stream(DisableMenu.values()) + .map(DisableMenu::getName) + .collect(Collectors.toList()) + ) + ) + .build() + ) + .phrase("Уведомления") + .nextUnit(disableNotifications) + .build(); + } + + @Bean + public AnswerProcessing disableNotifications() { + return AnswerProcessing.builder() + .processingData( + message -> { + final Person person = personService.getByTelegramId(message.getPersonId()) + .orElseThrow(() -> new NotFoundException("Не найдено")); + final NotifySetting notifySetting = notifyService.getSetting(person.getLogin()) + .orElseThrow(() -> new NotFoundException("Не найдено")); + notifySetting.setStartReceiving( + LocalDateTime.now().plusMinutes(DisableMenu.from(message.getText()).getMinutes()) + ); + notifyService.saveSettings(notifySetting); + return BoxAnswer.of("Настройки сохранены"); + } + ) + .build(); + } + + @Getter + @RequiredArgsConstructor + private enum DisableMenu { + + TURN_ON("Включить", 0), + TURN_OFF("Выключить", 525600), + DISABLE_15_MIN("15 мин", 15), + DISABLE_2_HOUR("2 часа", 120), + DISABLE_30_MIN("30 мин", 30), + DISABLE_4_HOUR("4 часа", 240), + DISABLE_60_MIN("60 мин", 60), + DISABLE_8_HOUR("8 часов", 480); + + private final String name; + private final int minutes; + + public static DisableMenu from(@NonNull String name) { + return Arrays.stream(DisableMenu.values()) + .filter(disableMenu -> disableMenu.getName().equals(name)) + .findFirst() + .orElseThrow(() -> new NotFoundException("Не найдено")); + } + + } + +} diff --git a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/unit/UnitConfig.java b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/unit/UnitConfig.java index 2da837b..e3307af 100644 --- a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/unit/UnitConfig.java +++ b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/unit/UnitConfig.java @@ -4,6 +4,7 @@ import lombok.RequiredArgsConstructor; import org.sadtech.bot.vcs.core.service.PersonService; import org.sadtech.bot.vcs.telegram.service.unit.PullRequestProcessing; import org.sadtech.bot.vcs.telegram.service.unit.TaskProcessing; +import org.sadtech.bot.vcs.telegram.utils.GeneratorKeyBoards; import org.sadtech.social.bot.domain.unit.AnswerCheck; import org.sadtech.social.bot.domain.unit.AnswerProcessing; import org.sadtech.social.bot.domain.unit.AnswerText; @@ -42,19 +43,37 @@ public class UnitConfig { @Bean public AnswerText menu( AnswerProcessing getTasks, - AnswerProcessing getPr + AnswerProcessing getPr, + AnswerText settings ) { return AnswerText.builder() .boxAnswer( BoxAnswer.builder() .message("Привет, выбери пункт меню!") - .keyBoard(KeyBoards.verticalMenuString( - "Мои задачи", "Проверить ПР" - )) + .keyBoard(GeneratorKeyBoards.menu()) .build() ) .nextUnit(getTasks) .nextUnit(getPr) + .nextUnit(settings) + .build(); + } + + @Bean + public AnswerText settings( + AnswerText notifySetting + ) { + return AnswerText.builder() + .boxAnswer( + BoxAnswer.builder() + .message("Здесь вы можете персонализировать бота") + .keyBoard( + KeyBoards.verticalMenuString("Уведомления") + ) + .build() + ) + .phrase("Настройки") + .nextUnit(notifySetting) .build(); } diff --git a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/utils/GeneratorKeyBoards.java b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/utils/GeneratorKeyBoards.java new file mode 100644 index 0000000..61bf43e --- /dev/null +++ b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/utils/GeneratorKeyBoards.java @@ -0,0 +1,37 @@ +package org.sadtech.bot.vcs.telegram.utils; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.sadtech.social.core.domain.keyboard.KeyBoard; +import org.sadtech.social.core.domain.keyboard.KeyBoardLine; +import org.sadtech.social.core.domain.keyboard.button.KeyBoardButtonText; + +/** + * // TODO: 20.09.2020 Добавить описание. + * + * @author upagge 20.09.2020 + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class GeneratorKeyBoards { + + public static KeyBoard menu() { + final KeyBoardButtonText tasks = KeyBoardButtonText.builder().label("Мои задачи").build(); + final KeyBoardButtonText pr = KeyBoardButtonText.builder().label("Проверить ПР").build(); + final KeyBoardButtonText settings = KeyBoardButtonText.builder().label("Настройки").build(); + + final KeyBoardLine oneLine = KeyBoardLine.builder() + .buttonKeyBoard(tasks) + .buttonKeyBoard(pr) + .build(); + + final KeyBoardLine twoLine = KeyBoardLine.builder() + .buttonKeyBoard(settings) + .build(); + + return KeyBoard.builder() + .lineKeyBoard(oneLine) + .lineKeyBoard(twoLine) + .build(); + } + +}