diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/AppLocale.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/AppLocale.java index 6cb9c05..d6ef2f1 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/AppLocale.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/AppLocale.java @@ -25,7 +25,7 @@ public enum AppLocale { return Arrays.stream(values()) .filter(appLocale -> appLocale.getLabel().equals(label)) .findFirst() - .orElseThrow(() -> new NotFoundException("Ошибка, локализация не найдена. Попробуйте снова.")); + .orElseThrow(NotFoundException.supplier("Ошибка, локализация не найдена. Попробуйте снова.")); } public Locale getValue() { diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/MessageSend.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/MessageSend.java index 3dbd5dc..c7e9898 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/MessageSend.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/MessageSend.java @@ -5,23 +5,18 @@ import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.NonNull; import lombok.Setter; -@NoArgsConstructor -@Builder -@AllArgsConstructor @Getter @Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor @EqualsAndHashCode(of = "id") public class MessageSend { private Long id; - - @NonNull private Long telegramId; - - @NonNull private String message; } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/PersonInformation.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/PersonInformation.java index d81f506..f456fe9 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/PersonInformation.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/PersonInformation.java @@ -1,13 +1,15 @@ package dev.struchkov.bot.gitlab.context.domain; -import lombok.Data; +import lombok.Getter; +import lombok.Setter; /** * // TODO: 15.01.2021 Добавить описание. * * @author upagge 15.01.2021 */ -@Data +@Getter +@Setter public class PersonInformation { private String username; diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/PointType.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/PointType.java deleted file mode 100644 index 95d1907..0000000 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/PointType.java +++ /dev/null @@ -1,26 +0,0 @@ -package dev.struchkov.bot.gitlab.context.domain; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -/** - * // TODO: 01.10.2020 Добавить описание. - * - * @author upagge 01.10.2020 - */ -@Getter -@RequiredArgsConstructor -public enum PointType { - - CREATE_PULL_REQUEST(10), - DECLINE_PULL_REQUEST(-CREATE_PULL_REQUEST.getPoints()), - COMMENT_ADD(1), - COMMENT_DELETE(-COMMENT_ADD.getPoints()), - TASK_CREATE(2), - TASK_DELETE(-TASK_CREATE.getPoints()), - TASK_RECIPIENT(-1), - TASK_DELETE_RECIPIENT(1); - - private final Integer points; - -} diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/NotifySetting.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/NotifySetting.java deleted file mode 100644 index 88485dd..0000000 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/NotifySetting.java +++ /dev/null @@ -1,35 +0,0 @@ -package dev.struchkov.bot.gitlab.context.domain.entity; - -import dev.struchkov.haiti.context.domain.BasicEntity; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -import javax.persistence.Column; -import javax.persistence.Id; -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 implements BasicEntity { - - @Id - @Column(name = "login") - @EqualsAndHashCode.Include - private String id; - - /** - * Дата, после которой пользователю будут поступать уведомления. - */ - @Column(name = "start_receiving") - private LocalDateTime startReceiving; - -} diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Pipeline.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Pipeline.java index f5a6f76..f354b43 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Pipeline.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Pipeline.java @@ -1,10 +1,10 @@ package dev.struchkov.bot.gitlab.context.domain.entity; +import dev.struchkov.bot.gitlab.context.domain.PipelineStatus; import dev.struchkov.haiti.context.domain.BasicEntity; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; -import dev.struchkov.bot.gitlab.context.domain.PipelineStatus; import javax.persistence.Column; import javax.persistence.Entity; diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/GoodMorningNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/GoodMorningNotify.java index e77aee5..3f30bc9 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/GoodMorningNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/GoodMorningNotify.java @@ -4,12 +4,10 @@ import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest; import dev.struchkov.bot.gitlab.context.service.AppSettingService; import dev.struchkov.bot.gitlab.context.utils.MessageUtils; import dev.struchkov.bot.gitlab.context.utils.Smile; -import dev.struchkov.bot.gitlab.context.utils.UpdateDataComparator; import lombok.Builder; import lombok.Getter; import java.util.List; -import java.util.stream.Collectors; /** * // TODO: 20.09.2020 Добавить описание. @@ -17,9 +15,9 @@ import java.util.stream.Collectors; * @author upagge 20.09.2020 */ @Getter -public class GoodMorningNotify extends Notify { +//TODO [28.01.2022]: Решить доработать и оставить или удалить. +public class GoodMorningNotify implements Notify { - private static final UpdateDataComparator COMPARATOR = new UpdateDataComparator(); private static final Integer PR_COUNT = 4; private final List mergeRequestsReviews; @@ -31,7 +29,9 @@ public class GoodMorningNotify extends Notify { protected GoodMorningNotify( List mergeRequestsReviews, List mergeRequestsNeedWork, - String personName, String version) { + String personName, + String version + ) { this.mergeRequestsReviews = mergeRequestsReviews; this.mergeRequestsNeedWork = mergeRequestsNeedWork; this.personName = personName; @@ -40,13 +40,13 @@ public class GoodMorningNotify extends Notify { @Override public String generateMessage(AppSettingService settingService) { - StringBuilder message = new StringBuilder().append(Smile.SUN).append(" *Доброе утро, ").append(personName).append("* ").append(Smile.SUN).append(Smile.TWO_BR); + final StringBuilder message = new StringBuilder().append(Smile.SUN).append(" *Доброе утро, ").append(personName).append("* ").append(Smile.SUN).append(Smile.TWO_BR); if (!mergeRequestsReviews.isEmpty()) { message.append("Необходимо проверить ").append(mergeRequestsReviews.size()).append(" ПР:").append(Smile.BR); MessageUtils.pullRequestForReview( mergeRequestsReviews.stream() .limit(3) - .collect(Collectors.toList()) + .toList() ).ifPresent(message::append); } else { message.append("Поздравляю, у тебя ни одного ПР на проверку!"); @@ -54,7 +54,7 @@ public class GoodMorningNotify extends Notify { MessageUtils.pullRequestForNeedWork( mergeRequestsNeedWork.stream() .limit(3) - .collect(Collectors.toList()) + .toList() ).ifPresent( messageNeedWork -> message.append(Smile.TWO_BR) .append(Smile.DANGEROUS).append(" Требуется доработать ").append(mergeRequestsNeedWork.size()).append(" ПР:").append(Smile.BR) diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/NewProjectNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/NewProjectNotify.java index 25f39ca..364cc24 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/NewProjectNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/NewProjectNotify.java @@ -2,14 +2,17 @@ package dev.struchkov.bot.gitlab.context.domain.notify; import dev.struchkov.bot.gitlab.context.service.AppSettingService; import dev.struchkov.bot.gitlab.context.utils.Smile; +import dev.struchkov.haiti.utils.Strings; import lombok.Builder; +import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; + /** * // TODO: 15.01.2021 Добавить описание. * * @author upagge 15.01.2021 */ -public class NewProjectNotify extends Notify { +public class NewProjectNotify implements Notify { private final String projectName; private final String projectUrl; @@ -29,7 +32,7 @@ public class NewProjectNotify extends Notify { return settingService.getMessage( "notify.project.new", Smile.FUN.getValue(), Smile.HR.getValue(), projectName, projectUrl, - (projectDescription != null && !"".equals(projectDescription)) ? escapeMarkdown(projectDescription) + Smile.HR : "", + (projectDescription != null && !"".equals(projectDescription)) ? escapeMarkdown(projectDescription) + Smile.HR : Strings.EMPTY, Smile.AUTHOR.getValue(), authorName ); } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/Notify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/Notify.java index 5918f2c..b09c2ac 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/Notify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/Notify.java @@ -1,34 +1,9 @@ package dev.struchkov.bot.gitlab.context.domain.notify; import dev.struchkov.bot.gitlab.context.service.AppSettingService; -import lombok.Getter; -import lombok.NonNull; -import lombok.Setter; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; +public interface Notify { -@Getter -@Setter -public abstract class Notify { - - protected static final Set FORBIDDEN_SYMBOLS = Stream.of( - '\\', '+', '`', '[', ']', '\"', '~', '*', '#', '=', '_', '>', '<' - ).collect(Collectors.toSet()); - - public abstract String generateMessage(AppSettingService appSettingService); - - public static String escapeMarkdown(@NonNull String s) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < s.length(); i++) { - char c = s.charAt(i); - if (FORBIDDEN_SYMBOLS.contains(c)) { - sb.append('\\'); - } - sb.append(c); - } - return sb.toString(); - } + String generateMessage(AppSettingService appSettingService); } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/SimpleTextNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/SimpleTextNotify.java index 16d399a..b0398e0 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/SimpleTextNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/SimpleTextNotify.java @@ -10,7 +10,7 @@ import lombok.Getter; * @author upagge 20.09.2020 */ @Getter -public class SimpleTextNotify extends Notify { +public class SimpleTextNotify implements Notify { private final String message; diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/comment/AnswerCommentNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/comment/AnswerCommentNotify.java index 820ae6e..93fcee8 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/comment/AnswerCommentNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/comment/AnswerCommentNotify.java @@ -1,18 +1,22 @@ package dev.struchkov.bot.gitlab.context.domain.notify.comment; import dev.struchkov.bot.gitlab.context.domain.Answer; -import dev.struchkov.bot.gitlab.context.utils.Smile; -import lombok.Builder; -import lombok.Getter; import dev.struchkov.bot.gitlab.context.domain.notify.Notify; import dev.struchkov.bot.gitlab.context.service.AppSettingService; +import dev.struchkov.bot.gitlab.context.utils.Smile; +import dev.struchkov.haiti.utils.Strings; +import lombok.Builder; +import lombok.Getter; import java.text.MessageFormat; import java.util.List; import java.util.stream.Collectors; +import static dev.struchkov.haiti.utils.Strings.TWO_NEW_LINE; +import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; + @Getter -public class AnswerCommentNotify extends Notify { +public class AnswerCommentNotify implements Notify { private final String youMessage; private final String url; @@ -33,7 +37,7 @@ public class AnswerCommentNotify extends Notify { public String generateMessage(AppSettingService settingService) { final String answerText = answers.stream() .map(answer -> answer.getAuthorName() + ": " + answer.getMessage().substring(0, Math.min(answer.getMessage().length(), 500))) - .collect(Collectors.joining("\n\n")); + .collect(Collectors.joining(TWO_NEW_LINE)); return MessageFormat.format( "{0} *Новые ответы* на [комментарий]({1}){2}" + "{3}{2}" + @@ -41,7 +45,7 @@ public class AnswerCommentNotify extends Notify { Smile.COMMENT, url, Smile.HR, - escapeMarkdown(youMessage.substring(0, Math.min(youMessage.length(), 180))), + escapeMarkdown(Strings.cutoff(youMessage, 180)), escapeMarkdown(answerText) ); } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/comment/CommentNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/comment/CommentNotify.java index 2751e07..63f3205 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/comment/CommentNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/comment/CommentNotify.java @@ -6,8 +6,10 @@ import dev.struchkov.bot.gitlab.context.utils.Smile; import lombok.Builder; import lombok.Getter; +import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; + @Getter -public class CommentNotify extends Notify { +public class CommentNotify implements Notify { private final String authorName; private final String message; diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pipeline/PipelineNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pipeline/PipelineNotify.java index b7769fc..b7689f9 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pipeline/PipelineNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pipeline/PipelineNotify.java @@ -1,18 +1,20 @@ package dev.struchkov.bot.gitlab.context.domain.notify.pipeline; -import lombok.Builder; import dev.struchkov.bot.gitlab.context.domain.notify.Notify; import dev.struchkov.bot.gitlab.context.service.AppSettingService; import dev.struchkov.bot.gitlab.context.utils.Smile; +import lombok.Builder; import java.text.MessageFormat; +import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; + /** * // TODO: 17.01.2021 Добавить описание. * * @author upagge 17.01.2021 */ -public class PipelineNotify extends Notify { +public class PipelineNotify implements Notify { private final Long pipelineId; private final String projectName; @@ -22,7 +24,14 @@ public class PipelineNotify extends Notify { private String oldStatus = "n/a"; @Builder - public PipelineNotify(Long pipelineId, String projectName, String refName, String oldStatus, String newStatus, String webUrl) { + public PipelineNotify( + Long pipelineId, + String projectName, + String refName, + String oldStatus, + String newStatus, + String webUrl + ) { this.pipelineId = pipelineId; this.projectName = projectName; this.refName = refName; diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/ForgottenSmartPrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/ForgottenSmartPrNotify.java index f2a65b9..269025e 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/ForgottenSmartPrNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/ForgottenSmartPrNotify.java @@ -11,6 +11,7 @@ import dev.struchkov.bot.gitlab.context.service.AppSettingService; * @author upagge 11.10.2020 */ @Getter +//TODO [28.01.2022]: Решить доработать и оставить или удалить public class ForgottenSmartPrNotify extends PrNotify { @Builder diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/NewPrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/NewPrNotify.java index d311467..aba542e 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/NewPrNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/NewPrNotify.java @@ -1,5 +1,6 @@ package dev.struchkov.bot.gitlab.context.domain.notify.pullrequest; +import dev.struchkov.haiti.utils.Strings; import lombok.Builder; import lombok.Getter; import dev.struchkov.bot.gitlab.context.service.AppSettingService; @@ -8,6 +9,8 @@ import dev.struchkov.bot.gitlab.context.utils.Smile; import java.util.Set; import java.util.stream.Collectors; +import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; + @Getter public class NewPrNotify extends PrNotify { @@ -52,7 +55,7 @@ public class NewPrNotify extends PrNotify { title, url, labelText, - (description != null && !"".equals(description)) ? escapeMarkdown(description) + Smile.HR : "", + (description != null && !"".equals(description)) ? escapeMarkdown(description) + Smile.HR : Strings.EMPTY, Smile.AUTHOR.getValue(), author, Smile.TREE.getValue(), diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/PrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/PrNotify.java index ff9c9b6..c9289e3 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/PrNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/PrNotify.java @@ -1,10 +1,10 @@ package dev.struchkov.bot.gitlab.context.domain.notify.pullrequest; -import lombok.Getter; import dev.struchkov.bot.gitlab.context.domain.notify.Notify; +import lombok.Getter; @Getter -public abstract class PrNotify extends Notify { +public abstract class PrNotify implements Notify { protected final String projectName; protected final String title; diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/TaskCloseNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/TaskCloseNotify.java index f003502..7b35f34 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/TaskCloseNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/TaskCloseNotify.java @@ -4,6 +4,8 @@ import dev.struchkov.bot.gitlab.context.service.AppSettingService; import dev.struchkov.bot.gitlab.context.utils.Smile; import lombok.Builder; +import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; + /** * // TODO: 10.09.2020 Добавить описание. * diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/TaskNewNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/TaskNewNotify.java index e84bab6..6819867 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/TaskNewNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/TaskNewNotify.java @@ -5,6 +5,8 @@ import dev.struchkov.bot.gitlab.context.utils.Smile; import lombok.Builder; import lombok.Getter; +import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; + /** * // TODO: 10.09.2020 Добавить описание. * diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/TaskNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/TaskNotify.java index 1b92caf..cfe9db0 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/TaskNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/TaskNotify.java @@ -1,12 +1,10 @@ package dev.struchkov.bot.gitlab.context.domain.notify.task; import dev.struchkov.bot.gitlab.context.domain.notify.Notify; -import lombok.EqualsAndHashCode; import lombok.Getter; @Getter -@EqualsAndHashCode(callSuper = true) -public abstract class TaskNotify extends Notify { +public abstract class TaskNotify implements Notify { protected final String authorName; protected final String url; diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/exception/BitbucketBotException.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/exception/GitlabBotException.java similarity index 50% rename from bot-context/src/main/java/dev/struchkov/bot/gitlab/context/exception/BitbucketBotException.java rename to bot-context/src/main/java/dev/struchkov/bot/gitlab/context/exception/GitlabBotException.java index 8d765b3..4dfae27 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/exception/BitbucketBotException.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/exception/GitlabBotException.java @@ -2,13 +2,13 @@ package dev.struchkov.bot.gitlab.context.exception; import dev.struchkov.haiti.context.exception.BasicException; -abstract class BitbucketBotException extends BasicException { +abstract class GitlabBotException extends BasicException { - public BitbucketBotException(String message) { + public GitlabBotException(String message) { super(message); } - public BitbucketBotException(String message, Throwable throwable) { + public GitlabBotException(String message, Throwable throwable) { super(message, throwable); } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/exception/RegException.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/exception/RegException.java deleted file mode 100644 index 5bff20e..0000000 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/exception/RegException.java +++ /dev/null @@ -1,9 +0,0 @@ -package dev.struchkov.bot.gitlab.context.exception; - -public class RegException extends BitbucketBotException { - - public RegException(String message) { - super(message); - } - -} diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/exception/UpdateException.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/exception/UpdateException.java deleted file mode 100644 index 9cd471f..0000000 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/exception/UpdateException.java +++ /dev/null @@ -1,9 +0,0 @@ -package dev.struchkov.bot.gitlab.context.exception; - -public class UpdateException extends BitbucketBotException { - - public UpdateException(String message) { - super(message); - } - -} diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/MergeRequestRepository.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/MergeRequestRepository.java index 78b9706..e7d5c3a 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/MergeRequestRepository.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/MergeRequestRepository.java @@ -1,19 +1,20 @@ package dev.struchkov.bot.gitlab.context.repository; +import dev.struchkov.bot.gitlab.context.domain.IdAndStatusPr; +import dev.struchkov.bot.gitlab.context.domain.MergeRequestState; import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest; import dev.struchkov.haiti.context.repository.SimpleManagerRepository; import dev.struchkov.haiti.filter.FilterOperation; import lombok.NonNull; -import dev.struchkov.bot.gitlab.context.domain.IdAndStatusPr; -import dev.struchkov.bot.gitlab.context.domain.MergeRequestState; import java.util.List; import java.util.Set; public interface MergeRequestRepository extends SimpleManagerRepository, FilterOperation { - Set findAllIdByStateIn(Set states); + Set findAllIdByStateIn(@NonNull Set states); + //TODO [28.01.2022]: Решить, нужно ли оставить List findAllByAssignee(@NonNull Long userId); } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/NotifySettingRepository.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/NotifySettingRepository.java deleted file mode 100644 index 89e6c1e..0000000 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/NotifySettingRepository.java +++ /dev/null @@ -1,13 +0,0 @@ -package dev.struchkov.bot.gitlab.context.repository; - -import dev.struchkov.bot.gitlab.context.domain.entity.NotifySetting; -import dev.struchkov.haiti.context.repository.SimpleManagerRepository; - -/** - * // TODO: 20.09.2020 Добавить описание. - * - * @author upagge 20.09.2020 - */ -public interface NotifySettingRepository extends SimpleManagerRepository { - -} diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/PipelineRepository.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/PipelineRepository.java index 9a51f87..89d4a39 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/PipelineRepository.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/PipelineRepository.java @@ -18,4 +18,5 @@ import java.util.Set; public interface PipelineRepository extends SimpleManagerRepository, FilterOperation { Sheet findAllByStatuses(@NonNull Set statuses, @NonNull Pagination pagination); + } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/NoteService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/NoteService.java index f889c10..7ac56a9 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/NoteService.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/NoteService.java @@ -12,6 +12,7 @@ public interface NoteService extends SimpleManagerService { List getAllPersonTask(@NonNull Long userId, boolean resolved); + //TODO [28.01.2022]: Решить нужно ли оставлять Sheet getAllByResolved(boolean resolved, @NonNull Pagination pagination); } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/utils/MessageUtils.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/utils/MessageUtils.java index 0dc3418..dcbf24e 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/utils/MessageUtils.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/utils/MessageUtils.java @@ -17,13 +17,10 @@ import java.util.stream.Collectors; @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class MessageUtils { - private static final UpdateDataComparator COMPARATOR = new UpdateDataComparator(); - public static Optional pullRequestForReview(@NonNull List mergeRequestsReviews) { if (!mergeRequestsReviews.isEmpty()) { return Optional.of( mergeRequestsReviews.stream() - .sorted(COMPARATOR) .map(MessageUtils::generateStringItemPullRequestReview) .collect(Collectors.joining("\n")) ); @@ -51,7 +48,6 @@ public final class MessageUtils { link(mergeRequest.getTitle(), mergeRequest.getWebUrl()); } - @NonNull private static String link(String name, String url) { return "[" + name + "](" + url + ")"; } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/utils/Smile.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/utils/Smile.java index 418c739..f29556b 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/utils/Smile.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/utils/Smile.java @@ -30,8 +30,6 @@ public enum Smile { TOP_ONE("\uD83C\uDF1F\uD83C\uDF1F\uD83C\uDF1F"), TOP_TWO("\uD83D\uDE0E"), TOP_THREE("\uD83E\uDD49"), - KAKASHKA("\uD83D\uDCA9"), - LUPA("\uD83D\uDD0D"), DANGEROUS("⚠️"), COMMENT("\uD83D\uDCAC"), ARROW("➜"), diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/utils/UpdateDataComparator.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/utils/UpdateDataComparator.java deleted file mode 100644 index d1cff79..0000000 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/utils/UpdateDataComparator.java +++ /dev/null @@ -1,15 +0,0 @@ -package dev.struchkov.bot.gitlab.context.utils; - -import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest; - -import java.util.Comparator; - -public class UpdateDataComparator implements Comparator { - - @Override - public int compare(MergeRequest mergeRequest, MergeRequest t1) { -// return mergeRequest.getUpdateDate().compareTo(t1.getUpdateDate()); - return 0; - } - -} diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/convert/DiscussionJsonConverter.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/convert/DiscussionJsonConverter.java index d3f5fc2..e98c558 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/convert/DiscussionJsonConverter.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/convert/DiscussionJsonConverter.java @@ -27,8 +27,9 @@ public class DiscussionJsonConverter implements Converter !noteJson.isSystem()) .map(noteJsonConvert::convert) - .collect(Collectors.toList()) + .toList() ); return discussion; } + } diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/convert/MergeRequestJsonConverter.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/convert/MergeRequestJsonConverter.java index 86c4853..c89fcbf 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/convert/MergeRequestJsonConverter.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/convert/MergeRequestJsonConverter.java @@ -44,17 +44,13 @@ public class MergeRequestJsonConverter implements Converter MergeRequestState.CLOSED; + case LOCKED -> MergeRequestState.LOCKED; + case MERGED -> MergeRequestState.MERGED; + case OPENED -> MergeRequestState.OPENED; + default -> throw new ConvertException("Статус ПР не найден"); + }; } } diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/convert/PipelineJsonConverter.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/convert/PipelineJsonConverter.java index 4bd2540..d6d839c 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/convert/PipelineJsonConverter.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/convert/PipelineJsonConverter.java @@ -45,30 +45,19 @@ public class PipelineJsonConverter implements Converter } private PipelineStatus convertStatus(PipelineStatusJson status) { - switch (status) { - case SKIPPED: - return SKIPPED; - case CANCELED: - return CANCELED; - case SUCCESS: - return SUCCESS; - case MANUAL: - return MANUAL; - case CREATED: - return CREATED; - case PENDING: - return PENDING; - case RUNNING: - return RUNNING; - case PREPARING: - return PREPARING; - case SCHEDULED: - return SCHEDULED; - case WAITING_FOR_RESOURCE: - return WAITING_FOR_RESOURCE; - default: - return FAILED; - } + return switch (status) { + case SKIPPED -> SKIPPED; + case CANCELED -> CANCELED; + case SUCCESS -> SUCCESS; + case MANUAL -> MANUAL; + case CREATED -> CREATED; + case PENDING -> PENDING; + case RUNNING -> RUNNING; + case PREPARING -> PREPARING; + case SCHEDULED -> SCHEDULED; + case WAITING_FOR_RESOURCE -> WAITING_FOR_RESOURCE; + default -> FAILED; + }; } } diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/AppSettingServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/AppSettingServiceImpl.java index d7819e5..5336e59 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/AppSettingServiceImpl.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/AppSettingServiceImpl.java @@ -12,6 +12,7 @@ import org.springframework.stereotype.Service; import java.util.Arrays; import java.util.Locale; +import java.util.function.Supplier; /** * // TODO: 16.01.2021 Добавить описание. @@ -23,7 +24,7 @@ import java.util.Locale; public class AppSettingServiceImpl implements AppSettingService { private static final Long KEY = 1L; - private static final NotFoundException EXCEPTION = new NotFoundException("Ошибка, невозможно найти настройки приложения, проверьте базу данных."); + public static final Supplier NOT_FOUND_SETTINGS = NotFoundException.supplier("Ошибка, невозможно найти настройки приложения, проверьте базу данных."); private final AppSettingRepository appSettingRepository; private final MessageSource messageSource; @@ -31,13 +32,13 @@ public class AppSettingServiceImpl implements AppSettingService { @Override public boolean isFirstStart() { return appSettingRepository.findById(KEY) - .orElseThrow(() -> EXCEPTION) + .orElseThrow(NOT_FOUND_SETTINGS) .isFirstStart(); } @Override public void disableFirstStart() { - final AppSetting appSetting = appSettingRepository.findById(KEY).orElseThrow(() -> EXCEPTION); + final AppSetting appSetting = appSettingRepository.findById(KEY).orElseThrow(NOT_FOUND_SETTINGS); appSetting.setFirstStart(false); appSettingRepository.save(appSetting); } @@ -45,12 +46,11 @@ public class AppSettingServiceImpl implements AppSettingService { @Override public String getMessage(@NonNull String label) { final Locale value = appSettingRepository.findById(KEY) - .orElseThrow(() -> EXCEPTION) + .orElseThrow(NOT_FOUND_SETTINGS) .getAppLocale().getValue(); - final String message = messageSource.getMessage( + return messageSource.getMessage( label, null, value ); - return message; } @Override @@ -60,14 +60,14 @@ public class AppSettingServiceImpl implements AppSettingService { label, paramsArray, appSettingRepository.findById(KEY) - .orElseThrow(() -> EXCEPTION) + .orElseThrow(NOT_FOUND_SETTINGS) .getAppLocale().getValue() ); } @Override public void setLocale(@NonNull AppLocale appLocale) { - final AppSetting appSetting = appSettingRepository.findById(KEY).orElseThrow(() -> EXCEPTION); + final AppSetting appSetting = appSettingRepository.findById(KEY).orElseThrow(NOT_FOUND_SETTINGS); appSetting.setAppLocale(appLocale); appSettingRepository.save(appSetting); } diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/CleanServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/CleanServiceImpl.java index 0f86ab7..6710448 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/CleanServiceImpl.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/CleanServiceImpl.java @@ -31,7 +31,7 @@ public class CleanServiceImpl implements CleanService { private static final int COUNT = 1000; private static final MergeRequestFilter CLEAN_FILTER = MergeRequestFilter.builder() - .states(Stream.of(MERGED, CLOSED).collect(Collectors.toSet())) + .states(Set.of(MERGED, CLOSED)) .build(); private final MergeRequestsService mergeRequestsService; @@ -45,7 +45,7 @@ public class CleanServiceImpl implements CleanService { while (mergeRequestSheet.hasContent()) { final Set ids = mergeRequestSheet.getContent().stream() .map(MergeRequest::getId) - .collect(Collectors.toSet()); + .collect(Collectors.toUnmodifiableSet()); mergeRequestsService.deleteAllById(ids); @@ -62,7 +62,7 @@ public class CleanServiceImpl implements CleanService { while (sheet.hasContent()) { final Set ids = sheet.getContent().stream() .map(Pipeline::getId) - .collect(Collectors.toSet()); + .collect(Collectors.toUnmodifiableSet()); pipelineService.deleteAllById(ids); diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/DiscussionServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/DiscussionServiceImpl.java index d69e389..7734fe3 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/DiscussionServiceImpl.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/DiscussionServiceImpl.java @@ -97,7 +97,7 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService new NotFoundException("Дискуссия не найдена")); + .orElseThrow(NotFoundException.supplier("Дискуссия не найдена")); final Map noteMap = oldDiscussion .getNotes().stream() .collect(Collectors.toMap(Note::getId, note -> note)); @@ -148,7 +148,7 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService discussions = getAllByMergeRequestId(mergeRequest.getId()) .stream() .filter(discussion -> Objects.nonNull(discussion.getResponsible())) - .collect(Collectors.toList()); + .toList(); final long allYouTasks = discussions.stream() .filter(discussion -> personInformation.getId().equals(discussion.getFirstNote().getAuthor().getId())) .count(); @@ -178,7 +178,7 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService new NotFoundException("Дисскусия " + discussionId + " не найдена")); + .orElseThrow(NotFoundException.supplier("Дисскусия {0} не найдена", discussionId)); final MergeRequest mergeRequest = discussion.getMergeRequest(); final Long projectId = mergeRequest.getProjectId(); diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java index 04737a7..d22c380 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java @@ -30,7 +30,6 @@ import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.Set; -import java.util.stream.Collectors; @Service public class MergeRequestsServiceImpl extends AbstractSimpleManagerService implements MergeRequestsService { @@ -82,7 +81,7 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService new NotFoundException("Проект не найден")) + .orElseThrow(NotFoundException.supplier("Проект не найден")) .getName(); if (!newMergeRequest.isConflict()) { notifyService.send( @@ -110,7 +109,7 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService new NotFoundException("МержРеквест не найден")); + .orElseThrow(NotFoundException.supplier("МержРеквест не найден")); if (mergeRequest.getNotification() == null) { mergeRequest.setNotification(oldMergeRequest.getNotification()); @@ -118,7 +117,7 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService new NotFoundException("Проект не найден")); + .orElseThrow(NotFoundException.supplier("Проект не найден")); if (Boolean.TRUE.equals(oldMergeRequest.getNotification())) { notifyStatus(oldMergeRequest, mergeRequest, project); @@ -140,7 +139,7 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService discussions = discussionService.getAllByMergeRequestId(oldMergeRequest.getId()) .stream() .filter(discussion -> Objects.nonNull(discussion.getResponsible())) - .collect(Collectors.toList()); + .toList(); final long allTask = discussions.size(); final long resolvedTask = discussions.stream() .filter(Discussion::getResolved) diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PipelineServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PipelineServiceImpl.java index afbb36a..d58729e 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PipelineServiceImpl.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PipelineServiceImpl.java @@ -19,8 +19,6 @@ import org.springframework.stereotype.Service; import java.util.Optional; import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.CANCELED; import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.FAILED; @@ -35,21 +33,25 @@ import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.SUCCESS; @Service public class PipelineServiceImpl extends AbstractSimpleManagerService implements PipelineService { - private static final Set notificationStatus = Stream.of( - FAILED, SUCCESS, CANCELED, SKIPPED - ).collect(Collectors.toSet()); + private static final Set notificationStatus = Set.of(FAILED, SUCCESS, CANCELED, SKIPPED); private final NotifyService notifyService; - private final PipelineRepository repository; + private final PipelineRepository pipelineRepository; private final PersonService personService; private final PipelineFilterService pipelineFilterService; private final PersonInformation personInformation; - public PipelineServiceImpl(NotifyService notifyService, PipelineRepository repository, PersonService personService, PipelineFilterService pipelineFilterService, PersonInformation personInformation) { - super(repository); + public PipelineServiceImpl( + NotifyService notifyService, + PipelineRepository pipelineRepository, + PersonService personService, + PipelineFilterService pipelineFilterService, + PersonInformation personInformation + ) { + super(pipelineRepository); this.notifyService = notifyService; - this.repository = repository; + this.pipelineRepository = pipelineRepository; this.personService = personService; this.pipelineFilterService = pipelineFilterService; this.personInformation = personInformation; @@ -58,7 +60,7 @@ public class PipelineServiceImpl extends AbstractSimpleManagerService new NotFoundException("Pipeline не найден")); + final Pipeline oldPipeline = pipelineRepository.findById(pipeline.getId()) + .orElseThrow(NotFoundException.supplier("Pipeline не найден")); if (!oldPipeline.getUpdated().equals(pipeline.getUpdated())) { pipeline.setProject(oldPipeline.getProject()); @@ -103,7 +105,7 @@ public class PipelineServiceImpl extends AbstractSimpleManagerService getAllByStatuses(@NonNull Set statuses, @NonNull Pagination pagination) { - return repository.findAllByStatuses(statuses, pagination); + return pipelineRepository.findAllByStatuses(statuses, pagination); } @Override @@ -135,4 +137,5 @@ public class PipelineServiceImpl extends AbstractSimpleManagerService new NotFoundException("Пользователь не найден")) + .orElseThrow(NotFoundException.supplier("Пользователь не найден")) .getName(); notifyService.send( NewProjectNotify.builder() diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/DiscussionParser.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/DiscussionParser.java index 28e8d72..d36dcf2 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/DiscussionParser.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/DiscussionParser.java @@ -93,7 +93,7 @@ public class DiscussionParser { return discussion; }) .filter(discussion -> discussion.getNotes() != null && !discussion.getNotes().isEmpty()) - .collect(Collectors.toList()); + .toList(); discussionService.createAll(newDiscussions); } } diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/MergeRequestParser.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/MergeRequestParser.java index c5f7cce..02f6c49 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/MergeRequestParser.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/MergeRequestParser.java @@ -25,7 +25,6 @@ import java.text.MessageFormat; import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import java.util.stream.Stream; import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT; @@ -35,9 +34,9 @@ import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT; public class MergeRequestParser { public static final Integer COUNT = 100; - private static final Set OLD_STATUSES = Stream.of( + private static final Set OLD_STATUSES = Set.of( MergeRequestState.MERGED, MergeRequestState.OPENED, MergeRequestState.CLOSED - ).collect(Collectors.toSet()); + ); private final GitlabProperty gitlabProperty; private final MergeRequestsService mergeRequestsService; @@ -58,7 +57,7 @@ public class MergeRequestParser { parsingCommits(newMergeRequest); return newMergeRequest; }) - .orElseThrow(() -> new NotFoundException("МержРеквест не найден, возможно удален")); + .orElseThrow(NotFoundException.supplier("МержРеквест не найден, возможно удален")); mergeRequestsService.update(mergeRequest); } @@ -98,7 +97,7 @@ public class MergeRequestParser { parsingCommits(mergeRequest); return mergeRequest; }) - .collect(Collectors.toList()); + .toList(); mergeRequestsService.createAll(newMergeRequests); } diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/PipelineParser.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/PipelineParser.java index 6a42382..4ffbc46 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/PipelineParser.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/PipelineParser.java @@ -45,9 +45,9 @@ import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT; public class PipelineParser { public static final Integer COUNT = 100; - private static final Set oldStatus = Stream.of( + private static final Set oldStatus = Set.of( CREATED, WAITING_FOR_RESOURCE, PREPARING, PENDING, RUNNING, MANUAL - ).collect(Collectors.toSet()); + ); private final PipelineService pipelineService; private final ProjectService projectService; private final GitlabProperty gitlabProperty; diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/ProjectParser.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/ProjectParser.java index 16cf753..7cbdb37 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/ProjectParser.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/ProjectParser.java @@ -70,7 +70,7 @@ public class ProjectParser { final List newProjects = projectJsons.stream() .filter(json -> existsContainer.getIdNoFound().contains(json.getId())) .map(json -> conversionService.convert(json, Project.class)) - .collect(Collectors.toList()); + .toList(); if (!newProjects.isEmpty()) { projectService.createAll(newProjects); @@ -97,7 +97,7 @@ public class ProjectParser { .header(StringUtils.H_PRIVATE_TOKEN, personProperty.getToken()) .execute(PersonJson.class) .map(json -> conversionService.convert(json, Person.class)).orElseThrow(() -> new ConvertException("Ошибка преобразования нового пользователя")) - ).collect(Collectors.toList()); + ).toList(); personService.createAll(newPersons); diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/utils/Pair.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/utils/Pair.java deleted file mode 100644 index fc6ad63..0000000 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/utils/Pair.java +++ /dev/null @@ -1,19 +0,0 @@ -package dev.struchkov.bot.gitlab.core.utils; - -import lombok.AllArgsConstructor; -import lombok.Data; - -/** - * Адаптированная реализация Pair из пакета javafx.util. Реализация необходима, так как в некоторых сборках JDK этот - * пакет может отсутствовать. - * - * @author mstruchkov 21.06.2019 - */ -@Data -@AllArgsConstructor -public class Pair { - - private K key; - private V value; - -} diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/utils/StringUtils.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/utils/StringUtils.java index 74d1df4..d9d6192 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/utils/StringUtils.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/utils/StringUtils.java @@ -13,11 +13,4 @@ public class StringUtils { public static final String H_PRIVATE_TOKEN = "PRIVATE-TOKEN"; - public static String cutOff(String string, int length) { - if (string != null) { - return string.length() > length ? string.substring(0, length) + "..." : string; - } - return null; - } - } diff --git a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/MergeRequestRepositoryImpl.java b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/MergeRequestRepositoryImpl.java index ff88340..3af294a 100644 --- a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/MergeRequestRepositoryImpl.java +++ b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/MergeRequestRepositoryImpl.java @@ -23,7 +23,7 @@ public class MergeRequestRepositoryImpl extends FilterManagerRepository findAllIdByStateIn(Set statuses) { + public Set findAllIdByStateIn(@NonNull Set statuses) { return repositoryJpa.findAllIdByStateIn(statuses); } diff --git a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/NotifySettingRepositoryImpl.java b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/NotifySettingRepositoryImpl.java deleted file mode 100644 index ae3ee5f..0000000 --- a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/NotifySettingRepositoryImpl.java +++ /dev/null @@ -1,23 +0,0 @@ -package dev.struchkov.bot.gitlab.data.impl; - -import dev.struchkov.bot.gitlab.context.domain.entity.NotifySetting; -import dev.struchkov.bot.gitlab.context.repository.NotifySettingRepository; -import dev.struchkov.bot.gitlab.data.jpa.NotifySettingJpaRepository; -import dev.struchkov.haiti.database.repository.manager.AbstractSimpleManagerRepository; - -/** - * // 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; - } - -} diff --git a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/jpa/NotifySettingJpaRepository.java b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/jpa/NotifySettingJpaRepository.java deleted file mode 100644 index 4bd0e9e..0000000 --- a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/jpa/NotifySettingJpaRepository.java +++ /dev/null @@ -1,25 +0,0 @@ -package dev.struchkov.bot.gitlab.data.jpa; - -import dev.struchkov.bot.gitlab.context.domain.entity.NotifySetting; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.repository.NoRepositoryBean; -import org.springframework.data.repository.query.Param; - -import java.time.LocalDateTime; -import java.util.Set; - -/** - * // TODO: 20.09.2020 Добавить описание. - * - * @author upagge 20.09.2020 - */ - -@NoRepositoryBean -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/gitlab-app/Dockerfile b/gitlab-app/Dockerfile index f39ad6a..06b6cf3 100644 --- a/gitlab-app/Dockerfile +++ b/gitlab-app/Dockerfile @@ -1,6 +1,6 @@ FROM openjdk:17.0.2-jdk-slim-buster MAINTAINER uPagge -RUN addgroup gitlabbot --disabled-password && \ +RUN apt upgrade && addgroup gitlabbot --disabled-password && \ adduser gitlabbot --ingroup gitlabbot && \ mkdir -p /bot && \ chown -R gitlabbot:gitlabbot /bot diff --git a/gitlab-app/src/main/java/dev/struchkov/bot/gitlab/app/config/AppConfig.java b/gitlab-app/src/main/java/dev/struchkov/bot/gitlab/app/config/AppConfig.java index abdb5bc..f55c121 100644 --- a/gitlab-app/src/main/java/dev/struchkov/bot/gitlab/app/config/AppConfig.java +++ b/gitlab-app/src/main/java/dev/struchkov/bot/gitlab/app/config/AppConfig.java @@ -61,7 +61,7 @@ public class AppConfig { .header(ACCEPT) .header(StringUtils.H_PRIVATE_TOKEN, personProperty.getToken()) .execute(PersonInformation.class) - .orElseThrow(() -> new NotFoundException("Пользователь не найден")); + .orElseThrow(NotFoundException.supplier("Пользователь не найден")); personInformation.setTelegramId(personProperty.getTelegramId()); return personInformation; } diff --git a/pom.xml b/pom.xml index 0657cfb..f0db406 100644 --- a/pom.xml +++ b/pom.xml @@ -52,7 +52,7 @@ 3.1.0 3.1.0 - 0.0.4 + 0.0.5 0.0.2 2.2 diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/ReplaceUrlLocalhost.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/ReplaceUrlLocalhost.java index 541cd58..d0a1c80 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/ReplaceUrlLocalhost.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/ReplaceUrlLocalhost.java @@ -1,9 +1,7 @@ package dev.struchkov.bot.gitlab.telegram.service; import dev.struchkov.bot.gitlab.core.config.properties.GitlabProperty; -import dev.struchkov.bot.gitlab.core.utils.StringUtils; import dev.struchkov.godfather.telegram.service.SendPreProcessing; -import dev.struchkov.haiti.utils.Strings; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -20,7 +18,7 @@ public class ReplaceUrlLocalhost implements SendPreProcessing { @Override public String pretreatment(String s) { - if (property.getReplaceUrl() !=null && !"${GITLAB_REPLACE_URL}".equals(property.getReplaceUrl())) { + if (property.getReplaceUrl() != null && !"${GITLAB_REPLACE_URL}".equals(property.getReplaceUrl())) { return s.replace(property.getReplaceUrl(), property.getBaseUrl()); } return s; diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/MenuConfig.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/MenuConfig.java index 3375490..00f00e0 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/MenuConfig.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/MenuConfig.java @@ -102,7 +102,7 @@ public class MenuConfig { ) { return AnswerText.builder() .boxAnswer(message -> { - final List urlList = Arrays.stream(message.getText().split("/")).collect(Collectors.toList()); + final List urlList = Arrays.stream(message.getText().split("/")).toList(); int lastElement = urlList.size() - 1; final String projectUrl = MessageFormat.format(gitlabProperty.getUrlMergeRequestAdd(), urlList.get(lastElement - 1), urlList.get(lastElement)); projectParser.parseByUrl(projectUrl);