Рабочая версия со сменой языка
This commit is contained in:
parent
24008c7989
commit
44949a650f
@ -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
|
||||
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
|
@ -2,4 +2,6 @@ main.yes=Да
|
||||
main.no=Нет
|
||||
ui.lang_changed=Язык успешно изменен
|
||||
ui.monitor_private_projects=Начать отслеживать приватные проекты?
|
||||
ui.monitor_project_private_success=Проекты успешно добавлены в отслеживание
|
||||
ui.monitor_project_private_success=Проекты успешно добавлены в отслеживание
|
||||
ui.monitor_owner_projects=Начать отслеживать публичные проекты, владельцем которых вы являетесь?
|
||||
ui.setup_finished=Настройка успешно завершена
|
@ -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
|
||||
|
@ -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<Merge
|
||||
private final PersonService personService;
|
||||
private final FilterService<MergeRequest, PullRequestFilter> filterService;
|
||||
private final ProjectService projectService;
|
||||
private final AppSettingService settingService;
|
||||
|
||||
private final PersonInformation personInformation;
|
||||
|
||||
@ -45,6 +47,7 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
|
||||
PersonService personService,
|
||||
@Qualifier("mergeRequestFilterService") FilterService<MergeRequest, PullRequestFilter> filterService,
|
||||
ProjectService projectService,
|
||||
AppSettingService settingService,
|
||||
PersonInformation personInformation
|
||||
) {
|
||||
super(mergeRequestRepository);
|
||||
@ -53,6 +56,7 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
|
||||
this.personService = personService;
|
||||
this.filterService = filterService;
|
||||
this.projectService = projectService;
|
||||
this.settingService = settingService;
|
||||
this.personInformation = personInformation;
|
||||
}
|
||||
|
||||
@ -63,6 +67,14 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
|
||||
|
||||
final MergeRequest newMergeRequest = mergeRequestRepository.save(mergeRequest);
|
||||
|
||||
if (!settingService.isFirstStart()) {
|
||||
notifyNewPr(newMergeRequest);
|
||||
}
|
||||
|
||||
return newMergeRequest;
|
||||
}
|
||||
|
||||
private void notifyNewPr(MergeRequest newMergeRequest) {
|
||||
if (!personInformation.getId().equals(newMergeRequest.getAuthor().getId())) {
|
||||
final String projectName = projectService.getById(newMergeRequest.getProjectId())
|
||||
.orElseThrow(() -> new NotFoundException("Проект не найден"))
|
||||
@ -80,7 +92,6 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
|
||||
.build()
|
||||
);
|
||||
}
|
||||
return newMergeRequest;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
2
pom.xml
2
pom.xml
@ -91,7 +91,7 @@
|
||||
<haiti.context.version>0.0.2-SNAPSHOT</haiti.context.version>
|
||||
<haiti.database.version>0.0.3-SNAPSHOT</haiti.database.version>
|
||||
<haiti.filter.criteria.version>0.0.2-RELEASE</haiti.filter.criteria.version>
|
||||
<sadtech.bot.telegram.core.version>0.0.1-RELEASE</sadtech.bot.telegram.core.version>
|
||||
<sadtech.bot.telegram.core.version>0.0.2-SNAPSHOT</sadtech.bot.telegram.core.version>
|
||||
<sadtech.bot.vsc.context.version>0.0.1-RELEASE</sadtech.bot.vsc.context.version>
|
||||
|
||||
<javax.persistance.version>2.2</javax.persistance.version>
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -23,7 +23,7 @@ public class PullRequestUnitConfig {
|
||||
AnswerProcessing<Message> needWorkPullRequest
|
||||
) {
|
||||
return AnswerText.builder()
|
||||
.boxAnswer(
|
||||
.boxAnswer(message ->
|
||||
BoxAnswer.builder()
|
||||
.message("Эта вкладка для работы с Pull Request")
|
||||
.keyBoard(
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user