From c5d4decf3962d5da3224dd601a9085178e1bef84 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Sun, 30 Jan 2022 12:34:18 +0300 Subject: [PATCH 1/5] test windows/amd64 --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 010a140..72bd7ba 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -31,4 +31,4 @@ docker-build: script: - cd gitlab-app - docker buildx create --use - - docker buildx build --push --platform linux/amd64,linux/arm64/v8 -t "$CI_REGISTRY_IMAGE:latest" -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG" . \ No newline at end of file + - docker buildx build --push --platform linux/amd64,linux/arm64/v8,windows/amd64 -t "$CI_REGISTRY_IMAGE:latest" -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG" . \ No newline at end of file From 4c2934652471a18d408890974dabd332509ca356 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Sun, 30 Jan 2022 12:35:24 +0300 Subject: [PATCH 2/5] fix cicd --- .gitlab-ci.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 72bd7ba..978d055 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,9 +8,10 @@ build: variables: MAVEN_OPTS: "-Dmaven.repo.local=./.m2/repository" only: - - /^v.*$/ - except: - - branches + - test +# - /^v.*$/ +# except: +# - branches script: - 'mvn -U clean package' artifacts: @@ -21,9 +22,10 @@ docker-build: image: upagge/docker-buildx:latest stage: deploy only: - - /^v.*$/ - except: - - branches +# - /^v.*$/ + - test +# except: +# - branches services: - docker:dind before_script: @@ -31,4 +33,4 @@ docker-build: script: - cd gitlab-app - docker buildx create --use - - docker buildx build --push --platform linux/amd64,linux/arm64/v8,windows/amd64 -t "$CI_REGISTRY_IMAGE:latest" -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG" . \ No newline at end of file + - docker buildx build --push --platform linux/amd64,linux/arm64/v8,windows/amd64 -t "$CI_REGISTRY_IMAGE:latest" . \ No newline at end of file From 2c51e079d6399e59850c131f3518111c7a8e8210 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Sun, 30 Jan 2022 12:46:06 +0300 Subject: [PATCH 3/5] Revert "fix cicd" This reverts commit 4c2934652471a18d408890974dabd332509ca356. --- .gitlab-ci.yml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 978d055..72bd7ba 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,10 +8,9 @@ build: variables: MAVEN_OPTS: "-Dmaven.repo.local=./.m2/repository" only: - - test -# - /^v.*$/ -# except: -# - branches + - /^v.*$/ + except: + - branches script: - 'mvn -U clean package' artifacts: @@ -22,10 +21,9 @@ docker-build: image: upagge/docker-buildx:latest stage: deploy only: -# - /^v.*$/ - - test -# except: -# - branches + - /^v.*$/ + except: + - branches services: - docker:dind before_script: @@ -33,4 +31,4 @@ docker-build: script: - cd gitlab-app - docker buildx create --use - - docker buildx build --push --platform linux/amd64,linux/arm64/v8,windows/amd64 -t "$CI_REGISTRY_IMAGE:latest" . \ No newline at end of file + - docker buildx build --push --platform linux/amd64,linux/arm64/v8,windows/amd64 -t "$CI_REGISTRY_IMAGE:latest" -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG" . \ No newline at end of file From c818b774f4ef86b625aedccc7657467331edb6ca Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Sun, 30 Jan 2022 12:46:07 +0300 Subject: [PATCH 4/5] Revert "test windows/amd64" This reverts commit c5d4decf3962d5da3224dd601a9085178e1bef84. --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 72bd7ba..010a140 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -31,4 +31,4 @@ docker-build: script: - cd gitlab-app - docker buildx create --use - - docker buildx build --push --platform linux/amd64,linux/arm64/v8,windows/amd64 -t "$CI_REGISTRY_IMAGE:latest" -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG" . \ No newline at end of file + - docker buildx build --push --platform linux/amd64,linux/arm64/v8 -t "$CI_REGISTRY_IMAGE:latest" -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG" . \ No newline at end of file From 1c5a083e5f20efbd7065bc6350f0bc4d8ef4ab76 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Sat, 3 Dec 2022 12:39:19 +0300 Subject: [PATCH 5/5] =?UTF-8?q?=D0=91=D0=BE=D0=BB=D1=8C=D1=88=D0=BE=D0=B9?= =?UTF-8?q?=20=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=BD?= =?UTF-8?q?=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot-context/pom.xml | 20 +- .../bot/gitlab/context/domain/AppLocale.java | 35 --- .../context/domain/ExistsContainer.java | 40 +++ .../context/domain/PersonInformation.java | 2 +- .../context/domain/entity/AppSetting.java | 10 +- .../context/domain/entity/Discussion.java | 3 +- .../context/domain/entity/MergeRequest.java | 7 +- .../gitlab/context/domain/entity/Note.java | 3 +- .../gitlab/context/domain/entity/Person.java | 3 +- .../context/domain/entity/Pipeline.java | 5 +- .../gitlab/context/domain/entity/Project.java | 3 +- .../domain/notify/GoodMorningNotify.java | 2 +- .../domain/notify/NewProjectNotify.java | 10 +- .../gitlab/context/domain/notify/Notify.java | 4 +- .../domain/notify/SimpleTextNotify.java | 3 +- .../notify/comment/AnswerCommentNotify.java | 2 +- .../domain/notify/comment/CommentNotify.java | 9 +- .../notify/pipeline/PipelineNotify.java | 5 +- .../notify/pullrequest/ConflictPrNotify.java | 11 +- .../pullrequest/ForgottenSmartPrNotify.java | 9 +- .../notify/pullrequest/NewPrNotify.java | 10 +- .../notify/pullrequest/StatusPrNotify.java | 8 +- .../notify/pullrequest/UpdatePrNotify.java | 9 +- .../domain/notify/task/TaskCloseNotify.java | 9 +- .../domain/notify/task/TaskNewNotify.java | 9 +- .../repository/AppSettingRepository.java | 8 +- .../repository/DiscussionRepository.java | 20 +- .../repository/MergeRequestRepository.java | 19 +- .../context/repository/NoteRepository.java | 14 +- .../context/repository/PersonRepository.java | 13 +- .../repository/PipelineRepository.java | 24 +- .../context/repository/ProjectRepository.java | 19 +- .../context/service/AppSettingService.java | 20 -- .../context/service/DiscussionService.java | 19 +- .../context/service/MergeRequestsService.java | 23 +- .../gitlab/context/service/NoteService.java | 11 +- .../gitlab/context/service/PersonService.java | 18 +- .../context/service/PipelineService.java | 21 +- .../context/service/ProjectService.java | 24 +- bot-core/pom.xml | 13 +- .../config/properties/PersonProperty.java | 2 +- .../convert/MergeRequestJsonConverter.java | 18 +- .../service/impl/AppSettingServiceImpl.java | 31 +- .../core/service/impl/CleanServiceImpl.java | 12 +- .../service/impl/DiscussionServiceImpl.java | 67 +++-- .../impl/MergeRequestsServiceImpl.java | 90 +++--- .../core/service/impl/PersonServiceImpl.java | 50 ++- .../service/impl/PipelineServiceImpl.java | 68 ++--- .../core/service/impl/ProjectServiceImpl.java | 86 ++++-- .../filter/MergeRequestFilterService.java | 22 +- .../impl/filter/PipelineFilterService.java | 22 +- .../service/impl/note/NoteServiceImpl.java | 34 +-- .../core/service/parser/DiscussionParser.java | 14 +- .../service/parser/MergeRequestParser.java | 10 +- .../core/service/parser/PipelineParser.java | 18 +- .../core/service/parser/ProjectParser.java | 8 +- bot-data/pom.xml | 7 +- .../data/impl/AppSettingRepositoryImpl.java | 20 +- .../data/impl/DiscussionRepositoryImpl.java | 39 ++- .../data/impl/MergeRequestRepositoryImpl.java | 51 +++- .../gitlab/data/impl/NoteRepositoryImpl.java | 30 +- .../data/impl/PersonRepositoryImpl.java | 28 +- .../data/impl/PipelineRepositoryImpl.java | 48 ++- .../data/impl/ProjectRepositoryImpl.java | 40 ++- ...ositoryJpa.java => NoteJpaRepository.java} | 2 +- gitlab-app/Dockerfile-debug | 23 ++ gitlab-app/pom.xml | 3 +- .../bot/gitlab/app/config/AppConfig.java | 4 +- .../{application.yaml => application.yml} | 8 +- .../{v.1.0.0/cumulative.xml => changelog.xml} | 2 +- ...ables.xml => 2022-12-03-create-tables.xml} | 70 +++-- .../liquibase/v.1.0.0/2022-12-03-insert.xml | 14 + .../{change-log.xml => v.1.0.0/changelog.xml} | 7 +- .../src/main/resources/messages_en.properties | 30 -- .../src/main/resources/messages_ru.properties | 30 -- gitlab-sdk/pom.xml | 3 +- pom.xml | 86 +++--- telegram-bot/pom.xml | 17 +- .../telegram/config/TelegramBotConfig.java | 104 ++++--- .../telegram/scheduler/CheckNewMessage.java | 19 -- .../service/MessageSendTelegramService.java | 11 +- .../telegram/service/ReplaceUrlLocalhost.java | 2 +- .../gitlab/telegram/service/StartNotify.java | 2 +- .../PullRequestNeedWorkProcessing.java | 12 +- .../PullRequestReviewProcessing.java | 12 +- .../bot/gitlab/telegram/unit/MenuConfig.java | 206 ++++++------- .../bot/gitlab/telegram/unit/UnitConfig.java | 284 ++++++++---------- .../unit/menu/MenuSettingsConfig.java | 54 ---- .../bot/gitlab/telegram/utils/UnitName.java | 29 ++ 89 files changed, 1306 insertions(+), 1040 deletions(-) delete mode 100644 bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/AppLocale.java create mode 100644 bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/ExistsContainer.java rename bot-data/src/main/java/dev/struchkov/bot/gitlab/data/jpa/{NoteRepositoryJpa.java => NoteJpaRepository.java} (87%) create mode 100644 gitlab-app/Dockerfile-debug rename gitlab-app/src/main/resources/{application.yaml => application.yml} (85%) rename gitlab-app/src/main/resources/liquibase/{v.1.0.0/cumulative.xml => changelog.xml} (80%) rename gitlab-app/src/main/resources/liquibase/v.1.0.0/{2021-01-14-create-tables.xml => 2022-12-03-create-tables.xml} (80%) create mode 100644 gitlab-app/src/main/resources/liquibase/v.1.0.0/2022-12-03-insert.xml rename gitlab-app/src/main/resources/liquibase/{change-log.xml => v.1.0.0/changelog.xml} (52%) delete mode 100644 gitlab-app/src/main/resources/messages_en.properties delete mode 100644 gitlab-app/src/main/resources/messages_ru.properties delete mode 100644 telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/scheduler/CheckNewMessage.java delete mode 100644 telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/menu/MenuSettingsConfig.java create mode 100644 telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/utils/UnitName.java diff --git a/bot-context/pom.xml b/bot-context/pom.xml index ca2154b..45bc7fa 100644 --- a/bot-context/pom.xml +++ b/bot-context/pom.xml @@ -6,13 +6,22 @@ dev.struchkov.bot.gitlab gitlab-bot - 1.0.0 + 1.1.0 bot-context - ${gitlab.context.version} + + dev.struchkov.haiti.utils + haiti-utils-field-constants + + + + org.springframework.data + spring-data-jpa + + org.projectlombok lombok @@ -20,7 +29,7 @@ dev.struchkov.haiti - haiti-context + haiti-utils @@ -32,11 +41,6 @@ javax.persistence javax.persistence-api - - - org.hibernate.orm - hibernate-jpamodelgen - \ No newline at end of file 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 deleted file mode 100644 index f4821de..0000000 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/AppLocale.java +++ /dev/null @@ -1,35 +0,0 @@ -package dev.struchkov.bot.gitlab.context.domain; - -import dev.struchkov.haiti.context.exception.NotFoundException; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NonNull; - -import java.util.Arrays; -import java.util.Locale; - -/** - * Список локализаций приложения. - * - * @author upagge 16.01.2021 - */ -@Getter -@AllArgsConstructor -public enum AppLocale { - - RU("Русский"), EN("English"); - - private final String label; - - public static AppLocale of(@NonNull String label) { - return Arrays.stream(values()) - .filter(appLocale -> appLocale.getLabel().equals(label)) - .findFirst() - .orElseThrow(NotFoundException.supplier("Ошибка, локализация не найдена. Попробуйте снова.")); - } - - public Locale getValue() { - return Locale.forLanguageTag(name().toLowerCase()); - } - -} diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/ExistsContainer.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/ExistsContainer.java new file mode 100644 index 0000000..be81a33 --- /dev/null +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/ExistsContainer.java @@ -0,0 +1,40 @@ +package dev.struchkov.bot.gitlab.context.domain; + +import lombok.NonNull; + +import java.util.Collection; +import java.util.Collections; + +public class ExistsContainer { + + protected final Collection container; + protected final boolean allFound; + protected final Collection idNoFound; + + protected ExistsContainer(Collection container, boolean allFound, Collection idNoFound) { + this.container = container; + this.allFound = allFound; + this.idNoFound = idNoFound; + } + + public static ExistsContainer allFind(@NonNull Collection container) { + return new ExistsContainer<>(container, true, Collections.emptyList()); + } + + public static ExistsContainer notAllFind(@NonNull Collection container, @NonNull Collection idNoFound) { + return new ExistsContainer<>(container, false, idNoFound); + } + + public Collection getContainer() { + return container; + } + + public boolean isAllFound() { + return allFound; + } + + public Collection getIdNoFound() { + return idNoFound; + } + +} 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 362753e..c95a4ea 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 @@ -13,6 +13,6 @@ public class PersonInformation { private String username; private String name; private Long id; - private Long telegramId; + private String telegramId; } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/AppSetting.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/AppSetting.java index 9a6ba7a..cf10d74 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/AppSetting.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/AppSetting.java @@ -1,14 +1,10 @@ package dev.struchkov.bot.gitlab.context.domain.entity; -import dev.struchkov.haiti.context.domain.BasicEntity; import lombok.Getter; import lombok.Setter; -import dev.struchkov.bot.gitlab.context.domain.AppLocale; import javax.persistence.Column; import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; import javax.persistence.Id; import javax.persistence.Table; @@ -21,16 +17,12 @@ import javax.persistence.Table; @Getter @Setter @Table(name = "app_setting") -public class AppSetting implements BasicEntity { +public class AppSetting { @Id @Column(name = "id") private Long id; - @Column(name = "language") - @Enumerated(EnumType.STRING) - private AppLocale appLocale; - @Column(name = "first_start") private boolean firstStart; diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Discussion.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Discussion.java index e8f4638..2887848 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Discussion.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Discussion.java @@ -1,6 +1,5 @@ package dev.struchkov.bot.gitlab.context.domain.entity; -import dev.struchkov.haiti.context.domain.BasicEntity; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @@ -25,7 +24,7 @@ import java.util.List; @Entity @Table(name = "discussion") @EqualsAndHashCode(onlyExplicitlyIncluded = true) -public class Discussion implements BasicEntity { +public class Discussion { @Id @Column(name = "id") diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/MergeRequest.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/MergeRequest.java index 6e207d7..92038d9 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/MergeRequest.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/MergeRequest.java @@ -1,10 +1,10 @@ package dev.struchkov.bot.gitlab.context.domain.entity; -import dev.struchkov.haiti.context.domain.BasicEntity; +import dev.struchkov.bot.gitlab.context.domain.MergeRequestState; +import dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; -import dev.struchkov.bot.gitlab.context.domain.MergeRequestState; import javax.persistence.CollectionTable; import javax.persistence.Column; @@ -28,9 +28,10 @@ import java.util.Set; @Getter @Setter @Entity +@FieldNames @Table(name = "merge_request") @EqualsAndHashCode(onlyExplicitlyIncluded = true) -public class MergeRequest implements BasicEntity { +public class MergeRequest { @Id @Column(name = "id") diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Note.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Note.java index 6982974..504d3d0 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Note.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Note.java @@ -1,6 +1,5 @@ package dev.struchkov.bot.gitlab.context.domain.entity; -import dev.struchkov.haiti.context.domain.BasicEntity; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @@ -18,7 +17,7 @@ import java.time.LocalDateTime; @Entity @Table(name = "note") @EqualsAndHashCode(onlyExplicitlyIncluded = true) -public class Note implements BasicEntity { +public class Note { @Id @Column diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Person.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Person.java index 5b26571..21ba442 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Person.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Person.java @@ -1,6 +1,5 @@ package dev.struchkov.bot.gitlab.context.domain.entity; -import dev.struchkov.haiti.context.domain.BasicEntity; import lombok.Getter; import lombok.Setter; @@ -16,7 +15,7 @@ import javax.persistence.Table; @Getter @Setter @Table(name = "person") -public class Person implements BasicEntity { +public class Person { @Id @Column(name = "id") 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 83f9ffe..2270802 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,7 +1,7 @@ package dev.struchkov.bot.gitlab.context.domain.entity; import dev.struchkov.bot.gitlab.context.domain.PipelineStatus; -import dev.struchkov.haiti.context.domain.BasicEntity; +import dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @@ -23,9 +23,10 @@ import java.time.LocalDateTime; @Entity @Getter @Setter +@FieldNames @Table(name = "pipeline") @EqualsAndHashCode(onlyExplicitlyIncluded = true) -public class Pipeline implements BasicEntity { +public class Pipeline { @Id @Column(name = "id") diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Project.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Project.java index 196cc7e..5780992 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Project.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Project.java @@ -1,6 +1,5 @@ package dev.struchkov.bot.gitlab.context.domain.entity; -import dev.struchkov.haiti.context.domain.BasicEntity; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @@ -19,7 +18,7 @@ import java.time.LocalDateTime; @Entity @Table(name = "project") @EqualsAndHashCode(onlyExplicitlyIncluded = true) -public class Project implements BasicEntity { +public class Project { @Id @Column(name = "id") 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 acc9539..aad6c68 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 @@ -27,7 +27,7 @@ public record GoodMorningNotify( } @Override - public String generateMessage(AppSettingService settingService) { + public String generateMessage() { 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); 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 524247c..436578d 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 @@ -1,16 +1,16 @@ 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 java.text.MessageFormat; + import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; /** * @author upagge 15.01.2021 */ - public record NewProjectNotify( String projectName, String projectUrl, @@ -23,9 +23,9 @@ public record NewProjectNotify( } @Override - public String generateMessage(AppSettingService settingService) { - return settingService.getMessage( - "notify.project.new", + public String generateMessage() { + return MessageFormat.format( + "{0} *New project*{1}[{2}]({3}){1}{4}{5}: {6}", Smile.FUN.getValue(), Smile.HR.getValue(), projectName, projectUrl, (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 b09c2ac..6c1bb37 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,9 +1,7 @@ package dev.struchkov.bot.gitlab.context.domain.notify; -import dev.struchkov.bot.gitlab.context.service.AppSettingService; - public interface Notify { - String generateMessage(AppSettingService appSettingService); + String generateMessage(); } 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 dd81239..4c20a25 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 @@ -1,6 +1,5 @@ package dev.struchkov.bot.gitlab.context.domain.notify; -import dev.struchkov.bot.gitlab.context.service.AppSettingService; import lombok.Builder; /** @@ -13,7 +12,7 @@ public record SimpleTextNotify(String message) implements Notify { } @Override - public String generateMessage(AppSettingService appSettingService) { + public String generateMessage() { return 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 93fcee8..951e988 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 @@ -34,7 +34,7 @@ public class AnswerCommentNotify implements Notify { } @Override - public String generateMessage(AppSettingService settingService) { + public String generateMessage() { final String answerText = answers.stream() .map(answer -> answer.getAuthorName() + ": " + answer.getMessage().substring(0, Math.min(answer.getMessage().length(), 500))) .collect(Collectors.joining(TWO_NEW_LINE)); 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 1ec4191..1f22e22 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 @@ -1,10 +1,11 @@ package dev.struchkov.bot.gitlab.context.domain.notify.comment; 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; public record CommentNotify( @@ -18,9 +19,9 @@ public record CommentNotify( } @Override - public String generateMessage(AppSettingService settingService) { - return settingService.getMessage( - "notify.comment.bell", + public String generateMessage() { + return MessageFormat.format( + "{0} *New mention* | [MR]({1}){2}*{3}*: {4}", Smile.COMMENT.getValue(), url, Smile.HR.getValue(), authorName, escapeMarkdown(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 99f0a63..28e7be1 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,7 +1,6 @@ package dev.struchkov.bot.gitlab.context.domain.notify.pipeline; 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; @@ -26,9 +25,9 @@ public record PipelineNotify( } @Override - public String generateMessage(AppSettingService appSettingService) { + public String generateMessage() { return MessageFormat.format( - appSettingService.getMessage("notify.pipeline"), + "{0} *Pipeline {1,number,#}* | {2}{3}[{4}]({5}){3}{6} {7} {8}", Smile.BUILD, pipelineId, escapeMarkdown(projectName), diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/ConflictPrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/ConflictPrNotify.java index 66805bf..4dae705 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/ConflictPrNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/ConflictPrNotify.java @@ -1,9 +1,10 @@ package dev.struchkov.bot.gitlab.context.domain.notify.pullrequest; +import dev.struchkov.bot.gitlab.context.utils.Smile; import lombok.Builder; import lombok.Getter; -import dev.struchkov.bot.gitlab.context.service.AppSettingService; -import dev.struchkov.bot.gitlab.context.utils.Smile; + +import java.text.MessageFormat; @Getter public class ConflictPrNotify extends PrNotify { @@ -22,9 +23,9 @@ public class ConflictPrNotify extends PrNotify { } @Override - public String generateMessage(AppSettingService settingService) { - return settingService.getMessage( - "notify.pr.conflict", + public String generateMessage() { + return MessageFormat.format( + "{0} *Attention! MergeRequest conflict | {4}*{1}[{2}]({3})", Smile.DANGEROUS.getValue(), Smile.HR.getValue(), title, url, projectName, sourceBranch ); } 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 269025e..a45a6c9 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 @@ -3,7 +3,8 @@ package dev.struchkov.bot.gitlab.context.domain.notify.pullrequest; import dev.struchkov.bot.gitlab.context.utils.Smile; import lombok.Builder; import lombok.Getter; -import dev.struchkov.bot.gitlab.context.service.AppSettingService; + +import java.text.MessageFormat; /** * // TODO: 11.10.2020 Добавить описание. @@ -25,9 +26,9 @@ public class ForgottenSmartPrNotify extends PrNotify { } @Override - public String generateMessage(AppSettingService appSettingService) { - return appSettingService.getMessage( - "notify.pr.forgotten", + public String generateMessage() { + return MessageFormat.format( + "{0} *MergeRequest Review Reminder | {4}*{3}[{1}]({2})", Smile.SMART.getValue(), title, url, Smile.HR.getValue(), projectName ); } 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 aba542e..5fbd1b2 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,11 +1,11 @@ package dev.struchkov.bot.gitlab.context.domain.notify.pullrequest; +import dev.struchkov.bot.gitlab.context.utils.Smile; import dev.struchkov.haiti.utils.Strings; import lombok.Builder; import lombok.Getter; -import dev.struchkov.bot.gitlab.context.service.AppSettingService; -import dev.struchkov.bot.gitlab.context.utils.Smile; +import java.text.MessageFormat; import java.util.Set; import java.util.stream.Collectors; @@ -40,15 +40,15 @@ public class NewPrNotify extends PrNotify { } @Override - public String generateMessage(AppSettingService settingService) { + public String generateMessage() { String labelText = labels.stream() .map(label -> "#" + label) .collect(Collectors.joining(" ")); if (!labelText.isEmpty()) { labelText = "\n\n" + labelText; } - return settingService.getMessage( - "notify.pr.new", + return MessageFormat.format( + "{0} *New MergeRequest | {1}*{2}[{3}]({4}){5}{2}{9}: {10} {12} {11}", Smile.FUN.getValue(), projectName, Smile.HR.getValue(), diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/StatusPrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/StatusPrNotify.java index 650bd14..7c0b2c2 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/StatusPrNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/StatusPrNotify.java @@ -6,6 +6,8 @@ import dev.struchkov.bot.gitlab.context.domain.MergeRequestState; import dev.struchkov.bot.gitlab.context.service.AppSettingService; import dev.struchkov.bot.gitlab.context.utils.Smile; +import java.text.MessageFormat; + @Getter public class StatusPrNotify extends PrNotify { @@ -26,9 +28,9 @@ public class StatusPrNotify extends PrNotify { } @Override - public String generateMessage(AppSettingService settingService) { - return settingService.getMessage( - "notify.pr.state", + public String generateMessage() { + return MessageFormat.format( + "{0} *MergeRequest status changed | {7}*{1}[{2}]({3}){1}{4} {5} {6}", Smile.PEN.getValue(), Smile.HR.getValue(), title, url, oldStatus.name(), Smile.ARROW.getValue(), newStatus.name(), projectName ); } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/UpdatePrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/UpdatePrNotify.java index 3dbf187..99a30b0 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/UpdatePrNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/UpdatePrNotify.java @@ -3,7 +3,8 @@ package dev.struchkov.bot.gitlab.context.domain.notify.pullrequest; import dev.struchkov.bot.gitlab.context.utils.Smile; import lombok.Builder; import lombok.Getter; -import dev.struchkov.bot.gitlab.context.service.AppSettingService; + +import java.text.MessageFormat; @Getter public class UpdatePrNotify extends PrNotify { @@ -34,9 +35,9 @@ public class UpdatePrNotify extends PrNotify { } @Override - public String generateMessage(AppSettingService settingService) { - return settingService.getMessage( - "notify.pr.update", + public String generateMessage() { + return MessageFormat.format( + "{0} *MergeRequest update | {6}*{3}[{1}]({2}){3}{4}: {5}", Smile.UPDATE.getValue(), title, url, Smile.HR.getValue(), Smile.AUTHOR.getValue(), author, projectName, allTasks, allResolvedTasks, personTasks, personResolvedTasks ); } 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 b4bfb28..776d5b1 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 @@ -1,9 +1,10 @@ package dev.struchkov.bot.gitlab.context.domain.notify.task; -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; /** @@ -28,9 +29,9 @@ public class TaskCloseNotify extends TaskNotify { } @Override - public String generateMessage(AppSettingService settingService) { - return settingService.getMessage( - "notify.task.close", + public String generateMessage() { + return MessageFormat.format( + "{0} *Closed [task]({1}){2}*{3}*: {4}", Smile.TASK.getValue(), url, Smile.HR.getValue(), authorName, escapeMarkdown(messageTask), personTasks, personResolvedTasks ); } 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 2f56056..8066f57 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 @@ -1,10 +1,11 @@ package dev.struchkov.bot.gitlab.context.domain.notify.task; -import dev.struchkov.bot.gitlab.context.service.AppSettingService; import dev.struchkov.bot.gitlab.context.utils.Smile; import lombok.Builder; import lombok.Getter; +import java.text.MessageFormat; + import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; /** @@ -23,9 +24,9 @@ public class TaskNewNotify extends TaskNotify { } @Override - public String generateMessage(AppSettingService settingService) { - return settingService.getMessage( - "notify.task.new", + public String generateMessage() { + return MessageFormat.format( + "{0} *New [task]({1}) assigned{2}*{3}*: {4}", Smile.TASK.getValue(), url, Smile.HR.getValue(), authorName, escapeMarkdown(messageTask) ); } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/AppSettingRepository.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/AppSettingRepository.java index 5fba2ef..00aaf16 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/AppSettingRepository.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/AppSettingRepository.java @@ -1,11 +1,15 @@ package dev.struchkov.bot.gitlab.context.repository; import dev.struchkov.bot.gitlab.context.domain.entity.AppSetting; -import dev.struchkov.haiti.context.repository.SimpleManagerRepository; + +import java.util.Optional; /** * @author upagge 16.01.2021 */ -public interface AppSettingRepository extends SimpleManagerRepository { +public interface AppSettingRepository { + AppSetting save(AppSetting appSetting); + + Optional findById(Long key); } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/DiscussionRepository.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/DiscussionRepository.java index 4bad62d..986d71b 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/DiscussionRepository.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/DiscussionRepository.java @@ -1,19 +1,31 @@ package dev.struchkov.bot.gitlab.context.repository; import dev.struchkov.bot.gitlab.context.domain.entity.Discussion; -import dev.struchkov.haiti.context.repository.SimpleManagerRepository; -import lombok.NonNull; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import java.util.List; +import java.util.Optional; +import java.util.Set; /** * @author upagge 11.02.2021 */ -public interface DiscussionRepository extends SimpleManagerRepository { +public interface DiscussionRepository { /** * Вернуть все дискусии для MR */ - List findAllByMergeRequestId(@NonNull Long mergeRequestId); + List findAllByMergeRequestId(Long mergeRequestId); + + Discussion save(Discussion discussion); + + Optional findById(String discussionId); + + void deleteById(String discussionId); + + Page findAll(Pageable pagination); + + List findAllById(Set discussionIds); } 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 e7d5c3a..cbe8d6a 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 @@ -3,18 +3,31 @@ 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 dev.struchkov.haiti.filter.Filter; import lombok.NonNull; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import java.util.List; +import java.util.Optional; import java.util.Set; -public interface MergeRequestRepository extends SimpleManagerRepository, FilterOperation { +public interface MergeRequestRepository { Set findAllIdByStateIn(@NonNull Set states); //TODO [28.01.2022]: Решить, нужно ли оставить List findAllByAssignee(@NonNull Long userId); + MergeRequest save(MergeRequest mergeRequest); + + Optional findById(Long mergeRequestId); + + Page findAll(Pageable pagination); + + List findAllById(Set mergeRequestIds); + + void deleteByIds(Set mergeRequestIds); + + Page filter(Filter filter, Pageable pageable); } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/NoteRepository.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/NoteRepository.java index 940b41a..9fab3b7 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/NoteRepository.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/NoteRepository.java @@ -1,20 +1,20 @@ package dev.struchkov.bot.gitlab.context.repository; import dev.struchkov.bot.gitlab.context.domain.entity.Note; -import dev.struchkov.haiti.context.page.Pagination; -import dev.struchkov.haiti.context.page.Sheet; -import dev.struchkov.haiti.context.repository.SimpleManagerRepository; -import lombok.NonNull; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import java.util.List; +import java.util.Optional; /** * @author upagge 08.09.2020 */ -public interface NoteRepository extends SimpleManagerRepository { +public interface NoteRepository { - List findAllByResponsibleIdAndResolved(@NonNull Long userId, boolean resolved); + List findAllByResponsibleIdAndResolved(Long userId, boolean resolved); - Sheet findAllByResolved(boolean resolved, @NonNull Pagination pagination); + Page findAllByResolved(boolean resolved, Pageable pagination); + Optional findById(Long noteId); } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/PersonRepository.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/PersonRepository.java index 70897ec..1cbe322 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/PersonRepository.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/PersonRepository.java @@ -1,11 +1,20 @@ package dev.struchkov.bot.gitlab.context.repository; import dev.struchkov.bot.gitlab.context.domain.entity.Person; -import dev.struchkov.haiti.context.repository.SimpleManagerRepository; + +import java.util.List; +import java.util.Optional; +import java.util.Set; /** * @author upagge 15.01.2021 */ -public interface PersonRepository extends SimpleManagerRepository { +public interface PersonRepository { + + Person save(Person person); + + Optional findById(Long personId); + + List findAllById(Set personIds); } 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 a0b43c6..4ec5d97 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 @@ -2,19 +2,29 @@ package dev.struchkov.bot.gitlab.context.repository; import dev.struchkov.bot.gitlab.context.domain.PipelineStatus; import dev.struchkov.bot.gitlab.context.domain.entity.Pipeline; -import dev.struchkov.haiti.context.page.Pagination; -import dev.struchkov.haiti.context.page.Sheet; -import dev.struchkov.haiti.context.repository.SimpleManagerRepository; -import dev.struchkov.haiti.filter.FilterOperation; -import lombok.NonNull; +import dev.struchkov.haiti.filter.Filter; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import java.util.List; +import java.util.Optional; import java.util.Set; /** * @author upagge 17.01.2021 */ -public interface PipelineRepository extends SimpleManagerRepository, FilterOperation { +public interface PipelineRepository { - Sheet findAllByStatuses(@NonNull Set statuses, @NonNull Pagination pagination); + Pipeline save(Pipeline pipeline); + + Optional findById(Long pipelineId); + + Page findAllByStatuses(Set statuses, Pageable pagination); + + List findAllById(Set pipelineIds); + + void deleteAllByIds(Set pipelineIds); + + Page filter(Filter filter, Pageable pagination); } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/ProjectRepository.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/ProjectRepository.java index 114935b..5130554 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/ProjectRepository.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/ProjectRepository.java @@ -1,11 +1,26 @@ package dev.struchkov.bot.gitlab.context.repository; import dev.struchkov.bot.gitlab.context.domain.entity.Project; -import dev.struchkov.haiti.context.repository.SimpleManagerRepository; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +import java.util.List; +import java.util.Optional; +import java.util.Set; /** * @author upagge 14.01.2021 */ -public interface ProjectRepository extends SimpleManagerRepository { +public interface ProjectRepository { + + Project save(Project project); + + Optional findById(Long projectId); + + List findAllById(Set projectIds); + + boolean existById(Long projectId); + + Page findAllById(Pageable pagination); } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/AppSettingService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/AppSettingService.java index ca06ffc..f42eb44 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/AppSettingService.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/AppSettingService.java @@ -1,8 +1,5 @@ package dev.struchkov.bot.gitlab.context.service; -import dev.struchkov.bot.gitlab.context.domain.AppLocale; -import lombok.NonNull; - /** * Сервис отвечает за пользовательские настройки приложения. * @@ -24,21 +21,4 @@ public interface AppSettingService { */ void disableFirstStart(); - /** - * Позволяет получить по ключу текст на языке, который установил пользователь - * - * @param label ключ сообщений - * @return Сообщение на языке пользователя - */ - String getMessage(@NonNull String label); - - String getMessage(@NonNull String label, Object... params); - - /** - * Устанавливает язык приложения - * - * @param appLocale Язык, который необходимо установить - */ - void setLocale(@NonNull AppLocale appLocale); - } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/DiscussionService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/DiscussionService.java index b1dc6bf..11707a7 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/DiscussionService.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/DiscussionService.java @@ -1,15 +1,22 @@ package dev.struchkov.bot.gitlab.context.service; +import dev.struchkov.bot.gitlab.context.domain.ExistsContainer; import dev.struchkov.bot.gitlab.context.domain.entity.Discussion; -import dev.struchkov.haiti.context.service.SimpleManagerService; import lombok.NonNull; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import java.util.List; +import java.util.Set; /** * @author upagge 11.02.2021 */ -public interface DiscussionService extends SimpleManagerService { +public interface DiscussionService { + + Discussion create(@NonNull Discussion discussion); + + Discussion update(@NonNull Discussion discussion); /** * Метод отправляющий коментарий в дискуссию. @@ -24,4 +31,12 @@ public interface DiscussionService extends SimpleManagerService getAllByMergeRequestId(@NonNull Long mergeRequestId); + ExistsContainer existsById(@NonNull Set discussionIds); + + List createAll(@NonNull List newDiscussions); + + Page getAll(@NonNull Pageable pagination); + + void deleteById(String discussionId); + } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/MergeRequestsService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/MergeRequestsService.java index ec5453d..91172bc 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/MergeRequestsService.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/MergeRequestsService.java @@ -1,15 +1,22 @@ package dev.struchkov.bot.gitlab.context.service; +import dev.struchkov.bot.gitlab.context.domain.ExistsContainer; 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.service.SimpleManagerService; -import dev.struchkov.haiti.context.service.simple.FilterService; import dev.struchkov.bot.gitlab.context.domain.filter.MergeRequestFilter; +import lombok.NonNull; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import java.util.List; import java.util.Set; -public interface MergeRequestsService extends SimpleManagerService, FilterService { +public interface MergeRequestsService { + + MergeRequest create(@NonNull MergeRequest mergeRequest); + + MergeRequest update(@NonNull MergeRequest mergeRequest); /** * Получить все идентификаторы вместе со статусами. @@ -19,4 +26,14 @@ public interface MergeRequestsService extends SimpleManagerService getAllId(Set statuses); + Page getAll(Pageable pagination); + + Page getAll(@NonNull MergeRequestFilter filter, Pageable pagination); + + ExistsContainer existsById(@NonNull Set mergeRequestIds); + + List createAll(List newMergeRequests); + + void deleteAllById(@NonNull Set mergeRequestIds); + } 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 7ac56a9..420dd5c 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 @@ -1,18 +1,19 @@ package dev.struchkov.bot.gitlab.context.service; import dev.struchkov.bot.gitlab.context.domain.entity.Note; -import dev.struchkov.haiti.context.page.Pagination; -import dev.struchkov.haiti.context.page.Sheet; -import dev.struchkov.haiti.context.service.SimpleManagerService; import lombok.NonNull; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import java.util.List; -public interface NoteService extends SimpleManagerService { +public interface NoteService { List getAllPersonTask(@NonNull Long userId, boolean resolved); //TODO [28.01.2022]: Решить нужно ли оставлять - Sheet getAllByResolved(boolean resolved, @NonNull Pagination pagination); + Page getAllByResolved(boolean resolved, @NonNull Pageable pagination); + + Note getByIdOrThrow(@NonNull Long noteId); } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PersonService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PersonService.java index ef59913..2fd6772 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PersonService.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PersonService.java @@ -1,11 +1,25 @@ package dev.struchkov.bot.gitlab.context.service; +import dev.struchkov.bot.gitlab.context.domain.ExistsContainer; import dev.struchkov.bot.gitlab.context.domain.entity.Person; -import dev.struchkov.haiti.context.service.SimpleManagerService; +import lombok.NonNull; + +import java.util.List; +import java.util.Set; /** * @author upagge 15.01.2021 */ -public interface PersonService extends SimpleManagerService { +public interface PersonService { + + Person create(@NonNull Person person); + + Person update(@NonNull Person person); + + Person getByIdOrThrown(@NonNull Long personId); + + ExistsContainer existsById(Set personIds); + + List createAll(List newPersons); } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PipelineService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PipelineService.java index 6410855..f2ceacd 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PipelineService.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PipelineService.java @@ -3,11 +3,10 @@ package dev.struchkov.bot.gitlab.context.service; import dev.struchkov.bot.gitlab.context.domain.PipelineStatus; import dev.struchkov.bot.gitlab.context.domain.entity.Pipeline; import dev.struchkov.bot.gitlab.context.domain.filter.PipelineFilter; -import dev.struchkov.haiti.context.page.Pagination; -import dev.struchkov.haiti.context.page.Sheet; -import dev.struchkov.haiti.context.service.SimpleManagerService; -import dev.struchkov.haiti.context.service.simple.FilterService; +import dev.struchkov.haiti.context.domain.ExistsContainer; import lombok.NonNull; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import java.util.Set; @@ -16,8 +15,18 @@ import java.util.Set; * * @author upagge 17.01.2021 */ -public interface PipelineService extends SimpleManagerService, FilterService { +public interface PipelineService { - Sheet getAllByStatuses(@NonNull Set statuses, @NonNull Pagination pagination); + Pipeline create(@NonNull Pipeline pipeline); + + Pipeline update(@NonNull Pipeline pipeline); + + Page getAllByStatuses(@NonNull Set statuses, @NonNull Pageable pagination); + + Page getAll(@NonNull PipelineFilter filter, @NonNull Pageable pagination); + + ExistsContainer existsById(@NonNull Set pipelineIds); + + void deleteAllById(Set pipelineIds); } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/ProjectService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/ProjectService.java index b6ffd59..8b23c4a 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/ProjectService.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/ProjectService.java @@ -1,11 +1,31 @@ package dev.struchkov.bot.gitlab.context.service; +import dev.struchkov.bot.gitlab.context.domain.ExistsContainer; import dev.struchkov.bot.gitlab.context.domain.entity.Project; -import dev.struchkov.haiti.context.service.SimpleManagerService; +import lombok.NonNull; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +import java.util.List; +import java.util.Set; /** * @author upagge 14.01.2021 */ -public interface ProjectService extends SimpleManagerService { +public interface ProjectService { + + Project create(@NonNull Project project); + + Project update(@NonNull Project project); + + Project getByIdOrThrow(@NonNull Long projectId); + + Page getAll(@NonNull Pageable pagination); + + List createAll(List newProjects); + + boolean existsById(Long projectId); + + ExistsContainer existsById(Set projectIds); } diff --git a/bot-core/pom.xml b/bot-core/pom.xml index ba56b45..8b895f9 100644 --- a/bot-core/pom.xml +++ b/bot-core/pom.xml @@ -6,11 +6,10 @@ dev.struchkov.bot.gitlab gitlab-bot - 1.0.0 + 1.1.0 bot-core - ${gitlab.core.version} @@ -23,16 +22,6 @@ bot-context - - dev.struchkov.haiti.data - haiti-database - - - - org.hibernate.orm - hibernate-jpamodelgen - - org.springframework.boot spring-boot-configuration-processor diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/config/properties/PersonProperty.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/config/properties/PersonProperty.java index 6a66c86..3d9d9f0 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/config/properties/PersonProperty.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/config/properties/PersonProperty.java @@ -16,6 +16,6 @@ import org.springframework.context.annotation.Configuration; public class PersonProperty { private String token; - private Long telegramId; + private String telegramId; } 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 804aac2..820ffdb 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 @@ -4,11 +4,15 @@ import dev.struchkov.bot.gitlab.context.domain.MergeRequestState; import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest; import dev.struchkov.bot.gitlab.sdk.domain.MergeRequestJson; import dev.struchkov.bot.gitlab.sdk.domain.MergeRequestStateJson; -import dev.struchkov.haiti.context.exception.ConvertException; import lombok.RequiredArgsConstructor; import org.springframework.core.convert.converter.Converter; import org.springframework.stereotype.Component; +import java.util.Set; +import java.util.stream.Collectors; + +import static dev.struchkov.haiti.utils.Checker.checkNotEmpty; + /** * @author upagge 15.01.2021 */ @@ -31,7 +35,7 @@ public class MergeRequestJsonConverter implements Converter convertLabels(Set source) { + if (checkNotEmpty(source)) { + return source.stream() + .map(label -> label.replaceAll("-", "_")) + .collect(Collectors.toSet()); + } + return null; + } + private MergeRequestState convertState(MergeRequestStateJson state) { return switch (state) { case CLOSED -> 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/impl/AppSettingServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/AppSettingServiceImpl.java index fca7932..d9ce143 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 @@ -1,19 +1,17 @@ package dev.struchkov.bot.gitlab.core.service.impl; -import dev.struchkov.bot.gitlab.context.domain.AppLocale; import dev.struchkov.bot.gitlab.context.domain.entity.AppSetting; import dev.struchkov.bot.gitlab.context.repository.AppSettingRepository; import dev.struchkov.bot.gitlab.context.service.AppSettingService; import dev.struchkov.haiti.context.exception.NotFoundException; -import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.springframework.context.MessageSource; import org.springframework.stereotype.Service; -import java.util.Arrays; -import java.util.Locale; import java.util.function.Supplier; +import static dev.struchkov.haiti.context.exception.NotFoundException.notFoundException; + /** * Сервис отвечает за пользовательские настройки приложения. * @@ -24,7 +22,7 @@ import java.util.function.Supplier; public class AppSettingServiceImpl implements AppSettingService { private static final Long KEY = 1L; - public static final Supplier NOT_FOUND_SETTINGS = NotFoundException.supplier("Ошибка, невозможно найти настройки приложения, проверьте базу данных."); + public static final Supplier NOT_FOUND_SETTINGS = notFoundException("Ошибка, невозможно найти настройки приложения, проверьте базу данных."); private final AppSettingRepository appSettingRepository; private final MessageSource messageSource; @@ -41,29 +39,6 @@ public class AppSettingServiceImpl implements AppSettingService { appSettingRepository.save(appSetting); } - @Override - public String getMessage(@NonNull String label) { - final Locale value = getAppSetting().getAppLocale().getValue(); - return messageSource.getMessage(label, null, value); - } - - @Override - public String getMessage(@NonNull String label, Object... params) { - final Object[] paramsArray = Arrays.stream(params).toArray(); - return messageSource.getMessage( - label, - paramsArray, - getAppSetting().getAppLocale().getValue() - ); - } - - @Override - public void setLocale(@NonNull AppLocale appLocale) { - final AppSetting appSetting = getAppSetting(); - appSetting.setAppLocale(appLocale); - appSettingRepository.save(appSetting); - } - private AppSetting getAppSetting() { return appSettingRepository.findById(KEY) .orElseThrow(NOT_FOUND_SETTINGS); 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 c9a7fb4..e8628e5 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 @@ -7,9 +7,9 @@ import dev.struchkov.bot.gitlab.context.domain.filter.PipelineFilter; import dev.struchkov.bot.gitlab.context.service.CleanService; import dev.struchkov.bot.gitlab.context.service.MergeRequestsService; import dev.struchkov.bot.gitlab.context.service.PipelineService; -import dev.struchkov.haiti.context.page.Sheet; -import dev.struchkov.haiti.context.page.impl.PaginationImpl; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; import java.time.LocalDateTime; @@ -39,7 +39,7 @@ public class CleanServiceImpl implements CleanService { @Override public void cleanOldMergedRequests() { int page = 0; - Sheet mergeRequestSheet = mergeRequestsService.getAll(MR_CLEAN_FILTER, PaginationImpl.of(page, COUNT)); + Page mergeRequestSheet = mergeRequestsService.getAll(MR_CLEAN_FILTER, PageRequest.of(page, COUNT)); while (mergeRequestSheet.hasContent()) { final Set ids = mergeRequestSheet.getContent().stream() @@ -48,7 +48,7 @@ public class CleanServiceImpl implements CleanService { mergeRequestsService.deleteAllById(ids); - mergeRequestSheet = mergeRequestsService.getAll(MR_CLEAN_FILTER, PaginationImpl.of(++page, COUNT)); + mergeRequestSheet = mergeRequestsService.getAll(MR_CLEAN_FILTER, PageRequest.of(++page, COUNT)); } } @@ -56,7 +56,7 @@ public class CleanServiceImpl implements CleanService { public void cleanOldPipelines() { int page = 0; final PipelineFilter filter = cleanPipelineFilter(); - Sheet sheet = pipelineService.getAll(filter, PaginationImpl.of(page, COUNT)); + Page sheet = pipelineService.getAll(filter, PageRequest.of(page, COUNT)); while (sheet.hasContent()) { final Set ids = sheet.getContent().stream() @@ -65,7 +65,7 @@ public class CleanServiceImpl implements CleanService { pipelineService.deleteAllById(ids); - sheet = pipelineService.getAll(filter, PaginationImpl.of(page, COUNT)); + sheet = pipelineService.getAll(filter, PageRequest.of(page, COUNT)); } } 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 32c6d87..31d2084 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 @@ -1,5 +1,6 @@ package dev.struchkov.bot.gitlab.core.service.impl; +import dev.struchkov.bot.gitlab.context.domain.ExistsContainer; import dev.struchkov.bot.gitlab.context.domain.PersonInformation; import dev.struchkov.bot.gitlab.context.domain.entity.Discussion; import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest; @@ -14,14 +15,15 @@ import dev.struchkov.bot.gitlab.context.service.PersonService; import dev.struchkov.bot.gitlab.core.config.properties.GitlabProperty; import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty; import dev.struchkov.bot.gitlab.core.utils.StringUtils; -import dev.struchkov.haiti.context.exception.NotFoundException; -import dev.struchkov.haiti.core.service.AbstractSimpleManagerService; import lombok.NonNull; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import okhttp3.FormBody; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import java.io.IOException; @@ -35,6 +37,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; +import static dev.struchkov.haiti.context.exception.NotFoundException.notFoundException; import static java.lang.Boolean.FALSE; /** @@ -44,12 +47,13 @@ import static java.lang.Boolean.FALSE; */ @Slf4j @Service -public class DiscussionServiceImpl extends AbstractSimpleManagerService implements DiscussionService { +@RequiredArgsConstructor +public class DiscussionServiceImpl implements DiscussionService { protected static final Pattern PATTERN = Pattern.compile("@[\\w]+"); private final PersonService personService; - private final DiscussionRepository discussionRepository; + private final DiscussionRepository repository; private final PersonInformation personInformation; private final OkHttpClient client = new OkHttpClient(); @@ -57,16 +61,6 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService personService.create(note.getAuthor())); @@ -76,7 +70,7 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService note.isResolvable() && note.getResolved()); discussion.setResolved(resolved); - return discussionRepository.save(discussion); + return repository.save(discussion); } /** @@ -104,8 +98,8 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService idAndNoteMap = oldDiscussion .getNotes().stream() .collect(Collectors.toMap(Note::getId, note -> note)); @@ -122,7 +116,7 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService note.isResolvable() && note.getResolved()); discussion.setResolved(resolved); - return discussionRepository.save(discussion); + return repository.save(discussion); } private void updateNote(Note note, Map noteMap, boolean inDiscussion) { @@ -189,8 +183,8 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService getAllByMergeRequestId(@NonNull Long mergeRequestId) { - return discussionRepository.findAllByMergeRequestId(mergeRequestId); + return repository.findAllByMergeRequestId(mergeRequestId); + } + + @Override + public ExistsContainer existsById(@NonNull Set discussionIds) { + final List existsEntity = repository.findAllById(discussionIds); + final Set existsIds = existsEntity.stream().map(Discussion::getId).collect(Collectors.toSet()); + if (existsIds.containsAll(discussionIds)) { + return dev.struchkov.bot.gitlab.context.domain.ExistsContainer.allFind(existsEntity); + } else { + final Set noExistsId = discussionIds.stream() + .filter(id -> !existsIds.contains(id)) + .collect(Collectors.toSet()); + return ExistsContainer.notAllFind(existsEntity, noExistsId); + } + } + + @Override + public List createAll(@NonNull List newDiscussions) { + return newDiscussions.stream() + .map(this::create) + .toList(); + } + + @Override + public Page getAll(@NonNull Pageable pagination) { + return repository.findAll(pagination); + } + + @Override + public void deleteById(String discussionId) { + repository.deleteById(discussionId); } /** 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 d22c380..a3c0f6b 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 @@ -1,5 +1,6 @@ package dev.struchkov.bot.gitlab.core.service.impl; +import dev.struchkov.bot.gitlab.context.domain.ExistsContainer; import dev.struchkov.bot.gitlab.context.domain.IdAndStatusPr; import dev.struchkov.bot.gitlab.context.domain.MergeRequestState; import dev.struchkov.bot.gitlab.context.domain.PersonInformation; @@ -17,50 +18,34 @@ import dev.struchkov.bot.gitlab.context.service.MergeRequestsService; import dev.struchkov.bot.gitlab.context.service.NotifyService; import dev.struchkov.bot.gitlab.context.service.PersonService; import dev.struchkov.bot.gitlab.context.service.ProjectService; -import dev.struchkov.haiti.context.exception.NotFoundException; -import dev.struchkov.haiti.context.page.Pagination; -import dev.struchkov.haiti.context.page.Sheet; -import dev.struchkov.haiti.context.service.simple.FilterService; -import dev.struchkov.haiti.core.service.AbstractSimpleManagerService; +import dev.struchkov.bot.gitlab.core.service.impl.filter.MergeRequestFilterService; import lombok.NonNull; -import org.springframework.beans.factory.annotation.Qualifier; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import java.util.List; import java.util.Objects; -import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; + +import static dev.struchkov.haiti.context.exception.NotFoundException.notFoundException; +import static java.lang.Boolean.TRUE; @Service -public class MergeRequestsServiceImpl extends AbstractSimpleManagerService implements MergeRequestsService { +@RequiredArgsConstructor +public class MergeRequestsServiceImpl implements MergeRequestsService { private final NotifyService notifyService; - private final MergeRequestRepository mergeRequestRepository; + private final MergeRequestRepository repository; private final PersonService personService; - private final FilterService filterService; + private final MergeRequestFilterService filterService; private final ProjectService projectService; private final DiscussionService discussionService; private final PersonInformation personInformation; - protected MergeRequestsServiceImpl( - MergeRequestRepository mergeRequestRepository, - NotifyService notifyService, - PersonService personService, - @Qualifier("mergeRequestFilterService") FilterService filterService, - ProjectService projectService, - DiscussionService discussionService, PersonInformation personInformation - ) { - super(mergeRequestRepository); - this.notifyService = notifyService; - this.mergeRequestRepository = mergeRequestRepository; - this.personService = personService; - this.filterService = filterService; - this.projectService = projectService; - this.discussionService = discussionService; - this.personInformation = personInformation; - } - @Override public MergeRequest create(@NonNull MergeRequest mergeRequest) { if (mergeRequest.getAssignee() != null) { @@ -70,7 +55,7 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService getAllId(Set statuses) { - return mergeRequestRepository.findAllIdByStateIn(statuses); + return repository.findAllIdByStateIn(statuses); } @Override - public Sheet getAll(@NonNull MergeRequestFilter filter, Pagination pagination) { + public Page getAll(Pageable pagination) { + return repository.findAll(pagination); + } + + @Override + public Page getAll(@NonNull MergeRequestFilter filter, Pageable pagination) { return filterService.getAll(filter, pagination); } @Override - public Optional getFirst(@NonNull MergeRequestFilter mergeRequestFilter) { - return filterService.getFirst(mergeRequestFilter); + public ExistsContainer existsById(@NonNull Set mergeRequestIds) { + final List existsEntity = repository.findAllById(mergeRequestIds); + final Set existsIds = existsEntity.stream().map(MergeRequest::getId).collect(Collectors.toSet()); + if (existsIds.containsAll(mergeRequestIds)) { + return ExistsContainer.allFind(existsEntity); + } else { + final Set noExistsId = mergeRequestIds.stream() + .filter(id -> !existsIds.contains(id)) + .collect(Collectors.toSet()); + return ExistsContainer.notAllFind(existsEntity, noExistsId); + } } @Override - public boolean exists(@NonNull MergeRequestFilter filter) { - return filterService.exists(filter); + public List createAll(List newMergeRequests) { + return newMergeRequests.stream() + .map(this::create) + .toList(); } @Override - public long count(@NonNull MergeRequestFilter mergeRequestFilter) { - return filterService.count(mergeRequestFilter); + public void deleteAllById(@NonNull Set mergeRequestIds) { + repository.deleteByIds(mergeRequestIds); } } diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PersonServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PersonServiceImpl.java index f3383c3..0d8632a 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PersonServiceImpl.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PersonServiceImpl.java @@ -1,33 +1,63 @@ package dev.struchkov.bot.gitlab.core.service.impl; +import dev.struchkov.bot.gitlab.context.domain.ExistsContainer; import dev.struchkov.bot.gitlab.context.domain.entity.Person; import dev.struchkov.bot.gitlab.context.repository.PersonRepository; import dev.struchkov.bot.gitlab.context.service.PersonService; -import dev.struchkov.haiti.core.service.AbstractSimpleManagerService; import lombok.NonNull; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import static dev.struchkov.haiti.context.exception.NotFoundException.notFoundException; + /** * @author upagge 15.01.2021 */ @Service -public class PersonServiceImpl extends AbstractSimpleManagerService implements PersonService { +@RequiredArgsConstructor +public class PersonServiceImpl implements PersonService { - private final PersonRepository personRepository; - - public PersonServiceImpl(PersonRepository personRepository) { - super(personRepository); - this.personRepository = personRepository; - } + private final PersonRepository repository; @Override public Person create(@NonNull Person person) { - return personRepository.save(person); + return repository.save(person); } @Override public Person update(@NonNull Person person) { - return personRepository.save(person); + return repository.save(person); + } + + @Override + public Person getByIdOrThrown(@NonNull Long personId) { + return repository.findById(personId) + .orElseThrow(notFoundException("Пользователь не найден")); + } + + @Override + public ExistsContainer existsById(Set personIds) { + final List existsEntity = repository.findAllById(personIds); + final Set existsIds = existsEntity.stream().map(Person::getId).collect(Collectors.toSet()); + if (existsIds.containsAll(personIds)) { + return ExistsContainer.allFind(existsEntity); + } else { + final Set noExistsId = personIds.stream() + .filter(id -> !existsIds.contains(id)) + .collect(Collectors.toSet()); + return ExistsContainer.notAllFind(existsEntity, noExistsId); + } + } + + @Override + public List createAll(List newPersons) { + return newPersons.stream() + .map(this::create) + .toList(); } } 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 e3e2dfb..3d145fa 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 @@ -11,20 +11,22 @@ import dev.struchkov.bot.gitlab.context.service.NotifyService; import dev.struchkov.bot.gitlab.context.service.PersonService; import dev.struchkov.bot.gitlab.context.service.PipelineService; import dev.struchkov.bot.gitlab.core.service.impl.filter.PipelineFilterService; -import dev.struchkov.haiti.context.exception.NotFoundException; -import dev.struchkov.haiti.context.page.Pagination; -import dev.struchkov.haiti.context.page.Sheet; -import dev.struchkov.haiti.core.service.AbstractSimpleManagerService; +import dev.struchkov.haiti.context.domain.ExistsContainer; import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; -import java.util.Optional; +import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.CANCELED; import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.FAILED; import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.SKIPPED; import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.SUCCESS; +import static dev.struchkov.haiti.context.exception.NotFoundException.notFoundException; /** * Реализация сервиса для работы с пайплайнами. @@ -32,37 +34,23 @@ import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.SUCCESS; * @author upagge 17.01.2021 */ @Service -public class PipelineServiceImpl extends AbstractSimpleManagerService implements PipelineService { +@RequiredArgsConstructor +public class PipelineServiceImpl implements PipelineService { // Статусы пайплайнов, о которых нужно уведомить private static final Set notificationStatus = Set.of(FAILED, SUCCESS, CANCELED, SKIPPED); private final NotifyService notifyService; - private final PipelineRepository pipelineRepository; + private final PipelineRepository repository; private final PersonService personService; private final PipelineFilterService pipelineFilterService; private final PersonInformation personInformation; - public PipelineServiceImpl( - NotifyService notifyService, - PipelineRepository pipelineRepository, - PersonService personService, - PipelineFilterService pipelineFilterService, - PersonInformation personInformation - ) { - super(pipelineRepository); - this.notifyService = notifyService; - this.pipelineRepository = pipelineRepository; - this.personService = personService; - this.pipelineFilterService = pipelineFilterService; - this.personInformation = personInformation; - } - @Override public Pipeline create(@NonNull Pipeline pipeline) { personService.create(pipeline.getPerson()); - final Pipeline newPipeline = pipelineRepository.save(pipeline); + final Pipeline newPipeline = repository.save(pipeline); notifyNewPipeline(pipeline, "n/a"); return newPipeline; } @@ -84,13 +72,13 @@ public class PipelineServiceImpl extends AbstractSimpleManagerService getAllByStatuses(@NonNull Set statuses, @NonNull Pagination pagination) { - return pipelineRepository.findAllByStatuses(statuses, pagination); + public Page getAllByStatuses(@NonNull Set statuses, @NonNull Pageable pagination) { + return repository.findAllByStatuses(statuses, pagination); } @Override - public Sheet getAll(@NonNull PipelineFilter filter, @NonNull Pagination pagination) { + public Page getAll(@NonNull PipelineFilter filter, @NonNull Pageable pagination) { return pipelineFilterService.getAll(filter, pagination); } @Override - public Optional getFirst(@NonNull PipelineFilter filter) { - return pipelineFilterService.getFirst(filter); + public ExistsContainer existsById(@NonNull Set pipelineIds) { + final List existsEntity = repository.findAllById(pipelineIds); + final Set existsIds = existsEntity.stream().map(Pipeline::getId).collect(Collectors.toSet()); + if (existsIds.containsAll(pipelineIds)) { + return ExistsContainer.allFind(existsEntity); + } else { + final Set noExistsId = pipelineIds.stream() + .filter(id -> !existsIds.contains(id)) + .collect(Collectors.toSet()); + return ExistsContainer.notAllFind(existsEntity, noExistsId); + } } @Override - public boolean exists(@NonNull PipelineFilter filter) { - return pipelineFilterService.exists(filter); - } - - @Override - public long count(@NonNull PipelineFilter filter) { - return pipelineFilterService.count(filter); + public void deleteAllById(Set pipelineIds) { + repository.deleteAllByIds(pipelineIds); } } diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/ProjectServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/ProjectServiceImpl.java index 6c972d6..6633af1 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/ProjectServiceImpl.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/ProjectServiceImpl.java @@ -1,5 +1,6 @@ package dev.struchkov.bot.gitlab.core.service.impl; +import dev.struchkov.bot.gitlab.context.domain.ExistsContainer; import dev.struchkov.bot.gitlab.context.domain.PersonInformation; import dev.struchkov.bot.gitlab.context.domain.entity.Project; import dev.struchkov.bot.gitlab.context.domain.notify.NewProjectNotify; @@ -7,51 +8,85 @@ import dev.struchkov.bot.gitlab.context.repository.ProjectRepository; import dev.struchkov.bot.gitlab.context.service.NotifyService; import dev.struchkov.bot.gitlab.context.service.PersonService; import dev.struchkov.bot.gitlab.context.service.ProjectService; -import dev.struchkov.haiti.context.exception.NotFoundException; -import dev.struchkov.haiti.context.repository.SimpleManagerRepository; -import dev.struchkov.haiti.core.service.AbstractSimpleManagerService; import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import static dev.struchkov.haiti.context.exception.NotFoundException.notFoundException; + /** * @author upagge 14.01.2021 */ @Service -public class ProjectServiceImpl extends AbstractSimpleManagerService implements ProjectService { +@RequiredArgsConstructor +public class ProjectServiceImpl implements ProjectService { + + private final ProjectRepository repository; - private final ProjectRepository projectRepository; private final NotifyService notifyService; private final PersonService personService; private final PersonInformation personInformation; - public ProjectServiceImpl( - SimpleManagerRepository repository, - ProjectRepository projectRepository, - NotifyService notifyService, - PersonService personService, - PersonInformation personInformation - ) { - super(repository); - this.projectRepository = projectRepository; - this.notifyService = notifyService; - this.personService = personService; - this.personInformation = personInformation; - } - @Override public Project create(@NonNull Project project) { - final Project newProject = projectRepository.save(project); + final Project newProject = repository.save(project); if (!personInformation.getId().equals(newProject.getCreatorId())) { - final String authorName = personService.getById(newProject.getCreatorId()) - .orElseThrow(NotFoundException.supplier("Пользователь не найден")) - .getName(); + final String authorName = personService.getByIdOrThrown(newProject.getCreatorId()).getName(); sendNotifyNewProject(newProject, authorName); } return newProject; } + @Override + public Project update(@NonNull Project project) { + return repository.save(project); + } + + @Override + public Project getByIdOrThrow(@NonNull Long projectId) { + return repository.findById(projectId) + .orElseThrow(notFoundException("Проект не найден")); + } + + @Override + public Page getAll(@NonNull Pageable pagination) { + return repository.findAllById(pagination); + } + + @Override + public List createAll(List newProjects) { + return newProjects.stream() + .map(this::create) + .toList(); + } + + @Override + public boolean existsById(Long projectId) { + return repository.existById(projectId); + } + + @Override + public ExistsContainer existsById(Set projectIds) { + final List existsEntity = repository.findAllById(projectIds); + final Set existsIds = existsEntity.stream().map(Project::getId).collect(Collectors.toSet()); + if (existsIds.containsAll(projectIds)) { + return ExistsContainer.allFind(existsEntity); + } else { + final Set noExistsId = projectIds.stream() + .filter(id -> !existsIds.contains(id)) + .collect(Collectors.toSet()); + return ExistsContainer.notAllFind(existsEntity, noExistsId); + } + } + private void sendNotifyNewProject(Project newProject, String authorName) { notifyService.send( NewProjectNotify.builder() @@ -63,9 +98,4 @@ public class ProjectServiceImpl extends AbstractSimpleManagerService { +@RequiredArgsConstructor +public class MergeRequestFilterService { - public MergeRequestFilterService(MergeRequestRepository filterOperation) { - super(filterOperation); + private final MergeRequestRepository repository; + + public Page getAll(MergeRequestFilter filter, Pageable pagination) { + return repository.filter(createFilter(filter), pagination); } - @Override - protected Filter createFilter(@NonNull MergeRequestFilter filter) { + private Filter createFilter(@NonNull MergeRequestFilter filter) { return CriteriaFilter.create() .and(convertFilter(filter)) .or(convertFilterOr(filter)); @@ -28,12 +32,12 @@ public class MergeRequestFilterService extends AbstractFilterServicecreate() - .matchPhrase(MergeRequest_.STATE, filter.getStates()); + .matchPhrase(MergeRequestFields.state, filter.getStates()); } private FilterQuery convertFilter(@NonNull MergeRequestFilter filter) { return CriteriaQuery.create() - .matchPhrase(MergeRequest_.ASSIGNEE, filter.getAssignee()); + .matchPhrase(MergeRequestFields.assignee, filter.getAssignee()); } } diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/filter/PipelineFilterService.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/filter/PipelineFilterService.java index fc43fa3..a18afc2 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/filter/PipelineFilterService.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/filter/PipelineFilterService.java @@ -1,15 +1,17 @@ package dev.struchkov.bot.gitlab.core.service.impl.filter; import dev.struchkov.bot.gitlab.context.domain.entity.Pipeline; -import dev.struchkov.bot.gitlab.context.domain.entity.Pipeline_; +import dev.struchkov.bot.gitlab.context.domain.entity.PipelineFields; import dev.struchkov.bot.gitlab.context.domain.filter.PipelineFilter; import dev.struchkov.bot.gitlab.context.repository.PipelineRepository; -import dev.struchkov.haiti.core.service.AbstractFilterService; import dev.struchkov.haiti.filter.Filter; import dev.struchkov.haiti.filter.FilterQuery; import dev.struchkov.haiti.filter.criteria.CriteriaFilter; import dev.struchkov.haiti.filter.criteria.CriteriaQuery; import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; /** @@ -18,20 +20,24 @@ import org.springframework.stereotype.Service; * @author upagge 08.02.2021 */ @Service -public class PipelineFilterService extends AbstractFilterService { +@RequiredArgsConstructor +public class PipelineFilterService { - public PipelineFilterService(PipelineRepository pipelineRepository) { - super(pipelineRepository); + private final PipelineRepository pipelineRepository; + + public Page getAll(PipelineFilter filter, Pageable pagination) { + return pipelineRepository.filter(createFilter(filter), pagination); } - @Override - protected Filter createFilter(@NonNull PipelineFilter pipelineFilter) { + private Filter createFilter(@NonNull PipelineFilter pipelineFilter) { return CriteriaFilter.create() .and(convertAnd(pipelineFilter)); } private FilterQuery convertAnd(PipelineFilter pipelineFilter) { return CriteriaQuery.create() - .lessThan(Pipeline_.CREATED, pipelineFilter.getLessThanCreatedDate()); + .lessThan(PipelineFields.created, pipelineFilter.getLessThanCreatedDate()); } + + } diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/note/NoteServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/note/NoteServiceImpl.java index 203bd44..8243f0c 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/note/NoteServiceImpl.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/note/NoteServiceImpl.java @@ -3,41 +3,35 @@ package dev.struchkov.bot.gitlab.core.service.impl.note; import dev.struchkov.bot.gitlab.context.domain.entity.Note; import dev.struchkov.bot.gitlab.context.repository.NoteRepository; import dev.struchkov.bot.gitlab.context.service.NoteService; -import dev.struchkov.haiti.context.page.Pagination; -import dev.struchkov.haiti.context.page.Sheet; -import dev.struchkov.haiti.core.service.AbstractSimpleManagerService; import lombok.NonNull; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import java.util.List; +import static dev.struchkov.haiti.context.exception.NotFoundException.notFoundException; + @Slf4j @Service -public class NoteServiceImpl extends AbstractSimpleManagerService implements NoteService { +@RequiredArgsConstructor +public class NoteServiceImpl implements NoteService { private final NoteRepository noteRepository; - public NoteServiceImpl(NoteRepository noteRepository) { - super(noteRepository); - this.noteRepository = noteRepository; - } - @Override - public Note create(@NonNull Note note) { - throw new UnsupportedOperationException(); - } - - @Override - public Note update(@NonNull Note note) { - throw new UnsupportedOperationException(); - } - - @Override - public Sheet getAllByResolved(boolean resolved, @NonNull Pagination pagination) { + public Page getAllByResolved(boolean resolved, @NonNull Pageable pagination) { return noteRepository.findAllByResolved(resolved, pagination); } + @Override + public Note getByIdOrThrow(@NonNull Long noteId) { + return noteRepository.findById(noteId) + .orElseThrow(notFoundException("Note не найдено")); + } + @Override public List getAllPersonTask(@NonNull Long userId, boolean resolved) { return noteRepository.findAllByResponsibleIdAndResolved(userId, resolved); 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 2aaf08c..b0b770e 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 @@ -1,5 +1,6 @@ package dev.struchkov.bot.gitlab.core.service.parser; +import dev.struchkov.bot.gitlab.context.domain.ExistsContainer; import dev.struchkov.bot.gitlab.context.domain.entity.Discussion; import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest; import dev.struchkov.bot.gitlab.context.domain.entity.Note; @@ -8,12 +9,11 @@ import dev.struchkov.bot.gitlab.context.service.MergeRequestsService; import dev.struchkov.bot.gitlab.core.config.properties.GitlabProperty; import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty; import dev.struchkov.bot.gitlab.sdk.domain.DiscussionJson; -import dev.struchkov.haiti.context.domain.ExistsContainer; -import dev.struchkov.haiti.context.page.Sheet; -import dev.struchkov.haiti.context.page.impl.PaginationImpl; import dev.struchkov.haiti.utils.network.HttpParse; import lombok.RequiredArgsConstructor; import org.springframework.core.convert.ConversionService; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Component; import java.text.MessageFormat; @@ -49,12 +49,12 @@ public class DiscussionParser { */ public void scanNewDiscussion() { int page = 0; - Sheet mergeRequestSheet = mergeRequestsService.getAll(PaginationImpl.of(page, COUNT)); + Page mergeRequestSheet = mergeRequestsService.getAll(PageRequest.of(page, COUNT)); while (mergeRequestSheet.hasContent()) { mergeRequestSheet.getContent() .forEach(this::processingMergeRequest); - mergeRequestSheet = mergeRequestsService.getAll(PaginationImpl.of(++page, COUNT)); + mergeRequestSheet = mergeRequestsService.getAll(PageRequest.of(++page, COUNT)); } } @@ -97,7 +97,7 @@ public class DiscussionParser { */ public void scanOldDiscussions() { int page = 0; - Sheet discussionSheet = discussionService.getAll(PaginationImpl.of(page, COUNT)); + Page discussionSheet = discussionService.getAll(PageRequest.of(page, COUNT)); while (discussionSheet.hasContent()) { final List discussions = discussionSheet.getContent(); @@ -119,7 +119,7 @@ public class DiscussionParser { } } - discussionSheet = discussionService.getAll(PaginationImpl.of(++page, COUNT)); + discussionSheet = discussionService.getAll(PageRequest.of(++page, COUNT)); } } 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 bcee415..fef4cca 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 @@ -1,5 +1,6 @@ package dev.struchkov.bot.gitlab.core.service.parser; +import dev.struchkov.bot.gitlab.context.domain.ExistsContainer; 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; @@ -11,13 +12,12 @@ import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty; import dev.struchkov.bot.gitlab.core.utils.StringUtils; import dev.struchkov.bot.gitlab.sdk.domain.CommitJson; import dev.struchkov.bot.gitlab.sdk.domain.MergeRequestJson; -import dev.struchkov.haiti.context.domain.ExistsContainer; -import dev.struchkov.haiti.context.page.Sheet; -import dev.struchkov.haiti.context.page.impl.PaginationImpl; import dev.struchkov.haiti.utils.network.HttpParse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.core.convert.ConversionService; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; import java.text.MessageFormat; @@ -66,7 +66,7 @@ public class MergeRequestParser { public void parsingNewMergeRequest() { int page = 0; - Sheet projectSheet = projectService.getAll(PaginationImpl.of(page, COUNT)); + Page projectSheet = projectService.getAll(PageRequest.of(page, COUNT)); while (projectSheet.hasContent()) { final List projects = projectSheet.getContent(); @@ -75,7 +75,7 @@ public class MergeRequestParser { projectProcessing(project); } - projectSheet = projectService.getAll(PaginationImpl.of(++page, COUNT)); + projectSheet = projectService.getAll(PageRequest.of(++page, COUNT)); } } 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 3ee6c08..b195199 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 @@ -10,12 +10,11 @@ import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty; import dev.struchkov.bot.gitlab.core.utils.StringUtils; import dev.struchkov.bot.gitlab.sdk.domain.PipelineJson; import dev.struchkov.haiti.context.domain.ExistsContainer; -import dev.struchkov.haiti.context.exception.ConvertException; -import dev.struchkov.haiti.context.page.Sheet; -import dev.struchkov.haiti.context.page.impl.PaginationImpl; import dev.struchkov.haiti.utils.network.HttpParse; import lombok.RequiredArgsConstructor; import org.springframework.core.convert.ConversionService; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; import java.text.MessageFormat; @@ -31,6 +30,7 @@ import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.PENDING; import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.PREPARING; import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.RUNNING; import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.WAITING_FOR_RESOURCE; +import static dev.struchkov.haiti.context.exception.ConvertException.convertException; import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT; /** @@ -56,7 +56,7 @@ public class PipelineParser { public void scanNewPipeline() { int page = 0; - Sheet projectSheet = projectService.getAll(PaginationImpl.of(page, COUNT)); + Page projectSheet = projectService.getAll(PageRequest.of(page, COUNT)); while (projectSheet.hasContent()) { final List projects = projectSheet.getContent(); @@ -65,7 +65,7 @@ public class PipelineParser { processingProject(project); } - projectSheet = projectService.getAll(PaginationImpl.of(++page, COUNT)); + projectSheet = projectService.getAll(PageRequest.of(++page, COUNT)); } } @@ -99,7 +99,7 @@ public class PipelineParser { pipeline.setProject(project); return pipeline; }) - .orElseThrow(ConvertException.supplier("Ошибка обновления Pipelines")); + .orElseThrow(convertException("Ошибка обновления Pipelines")); pipelineService.create(newPipeline); } @@ -121,7 +121,7 @@ public class PipelineParser { public void scanOldPipeline() { int page = 0; - Sheet pipelineSheet = pipelineService.getAllByStatuses(oldStatus, PaginationImpl.of(page, COUNT)); + Page pipelineSheet = pipelineService.getAllByStatuses(oldStatus, PageRequest.of(page, COUNT)); while (pipelineSheet.hasContent()) { final List pipelines = pipelineSheet.getContent(); @@ -134,12 +134,12 @@ public class PipelineParser { .header(StringUtils.H_PRIVATE_TOKEN, personProperty.getToken()) .execute(PipelineJson.class) .map(json -> conversionService.convert(json, Pipeline.class)) - .orElseThrow(ConvertException.supplier("Ошибка обновления Pipelines")); + .orElseThrow(convertException("Ошибка обновления Pipelines")); pipelineService.update(newPipeline); } - pipelineSheet = pipelineService.getAllByStatuses(oldStatus, PaginationImpl.of(++page, COUNT)); + pipelineSheet = pipelineService.getAllByStatuses(oldStatus, PageRequest.of(++page, COUNT)); } } 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 3b70c68..ed4ba01 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 @@ -1,5 +1,6 @@ package dev.struchkov.bot.gitlab.core.service.parser; +import dev.struchkov.bot.gitlab.context.domain.ExistsContainer; import dev.struchkov.bot.gitlab.context.domain.entity.Person; import dev.struchkov.bot.gitlab.context.domain.entity.Project; import dev.struchkov.bot.gitlab.context.service.PersonService; @@ -9,8 +10,6 @@ import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty; import dev.struchkov.bot.gitlab.core.utils.StringUtils; import dev.struchkov.bot.gitlab.sdk.domain.PersonJson; import dev.struchkov.bot.gitlab.sdk.domain.ProjectJson; -import dev.struchkov.haiti.context.domain.ExistsContainer; -import dev.struchkov.haiti.context.exception.ConvertException; import dev.struchkov.haiti.utils.network.HttpParse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -23,6 +22,7 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; +import static dev.struchkov.haiti.context.exception.ConvertException.convertException; import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT; /** @@ -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(ConvertException.supplier("Ошибка преобразования нового пользователя")) + .orElseThrow(convertException("Ошибка преобразования нового пользователя")) ).toList(); personService.createAll(newPersons); @@ -119,7 +119,7 @@ public class ProjectParser { .header(StringUtils.H_PRIVATE_TOKEN, personProperty.getToken()) .execute(ProjectJson.class) .map(json -> conversionService.convert(json, Project.class)) - .orElseThrow(ConvertException.supplier("Ошибка получения проекта")); + .orElseThrow(convertException("Ошибка получения проекта")); if (!projectService.existsById(project.getId())) { projectService.create(project); } diff --git a/bot-data/pom.xml b/bot-data/pom.xml index 6f62e3a..fef3d3d 100644 --- a/bot-data/pom.xml +++ b/bot-data/pom.xml @@ -6,21 +6,16 @@ dev.struchkov.bot.gitlab gitlab-bot - 1.0.0 + 1.1.0 bot-data - ${gitlab.data.version} GitLab Server Data Implementation of the Bitbucket server version repository layer https://github.com/uPagge/bitbucketbot - - dev.struchkov.haiti.data - haiti-database - dev.struchkov.bot.gitlab bot-context diff --git a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/AppSettingRepositoryImpl.java b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/AppSettingRepositoryImpl.java index 230c68a..dfc4f67 100644 --- a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/AppSettingRepositoryImpl.java +++ b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/AppSettingRepositoryImpl.java @@ -2,18 +2,28 @@ package dev.struchkov.bot.gitlab.data.impl; import dev.struchkov.bot.gitlab.context.domain.entity.AppSetting; import dev.struchkov.bot.gitlab.context.repository.AppSettingRepository; -import dev.struchkov.haiti.database.repository.manager.AbstractSimpleManagerRepository; -import org.springframework.data.jpa.repository.JpaRepository; +import dev.struchkov.bot.gitlab.data.jpa.AppSettingJpaRepository; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; +import java.util.Optional; + /** * @author upagge 16.01.2021 */ @Repository -public class AppSettingRepositoryImpl extends AbstractSimpleManagerRepository implements AppSettingRepository { +@RequiredArgsConstructor +public class AppSettingRepositoryImpl implements AppSettingRepository { - public AppSettingRepositoryImpl(JpaRepository jpaRepository) { - super(jpaRepository); + private final AppSettingJpaRepository jpaRepository; + + @Override + public AppSetting save(AppSetting appSetting) { + return jpaRepository.save(appSetting); } + @Override + public Optional findById(Long key) { + return jpaRepository.findById(key); + } } diff --git a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/DiscussionRepositoryImpl.java b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/DiscussionRepositoryImpl.java index f690e74..3ed56d5 100644 --- a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/DiscussionRepositoryImpl.java +++ b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/DiscussionRepositoryImpl.java @@ -3,28 +3,53 @@ package dev.struchkov.bot.gitlab.data.impl; import dev.struchkov.bot.gitlab.context.domain.entity.Discussion; import dev.struchkov.bot.gitlab.context.repository.DiscussionRepository; import dev.struchkov.bot.gitlab.data.jpa.DiscussionJpaRepository; -import dev.struchkov.haiti.database.repository.manager.AbstractSimpleManagerRepository; import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Optional; +import java.util.Set; /** * @author upagge 11.02.2021 */ @Repository -public class DiscussionRepositoryImpl extends AbstractSimpleManagerRepository implements DiscussionRepository { +@RequiredArgsConstructor +public class DiscussionRepositoryImpl implements DiscussionRepository { private final DiscussionJpaRepository jpaRepository; - public DiscussionRepositoryImpl(DiscussionJpaRepository jpaRepository) { - super(jpaRepository); - this.jpaRepository = jpaRepository; - } - @Override public List findAllByMergeRequestId(@NonNull Long mergeRequestId) { return jpaRepository.findAllByMergeRequestId(mergeRequestId); } + @Override + public Discussion save(Discussion discussion) { + return jpaRepository.save(discussion); + } + + @Override + public Optional findById(String discussionId) { + return jpaRepository.findById(discussionId); + } + + @Override + public void deleteById(String discussionId) { + jpaRepository.deleteById(discussionId); + } + + @Override + public Page findAll(Pageable pagination) { + return jpaRepository.findAll(pagination); + } + + @Override + public List findAllById(Set discussionIds) { + return jpaRepository.findAllById(discussionIds); + } + } 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 3af294a..dcb21ef 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 @@ -5,31 +5,62 @@ import dev.struchkov.bot.gitlab.context.domain.MergeRequestState; import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest; import dev.struchkov.bot.gitlab.context.repository.MergeRequestRepository; import dev.struchkov.bot.gitlab.data.jpa.MergeRequestJpaRepository; -import dev.struchkov.haiti.database.repository.manager.FilterManagerRepository; +import dev.struchkov.haiti.filter.Filter; import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Optional; import java.util.Set; @Repository -public class MergeRequestRepositoryImpl extends FilterManagerRepository implements MergeRequestRepository { +@RequiredArgsConstructor +public class MergeRequestRepositoryImpl implements MergeRequestRepository { - private final MergeRequestJpaRepository repositoryJpa; - - public MergeRequestRepositoryImpl(MergeRequestJpaRepository jpaRepository) { - super(jpaRepository); - repositoryJpa = jpaRepository; - } + private final MergeRequestJpaRepository jpaRepository; @Override public Set findAllIdByStateIn(@NonNull Set statuses) { - return repositoryJpa.findAllIdByStateIn(statuses); + return jpaRepository.findAllIdByStateIn(statuses); } @Override public List findAllByAssignee(@NonNull Long userId) { - return repositoryJpa.findAllByAssigneeId(userId); + return jpaRepository.findAllByAssigneeId(userId); + } + + @Override + public MergeRequest save(MergeRequest mergeRequest) { + return jpaRepository.save(mergeRequest); + } + + @Override + public Optional findById(Long mergeRequestId) { + return jpaRepository.findById(mergeRequestId); + } + + @Override + public Page findAll(Pageable pagination) { + return jpaRepository.findAll(pagination); + } + + @Override + public List findAllById(Set mergeRequestIds) { + return jpaRepository.findAllById(mergeRequestIds); + } + + @Override + public void deleteByIds(Set mergeRequestIds) { + jpaRepository.deleteAllByIdIn(mergeRequestIds); + } + + @Override + public Page filter(Filter filter, Pageable pageable) { + return jpaRepository.findAll(filter.>build(), pageable); } } diff --git a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/NoteRepositoryImpl.java b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/NoteRepositoryImpl.java index 66ce9fb..694bb0c 100644 --- a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/NoteRepositoryImpl.java +++ b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/NoteRepositoryImpl.java @@ -2,40 +2,38 @@ package dev.struchkov.bot.gitlab.data.impl; import dev.struchkov.bot.gitlab.context.domain.entity.Note; import dev.struchkov.bot.gitlab.context.repository.NoteRepository; -import dev.struchkov.bot.gitlab.data.jpa.NoteRepositoryJpa; -import dev.struchkov.haiti.context.page.Pagination; -import dev.struchkov.haiti.context.page.Sheet; -import dev.struchkov.haiti.database.repository.manager.AbstractSimpleManagerRepository; -import dev.struchkov.haiti.database.util.Converter; +import dev.struchkov.bot.gitlab.data.jpa.NoteJpaRepository; import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Optional; /** - * * @author upagge 08.09.2020 */ @Repository -public class NoteRepositoryImpl extends AbstractSimpleManagerRepository implements NoteRepository { +@RequiredArgsConstructor +public class NoteRepositoryImpl implements NoteRepository { - private final NoteRepositoryJpa repositoryJpa; + private final NoteJpaRepository jpaRepository; - public NoteRepositoryImpl(NoteRepositoryJpa repositoryJpa) { - super(repositoryJpa); - this.repositoryJpa = repositoryJpa; + @Override + public Page findAllByResolved(boolean resolved, @NonNull Pageable pagination) { + return jpaRepository.findAllByResolved(resolved, pagination); } @Override - public Sheet findAllByResolved(boolean resolved, @NonNull Pagination pagination) { - return Converter.page( - repositoryJpa.findAllByResolved(resolved, Converter.pagination(pagination)) - ); + public Optional findById(Long noteId) { + return jpaRepository.findById(noteId); } @Override public List findAllByResponsibleIdAndResolved(@NonNull Long userId, boolean resolved) { - return repositoryJpa.findAllByDiscussionResponsibleIdAndResolved(userId, resolved); + return jpaRepository.findAllByDiscussionResponsibleIdAndResolved(userId, resolved); } diff --git a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/PersonRepositoryImpl.java b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/PersonRepositoryImpl.java index 0818e8f..ad830b6 100644 --- a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/PersonRepositoryImpl.java +++ b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/PersonRepositoryImpl.java @@ -2,18 +2,36 @@ package dev.struchkov.bot.gitlab.data.impl; import dev.struchkov.bot.gitlab.context.domain.entity.Person; import dev.struchkov.bot.gitlab.context.repository.PersonRepository; -import dev.struchkov.haiti.database.repository.manager.AbstractSimpleManagerRepository; -import org.springframework.data.jpa.repository.JpaRepository; +import dev.struchkov.bot.gitlab.data.jpa.PersonJpaRepository; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; +import java.util.List; +import java.util.Optional; +import java.util.Set; + /** * @author upagge 15.01.2021 */ @Repository -public class PersonRepositoryImpl extends AbstractSimpleManagerRepository implements PersonRepository { +@RequiredArgsConstructor +public class PersonRepositoryImpl implements PersonRepository { - public PersonRepositoryImpl(JpaRepository jpaRepository) { - super(jpaRepository); + private final PersonJpaRepository jpaRepository; + + @Override + public Person save(Person person) { + return jpaRepository.save(person); + } + + @Override + public Optional findById(Long personId) { + return jpaRepository.findById(personId); + } + + @Override + public List findAllById(Set personIds) { + return jpaRepository.findAllById(personIds); } } diff --git a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/PipelineRepositoryImpl.java b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/PipelineRepositoryImpl.java index 50eef2c..0872c42 100644 --- a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/PipelineRepositoryImpl.java +++ b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/PipelineRepositoryImpl.java @@ -4,32 +4,54 @@ import dev.struchkov.bot.gitlab.context.domain.PipelineStatus; import dev.struchkov.bot.gitlab.context.domain.entity.Pipeline; import dev.struchkov.bot.gitlab.context.repository.PipelineRepository; import dev.struchkov.bot.gitlab.data.jpa.PipelineJpaRepository; -import dev.struchkov.haiti.context.page.Pagination; -import dev.struchkov.haiti.context.page.Sheet; -import dev.struchkov.haiti.database.repository.manager.FilterManagerRepository; -import dev.struchkov.haiti.database.util.Converter; -import lombok.NonNull; +import dev.struchkov.haiti.filter.Filter; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Repository; +import java.util.List; +import java.util.Optional; import java.util.Set; /** * @author upagge 17.01.2021 */ @Repository -public class PipelineRepositoryImpl extends FilterManagerRepository implements PipelineRepository { +@RequiredArgsConstructor +public class PipelineRepositoryImpl implements PipelineRepository { private final PipelineJpaRepository jpaRepository; - public PipelineRepositoryImpl(PipelineJpaRepository jpaRepository) { - super(jpaRepository); - this.jpaRepository = jpaRepository; + @Override + public Pipeline save(Pipeline pipeline) { + return jpaRepository.save(pipeline); } @Override - public Sheet findAllByStatuses(@NonNull Set statuses, @NonNull Pagination pagination) { - return Converter.page( - jpaRepository.findAllByStatusIn(statuses, Converter.pagination(pagination)) - ); + public Optional findById(Long pipelineId) { + return jpaRepository.findById(pipelineId); } + + @Override + public Page findAllByStatuses(Set statuses, Pageable pagination) { + return jpaRepository.findAllByStatusIn(statuses, pagination); + } + + @Override + public List findAllById(Set pipelineIds) { + return jpaRepository.findAllById(pipelineIds); + } + + @Override + public void deleteAllByIds(Set pipelineIds) { + jpaRepository.deleteAllById(pipelineIds); + } + + @Override + public Page filter(Filter filter, Pageable pagination) { + return jpaRepository.findAll(filter.>build(), pagination); + } + } diff --git a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/ProjectRepositoryImpl.java b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/ProjectRepositoryImpl.java index 1665fe6..6f7c5a3 100644 --- a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/ProjectRepositoryImpl.java +++ b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/ProjectRepositoryImpl.java @@ -2,18 +2,48 @@ package dev.struchkov.bot.gitlab.data.impl; import dev.struchkov.bot.gitlab.context.domain.entity.Project; import dev.struchkov.bot.gitlab.context.repository.ProjectRepository; -import dev.struchkov.haiti.database.repository.manager.AbstractSimpleManagerRepository; -import org.springframework.data.jpa.repository.JpaRepository; +import dev.struchkov.bot.gitlab.data.jpa.ProjectJpaRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Repository; +import java.util.List; +import java.util.Optional; +import java.util.Set; + /** * @author upagge 14.01.2021 */ @Repository -public class ProjectRepositoryImpl extends AbstractSimpleManagerRepository implements ProjectRepository { +@RequiredArgsConstructor +public class ProjectRepositoryImpl implements ProjectRepository { - public ProjectRepositoryImpl(JpaRepository jpaRepository) { - super(jpaRepository); + private final ProjectJpaRepository jpaRepository; + + @Override + public Project save(Project project) { + return jpaRepository.save(project); + } + + @Override + public Optional findById(Long projectId) { + return jpaRepository.findById(projectId); + } + + @Override + public List findAllById(Set projectIds) { + return jpaRepository.findAllById(projectIds); + } + + @Override + public boolean existById(Long projectId) { + return jpaRepository.existsById(projectId); + } + + @Override + public Page findAllById(Pageable pagination) { + return jpaRepository.findAll(pagination); } } diff --git a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/jpa/NoteRepositoryJpa.java b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/jpa/NoteJpaRepository.java similarity index 87% rename from bot-data/src/main/java/dev/struchkov/bot/gitlab/data/jpa/NoteRepositoryJpa.java rename to bot-data/src/main/java/dev/struchkov/bot/gitlab/data/jpa/NoteJpaRepository.java index 1613846..939844c 100644 --- a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/jpa/NoteRepositoryJpa.java +++ b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/jpa/NoteJpaRepository.java @@ -7,7 +7,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; -public interface NoteRepositoryJpa extends JpaRepository { +public interface NoteJpaRepository extends JpaRepository { Page findAllByResolved(boolean resolved, Pageable pageable); diff --git a/gitlab-app/Dockerfile-debug b/gitlab-app/Dockerfile-debug new file mode 100644 index 0000000..eab6676 --- /dev/null +++ b/gitlab-app/Dockerfile-debug @@ -0,0 +1,23 @@ +FROM openjdk:17.0.2-jdk-slim-buster +MAINTAINER uPagge +RUN apt upgrade && addgroup gitlabbot --disabled-password && \ + adduser gitlabbot --ingroup gitlabbot && \ + mkdir -p /bot && \ + chown -R gitlabbot:gitlabbot /bot +WORKDIR /bot +USER gitlabbot:gitlabbot +COPY target/gitlab-notification.jar app.jar +ENV TELEGRAM_PERSON_ID=TELEGRAM_PERSON_ID DATASOURCE_URL=DATASOURCE_URL \ + DATASOURCE_PASSWORD=DATASOURCE_PASSWORD DATASOURCE_USERNAME=DATASOURCE_USERNAME \ + GITLAB_PERSONAL_TOKEN=GITLAB_PERSONAL_TOKEN TELEGRAM_BOT_TOKEN=TELEGRAM_BOT_TOKEN \ + TELEGRAM_BOT_USERNAME=TELEGRAM_BOT_USERNAME GITLAB_URL=GITLAB_URL GITLAB_REPLACE_URL=GITLAB_REPLACE_URL +ENTRYPOINT java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -DTELEGRAM_BOT_USERNAME=${TELEGRAM_BOT_USERNAME} \ + -DTELEGRAM_BOT_TOKEN=$TELEGRAM_BOT_TOKEN \ + -DTELEGRAM_PERSON_ID=$TELEGRAM_PERSON_ID \ + -DDATASOURCE_URL=$DATASOURCE_URL \ + -DDATASOURCE_PASSWORD=$DATASOURCE_PASSWORD \ + -DDATASOURCE_USERNAME=$DATASOURCE_USERNAME \ + -DGITLAB_PERSONAL_TOKEN=$GITLAB_PERSONAL_TOKEN \ + -DGITLAB_URL=$GITLAB_URL \ + -DGITLAB_REPLACE_URL=$GITLAB_REPLACE_URL \ + -jar app.jar \ No newline at end of file diff --git a/gitlab-app/pom.xml b/gitlab-app/pom.xml index 3ed306a..10ea202 100644 --- a/gitlab-app/pom.xml +++ b/gitlab-app/pom.xml @@ -6,11 +6,10 @@ dev.struchkov.bot.gitlab gitlab-bot - 1.0.0 + 1.1.0 gitlab-app - ${gitlab.app.version} Gitlab Notification Bot Notifications about Gitlab Server events in Telegram 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 f55c121..efa0b6d 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 @@ -4,7 +4,6 @@ import dev.struchkov.bot.gitlab.context.domain.PersonInformation; import dev.struchkov.bot.gitlab.core.config.properties.GitlabProperty; import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty; import dev.struchkov.bot.gitlab.core.utils.StringUtils; -import dev.struchkov.haiti.context.exception.NotFoundException; import dev.struchkov.haiti.utils.network.HttpParse; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -19,6 +18,7 @@ import java.util.Arrays; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import static dev.struchkov.haiti.context.exception.NotFoundException.notFoundException; import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT; /** @@ -61,7 +61,7 @@ public class AppConfig { .header(ACCEPT) .header(StringUtils.H_PRIVATE_TOKEN, personProperty.getToken()) .execute(PersonInformation.class) - .orElseThrow(NotFoundException.supplier("Пользователь не найден")); + .orElseThrow(notFoundException("Пользователь не найден")); personInformation.setTelegramId(personProperty.getTelegramId()); return personInformation; } diff --git a/gitlab-app/src/main/resources/application.yaml b/gitlab-app/src/main/resources/application.yml similarity index 85% rename from gitlab-app/src/main/resources/application.yaml rename to gitlab-app/src/main/resources/application.yml index c62ea14..d0c4dd7 100644 --- a/gitlab-app/src/main/resources/application.yaml +++ b/gitlab-app/src/main/resources/application.yml @@ -7,7 +7,7 @@ spring: driver-class-name: org.postgresql.Driver password: ${DATASOURCE_PASSWORD} liquibase: - change-log: classpath:liquibase/change-log.xml + change-log: classpath:liquibase/changelog.xml jpa: show-sql: false hibernate: @@ -22,7 +22,7 @@ telegram-config: bot-username: ${TELEGRAM_BOT_USERNAME} bot-token: ${TELEGRAM_BOT_TOKEN} gitlab-bot: - version: 0.0.6 Beta + version: 0.0.7 Beta person: telegram-id: ${TELEGRAM_PERSON_ID} token: ${GITLAB_PERSONAL_TOKEN} @@ -30,8 +30,8 @@ gitlab-bot: base-url: ${GITLAB_URL} replaceUrl: ${GITLAB_REPLACE_URL} url-project: ${GITLAB_URL}/api/v4/projects?page={0, number, integer}&per_page=100 - url-pull-request-open: ${GITLAB_URL}/api/v4/projects/{0, number, integer}/merge_requests?state=opened&page={1, number, integer}&per_page=100 - url-pull-request-close: ${GITLAB_URL} + url-pull-request-open: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests?state=opened&page={1, number, integer}&per_page=100" + url-pull-request-close: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests?state=closed&page={1, number, integer}&per_page=100" url-pull-request-comment: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/notes?&page={2,number,#}&per_page=100" url-pull-request: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}" url-merge-request-add: ${GITLAB_URL}/api/v4/projects/{0}%2F{1} diff --git a/gitlab-app/src/main/resources/liquibase/v.1.0.0/cumulative.xml b/gitlab-app/src/main/resources/liquibase/changelog.xml similarity index 80% rename from gitlab-app/src/main/resources/liquibase/v.1.0.0/cumulative.xml rename to gitlab-app/src/main/resources/liquibase/changelog.xml index 15252f0..be68aec 100644 --- a/gitlab-app/src/main/resources/liquibase/v.1.0.0/cumulative.xml +++ b/gitlab-app/src/main/resources/liquibase/changelog.xml @@ -3,6 +3,6 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd"> - + \ No newline at end of file diff --git a/gitlab-app/src/main/resources/liquibase/v.1.0.0/2021-01-14-create-tables.xml b/gitlab-app/src/main/resources/liquibase/v.1.0.0/2022-12-03-create-tables.xml similarity index 80% rename from gitlab-app/src/main/resources/liquibase/v.1.0.0/2021-01-14-create-tables.xml rename to gitlab-app/src/main/resources/liquibase/v.1.0.0/2022-12-03-create-tables.xml index 2979703..6ceede6 100644 --- a/gitlab-app/src/main/resources/liquibase/v.1.0.0/2021-01-14-create-tables.xml +++ b/gitlab-app/src/main/resources/liquibase/v.1.0.0/2022-12-03-create-tables.xml @@ -1,27 +1,18 @@ + xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.17.xsd"> - + - - - - - - - - - - + @@ -42,7 +33,7 @@ - + @@ -57,7 +48,7 @@ - + @@ -105,12 +96,26 @@ + + + + + + + + + + + + - + + + - + @@ -122,10 +127,13 @@ + + + - + @@ -136,9 +144,13 @@ + + + + - + - + @@ -183,9 +195,16 @@ + + + + + + + - + @@ -208,12 +227,13 @@ - - - - - + + + + + + \ No newline at end of file diff --git a/gitlab-app/src/main/resources/liquibase/v.1.0.0/2022-12-03-insert.xml b/gitlab-app/src/main/resources/liquibase/v.1.0.0/2022-12-03-insert.xml new file mode 100644 index 0000000..63f1126 --- /dev/null +++ b/gitlab-app/src/main/resources/liquibase/v.1.0.0/2022-12-03-insert.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/gitlab-app/src/main/resources/liquibase/change-log.xml b/gitlab-app/src/main/resources/liquibase/v.1.0.0/changelog.xml similarity index 52% rename from gitlab-app/src/main/resources/liquibase/change-log.xml rename to gitlab-app/src/main/resources/liquibase/v.1.0.0/changelog.xml index cec031a..9d00dee 100644 --- a/gitlab-app/src/main/resources/liquibase/change-log.xml +++ b/gitlab-app/src/main/resources/liquibase/v.1.0.0/changelog.xml @@ -3,6 +3,11 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd"> - + + + + + + \ No newline at end of file diff --git a/gitlab-app/src/main/resources/messages_en.properties b/gitlab-app/src/main/resources/messages_en.properties deleted file mode 100644 index ae9b348..0000000 --- a/gitlab-app/src/main/resources/messages_en.properties +++ /dev/null @@ -1,30 +0,0 @@ -main.yes=Yes -main.no=No -ui.lang_changed=Language changed successfully -ui.monitor_private_projects=Start tracking private projects? -ui.monitor_project_private_success=Projects have been successfully added to tracking -ui.monitor_owner_projects=Start tracking public projects that you own? -ui.setup_finished=Configuration completed successfully\n-- -- -- -- --\nDeveloper: [uPagge](https://uPagge.ru) -ui.menu.header=This is the bot menu, select a new item -ui.menu.task=My tasks -ui.menu.mr=Merge Request -ui.menu.setting=Settings -ui.menu.add_mr=Add project -ui.menu.add_mr.text=Copy the url of the project and send it to me -menu.add_project_success=Project added successfully -ui.menu.setting.text=This is the settings menu -ui.menu.setting.language=Language settings -ui.menu.setting.language.text=Choose your language -ui.answer.no_task=No tasks found -ui.answer.no_mr=You are not assigned in charge of MR -notify.pr.new={0} *New MergeRequest | {1}*{2}[{3}]({4}){5}{2}{9}: {10} {12} {11}\n{7}: {8} -notify.pr.forgotten={0} *MergeRequest Review Reminder | {4}*{3}[{1}]({2}) -notify.pr.conflict={0} *Attention! MergeRequest conflict | {4}*{1}[{2}]({3}) -notify.pr.smart={0} *MergeRequest Reminder | {6}*{3}[{1}]({2}){3}{4} изменил свое решение на {5} -notify.pr.state={0} *MergeRequest status changed | {7}*{1}[{2}]({3}){1}{4} {5} {6} -notify.pr.update={0} *MergeRequest update | {6}*{3}[{1}]({2}){3}{4}: {5} -notify.task.close={0} *Closed [task]({1}){2}*{3}*: {4} -notify.task.new={0} *New [task]({1}) assigned{2}*{3}*: {4} -notify.project.new={0} *New project*{1}[{2}]({3}){1}{4}{5}: {6} -notify.comment.bell={0} *New mention* | [MR]({1}){2}*{3}*: {4} -notify.pipeline={0} *Pipeline {1,number,#}* | {2}{3}[{4}]({5}){3}{6} {7} {8} \ No newline at end of file diff --git a/gitlab-app/src/main/resources/messages_ru.properties b/gitlab-app/src/main/resources/messages_ru.properties deleted file mode 100644 index 69ca866..0000000 --- a/gitlab-app/src/main/resources/messages_ru.properties +++ /dev/null @@ -1,30 +0,0 @@ -main.yes=Да -main.no=Нет -ui.lang_changed=Язык успешно изменен -ui.monitor_private_projects=Начать отслеживать приватные проекты? -ui.monitor_project_private_success=Проекты успешно добавлены в отслеживание -ui.monitor_owner_projects=Начать отслеживать публичные проекты, владельцем которых вы являетесь? -ui.setup_finished=Настройка успешно завершена\n-- -- -- -- --\nРазработчик: [uPagge](https://struchkov.dev/blog) -ui.menu.header=Это меню бота, выберите новый пункт -ui.menu.task=Мои задачи -ui.menu.mr=Merge Request -ui.menu.setting=Настройки -ui.menu.add_mr=Добавить проект -ui.menu.add_mr.text=Скопируйте url проекта и отправьте его мне -menu.add_project_success=Проект успешно добавлен -ui.menu.setting.text=Это меню настроек -ui.menu.setting.language=Настройки языка -ui.menu.setting.language.text=Выберете язык -ui.answer.no_task=Задачи не найдены -ui.answer.no_mr=Вы не назначены ответственным за MR -notify.pr.new={0} *Новый MergeRequest | {1}*{2}[{3}]({4}){5}{2}{9}: {10} {12} {11}\n{7}: {8} -notify.pr.forgotten={0} *Напоминание о просмотре PullRequest | {4}*{3}[{1}]({2}) -notify.pr.conflict={0} *Внимание! Конфликт в MergeRequest | {4}*{1}[{2}]({3}){1}Ветка: {5} -notify.pr.smart={0} *Напоминание о MergeRequest | {6}*{3}[{1}]({2}){3}{4} изменил свое решение на {5} -notify.pr.state={0} *Изменился статус MergeRequest | {7}*{1}[{2}]({3}){1}{4} {5} {6} -notify.pr.update={0} *Обновление MergeRequest | {6}*{3}[{1}]({2}){3}Все задачи: {8}/{7}\nВаши задачи: {10}/{9}{3}{4}: {5} -notify.task.close={0} *Закрыта* [задача]({1}){2}*{3}*: {4}{2}Ваши задачи: {5}/{6} -notify.task.new={0} *Назначена новая* [задача]({1}){2}*{3}*: {4} -notify.project.new={0} *Новый Проект*{1}[{2}]({3}){1}{4}{5}: {6} -notify.comment.bell={0} *Новое упоминание* | [MR]({1}){2}*{3}*: {4} -notify.pipeline={0} *Сборка {1,number,#}* | {2}{3}[{4}]({5}){3}{6} {7} {8} \ No newline at end of file diff --git a/gitlab-sdk/pom.xml b/gitlab-sdk/pom.xml index bc66693..9f219fb 100644 --- a/gitlab-sdk/pom.xml +++ b/gitlab-sdk/pom.xml @@ -6,11 +6,10 @@ dev.struchkov.bot.gitlab gitlab-bot - 1.0.0 + 1.1.0 gitlab-sdk - ${gitlab.sdk.version} diff --git a/pom.xml b/pom.xml index 7f6ad95..9967bb8 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ dev.struchkov.bot.gitlab gitlab-bot - 1.0.0 + 1.1.0 pom @@ -44,20 +44,10 @@ UTF-8 UTF-8 - 1.0.0 - 1.0.0 - 1.0.0 - 1.0.0 - 1.0.0 - 1.0.0 - 1.0.0 - - 1.0.0 - 0.0.2 + 0.0.37 2.2 - 6.0.0.Alpha5 31.0.1-jre 2.13.1 2.13.1 @@ -71,69 +61,97 @@ - - dev.struchkov.haiti - haiti-bom - ${haiti.ver} - pom - import - - dev.struchkov.bot.gitlab bot-core - ${gitlab.core.version} + ${project.version} dev.struchkov.bot.gitlab gitlab-core - ${gitlab.core.version} + ${project.version} dev.struchkov.bot.gitlab telegram-bot - ${gitlab.telegram.version} + ${project.version} dev.struchkov.bot.gitlab bot-context - ${gitlab.context.version} + ${project.version} dev.struchkov.bot.gitlab gitlab-sdk - ${gitlab.sdk.version} + ${project.version} dev.struchkov.bot.gitlab bot-data - ${gitlab.data.version} + ${project.version} - dev.struchkov.godfather - telegram-core + dev.struchkov.haiti.utils + haiti-utils-field-constants + 0.0.6 + + + + dev.struchkov.haiti + haiti-utils + 2.0.0 + + + + dev.struchkov.haiti + haiti-exception + 2.0.0 + + + + dev.struchkov.haiti.utils + haiti-utils-network + 0.0.5 + + + + dev.struchkov.haiti.filter + haiti-filter-criteria + 0.0.5 + + + + dev.struchkov.godfather.telegram + telegram-consumer-simple + ${godfather.telegram.core.version} + + + + dev.struchkov.godfather.telegram + telegram-core-simple + ${godfather.telegram.core.version} + + + + dev.struchkov.godfather.telegram + telegram-sender-simple ${godfather.telegram.core.version} - - org.hibernate.orm - hibernate-jpamodelgen - ${hibernate.jpa-modelgen.version} - - org.postgresql postgresql diff --git a/telegram-bot/pom.xml b/telegram-bot/pom.xml index d60828a..1ed0aa9 100644 --- a/telegram-bot/pom.xml +++ b/telegram-bot/pom.xml @@ -6,11 +6,10 @@ dev.struchkov.bot.gitlab gitlab-bot - 1.0.0 + 1.1.0 telegram-bot - ${gitlab.telegram.version} @@ -19,8 +18,18 @@ - dev.struchkov.godfather - telegram-core + dev.struchkov.godfather.telegram + telegram-consumer-simple + + + + dev.struchkov.godfather.telegram + telegram-sender-simple + + + + dev.struchkov.godfather.telegram + telegram-core-simple diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/config/TelegramBotConfig.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/config/TelegramBotConfig.java index 7ee30c2..9b8fb6f 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/config/TelegramBotConfig.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/config/TelegramBotConfig.java @@ -1,27 +1,34 @@ package dev.struchkov.bot.gitlab.telegram.config; import dev.struchkov.bot.gitlab.telegram.service.ReplaceUrlLocalhost; -import dev.struchkov.godfather.context.domain.content.Mail; -import dev.struchkov.godfather.context.repository.impl.local.MailRepositoryList; -import dev.struchkov.godfather.context.service.MailService; -import dev.struchkov.godfather.context.service.MessageService; -import dev.struchkov.godfather.context.service.impl.MailServiceImpl; -import dev.struchkov.godfather.context.service.sender.Sending; -import dev.struchkov.godfather.core.domain.unit.AnswerCheck; -import dev.struchkov.godfather.telegram.autoresponder.MessageAutoresponderTelegram; -import dev.struchkov.godfather.telegram.config.TelegramPollingConfig; -import dev.struchkov.godfather.telegram.listen.EventDistributor; -import dev.struchkov.godfather.telegram.listen.EventDistributorImpl; -import dev.struchkov.godfather.telegram.listen.TelegramConnect; -import dev.struchkov.godfather.telegram.listen.TelegramSender; -import org.sadtech.autoresponder.repository.UnitPointerRepository; -import org.sadtech.autoresponder.repository.UnitPointerRepositoryMap; +import dev.struchkov.bot.gitlab.telegram.unit.MenuConfig; +import dev.struchkov.bot.gitlab.telegram.unit.UnitConfig; +import dev.struchkov.godfather.main.domain.content.Mail; +import dev.struchkov.godfather.simple.context.service.EventHandler; +import dev.struchkov.godfather.simple.context.service.PersonSettingService; +import dev.struchkov.godfather.simple.context.service.UnitPointerService; +import dev.struchkov.godfather.simple.core.provider.StoryLineHandler; +import dev.struchkov.godfather.simple.core.service.PersonSettingServiceImpl; +import dev.struchkov.godfather.simple.core.service.StorylineMailService; +import dev.struchkov.godfather.simple.core.service.StorylineService; +import dev.struchkov.godfather.simple.core.service.UnitPointerServiceImpl; +import dev.struchkov.godfather.simple.data.repository.impl.PersonSettingLocalRepository; +import dev.struchkov.godfather.simple.data.repository.impl.StorylineMapRepository; +import dev.struchkov.godfather.simple.data.repository.impl.UnitPointLocalRepository; +import dev.struchkov.godfather.telegram.domain.config.TelegramConnectConfig; +import dev.struchkov.godfather.telegram.main.context.TelegramConnect; +import dev.struchkov.godfather.telegram.simple.consumer.EventDistributorService; +import dev.struchkov.godfather.telegram.simple.context.service.EventDistributor; +import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending; +import dev.struchkov.godfather.telegram.simple.core.MailAutoresponderTelegram; +import dev.struchkov.godfather.telegram.simple.core.TelegramConnectBot; +import dev.struchkov.godfather.telegram.simple.sender.TelegramSender; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; -import java.util.Collections; +import java.util.List; /** * @author upagge [30.01.2020] @@ -31,32 +38,46 @@ import java.util.Collections; public class TelegramBotConfig { @Bean - public MailService messageService() { - return new MailServiceImpl(new MailRepositoryList()); + public UnitPointerService unitPointerService() { + return new UnitPointerServiceImpl(new UnitPointLocalRepository()); } @Bean - public UnitPointerRepository unitPointerRepository() { - return new UnitPointerRepositoryMap(); + public PersonSettingService personSettingService() { + return new PersonSettingServiceImpl(new PersonSettingLocalRepository()); } @Bean - public MessageAutoresponderTelegram messageAutoresponderTelegram( - Sending sending, - MessageService messageService, - UnitPointerRepository unitPointerRepository, - AnswerCheck checkFirstStart + public StorylineService storylineService( + UnitPointerService unitPointerService, + + MenuConfig menuConfig, + UnitConfig unitConfig ) { - return new MessageAutoresponderTelegram( - Collections.singleton(checkFirstStart), - sending, - messageService, - unitPointerRepository + final List config = List.of(menuConfig, unitConfig); + + return new StorylineMailService( + unitPointerService, + new StorylineMapRepository(), + config ); } @Bean - public Sending sending( + public MailAutoresponderTelegram messageAutoresponderTelegram( + TelegramSending sending, + PersonSettingService personSettingService, + + StorylineService mailStorylineService + ) { + final MailAutoresponderTelegram autoresponder = new MailAutoresponderTelegram( + sending, personSettingService, mailStorylineService + ); + return autoresponder; + } + + @Bean + public TelegramSending sending( TelegramConnect telegramConnect, ReplaceUrlLocalhost replaceUrlLocalhost ) { @@ -66,22 +87,29 @@ public class TelegramBotConfig { } @Bean - public TelegramConnect telegramConnect(TelegramPollingConfig telegramConfig) { - return new TelegramConnect(telegramConfig); + public TelegramConnectBot telegramConnect(TelegramConnectConfig telegramConfig) { + return new TelegramConnectBot(telegramConfig); } @Bean @ConfigurationProperties("telegram-config") - public TelegramPollingConfig telegramConfig() { - return new TelegramPollingConfig(); + public TelegramConnectConfig telegramConfig() { + return new TelegramConnectConfig(); + } + + @Bean + public StoryLineHandler storyLineHandler( + MailAutoresponderTelegram mailAutoresponderTelegram + ) { + return new StoryLineHandler(mailAutoresponderTelegram); } @Bean public EventDistributor eventDistributor( - TelegramConnect telegramConnect, - MailService mailService + TelegramConnectBot telegramConnect, + List eventProviders ) { - return new EventDistributorImpl(telegramConnect, mailService); + return new EventDistributorService(telegramConnect, eventProviders); } } diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/scheduler/CheckNewMessage.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/scheduler/CheckNewMessage.java deleted file mode 100644 index 7b703b3..0000000 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/scheduler/CheckNewMessage.java +++ /dev/null @@ -1,19 +0,0 @@ -package dev.struchkov.bot.gitlab.telegram.scheduler; - -import dev.struchkov.godfather.telegram.autoresponder.MessageAutoresponderTelegram; -import lombok.RequiredArgsConstructor; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Service; - -@Service -@RequiredArgsConstructor -public class CheckNewMessage { - - private final MessageAutoresponderTelegram messageAutoresponderTelegram; - - @Scheduled(fixedDelay = 5000) - public void check() { - messageAutoresponderTelegram.checkNewMessage(); - } - -} diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/MessageSendTelegramService.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/MessageSendTelegramService.java index 4106417..8638a0d 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/MessageSendTelegramService.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/MessageSendTelegramService.java @@ -2,14 +2,14 @@ package dev.struchkov.bot.gitlab.telegram.service; import dev.struchkov.bot.gitlab.context.domain.PersonInformation; import dev.struchkov.bot.gitlab.context.domain.notify.Notify; -import dev.struchkov.bot.gitlab.context.service.AppSettingService; import dev.struchkov.bot.gitlab.context.service.MessageSendService; -import dev.struchkov.godfather.context.domain.BoxAnswer; -import dev.struchkov.godfather.context.service.sender.Sending; +import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import static dev.struchkov.godfather.main.domain.BoxAnswer.boxAnswer; + /** * Отправляет сообщение в телеграмм. * @@ -19,14 +19,13 @@ import org.springframework.stereotype.Service; @RequiredArgsConstructor public class MessageSendTelegramService implements MessageSendService { - private final Sending sending; + private final TelegramSending sending; private final PersonInformation personInformation; - private final AppSettingService settingService; @Override public void send(@NonNull Notify notify) { - sending.send(personInformation.getTelegramId(), BoxAnswer.of(notify.generateMessage(settingService))); + sending.send(personInformation.getTelegramId(), boxAnswer(notify.generateMessage())); } } 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 26ecd30..be4b2d6 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,7 +1,7 @@ package dev.struchkov.bot.gitlab.telegram.service; import dev.struchkov.bot.gitlab.core.config.properties.GitlabProperty; -import dev.struchkov.godfather.telegram.service.SendPreProcessing; +import dev.struchkov.godfather.telegram.simple.sender.SendPreProcessing; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/StartNotify.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/StartNotify.java index 72a1940..0173756 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/StartNotify.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/StartNotify.java @@ -27,7 +27,7 @@ public class StartNotify { SimpleTextNotify.builder() .message("Привет. Желаю продуктивного дня :)" + "\n-- -- -- -- --\n" + - "Version " + appProperty.getVersion() + " | Developer: [uPagge](https://struchkov.dev/blog)") + "Version " + appProperty.getVersion() + " | Developer: [uPagge](https://mark.struchkov.dev)") .build() ); } diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/unit/pullrequest/PullRequestNeedWorkProcessing.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/unit/pullrequest/PullRequestNeedWorkProcessing.java index 649e49e..c7625f1 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/unit/pullrequest/PullRequestNeedWorkProcessing.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/unit/pullrequest/PullRequestNeedWorkProcessing.java @@ -1,11 +1,13 @@ package dev.struchkov.bot.gitlab.telegram.service.unit.pullrequest; import dev.struchkov.bot.gitlab.context.service.MergeRequestsService; -import dev.struchkov.godfather.context.domain.BoxAnswer; -import dev.struchkov.godfather.context.domain.content.Message; -import dev.struchkov.godfather.context.service.usercode.ProcessingData; +import dev.struchkov.godfather.main.domain.BoxAnswer; +import dev.struchkov.godfather.main.domain.content.Message; +import dev.struchkov.godfather.simple.core.unit.func.ProcessingData; import lombok.RequiredArgsConstructor; +import java.util.Optional; + /** * @author upagge 17.09.2020 */ @@ -16,7 +18,7 @@ public class PullRequestNeedWorkProcessing implements ProcessingData { private final MergeRequestsService mergeRequestsService; @Override - public BoxAnswer processing(Message message) { + public Optional processing(Message message) { // final Person person = personService.getByTelegramId(message.getPersonId()) // .orElseThrow(() -> new NotFoundException("Пользователь не найден")); // final List pullRequests = pullRequestsService.getAllByAuthorAndReviewerStatus(person.getLogin(), ReviewerStatus.UNAPPROVED); @@ -24,7 +26,7 @@ public class PullRequestNeedWorkProcessing implements ProcessingData { // MessageUtils.pullRequestForNeedWork(pullRequests) // .orElse("Не найдено ПРов, которые нуждаются в доработке :)") // ); - return null; + return Optional.empty(); } } diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/unit/pullrequest/PullRequestReviewProcessing.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/unit/pullrequest/PullRequestReviewProcessing.java index df90cab..0c4c33d 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/unit/pullrequest/PullRequestReviewProcessing.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/unit/pullrequest/PullRequestReviewProcessing.java @@ -1,11 +1,13 @@ package dev.struchkov.bot.gitlab.telegram.service.unit.pullrequest; import dev.struchkov.bot.gitlab.context.service.MergeRequestsService; -import dev.struchkov.godfather.context.domain.BoxAnswer; -import dev.struchkov.godfather.context.domain.content.Message; -import dev.struchkov.godfather.context.service.usercode.ProcessingData; +import dev.struchkov.godfather.main.domain.BoxAnswer; +import dev.struchkov.godfather.main.domain.content.Message; +import dev.struchkov.godfather.simple.core.unit.func.ProcessingData; import lombok.RequiredArgsConstructor; +import java.util.Optional; + /** * @author upagge 17.09.2020 */ @@ -16,7 +18,7 @@ public class PullRequestReviewProcessing implements ProcessingData { private final MergeRequestsService mergeRequestsService; @Override - public BoxAnswer processing(Message message) { + public Optional processing(Message message) { // final Person person = personService.getByTelegramId(message.getPersonId()) // .orElseThrow(() -> new NotFoundException("Пользователь не найден")); // final List pullRequests = pullRequestsService.getAllByReviewerAndStatuses( @@ -28,7 +30,7 @@ public class PullRequestReviewProcessing implements ProcessingData { // MessageUtils.pullRequestForReview(pullRequests) // .orElse("Все ПР проверены :)") // ); - return null; + return Optional.empty(); } } 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 e9e16f1..1bffaf6 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 @@ -4,22 +4,19 @@ import dev.struchkov.bot.gitlab.context.domain.MergeRequestState; import dev.struchkov.bot.gitlab.context.domain.PersonInformation; import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest; import dev.struchkov.bot.gitlab.context.domain.filter.MergeRequestFilter; -import dev.struchkov.bot.gitlab.context.service.AppSettingService; import dev.struchkov.bot.gitlab.context.service.MergeRequestsService; import dev.struchkov.bot.gitlab.context.service.NoteService; import dev.struchkov.bot.gitlab.core.config.properties.GitlabProperty; import dev.struchkov.bot.gitlab.core.service.parser.ProjectParser; -import dev.struchkov.godfather.context.domain.BoxAnswer; -import dev.struchkov.godfather.context.domain.content.Message; -import dev.struchkov.godfather.context.domain.keyboard.KeyBoard; -import dev.struchkov.godfather.context.domain.keyboard.KeyBoardLine; -import dev.struchkov.godfather.context.domain.keyboard.button.KeyBoardButtonText; -import dev.struchkov.godfather.context.utils.KeyBoards; -import dev.struchkov.godfather.core.domain.unit.AnswerText; -import dev.struchkov.haiti.context.page.Sheet; -import dev.struchkov.haiti.context.page.impl.PaginationImpl; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; +import dev.struchkov.bot.gitlab.telegram.utils.UnitName; +import dev.struchkov.godfather.main.domain.annotation.Unit; +import dev.struchkov.godfather.main.domain.content.Mail; +import dev.struchkov.godfather.simple.core.unit.AnswerText; +import dev.struchkov.godfather.simple.core.unit.MainUnit; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.stereotype.Component; import java.text.MessageFormat; import java.util.Arrays; @@ -27,123 +24,106 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; +import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.ADD_NEW_PROJECT; +import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.GENERAL_MENU; +import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.GET_ASSIGNEE_MERGE_REQUEST; +import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.GET_TASKS; +import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.SETTINGS; +import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.TEXT_ADD_NEW_PROJECT; +import static dev.struchkov.godfather.main.domain.BoxAnswer.boxAnswer; +import static dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton.simpleButton; +import static dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine; +import static dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard.inlineKeyBoard; + /** * // TODO: 16.01.2021 Добавить описание. * * @author upagge 16.01.2021 */ -@Configuration +@Component +@RequiredArgsConstructor public class MenuConfig { - @Bean - public AnswerText menu( - AppSettingService settingService, - AnswerText settings, - AnswerText textAddNewProject, - AnswerText getTasks, - AnswerText getAssigneeMergeRequest + private final ProjectParser projectParser; + private final GitlabProperty gitlabProperty; + private final PersonInformation personInformation; + private final NoteService noteService; + private final MergeRequestsService mergeRequestsService; + + @Unit(GENERAL_MENU) + public AnswerText menu( + @Unit(SETTINGS) MainUnit settings, + @Unit(TEXT_ADD_NEW_PROJECT) MainUnit textAddNewProject, + @Unit(GET_TASKS) MainUnit getTasks, + @Unit(GET_ASSIGNEE_MERGE_REQUEST) MainUnit getAssigneeMergeRequest ) { - return AnswerText.builder() - .boxAnswer(message -> - { - final KeyBoardButtonText newMr = KeyBoardButtonText.builder().label(settingService.getMessage("ui.menu.add_mr")).build(); - final KeyBoardButtonText tasks = KeyBoardButtonText.builder().label(settingService.getMessage("ui.menu.task")).build(); - final KeyBoardButtonText pr = KeyBoardButtonText.builder().label(settingService.getMessage("ui.menu.mr")).build(); - final KeyBoardButtonText settingsKeyBoard = KeyBoardButtonText.builder().label(settingService.getMessage("ui.menu.setting")).build(); - - final KeyBoardLine oneLine = KeyBoardLine.builder() - .buttonKeyBoard(newMr) - .build(); - - final KeyBoardLine twoLine = KeyBoardLine.builder() - .buttonKeyBoard(tasks) - .buttonKeyBoard(pr) - .build(); - - final KeyBoardLine threeLine = KeyBoardLine.builder() - .buttonKeyBoard(settingsKeyBoard) - .build(); - - final KeyBoard keyBoard = KeyBoard.builder() - .lineKeyBoard(oneLine) - .lineKeyBoard(twoLine) - .lineKeyBoard(threeLine) - .build(); - - return BoxAnswer.builder() - .message(settingService.getMessage("ui.menu.header")) - .keyBoard(keyBoard) - .build(); - } + return AnswerText.builder() + .answer(boxAnswer( + "This is the bot menu, select a new item", + inlineKeyBoard( + simpleLine(simpleButton("Add project", TEXT_ADD_NEW_PROJECT)), + simpleLine( + simpleButton("My tasks", GET_TASKS), + simpleButton("Merge Request", GET_ASSIGNEE_MERGE_REQUEST) + ), + simpleLine(simpleButton("Settings", SETTINGS)) + ) + ) ) - .nextUnit(settings) - .nextUnit(textAddNewProject) - .nextUnit(getTasks) - .nextUnit(getAssigneeMergeRequest) + .next(settings) + .next(textAddNewProject) + .next(getTasks) + .next(getAssigneeMergeRequest) .build(); } - @Bean - public AnswerText textAddNewProject( - AppSettingService settingService, - AnswerText addNewProject + @Unit(TEXT_ADD_NEW_PROJECT) + public AnswerText textAddNewProject( + @Unit(ADD_NEW_PROJECT) MainUnit addNewProject ) { - return AnswerText.builder() - .boxAnswer(BoxAnswer.processing(settingService.getMessage("ui.menu.add_mr.text"))) - .phrase(settingService.getMessage("ui.menu.add_mr")) - .nextUnit(addNewProject) + return AnswerText.builder() + .triggerPhrase(TEXT_ADD_NEW_PROJECT) + .answer(boxAnswer("Copy the url of the project and send it to me")) + .next(addNewProject) .build(); } - @Bean - public AnswerText addNewProject( - AppSettingService settingService, - ProjectParser projectParser, - GitlabProperty gitlabProperty - ) { - return AnswerText.builder() - .boxAnswer(message -> { - final List urlList = Arrays.stream(message.getText().split("/")).toList(); + @Unit(ADD_NEW_PROJECT) + public AnswerText addNewProject() { + return AnswerText.builder() + .answer(mail -> { + final List urlList = Arrays.stream(mail.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); - return BoxAnswer.of(settingService.getMessage("menu.add_project_success")); + return boxAnswer("Project added successfully"); }) .build(); } - @Bean - public AnswerText settings( - AppSettingService settingService, - AnswerText settingsLanguage - ) { - return AnswerText.builder() - .boxAnswer(message -> - BoxAnswer.builder() - .message(settingService.getMessage("ui.menu.setting.text")) - .keyBoard(KeyBoards.verticalMenuString(settingService.getMessage("ui.menu.setting.language"))) - .build()) - .phrase(settingService.getMessage("ui.menu.setting")) - .nextUnit(settingsLanguage) + @Unit(SETTINGS) + public AnswerText settings() { + return AnswerText.builder() + .triggerPhrase(SETTINGS) + .answer( + boxAnswer("This is the settings menu") + ) .build(); } - @Bean - public AnswerText getTasks( - AppSettingService settingService, - PersonInformation personInformation, - NoteService noteService - ) { - return AnswerText.builder() - .boxAnswer(message -> - { - final Long userId = personInformation.getId(); - final String text = noteService.getAllPersonTask(userId, false).stream() - .map(note -> MessageFormat.format("- [{0}]({1})", trim(note.getBody()).replace("\n", " "), note.getWebUrl())) - .collect(Collectors.joining("\n")); - return BoxAnswer.of("".equals(text) ? settingService.getMessage("ui.answer.no_task") : text); - }) - .phrase(settingService.getMessage("ui.menu.task")) + @Unit(GET_TASKS) + public AnswerText getTasks() { + return AnswerText.builder() + .triggerPhrase(GET_TASKS) + .answer( + () -> { + final Long userId = personInformation.getId(); + final String text = noteService.getAllPersonTask(userId, false).stream() + .map(note -> MessageFormat.format("- [{0}]({1})", trim(note.getBody()).replace("\n", " "), note.getWebUrl())) + .collect(Collectors.joining("\n")); + return boxAnswer("".equals(text) ? "No tasks found" : text); + } + ) .build(); } @@ -151,26 +131,22 @@ public class MenuConfig { return body.length() > 31 ? body.substring(0, 30) : body; } - @Bean - public AnswerText getAssigneeMergeRequest( - MergeRequestsService mergeRequestsService, - PersonInformation personInformation, - AppSettingService settingService - ) { - return AnswerText.builder() - .boxAnswer(message -> { + @Unit(UnitName.GET_ASSIGNEE_MERGE_REQUEST) + public AnswerText getAssigneeMergeRequest() { + return AnswerText.builder() + .triggerPhrase(GET_ASSIGNEE_MERGE_REQUEST) + .answer(() -> { final Long userId = personInformation.getId(); - final Sheet sheet = mergeRequestsService.getAll(getAssigneeFilter(userId), PaginationImpl.of(0, 20)); + final Page sheet = mergeRequestsService.getAll(getAssigneeFilter(userId), PageRequest.of(0, 20)); if (sheet.hasContent()) { final List mergeRequests = sheet.getContent(); final String text = mergeRequests.stream() .map(mergeRequest -> MessageFormat.format("[{0}]({1})", mergeRequest.getTitle(), mergeRequest.getWebUrl())) .collect(Collectors.joining("\n")); - return BoxAnswer.of(text); + return boxAnswer(text); } - return BoxAnswer.of(settingService.getMessage("ui.answer.no_mr")); + return boxAnswer("You are not assigned in charge of MR"); }) - .phrase(settingService.getMessage("ui.menu.mr")) .build(); } diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/UnitConfig.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/UnitConfig.java index 3ba511b..7fab8a7 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/UnitConfig.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/UnitConfig.java @@ -1,72 +1,85 @@ package dev.struchkov.bot.gitlab.telegram.unit; -import dev.struchkov.bot.gitlab.context.domain.AppLocale; import dev.struchkov.bot.gitlab.context.domain.entity.Note; import dev.struchkov.bot.gitlab.context.service.AppSettingService; import dev.struchkov.bot.gitlab.context.service.DiscussionService; import dev.struchkov.bot.gitlab.context.service.NoteService; import dev.struchkov.bot.gitlab.core.service.parser.ProjectParser; -import dev.struchkov.godfather.context.domain.BoxAnswer; -import dev.struchkov.godfather.context.domain.content.Mail; -import dev.struchkov.godfather.context.domain.content.Message; -import dev.struchkov.godfather.context.domain.content.attachment.Attachment; -import dev.struchkov.godfather.context.domain.content.attachment.AttachmentType; -import dev.struchkov.godfather.context.domain.content.attachment.Link; -import dev.struchkov.godfather.context.utils.KeyBoards; -import dev.struchkov.godfather.core.domain.unit.AnswerCheck; -import dev.struchkov.godfather.core.domain.unit.AnswerProcessing; -import dev.struchkov.godfather.core.domain.unit.AnswerText; -import dev.struchkov.godfather.core.domain.unit.UnitActiveType; -import dev.struchkov.haiti.context.exception.NotFoundException; +import dev.struchkov.godfather.main.core.unit.UnitActiveType; +import dev.struchkov.godfather.main.domain.BoxAnswer; +import dev.struchkov.godfather.main.domain.annotation.Unit; +import dev.struchkov.godfather.main.domain.content.Attachment; +import dev.struchkov.godfather.main.domain.content.Mail; +import dev.struchkov.godfather.simple.core.unit.AnswerCheck; +import dev.struchkov.godfather.simple.core.unit.AnswerText; +import dev.struchkov.godfather.simple.core.unit.MainUnit; +import dev.struchkov.godfather.telegram.domain.attachment.LinkAttachment; +import dev.struchkov.godfather.telegram.domain.attachment.TelegramAttachmentType; +import dev.struchkov.godfather.telegram.main.core.util.Attachments; import lombok.RequiredArgsConstructor; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; import java.text.MessageFormat; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.ANSWER_NOTE; +import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.CHECK_FIRST_START; +import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.CHECK_MENU_OR_ANSWER; +import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.CHECK_PARSER_PRIVATE_PROJECT; +import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.CHECK_PARSE_OWNER_PROJECT; +import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.END_SETTING; +import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.GENERAL_MENU; +import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.PARSER_PRIVATE_PROJECT; +import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.PARSE_OWNER_PROJECT; +import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.TEXT_PARSER_PRIVATE_PROJECT; +import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.TEXT_PARSE_OWNER_PROJECT; +import static dev.struchkov.godfather.main.domain.BoxAnswer.boxAnswer; +import static dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton.simpleButton; +import static dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine; +import static dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard.inlineKeyBoard; + /** * TODO: Добавить описание класса. * * @author upagge [30.01.2020] */ -@Configuration +@Component @RequiredArgsConstructor public class UnitConfig { private static final Pattern NOTE_LINK = Pattern.compile("#note_\\d+$"); - @Bean - public AnswerCheck checkFirstStart( - AppSettingService settingService, - AnswerText textCheckLanguage, - AnswerCheck checkMenuOrAnswer + private final AppSettingService settingService; + private final NoteService noteService; + private final DiscussionService discussionService; + private final ProjectParser projectParser; + + @Unit(value = CHECK_FIRST_START, main = true) + public AnswerCheck checkFirstStart( + @Unit(TEXT_PARSER_PRIVATE_PROJECT) MainUnit textParserPrivateProject, + @Unit(CHECK_MENU_OR_ANSWER) MainUnit checkMenuOrAnswer ) { - return AnswerCheck.builder() - .check( - message -> settingService.isFirstStart() - ) + return AnswerCheck.builder() + .check(message -> settingService.isFirstStart()) .unitFalse(checkMenuOrAnswer) - .unitTrue(textCheckLanguage) + .unitTrue(textParserPrivateProject) .build(); } - @Bean - public AnswerCheck checkMenuOrAnswer( - AnswerText menu, - AnswerText answerNote + @Unit(value = CHECK_MENU_OR_ANSWER) + public AnswerCheck checkMenuOrAnswer( + @Unit(GENERAL_MENU) MainUnit menu, + @Unit(ANSWER_NOTE) MainUnit answerNote ) { - return AnswerCheck.builder() + return AnswerCheck.builder() .check( - message -> { - Mail mail = (Mail) message; + mail -> { final List forwardMails = mail.getForwardMail(); if (forwardMails != null && forwardMails.size() == 1) { final Mail forwardMail = forwardMails.get(0); - return forwardMail.getAttachments().stream() - .anyMatch(attachment -> AttachmentType.LINK.equals(attachment.getType())); + return Attachments.findFirstLink(forwardMail.getAttachments()).isPresent(); } return false; } @@ -76,177 +89,134 @@ public class UnitConfig { .build(); } - @Bean - public AnswerText answerNote( - NoteService noteService, - DiscussionService discussionService - ) { - return AnswerText.builder() - .boxAnswer( - message -> { - final List attachments = ((Mail) message).getForwardMail().get(0).getAttachments(); + @Unit(ANSWER_NOTE) + public AnswerText answerNote() { + return AnswerText.builder() + .answer( + mail -> { + final List attachments = mail.getForwardMail().get(0).getAttachments(); for (Attachment attachment : attachments) { - if (AttachmentType.LINK.equals(attachment.getType())) { - final String url = ((Link) attachment).getUrl(); - Matcher matcher = NOTE_LINK.matcher(url); + if (TelegramAttachmentType.LINK.name().equals(attachment.getType())) { + final String url = ((LinkAttachment) attachment).getUrl(); + final Matcher matcher = NOTE_LINK.matcher(url); if (matcher.find()) { final String noteText = url.substring(matcher.start(), matcher.end()); - Long noteId = Long.valueOf(noteText.replaceAll("#note_", "")); - final Note note = noteService.getById(noteId).orElseThrow(NotFoundException.supplier("Note не найдено")); + final Long noteId = Long.valueOf(noteText.replaceAll("#note_", "")); + final Note note = noteService.getByIdOrThrow(noteId); final String discussionId = note.getDiscussion().getId(); - discussionService.answer(discussionId, MessageFormat.format("@{0}, {1}", note.getAuthor().getUserName(), message.getText())); + discussionService.answer(discussionId, MessageFormat.format("@{0}, {1}", note.getAuthor().getUserName(), mail.getText())); + return BoxAnswer.builder().build(); } - return BoxAnswer.of(""); } } - return BoxAnswer.of("Ошибка"); + return boxAnswer("Ошибка"); } ) .build(); } - @Bean - public AnswerText textCheckLanguage( - AnswerProcessing checkLanguage + @Unit(TEXT_PARSER_PRIVATE_PROJECT) + public AnswerText textParserPrivateProject( + @Unit(CHECK_PARSER_PRIVATE_PROJECT) MainUnit checkParserPrivateProject ) { - return AnswerText.builder() - .boxAnswer(message -> - BoxAnswer.builder() - .message("Hi :)\n\nLet's choose a language for.") - .keyBoard(KeyBoards.verticalDuoMenuString("Русский", "English")) - .build() - ) - .nextUnit(checkLanguage) - .build(); - } - - @Bean - public AnswerProcessing checkLanguage( - AppSettingService settingService, - AnswerText textParserPrivateProject - ) { - return AnswerProcessing - .builder() - .processingData( - message -> { - final AppLocale appLocale = AppLocale.of(message.getText()); - settingService.setLocale(appLocale); - return BoxAnswer.of( - settingService.getMessage("ui.lang_changed") - ); - } - ) - .nextUnit(textParserPrivateProject) - .build(); - } - - @Bean - public AnswerText textParserPrivateProject( - AnswerCheck checkParserPrivateProject, - AppSettingService settingService - ) { - return AnswerText.builder() - .boxAnswer(message -> - BoxAnswer.builder() - .message(settingService.getMessage("ui.monitor_private_projects")) - .keyBoard(KeyBoards.verticalDuoMenuString( - settingService.getMessage("main.yes"), settingService.getMessage("main.no") - )) - .build() + return AnswerText.builder() + .answer( + boxAnswer( + "Start tracking private projects?", + inlineKeyBoard( + simpleLine( + simpleButton("Yes", "YES"), + simpleButton("No", "NO") + ) + ) + ) ) .activeType(UnitActiveType.AFTER) - .nextUnit(checkParserPrivateProject) + .next(checkParserPrivateProject) .build(); } - @Bean - public AnswerCheck checkParserPrivateProject( - AppSettingService appSettingService, - AnswerProcessing parserPrivateProject, - AnswerText textParseOwnerProject + @Unit(CHECK_PARSER_PRIVATE_PROJECT) + public AnswerCheck checkParserPrivateProject( + @Unit(PARSER_PRIVATE_PROJECT) AnswerText parserPrivateProject, + @Unit(TEXT_PARSE_OWNER_PROJECT) MainUnit textParseOwnerProject ) { - return AnswerCheck.builder() - .check( - message -> appSettingService.getMessage("main.yes").equalsIgnoreCase(message.getText()) - ) + return AnswerCheck.builder() + .check(mail -> "YES".equalsIgnoreCase(mail.getText())) .unitTrue(parserPrivateProject) .unitFalse(textParseOwnerProject) .build(); } - @Bean - public AnswerProcessing parserPrivateProject( - ProjectParser projectParser, - AppSettingService settingService, - AnswerText textParseOwnerProject + @Unit(PARSER_PRIVATE_PROJECT) + public AnswerText parserPrivateProject( + @Unit(TEXT_PARSE_OWNER_PROJECT) MainUnit textParseOwnerProject ) { - return AnswerProcessing.builder() - .processingData(message -> { + return AnswerText.builder() + .answer(() -> { projectParser.parseAllPrivateProject(); - return BoxAnswer.of(settingService.getMessage("ui.monitor_project_private_success")); + return boxAnswer("Projects have been successfully added to tracking"); }) - .nextUnit(textParseOwnerProject) + .next(textParseOwnerProject) .build(); } - @Bean - public AnswerText textParseOwnerProject( - AppSettingService settingService, - AnswerCheck checkParseOwnerProject + @Unit(TEXT_PARSE_OWNER_PROJECT) + public AnswerText textParseOwnerProject( + @Unit(CHECK_PARSE_OWNER_PROJECT) MainUnit checkParseOwnerProject ) { - return AnswerText.builder() - .boxAnswer(message -> - BoxAnswer.builder() - .message(settingService.getMessage("ui.monitor_owner_projects")) - .keyBoard(KeyBoards.verticalDuoMenuString( - settingService.getMessage("main.yes"), settingService.getMessage("main.no") - )) - .build() + return AnswerText.builder() + .answer( + boxAnswer( + "Start tracking public projects that you own?", + inlineKeyBoard( + simpleLine( + simpleButton("Yes", "YES"), + simpleButton("No", "NO") + ) + ) + ) ) .activeType(UnitActiveType.AFTER) - .nextUnit(checkParseOwnerProject) + .next(checkParseOwnerProject) .build(); } - @Bean - public AnswerCheck checkParseOwnerProject( - AppSettingService appSettingService, - AnswerProcessing parseOwnerProject, - AnswerProcessing endSetting + @Unit(CHECK_PARSE_OWNER_PROJECT) + public AnswerCheck checkParseOwnerProject( + @Unit(PARSE_OWNER_PROJECT) MainUnit parseOwnerProject, + @Unit(END_SETTING) MainUnit endSetting ) { - return AnswerCheck.builder() - .check( - message -> appSettingService.getMessage("main.yes").equalsIgnoreCase(message.getText()) - ) + return AnswerCheck.builder() + .check(message -> "YES".equalsIgnoreCase(message.getText())) .unitTrue(parseOwnerProject) .unitFalse(endSetting) .build(); } - @Bean - public AnswerProcessing parseOwnerProject( - ProjectParser projectParser, - AppSettingService settingService, - AnswerProcessing endSetting + @Unit(PARSE_OWNER_PROJECT) + public AnswerText parseOwnerProject( + @Unit(END_SETTING) MainUnit endSetting ) { - return AnswerProcessing.builder() - .processingData(message -> { + return AnswerText.builder() + .answer(() -> { projectParser.parseAllProjectOwner(); - return BoxAnswer.of(settingService.getMessage("ui.monitor_project_private_success")); + return boxAnswer("Projects have been successfully added to tracking"); }) - .nextUnit(endSetting) + .next(endSetting) .build(); } - @Bean - public AnswerProcessing endSetting( - AppSettingService settingService - ) { - return AnswerProcessing.builder() - .processingData( - message -> { + @Unit(END_SETTING) + public AnswerText endSetting() { + return AnswerText.builder() + .answer( + () -> { settingService.disableFirstStart(); - return BoxAnswer.of(settingService.getMessage("ui.setup_finished")); + return boxAnswer(""" + Configuration completed successfully + Developer: [uPagge](https://mark.struchkov.dev) + """); } ) .activeType(UnitActiveType.AFTER) diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/menu/MenuSettingsConfig.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/menu/MenuSettingsConfig.java deleted file mode 100644 index 1368293..0000000 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/menu/MenuSettingsConfig.java +++ /dev/null @@ -1,54 +0,0 @@ -package dev.struchkov.bot.gitlab.telegram.unit.menu; - -import dev.struchkov.bot.gitlab.context.domain.AppLocale; -import dev.struchkov.bot.gitlab.context.service.AppSettingService; -import dev.struchkov.godfather.context.domain.BoxAnswer; -import dev.struchkov.godfather.context.domain.content.Message; -import dev.struchkov.godfather.context.utils.KeyBoards; -import dev.struchkov.godfather.core.domain.unit.AnswerText; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * // TODO: 16.01.2021 Добавить описание. - * - * @author upagge 16.01.2021 - */ -@Configuration -public class MenuSettingsConfig { - - @Bean - public AnswerText settingsLanguage( - AppSettingService settingService, - AnswerText setLanguage - ) { - return AnswerText.builder() - .boxAnswer( - message -> BoxAnswer.builder() - .message(settingService.getMessage("ui.menu.setting.language.text")) - .keyBoard(KeyBoards.verticalDuoMenuString("Русский", "English")) - .build() - ) - .nextUnit(setLanguage) - .phrase(settingService.getMessage("ui.menu.setting.language")) - .build(); - } - - @Bean - public AnswerText setLanguage( - AppSettingService settingService - ) { - return AnswerText.builder() - .boxAnswer( - message -> { - final AppLocale appLocale = AppLocale.of(message.getText()); - settingService.setLocale(appLocale); - return BoxAnswer.of( - settingService.getMessage("ui.lang_changed") - ); - } - ) - .build(); - } - -} diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/utils/UnitName.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/utils/UnitName.java new file mode 100644 index 0000000..1ad66c1 --- /dev/null +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/utils/UnitName.java @@ -0,0 +1,29 @@ +package dev.struchkov.bot.gitlab.telegram.utils; + +import static dev.struchkov.haiti.utils.Exceptions.utilityClass; + +public final class UnitName { + + public static final String SETTINGS_LANGUAGE = "settingsLanguage"; + public static final String GENERAL_MENU = "generalMenu"; + public static final String TEXT_ADD_NEW_PROJECT = "textAddNewProject"; + public static final String ADD_NEW_PROJECT = "addNewProject"; + public static final String SETTINGS = "settings"; + public static final String GET_TASKS = "getTasks"; + public static final String GET_ASSIGNEE_MERGE_REQUEST = "getAssigneeMergeRequest"; + public static final String CHECK_FIRST_START = "checkFirstStart"; + public static final String CHECK_MENU_OR_ANSWER = "checkMenuOrAnswer"; + public static final String ANSWER_NOTE = "answerNote"; + public static final String TEXT_PARSER_PRIVATE_PROJECT = "textParserPrivateProject"; + public static final String CHECK_PARSER_PRIVATE_PROJECT = "checkParserPrivateProject"; + public static final String PARSER_PRIVATE_PROJECT = "parserPrivateProject"; + public static final String TEXT_PARSE_OWNER_PROJECT = "textParseOwnerProject"; + public static final String CHECK_PARSE_OWNER_PROJECT = "checkParseOwnerProject"; + public static final String PARSE_OWNER_PROJECT = "parseOwnerProject"; + public static final String END_SETTING = "endSetting"; + + private UnitName() { + utilityClass(); + } + +}