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