Рабочая версия со сменой языка

This commit is contained in:
uPagge 2021-01-16 17:57:16 +03:00
parent 24008c7989
commit 44949a650f
No known key found for this signature in database
GPG Key ID: 964B40928E4C9088
10 changed files with 102 additions and 16 deletions

View File

@ -3,3 +3,5 @@ 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

View File

@ -3,3 +3,5 @@ main.no=Нет
ui.lang_changed=Язык успешно изменен
ui.monitor_private_projects=Начать отслеживать приватные проекты?
ui.monitor_project_private_success=Проекты успешно добавлены в отслеживание
ui.monitor_owner_projects=Начать отслеживать публичные проекты, владельцем которых вы являетесь?
ui.setup_finished=Настройка успешно завершена

View File

@ -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)
final Locale value = appSettingRepository.findById(KEY)
.orElseThrow(() -> EXCEPTION)
.getAppLocale().getValue()
.getAppLocale().getValue();
final String message = messageSource.getMessage(
label, null, value
);
return message;
}
@Override

View File

@ -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

View File

@ -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>

View File

@ -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;

View File

@ -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;
/**

View File

@ -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;
/**

View File

@ -23,7 +23,7 @@ public class PullRequestUnitConfig {
AnswerProcessing<Message> needWorkPullRequest
) {
return AnswerText.builder()
.boxAnswer(
.boxAnswer(message ->
BoxAnswer.builder()
.message("Эта вкладка для работы с Pull Request")
.keyBoard(

View File

@ -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();
}