diff --git a/bot-app/src/main/resources/messages_en.properties b/bot-app/src/main/resources/messages_en.properties index 555d6a6..654e31f 100644 --- a/bot-app/src/main/resources/messages_en.properties +++ b/bot-app/src/main/resources/messages_en.properties @@ -2,4 +2,6 @@ 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 \ No newline at end of file +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 \ No newline at end of file diff --git a/bot-app/src/main/resources/messages_ru.properties b/bot-app/src/main/resources/messages_ru.properties index f847dc9..6c85b8f 100644 --- a/bot-app/src/main/resources/messages_ru.properties +++ b/bot-app/src/main/resources/messages_ru.properties @@ -2,4 +2,6 @@ main.yes=Да main.no=Нет ui.lang_changed=Язык успешно изменен ui.monitor_private_projects=Начать отслеживать приватные проекты? -ui.monitor_project_private_success=Проекты успешно добавлены в отслеживание \ No newline at end of file +ui.monitor_project_private_success=Проекты успешно добавлены в отслеживание +ui.monitor_owner_projects=Начать отслеживать публичные проекты, владельцем которых вы являетесь? +ui.setup_finished=Настройка успешно завершена \ No newline at end of file diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/AppSettingServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/AppSettingServiceImpl.java index 5a7afa4..5c76c12 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/AppSettingServiceImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/AppSettingServiceImpl.java @@ -11,6 +11,7 @@ import org.springframework.context.MessageSource; import org.springframework.stereotype.Service; import java.util.Arrays; +import java.util.Locale; /** * // TODO: 16.01.2021 Добавить описание. @@ -43,11 +44,13 @@ public class AppSettingServiceImpl implements AppSettingService { @Override public String getMessage(@NonNull String label) { - return messageSource.getMessage( - label, null, appSettingRepository.findById(KEY) - .orElseThrow(() -> EXCEPTION) - .getAppLocale().getValue() + final Locale value = appSettingRepository.findById(KEY) + .orElseThrow(() -> EXCEPTION) + .getAppLocale().getValue(); + final String message = messageSource.getMessage( + label, null, value ); + return message; } @Override diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java index 378d82a..8a7c3be 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java @@ -12,6 +12,7 @@ import org.sadtech.bot.gitlab.context.domain.notify.pullrequest.ConflictPrNotify import org.sadtech.bot.gitlab.context.domain.notify.pullrequest.NewPrNotify; import org.sadtech.bot.gitlab.context.domain.notify.pullrequest.StatusPrNotify; import org.sadtech.bot.gitlab.context.repository.MergeRequestRepository; +import org.sadtech.bot.gitlab.context.service.AppSettingService; import org.sadtech.bot.gitlab.context.service.MergeRequestsService; import org.sadtech.bot.gitlab.context.service.NotifyService; import org.sadtech.bot.gitlab.context.service.PersonService; @@ -36,6 +37,7 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService filterService; private final ProjectService projectService; + private final AppSettingService settingService; private final PersonInformation personInformation; @@ -45,6 +47,7 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService filterService, ProjectService projectService, + AppSettingService settingService, PersonInformation personInformation ) { super(mergeRequestRepository); @@ -53,6 +56,7 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService new NotFoundException("Проект не найден")) @@ -80,7 +92,6 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService0.0.2-SNAPSHOT 0.0.3-SNAPSHOT 0.0.2-RELEASE - 0.0.1-RELEASE + 0.0.2-SNAPSHOT 0.0.1-RELEASE 2.2 diff --git a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/TaskProcessing.java b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/TaskProcessing.java index 702de5c..e00f61b 100644 --- a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/TaskProcessing.java +++ b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/TaskProcessing.java @@ -3,8 +3,8 @@ package org.sadtech.bot.gitlab.telegram.service.unit; import lombok.RequiredArgsConstructor; import org.sadtech.bot.gitlab.context.domain.entity.Task; import org.sadtech.bot.gitlab.context.service.TaskService; -import org.sadtech.social.bot.service.usercode.ProcessingData; import org.sadtech.social.core.domain.BoxAnswer; +import org.sadtech.social.core.domain.ProcessingData; import org.sadtech.social.core.domain.content.Message; import java.text.MessageFormat; diff --git a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/pullrequest/PullRequestNeedWorkProcessing.java b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/pullrequest/PullRequestNeedWorkProcessing.java index af6b3b7..a37ba10 100644 --- a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/pullrequest/PullRequestNeedWorkProcessing.java +++ b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/pullrequest/PullRequestNeedWorkProcessing.java @@ -2,8 +2,8 @@ package org.sadtech.bot.gitlab.telegram.service.unit.pullrequest; import lombok.RequiredArgsConstructor; import org.sadtech.bot.gitlab.context.service.MergeRequestsService; -import org.sadtech.social.bot.service.usercode.ProcessingData; import org.sadtech.social.core.domain.BoxAnswer; +import org.sadtech.social.core.domain.ProcessingData; import org.sadtech.social.core.domain.content.Message; /** diff --git a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/pullrequest/PullRequestReviewProcessing.java b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/pullrequest/PullRequestReviewProcessing.java index 512e788..1b1646b 100644 --- a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/pullrequest/PullRequestReviewProcessing.java +++ b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/pullrequest/PullRequestReviewProcessing.java @@ -2,8 +2,8 @@ package org.sadtech.bot.gitlab.telegram.service.unit.pullrequest; import lombok.RequiredArgsConstructor; import org.sadtech.bot.gitlab.context.service.MergeRequestsService; -import org.sadtech.social.bot.service.usercode.ProcessingData; import org.sadtech.social.core.domain.BoxAnswer; +import org.sadtech.social.core.domain.ProcessingData; import org.sadtech.social.core.domain.content.Message; /** diff --git a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/PullRequestUnitConfig.java b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/PullRequestUnitConfig.java index 44ac0a7..192e34b 100644 --- a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/PullRequestUnitConfig.java +++ b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/PullRequestUnitConfig.java @@ -23,7 +23,7 @@ public class PullRequestUnitConfig { AnswerProcessing needWorkPullRequest ) { return AnswerText.builder() - .boxAnswer( + .boxAnswer(message -> BoxAnswer.builder() .message("Эта вкладка для работы с Pull Request") .keyBoard( diff --git a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/UnitConfig.java b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/UnitConfig.java index 13fce7f..32ab06f 100644 --- a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/UnitConfig.java +++ b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/UnitConfig.java @@ -40,7 +40,7 @@ public class UnitConfig { AnswerProcessing checkLanguage ) { return AnswerText.builder() - .boxAnswer( + .boxAnswer(message -> BoxAnswer.builder() .message("Hi :)\n\nLet's choose a language for.") .keyBoard(KeyBoards.verticalDuoMenuString("Русский", "English")) @@ -76,7 +76,7 @@ public class UnitConfig { AppSettingService settingService ) { return AnswerText.builder() - .boxAnswer( + .boxAnswer(message -> BoxAnswer.builder() .message(settingService.getMessage("ui.monitor_private_projects")) .keyBoard(KeyBoards.verticalDuoMenuString( @@ -92,26 +92,94 @@ public class UnitConfig { @Bean public AnswerCheck checkParserPrivateProject( AppSettingService appSettingService, - AnswerProcessing parserPrivateProject + AnswerProcessing parserPrivateProject, + AnswerText textParseOwnerProject ) { return AnswerCheck.builder() .check( message -> appSettingService.getMessage("main.yes").equalsIgnoreCase(message.getText()) ) .unitTrue(parserPrivateProject) + .unitFalse(textParseOwnerProject) .build(); } @Bean public AnswerProcessing parserPrivateProject( ProjectParser projectParser, - AppSettingService settingService + AppSettingService settingService, + AnswerText textParseOwnerProject ) { return AnswerProcessing.builder() .processingData(message -> { projectParser.parseAllPrivateProject(); return BoxAnswer.of(settingService.getMessage("ui.monitor_project_private_success")); }) + .nextUnit(textParseOwnerProject) + .build(); + } + + @Bean + public AnswerText textParseOwnerProject( + AppSettingService settingService, + AnswerCheck 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() + ) + .activeType(UnitActiveType.AFTER) + .nextUnit(checkParseOwnerProject) + .build(); + } + + @Bean + public AnswerCheck checkParseOwnerProject( + AppSettingService appSettingService, + AnswerProcessing parseOwnerProject, + AnswerProcessing endSetting + ) { + return AnswerCheck.builder() + .check( + message -> appSettingService.getMessage("main.yes").equalsIgnoreCase(message.getText()) + ) + .unitTrue(parseOwnerProject) + .unitFalse(endSetting) + .build(); + } + + @Bean + public AnswerProcessing parseOwnerProject( + ProjectParser projectParser, + AppSettingService settingService, + AnswerProcessing endSetting + ) { + return AnswerProcessing.builder() + .processingData(message -> { + projectParser.parseAllProjectOwner(); + return BoxAnswer.of(settingService.getMessage("ui.monitor_project_private_success")); + }) + .nextUnit(endSetting) + .build(); + } + + @Bean + public AnswerProcessing endSetting( + AppSettingService settingService + ) { + return AnswerProcessing.builder() + .processingData( + message -> { + settingService.disableFirstStart(); + return BoxAnswer.of(settingService.getMessage("ui.setup_finished")); + } + ) + .activeType(UnitActiveType.AFTER) .build(); }