Большой рефакторинг

This commit is contained in:
Struchkov Mark 2022-12-03 12:39:19 +03:00
parent c818b774f4
commit 1c5a083e5f
89 changed files with 1306 additions and 1040 deletions

View File

@ -6,13 +6,22 @@
<parent>
<groupId>dev.struchkov.bot.gitlab</groupId>
<artifactId>gitlab-bot</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
</parent>
<artifactId>bot-context</artifactId>
<version>${gitlab.context.version}</version>
<dependencies>
<dependency>
<groupId>dev.struchkov.haiti.utils</groupId>
<artifactId>haiti-utils-field-constants</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
@ -20,7 +29,7 @@
<dependency>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-context</artifactId>
<artifactId>haiti-utils</artifactId>
</dependency>
<dependency>
@ -32,11 +41,6 @@
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
</dependency>
</dependencies>
</project>

View File

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

View File

@ -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<Entity, Key> {
protected final Collection<Entity> container;
protected final boolean allFound;
protected final Collection<Key> idNoFound;
protected ExistsContainer(Collection<Entity> container, boolean allFound, Collection<Key> idNoFound) {
this.container = container;
this.allFound = allFound;
this.idNoFound = idNoFound;
}
public static <T, K> ExistsContainer<T, K> allFind(@NonNull Collection<T> container) {
return new ExistsContainer<>(container, true, Collections.emptyList());
}
public static <T, K> ExistsContainer<T, K> notAllFind(@NonNull Collection<T> container, @NonNull Collection<K> idNoFound) {
return new ExistsContainer<>(container, false, idNoFound);
}
public Collection<Entity> getContainer() {
return container;
}
public boolean isAllFound() {
return allFound;
}
public Collection<Key> getIdNoFound() {
return idNoFound;
}
}

View File

@ -13,6 +13,6 @@ public class PersonInformation {
private String username;
private String name;
private Long id;
private Long telegramId;
private String telegramId;
}

View File

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

View File

@ -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<String> {
public class Discussion {
@Id
@Column(name = "id")

View File

@ -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<Long> {
public class MergeRequest {
@Id
@Column(name = "id")

View File

@ -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<Long> {
public class Note {
@Id
@Column

View File

@ -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<Long> {
public class Person {
@Id
@Column(name = "id")

View File

@ -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<Long> {
public class Pipeline {
@Id
@Column(name = "id")

View File

@ -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<Long> {
public class Project {
@Id
@Column(name = "id")

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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(),

View File

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

View File

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

View File

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

View File

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

View File

@ -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<AppSetting, Long> {
public interface AppSettingRepository {
AppSetting save(AppSetting appSetting);
Optional<AppSetting> findById(Long key);
}

View File

@ -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<Discussion, String> {
public interface DiscussionRepository {
/**
* Вернуть все дискусии для MR
*/
List<Discussion> findAllByMergeRequestId(@NonNull Long mergeRequestId);
List<Discussion> findAllByMergeRequestId(Long mergeRequestId);
Discussion save(Discussion discussion);
Optional<Discussion> findById(String discussionId);
void deleteById(String discussionId);
Page<Discussion> findAll(Pageable pagination);
List<Discussion> findAllById(Set<String> discussionIds);
}

View File

@ -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<MergeRequest, Long>, FilterOperation<MergeRequest> {
public interface MergeRequestRepository {
Set<IdAndStatusPr> findAllIdByStateIn(@NonNull Set<MergeRequestState> states);
//TODO [28.01.2022]: Решить, нужно ли оставить
List<MergeRequest> findAllByAssignee(@NonNull Long userId);
MergeRequest save(MergeRequest mergeRequest);
Optional<MergeRequest> findById(Long mergeRequestId);
Page<MergeRequest> findAll(Pageable pagination);
List<MergeRequest> findAllById(Set<Long> mergeRequestIds);
void deleteByIds(Set<Long> mergeRequestIds);
Page<MergeRequest> filter(Filter filter, Pageable pageable);
}

View File

@ -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<Note, Long> {
public interface NoteRepository {
List<Note> findAllByResponsibleIdAndResolved(@NonNull Long userId, boolean resolved);
List<Note> findAllByResponsibleIdAndResolved(Long userId, boolean resolved);
Sheet<Note> findAllByResolved(boolean resolved, @NonNull Pagination pagination);
Page<Note> findAllByResolved(boolean resolved, Pageable pagination);
Optional<Note> findById(Long noteId);
}

View File

@ -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<Person, Long> {
public interface PersonRepository {
Person save(Person person);
Optional<Person> findById(Long personId);
List<Person> findAllById(Set<Long> personIds);
}

View File

@ -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<Pipeline, Long>, FilterOperation<Pipeline> {
public interface PipelineRepository {
Sheet<Pipeline> findAllByStatuses(@NonNull Set<PipelineStatus> statuses, @NonNull Pagination pagination);
Pipeline save(Pipeline pipeline);
Optional<Pipeline> findById(Long pipelineId);
Page<Pipeline> findAllByStatuses(Set<PipelineStatus> statuses, Pageable pagination);
List<Pipeline> findAllById(Set<Long> pipelineIds);
void deleteAllByIds(Set<Long> pipelineIds);
Page<Pipeline> filter(Filter filter, Pageable pagination);
}

View File

@ -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<Project, Long> {
public interface ProjectRepository {
Project save(Project project);
Optional<Project> findById(Long projectId);
List<Project> findAllById(Set<Long> projectIds);
boolean existById(Long projectId);
Page<Project> findAllById(Pageable pagination);
}

View File

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

View File

@ -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<Discussion, String> {
public interface DiscussionService {
Discussion create(@NonNull Discussion discussion);
Discussion update(@NonNull Discussion discussion);
/**
* Метод отправляющий коментарий в дискуссию.
@ -24,4 +31,12 @@ public interface DiscussionService extends SimpleManagerService<Discussion, Stri
*/
List<Discussion> getAllByMergeRequestId(@NonNull Long mergeRequestId);
ExistsContainer<Discussion, String> existsById(@NonNull Set<String> discussionIds);
List<Discussion> createAll(@NonNull List<Discussion> newDiscussions);
Page<Discussion> getAll(@NonNull Pageable pagination);
void deleteById(String discussionId);
}

View File

@ -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<MergeRequest, Long>, FilterService<MergeRequest, MergeRequestFilter> {
public interface MergeRequestsService {
MergeRequest create(@NonNull MergeRequest mergeRequest);
MergeRequest update(@NonNull MergeRequest mergeRequest);
/**
* Получить все идентификаторы вместе со статусами.
@ -19,4 +26,14 @@ public interface MergeRequestsService extends SimpleManagerService<MergeRequest,
*/
Set<IdAndStatusPr> getAllId(Set<MergeRequestState> statuses);
Page<MergeRequest> getAll(Pageable pagination);
Page<MergeRequest> getAll(@NonNull MergeRequestFilter filter, Pageable pagination);
ExistsContainer<MergeRequest, Long> existsById(@NonNull Set<Long> mergeRequestIds);
List<MergeRequest> createAll(List<MergeRequest> newMergeRequests);
void deleteAllById(@NonNull Set<Long> mergeRequestIds);
}

View File

@ -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<Note, Long> {
public interface NoteService {
List<Note> getAllPersonTask(@NonNull Long userId, boolean resolved);
//TODO [28.01.2022]: Решить нужно ли оставлять
Sheet<Note> getAllByResolved(boolean resolved, @NonNull Pagination pagination);
Page<Note> getAllByResolved(boolean resolved, @NonNull Pageable pagination);
Note getByIdOrThrow(@NonNull Long noteId);
}

View File

@ -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<Person, Long> {
public interface PersonService {
Person create(@NonNull Person person);
Person update(@NonNull Person person);
Person getByIdOrThrown(@NonNull Long personId);
ExistsContainer<Person, Long> existsById(Set<Long> personIds);
List<Person> createAll(List<Person> newPersons);
}

View File

@ -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<Pipeline, Long>, FilterService<Pipeline, PipelineFilter> {
public interface PipelineService {
Sheet<Pipeline> getAllByStatuses(@NonNull Set<PipelineStatus> statuses, @NonNull Pagination pagination);
Pipeline create(@NonNull Pipeline pipeline);
Pipeline update(@NonNull Pipeline pipeline);
Page<Pipeline> getAllByStatuses(@NonNull Set<PipelineStatus> statuses, @NonNull Pageable pagination);
Page<Pipeline> getAll(@NonNull PipelineFilter filter, @NonNull Pageable pagination);
ExistsContainer<Pipeline, Long> existsById(@NonNull Set<Long> pipelineIds);
void deleteAllById(Set<Long> pipelineIds);
}

View File

@ -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<Project, Long> {
public interface ProjectService {
Project create(@NonNull Project project);
Project update(@NonNull Project project);
Project getByIdOrThrow(@NonNull Long projectId);
Page<Project> getAll(@NonNull Pageable pagination);
List<Project> createAll(List<Project> newProjects);
boolean existsById(Long projectId);
ExistsContainer<Project, Long> existsById(Set<Long> projectIds);
}

View File

@ -6,11 +6,10 @@
<parent>
<groupId>dev.struchkov.bot.gitlab</groupId>
<artifactId>gitlab-bot</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
</parent>
<artifactId>bot-core</artifactId>
<version>${gitlab.core.version}</version>
<dependencies>
<dependency>
@ -23,16 +22,6 @@
<artifactId>bot-context</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.haiti.data</groupId>
<artifactId>haiti-database</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>

View File

@ -16,6 +16,6 @@ import org.springframework.context.annotation.Configuration;
public class PersonProperty {
private String token;
private Long telegramId;
private String telegramId;
}

View File

@ -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<MergeRequestJson, Me
mergeRequest.setState(convertState(source.getState()));
mergeRequest.setProjectId(source.getProjectId());
mergeRequest.setWebUrl(source.getWebUrl());
mergeRequest.setLabels(source.getLabels());
mergeRequest.setLabels(convertLabels(source.getLabels()));
if (source.getAssignee() != null) {
mergeRequest.setAssignee(convertPerson.convert(source.getAssignee()));
}
@ -41,13 +45,21 @@ public class MergeRequestJsonConverter implements Converter<MergeRequestJson, Me
return mergeRequest;
}
private static Set<String> convertLabels(Set<String> 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("Статус ПР не найден");
};
}

View File

@ -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<NotFoundException> NOT_FOUND_SETTINGS = NotFoundException.supplier("Ошибка, невозможно найти настройки приложения, проверьте базу данных.");
public static final Supplier<NotFoundException> 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);

View File

@ -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<MergeRequest> mergeRequestSheet = mergeRequestsService.getAll(MR_CLEAN_FILTER, PaginationImpl.of(page, COUNT));
Page<MergeRequest> mergeRequestSheet = mergeRequestsService.getAll(MR_CLEAN_FILTER, PageRequest.of(page, COUNT));
while (mergeRequestSheet.hasContent()) {
final Set<Long> 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<Pipeline> sheet = pipelineService.getAll(filter, PaginationImpl.of(page, COUNT));
Page<Pipeline> sheet = pipelineService.getAll(filter, PageRequest.of(page, COUNT));
while (sheet.hasContent()) {
final Set<Long> 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));
}
}

View File

@ -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<Discussion, String> 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<Discussi
private final PersonProperty personProperty;
private final NotifyService notifyService;
public DiscussionServiceImpl(PersonService personService, DiscussionRepository discussionRepository, PersonInformation personInformation, GitlabProperty gitlabProperty, PersonProperty personProperty, NotifyService notifyService) {
super(discussionRepository);
this.personService = personService;
this.discussionRepository = discussionRepository;
this.personInformation = personInformation;
this.gitlabProperty = gitlabProperty;
this.personProperty = personProperty;
this.notifyService = notifyService;
}
@Override
public Discussion create(@NonNull Discussion discussion) {
discussion.getNotes().forEach(note -> personService.create(note.getAuthor()));
@ -76,7 +70,7 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService<Discussi
final boolean resolved = discussion.getNotes().stream()
.allMatch(note -> note.isResolvable() && note.getResolved());
discussion.setResolved(resolved);
return discussionRepository.save(discussion);
return repository.save(discussion);
}
/**
@ -104,8 +98,8 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService<Discussi
@Override
public Discussion update(@NonNull Discussion discussion) {
final Discussion oldDiscussion = discussionRepository.findById(discussion.getId())
.orElseThrow(NotFoundException.supplier("Дискуссия не найдена"));
final Discussion oldDiscussion = repository.findById(discussion.getId())
.orElseThrow(notFoundException("Дискуссия не найдена"));
final Map<Long, Note> idAndNoteMap = oldDiscussion
.getNotes().stream()
.collect(Collectors.toMap(Note::getId, note -> note));
@ -122,7 +116,7 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService<Discussi
.allMatch(note -> note.isResolvable() && note.getResolved());
discussion.setResolved(resolved);
return discussionRepository.save(discussion);
return repository.save(discussion);
}
private void updateNote(Note note, Map<Long, Note> noteMap, boolean inDiscussion) {
@ -189,8 +183,8 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService<Discussi
@Override
public void answer(@NonNull String discussionId, @NonNull String text) {
final Discussion discussion = discussionRepository.findById(discussionId)
.orElseThrow(NotFoundException.supplier("Дисскусия {0} не найдена", discussionId));
final Discussion discussion = repository.findById(discussionId)
.orElseThrow(notFoundException("Дисскусия {0} не найдена", discussionId));
final MergeRequest mergeRequest = discussion.getMergeRequest();
final Long projectId = mergeRequest.getProjectId();
@ -214,7 +208,38 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService<Discussi
@Override
public List<Discussion> getAllByMergeRequestId(@NonNull Long mergeRequestId) {
return discussionRepository.findAllByMergeRequestId(mergeRequestId);
return repository.findAllByMergeRequestId(mergeRequestId);
}
@Override
public ExistsContainer<Discussion, String> existsById(@NonNull Set<String> discussionIds) {
final List<Discussion> existsEntity = repository.findAllById(discussionIds);
final Set<String> 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<String> noExistsId = discussionIds.stream()
.filter(id -> !existsIds.contains(id))
.collect(Collectors.toSet());
return ExistsContainer.notAllFind(existsEntity, noExistsId);
}
}
@Override
public List<Discussion> createAll(@NonNull List<Discussion> newDiscussions) {
return newDiscussions.stream()
.map(this::create)
.toList();
}
@Override
public Page<Discussion> getAll(@NonNull Pageable pagination) {
return repository.findAll(pagination);
}
@Override
public void deleteById(String discussionId) {
repository.deleteById(discussionId);
}
/**

View File

@ -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<MergeRequest, Long> 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<MergeRequest, MergeRequestFilter> 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<MergeRequest, MergeRequestFilter> 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<Merge
mergeRequest.setNotification(true);
final MergeRequest newMergeRequest = mergeRequestRepository.save(mergeRequest);
final MergeRequest newMergeRequest = repository.save(mergeRequest);
notifyNewPr(newMergeRequest);
@ -80,9 +65,7 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
private void notifyNewPr(MergeRequest newMergeRequest) {
if (!personInformation.getId().equals(newMergeRequest.getAuthor().getId())) {
final String projectName = projectService.getById(newMergeRequest.getProjectId())
.orElseThrow(NotFoundException.supplier("Проект не найден"))
.getName();
final String projectName = projectService.getByIdOrThrow(newMergeRequest.getProjectId()).getName();
if (!newMergeRequest.isConflict()) {
notifyService.send(
NewPrNotify.builder()
@ -108,24 +91,23 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
}
personService.create(mergeRequest.getAuthor());
final MergeRequest oldMergeRequest = mergeRequestRepository.findById(mergeRequest.getId())
.orElseThrow(NotFoundException.supplier("МержРеквест не найден"));
final MergeRequest oldMergeRequest = repository.findById(mergeRequest.getId())
.orElseThrow(notFoundException("МержРеквест не найден"));
if (mergeRequest.getNotification() == null) {
mergeRequest.setNotification(oldMergeRequest.getNotification());
}
if (!oldMergeRequest.getUpdatedDate().equals(mergeRequest.getUpdatedDate()) || oldMergeRequest.isConflict() != mergeRequest.isConflict()) {
final Project project = projectService.getById(mergeRequest.getProjectId())
.orElseThrow(NotFoundException.supplier("Проект не найден"));
final Project project = projectService.getByIdOrThrow(mergeRequest.getProjectId());
if (Boolean.TRUE.equals(oldMergeRequest.getNotification())) {
if (TRUE.equals(oldMergeRequest.getNotification())) {
notifyStatus(oldMergeRequest, mergeRequest, project);
notifyConflict(oldMergeRequest, mergeRequest, project);
notifyUpdate(oldMergeRequest, mergeRequest, project);
}
return mergeRequestRepository.save(mergeRequest);
return repository.save(mergeRequest);
}
return oldMergeRequest;
}
@ -204,27 +186,43 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
@Override
public Set<IdAndStatusPr> getAllId(Set<MergeRequestState> statuses) {
return mergeRequestRepository.findAllIdByStateIn(statuses);
return repository.findAllIdByStateIn(statuses);
}
@Override
public Sheet<MergeRequest> getAll(@NonNull MergeRequestFilter filter, Pagination pagination) {
public Page<MergeRequest> getAll(Pageable pagination) {
return repository.findAll(pagination);
}
@Override
public Page<MergeRequest> getAll(@NonNull MergeRequestFilter filter, Pageable pagination) {
return filterService.getAll(filter, pagination);
}
@Override
public Optional<MergeRequest> getFirst(@NonNull MergeRequestFilter mergeRequestFilter) {
return filterService.getFirst(mergeRequestFilter);
public ExistsContainer<MergeRequest, Long> existsById(@NonNull Set<Long> mergeRequestIds) {
final List<MergeRequest> existsEntity = repository.findAllById(mergeRequestIds);
final Set<Long> existsIds = existsEntity.stream().map(MergeRequest::getId).collect(Collectors.toSet());
if (existsIds.containsAll(mergeRequestIds)) {
return ExistsContainer.allFind(existsEntity);
} else {
final Set<Long> 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<MergeRequest> createAll(List<MergeRequest> newMergeRequests) {
return newMergeRequests.stream()
.map(this::create)
.toList();
}
@Override
public long count(@NonNull MergeRequestFilter mergeRequestFilter) {
return filterService.count(mergeRequestFilter);
public void deleteAllById(@NonNull Set<Long> mergeRequestIds) {
repository.deleteByIds(mergeRequestIds);
}
}

View File

@ -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<Person, Long> 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<Person, Long> existsById(Set<Long> personIds) {
final List<Person> existsEntity = repository.findAllById(personIds);
final Set<Long> existsIds = existsEntity.stream().map(Person::getId).collect(Collectors.toSet());
if (existsIds.containsAll(personIds)) {
return ExistsContainer.allFind(existsEntity);
} else {
final Set<Long> noExistsId = personIds.stream()
.filter(id -> !existsIds.contains(id))
.collect(Collectors.toSet());
return ExistsContainer.notAllFind(existsEntity, noExistsId);
}
}
@Override
public List<Person> createAll(List<Person> newPersons) {
return newPersons.stream()
.map(this::create)
.toList();
}
}

View File

@ -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<Pipeline, Long> implements PipelineService {
@RequiredArgsConstructor
public class PipelineServiceImpl implements PipelineService {
// Статусы пайплайнов, о которых нужно уведомить
private static final Set<PipelineStatus> 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<Pipeline,
@Override
public Pipeline update(@NonNull Pipeline pipeline) {
final Pipeline oldPipeline = pipelineRepository.findById(pipeline.getId())
.orElseThrow(NotFoundException.supplier("Pipeline не найден"));
final Pipeline oldPipeline = repository.findById(pipeline.getId())
.orElseThrow(notFoundException("Pipeline не найден"));
if (!oldPipeline.getUpdated().equals(pipeline.getUpdated())) {
pipeline.setProject(oldPipeline.getProject());
notifyNewPipeline(pipeline, oldPipeline.getStatus().name());
return pipelineRepository.save(pipeline);
return repository.save(pipeline);
}
return oldPipeline;
@ -104,28 +92,32 @@ public class PipelineServiceImpl extends AbstractSimpleManagerService<Pipeline,
}
@Override
public Sheet<Pipeline> getAllByStatuses(@NonNull Set<PipelineStatus> statuses, @NonNull Pagination pagination) {
return pipelineRepository.findAllByStatuses(statuses, pagination);
public Page<Pipeline> getAllByStatuses(@NonNull Set<PipelineStatus> statuses, @NonNull Pageable pagination) {
return repository.findAllByStatuses(statuses, pagination);
}
@Override
public Sheet<Pipeline> getAll(@NonNull PipelineFilter filter, @NonNull Pagination pagination) {
public Page<Pipeline> getAll(@NonNull PipelineFilter filter, @NonNull Pageable pagination) {
return pipelineFilterService.getAll(filter, pagination);
}
@Override
public Optional<Pipeline> getFirst(@NonNull PipelineFilter filter) {
return pipelineFilterService.getFirst(filter);
public ExistsContainer<Pipeline, Long> existsById(@NonNull Set<Long> pipelineIds) {
final List<Pipeline> existsEntity = repository.findAllById(pipelineIds);
final Set<Long> existsIds = existsEntity.stream().map(Pipeline::getId).collect(Collectors.toSet());
if (existsIds.containsAll(pipelineIds)) {
return ExistsContainer.allFind(existsEntity);
} else {
final Set<Long> 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<Long> pipelineIds) {
repository.deleteAllByIds(pipelineIds);
}
}

View File

@ -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<Project, Long> 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<Project, Long> 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<Project> getAll(@NonNull Pageable pagination) {
return repository.findAllById(pagination);
}
@Override
public List<Project> createAll(List<Project> newProjects) {
return newProjects.stream()
.map(this::create)
.toList();
}
@Override
public boolean existsById(Long projectId) {
return repository.existById(projectId);
}
@Override
public ExistsContainer<Project, Long> existsById(Set<Long> projectIds) {
final List<Project> existsEntity = repository.findAllById(projectIds);
final Set<Long> existsIds = existsEntity.stream().map(Project::getId).collect(Collectors.toSet());
if (existsIds.containsAll(projectIds)) {
return ExistsContainer.allFind(existsEntity);
} else {
final Set<Long> 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<Project, Lo
);
}
@Override
public Project update(@NonNull Project project) {
return projectRepository.save(project);
}
}

View File

@ -1,26 +1,30 @@
package dev.struchkov.bot.gitlab.core.service.impl.filter;
import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest;
import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest_;
import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequestFields;
import dev.struchkov.bot.gitlab.context.domain.filter.MergeRequestFilter;
import dev.struchkov.bot.gitlab.context.repository.MergeRequestRepository;
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;
@Service
public class MergeRequestFilterService extends AbstractFilterService<MergeRequest, MergeRequestFilter> {
@RequiredArgsConstructor
public class MergeRequestFilterService {
public MergeRequestFilterService(MergeRequestRepository filterOperation) {
super(filterOperation);
private final MergeRequestRepository repository;
public Page<MergeRequest> 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.<MergeRequest>create()
.and(convertFilter(filter))
.or(convertFilterOr(filter));
@ -28,12 +32,12 @@ public class MergeRequestFilterService extends AbstractFilterService<MergeReques
private FilterQuery convertFilterOr(MergeRequestFilter filter) {
return CriteriaQuery.<MergeRequest>create()
.matchPhrase(MergeRequest_.STATE, filter.getStates());
.matchPhrase(MergeRequestFields.state, filter.getStates());
}
private FilterQuery convertFilter(@NonNull MergeRequestFilter filter) {
return CriteriaQuery.<MergeRequest>create()
.matchPhrase(MergeRequest_.ASSIGNEE, filter.getAssignee());
.matchPhrase(MergeRequestFields.assignee, filter.getAssignee());
}
}

View File

@ -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<Pipeline, PipelineFilter> {
@RequiredArgsConstructor
public class PipelineFilterService {
public PipelineFilterService(PipelineRepository pipelineRepository) {
super(pipelineRepository);
private final PipelineRepository pipelineRepository;
public Page<Pipeline> 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.<Pipeline>create()
.and(convertAnd(pipelineFilter));
}
private FilterQuery convertAnd(PipelineFilter pipelineFilter) {
return CriteriaQuery.<Pipeline>create()
.lessThan(Pipeline_.CREATED, pipelineFilter.getLessThanCreatedDate());
.lessThan(PipelineFields.created, pipelineFilter.getLessThanCreatedDate());
}
}

View File

@ -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<Note, Long> 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<Note> getAllByResolved(boolean resolved, @NonNull Pagination pagination) {
public Page<Note> 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<Note> getAllPersonTask(@NonNull Long userId, boolean resolved) {
return noteRepository.findAllByResponsibleIdAndResolved(userId, resolved);

View File

@ -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<MergeRequest> mergeRequestSheet = mergeRequestsService.getAll(PaginationImpl.of(page, COUNT));
Page<MergeRequest> 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<Discussion> discussionSheet = discussionService.getAll(PaginationImpl.of(page, COUNT));
Page<Discussion> discussionSheet = discussionService.getAll(PageRequest.of(page, COUNT));
while (discussionSheet.hasContent()) {
final List<Discussion> discussions = discussionSheet.getContent();
@ -119,7 +119,7 @@ public class DiscussionParser {
}
}
discussionSheet = discussionService.getAll(PaginationImpl.of(++page, COUNT));
discussionSheet = discussionService.getAll(PageRequest.of(++page, COUNT));
}
}

View File

@ -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<Project> projectSheet = projectService.getAll(PaginationImpl.of(page, COUNT));
Page<Project> projectSheet = projectService.getAll(PageRequest.of(page, COUNT));
while (projectSheet.hasContent()) {
final List<Project> 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));
}
}

View File

@ -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<Project> projectSheet = projectService.getAll(PaginationImpl.of(page, COUNT));
Page<Project> projectSheet = projectService.getAll(PageRequest.of(page, COUNT));
while (projectSheet.hasContent()) {
final List<Project> 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<Pipeline> pipelineSheet = pipelineService.getAllByStatuses(oldStatus, PaginationImpl.of(page, COUNT));
Page<Pipeline> pipelineSheet = pipelineService.getAllByStatuses(oldStatus, PageRequest.of(page, COUNT));
while (pipelineSheet.hasContent()) {
final List<Pipeline> 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));
}
}

View File

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

View File

@ -6,21 +6,16 @@
<parent>
<groupId>dev.struchkov.bot.gitlab</groupId>
<artifactId>gitlab-bot</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
</parent>
<artifactId>bot-data</artifactId>
<version>${gitlab.data.version}</version>
<name>GitLab Server Data</name>
<description>Implementation of the Bitbucket server version repository layer</description>
<url>https://github.com/uPagge/bitbucketbot</url>
<dependencies>
<dependency>
<groupId>dev.struchkov.haiti.data</groupId>
<artifactId>haiti-database</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.bot.gitlab</groupId>
<artifactId>bot-context</artifactId>

View File

@ -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<AppSetting, Long> implements AppSettingRepository {
@RequiredArgsConstructor
public class AppSettingRepositoryImpl implements AppSettingRepository {
public AppSettingRepositoryImpl(JpaRepository<AppSetting, Long> jpaRepository) {
super(jpaRepository);
private final AppSettingJpaRepository jpaRepository;
@Override
public AppSetting save(AppSetting appSetting) {
return jpaRepository.save(appSetting);
}
@Override
public Optional<AppSetting> findById(Long key) {
return jpaRepository.findById(key);
}
}

View File

@ -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<Discussion, String> implements DiscussionRepository {
@RequiredArgsConstructor
public class DiscussionRepositoryImpl implements DiscussionRepository {
private final DiscussionJpaRepository jpaRepository;
public DiscussionRepositoryImpl(DiscussionJpaRepository jpaRepository) {
super(jpaRepository);
this.jpaRepository = jpaRepository;
}
@Override
public List<Discussion> findAllByMergeRequestId(@NonNull Long mergeRequestId) {
return jpaRepository.findAllByMergeRequestId(mergeRequestId);
}
@Override
public Discussion save(Discussion discussion) {
return jpaRepository.save(discussion);
}
@Override
public Optional<Discussion> findById(String discussionId) {
return jpaRepository.findById(discussionId);
}
@Override
public void deleteById(String discussionId) {
jpaRepository.deleteById(discussionId);
}
@Override
public Page<Discussion> findAll(Pageable pagination) {
return jpaRepository.findAll(pagination);
}
@Override
public List<Discussion> findAllById(Set<String> discussionIds) {
return jpaRepository.findAllById(discussionIds);
}
}

View File

@ -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<MergeRequest, Long> 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<IdAndStatusPr> findAllIdByStateIn(@NonNull Set<MergeRequestState> statuses) {
return repositoryJpa.findAllIdByStateIn(statuses);
return jpaRepository.findAllIdByStateIn(statuses);
}
@Override
public List<MergeRequest> 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<MergeRequest> findById(Long mergeRequestId) {
return jpaRepository.findById(mergeRequestId);
}
@Override
public Page<MergeRequest> findAll(Pageable pagination) {
return jpaRepository.findAll(pagination);
}
@Override
public List<MergeRequest> findAllById(Set<Long> mergeRequestIds) {
return jpaRepository.findAllById(mergeRequestIds);
}
@Override
public void deleteByIds(Set<Long> mergeRequestIds) {
jpaRepository.deleteAllByIdIn(mergeRequestIds);
}
@Override
public Page<MergeRequest> filter(Filter filter, Pageable pageable) {
return jpaRepository.findAll(filter.<Specification<MergeRequest>>build(), pageable);
}
}

View File

@ -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<Note, Long> 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<Note> findAllByResolved(boolean resolved, @NonNull Pageable pagination) {
return jpaRepository.findAllByResolved(resolved, pagination);
}
@Override
public Sheet<Note> findAllByResolved(boolean resolved, @NonNull Pagination pagination) {
return Converter.page(
repositoryJpa.findAllByResolved(resolved, Converter.pagination(pagination))
);
public Optional<Note> findById(Long noteId) {
return jpaRepository.findById(noteId);
}
@Override
public List<Note> findAllByResponsibleIdAndResolved(@NonNull Long userId, boolean resolved) {
return repositoryJpa.findAllByDiscussionResponsibleIdAndResolved(userId, resolved);
return jpaRepository.findAllByDiscussionResponsibleIdAndResolved(userId, resolved);
}

View File

@ -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<Person, Long> implements PersonRepository {
@RequiredArgsConstructor
public class PersonRepositoryImpl implements PersonRepository {
public PersonRepositoryImpl(JpaRepository<Person, Long> jpaRepository) {
super(jpaRepository);
private final PersonJpaRepository jpaRepository;
@Override
public Person save(Person person) {
return jpaRepository.save(person);
}
@Override
public Optional<Person> findById(Long personId) {
return jpaRepository.findById(personId);
}
@Override
public List<Person> findAllById(Set<Long> personIds) {
return jpaRepository.findAllById(personIds);
}
}

View File

@ -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<Pipeline, Long> 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<Pipeline> findAllByStatuses(@NonNull Set<PipelineStatus> statuses, @NonNull Pagination pagination) {
return Converter.page(
jpaRepository.findAllByStatusIn(statuses, Converter.pagination(pagination))
);
public Optional<Pipeline> findById(Long pipelineId) {
return jpaRepository.findById(pipelineId);
}
@Override
public Page<Pipeline> findAllByStatuses(Set<PipelineStatus> statuses, Pageable pagination) {
return jpaRepository.findAllByStatusIn(statuses, pagination);
}
@Override
public List<Pipeline> findAllById(Set<Long> pipelineIds) {
return jpaRepository.findAllById(pipelineIds);
}
@Override
public void deleteAllByIds(Set<Long> pipelineIds) {
jpaRepository.deleteAllById(pipelineIds);
}
@Override
public Page<Pipeline> filter(Filter filter, Pageable pagination) {
return jpaRepository.findAll(filter.<Specification<Pipeline>>build(), pagination);
}
}

View File

@ -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<Project, Long> implements ProjectRepository {
@RequiredArgsConstructor
public class ProjectRepositoryImpl implements ProjectRepository {
public ProjectRepositoryImpl(JpaRepository<Project, Long> jpaRepository) {
super(jpaRepository);
private final ProjectJpaRepository jpaRepository;
@Override
public Project save(Project project) {
return jpaRepository.save(project);
}
@Override
public Optional<Project> findById(Long projectId) {
return jpaRepository.findById(projectId);
}
@Override
public List<Project> findAllById(Set<Long> projectIds) {
return jpaRepository.findAllById(projectIds);
}
@Override
public boolean existById(Long projectId) {
return jpaRepository.existsById(projectId);
}
@Override
public Page<Project> findAllById(Pageable pagination) {
return jpaRepository.findAll(pagination);
}
}

View File

@ -7,7 +7,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface NoteRepositoryJpa extends JpaRepository<Note, Long> {
public interface NoteJpaRepository extends JpaRepository<Note, Long> {
Page<Note> findAllByResolved(boolean resolved, Pageable pageable);

View File

@ -0,0 +1,23 @@
FROM openjdk:17.0.2-jdk-slim-buster
MAINTAINER uPagge <me@upagge.ru>
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

View File

@ -6,11 +6,10 @@
<parent>
<groupId>dev.struchkov.bot.gitlab</groupId>
<artifactId>gitlab-bot</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
</parent>
<artifactId>gitlab-app</artifactId>
<version>${gitlab.app.version}</version>
<name>Gitlab Notification Bot</name>
<description>Notifications about Gitlab Server events in Telegram</description>

View File

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

View File

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

View File

@ -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">
<include file="liquibase/v.1.0.0/2021-01-14-create-tables.xml"/>
<include file="v.1.0.0/changelog.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@ -1,27 +1,18 @@
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
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">
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.17.xsd">
<changeSet id="2020-01-16-create-table-app-setting" author="uPagge">
<changeSet id="2022-12-03-create-table-app-setting" author="uPagge">
<createTable tableName="app_setting">
<column name="id" type="int">
<constraints primaryKey="true"/>
</column>
<column name="language" type="varchar(10)"/>
<column name="first_start" type="boolean"/>
</createTable>
</changeSet>
<changeSet id="2020-01-16" author="uPagge">
<insert tableName="app_setting">
<column name="id" value="1"/>
<column name="first_start" value="true"/>
<column name="language" value="EN"/>
</insert>
</changeSet>
<changeSet id="2020-01-14-create-table-project" author="uPagge">
<changeSet id="2022-12-03-create-table-project" author="uPagge">
<createTable tableName="project">
<column name="id" type="int">
<constraints nullable="false" primaryKey="true"/>
@ -42,7 +33,7 @@
</createTable>
</changeSet>
<changeSet id="2020-01-14-create-table-person" author="uPagge">
<changeSet id="2022-12-03-create-table-person" author="uPagge">
<createTable tableName="person">
<column name="id" type="int">
<constraints nullable="false" primaryKey="true"/>
@ -57,7 +48,7 @@
</createTable>
</changeSet>
<changeSet id="2020-01-14-create-merge-request" author="uPagge">
<changeSet id="2022-12-03-create-merge-request" author="uPagge">
<createTable tableName="merge_request">
<column name="id" type="int">
<constraints nullable="false" primaryKey="true"/>
@ -105,12 +96,26 @@
<column name="notification" type="boolean">
<constraints nullable="false"/>
</column>
<column name="date_last_commit" type="datetime"/>
</createTable>
<createIndex tableName="merge_request" indexName="i_merge_request_project_id">
<column name="project_id"/>
</createIndex>
<createIndex tableName="merge_request" indexName="i_merge_request_assignee_id">
<column name="assignee_id"/>
</createIndex>
<createIndex tableName="merge_request" indexName="i_merge_request_author_id">
<column name="author_id"/>
</createIndex>
</changeSet>
<changeSet id="2020-01-15-create-table-labels" author="uPagge">
<changeSet id="2022-12-03-create-table-labels" author="uPagge">
<createSequence sequenceName="seq_merge_request" startValue="1" incrementBy="1" cacheSize="20"/>
<createTable tableName="merge_request_label">
<column name="id" type="int" autoIncrement="true">
<column name="id" type="int" defaultValueSequenceNext="seq_merge_request">
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="merge_request_id" type="int">
@ -122,10 +127,13 @@
</column>
</createTable>
<createIndex tableName="merge_request_label" indexName="i_merge_request_label_merge_request_id">
<column name="merge_request_id"/>
</createIndex>
<addUniqueConstraint tableName="merge_request_label" columnNames="merge_request_id, label"/>
</changeSet>
<changeSet id="2021-02-11-create-discussion" author="uPagge">
<changeSet id="2022-12-03-create-discussion" author="uPagge">
<createTable tableName="discussion">
<column name="id" type="varchar(200)">
<constraints nullable="false" primaryKey="true"/>
@ -136,9 +144,13 @@
</column>
<column name="resolved" type="boolean"/>
</createTable>
<createIndex tableName="discussion" indexName="i_discussion_responsible_id">
<column name="responsible_id"/>
</createIndex>
</changeSet>
<changeSet id="2021-02-11-create-discussion-task" author="uPagge">
<changeSet id="2022-12-03-create-discussion-task" author="uPagge">
<createTable tableName="discussion_merge_request">
<column name="discussion_id" type="varchar(200)">
<constraints nullable="false" foreignKeyName="discussion_merge_request_discussion_id"
@ -153,7 +165,7 @@
<addPrimaryKey tableName="discussion_merge_request" columnNames="discussion_id, merge_request_id"/>
</changeSet>
<changeSet id="2020-01-16-create-table-note" author="uPagge">
<changeSet id="2022-12-03-create-table-note" author="uPagge">
<createTable tableName="note">
<column name="id" type="int">
<constraints nullable="false" primaryKey="true"/>
@ -183,9 +195,16 @@
<constraints foreignKeyName="note_discussion_id" references="discussion(id)" deleteCascade="true"/>
</column>
</createTable>
<createIndex tableName="note" indexName="i_note_author_id">
<column name="author_id"/>
</createIndex>
<createIndex tableName="note" indexName="i_note_discussion_id">
<column name="discussion_id"/>
</createIndex>
</changeSet>
<changeSet id="2020-01-17-create-table-pipelines" author="uPagge">
<changeSet id="2022-12-03-create-table-pipelines" author="uPagge">
<createTable tableName="pipeline">
<column name="id" type="int">
<constraints nullable="false" primaryKey="true"/>
@ -208,12 +227,13 @@
<constraints foreignKeyName="pipeline_person_id" references="person(id)"/>
</column>
</createTable>
</changeSet>
<changeSet id="2020-01-19-create-table-commit" author="uPagge">
<addColumn tableName="merge_request">
<column name="date_last_commit" type="datetime"/>
</addColumn>
<createIndex tableName="pipeline" indexName="i_pipeline_project_id">
<column name="project_id"/>
</createIndex>
<createIndex tableName="pipeline" indexName="i_pipeline_person_id">
<column name="person_id"/>
</createIndex>
</changeSet>
</databaseChangeLog>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
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-4.6.xsd">
<changeSet id="2022-12-03-create-table-app-setting" author="uPagge">
<insert tableName="app_setting">
<column name="id" value="1"/>
<column name="first_start" value="true"/>
</insert>
</changeSet>
</databaseChangeLog>

View File

@ -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">
<include file="liquibase/v.1.0.0/cumulative.xml"/>
<changeSet id="2022-12-03-add-tab-v-1-0-0" author="uPagge">
<tagDatabase tag="v.1.0.0"/>
</changeSet>
<include file="2022-12-03-create-tables.xml" relativeToChangelogFile="true"/>
<include file="2022-12-03-insert.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

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

View File

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

View File

@ -6,11 +6,10 @@
<parent>
<groupId>dev.struchkov.bot.gitlab</groupId>
<artifactId>gitlab-bot</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
</parent>
<artifactId>gitlab-sdk</artifactId>
<version>${gitlab.sdk.version}</version>
<dependencies>
<dependency>

86
pom.xml
View File

@ -11,7 +11,7 @@
<groupId>dev.struchkov.bot.gitlab</groupId>
<artifactId>gitlab-bot</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
<packaging>pom</packaging>
<modules>
@ -44,20 +44,10 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<gitlab.core.version>1.0.0</gitlab.core.version>
<gitlab.app.version>1.0.0</gitlab.app.version>
<gitlab.sdk.version>1.0.0</gitlab.sdk.version>
<gitlab.context.version>1.0.0</gitlab.context.version>
<gitlab.data.version>1.0.0</gitlab.data.version>
<gitlab.telegram.version>1.0.0</gitlab.telegram.version>
<gitlab.core.version>1.0.0</gitlab.core.version>
<haiti.ver>1.0.0</haiti.ver>
<godfather.telegram.core.version>0.0.2</godfather.telegram.core.version>
<godfather.telegram.core.version>0.0.37</godfather.telegram.core.version>
<javax.persistance.version>2.2</javax.persistance.version>
<hibernate.jpa-modelgen.version>6.0.0.Alpha5</hibernate.jpa-modelgen.version>
<google.guava.version>31.0.1-jre</google.guava.version>
<jackson.databind.version>2.13.1</jackson.databind.version>
<jackson.datatype.jsr310.version>2.13.1</jackson.datatype.jsr310.version>
@ -71,69 +61,97 @@
<dependencyManagement>
<dependencies>
<dependency>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-bom</artifactId>
<version>${haiti.ver}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- модули проекта -->
<dependency>
<groupId>dev.struchkov.bot.gitlab</groupId>
<artifactId>bot-core</artifactId>
<version>${gitlab.core.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.bot.gitlab</groupId>
<artifactId>gitlab-core</artifactId>
<version>${gitlab.core.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.bot.gitlab</groupId>
<artifactId>telegram-bot</artifactId>
<version>${gitlab.telegram.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.bot.gitlab</groupId>
<artifactId>bot-context</artifactId>
<version>${gitlab.context.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.bot.gitlab</groupId>
<artifactId>gitlab-sdk</artifactId>
<version>${gitlab.sdk.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.bot.gitlab</groupId>
<artifactId>bot-data</artifactId>
<version>${gitlab.data.version}</version>
<version>${project.version}</version>
</dependency>
<!-- /модули проекта -->
<!-- haiti -->
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>telegram-core</artifactId>
<groupId>dev.struchkov.haiti.utils</groupId>
<artifactId>haiti-utils-field-constants</artifactId>
<version>0.0.6</version>
</dependency>
<dependency>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-utils</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-exception</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>dev.struchkov.haiti.utils</groupId>
<artifactId>haiti-utils-network</artifactId>
<version>0.0.5</version>
</dependency>
<dependency>
<groupId>dev.struchkov.haiti.filter</groupId>
<artifactId>haiti-filter-criteria</artifactId>
<version>0.0.5</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-consumer-simple</artifactId>
<version>${godfather.telegram.core.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-core-simple</artifactId>
<version>${godfather.telegram.core.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-sender-simple</artifactId>
<version>${godfather.telegram.core.version}</version>
</dependency>
<!-- /SADTECH -->
<!-- БД -->
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${hibernate.jpa-modelgen.version}</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>

View File

@ -6,11 +6,10 @@
<parent>
<groupId>dev.struchkov.bot.gitlab</groupId>
<artifactId>gitlab-bot</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
</parent>
<artifactId>telegram-bot</artifactId>
<version>${gitlab.telegram.version}</version>
<dependencies>
<dependency>
@ -19,8 +18,18 @@
</dependency>
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>telegram-core</artifactId>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-consumer-simple</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-sender-simple</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-core-simple</artifactId>
</dependency>
</dependencies>

View File

@ -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<Mail> messageService,
UnitPointerRepository unitPointerRepository,
AnswerCheck checkFirstStart
public StorylineService<Mail> storylineService(
UnitPointerService unitPointerService,
MenuConfig menuConfig,
UnitConfig unitConfig
) {
return new MessageAutoresponderTelegram(
Collections.singleton(checkFirstStart),
sending,
messageService,
unitPointerRepository
final List<Object> config = List.of(menuConfig, unitConfig);
return new StorylineMailService(
unitPointerService,
new StorylineMapRepository(),
config
);
}
@Bean
public Sending sending(
public MailAutoresponderTelegram messageAutoresponderTelegram(
TelegramSending sending,
PersonSettingService personSettingService,
StorylineService<Mail> 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<EventHandler> eventProviders
) {
return new EventDistributorImpl(telegramConnect, mailService);
return new EventDistributorService(telegramConnect, eventProviders);
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -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<Message> {
private final MergeRequestsService mergeRequestsService;
@Override
public BoxAnswer processing(Message message) {
public Optional<BoxAnswer> processing(Message message) {
// final Person person = personService.getByTelegramId(message.getPersonId())
// .orElseThrow(() -> new NotFoundException("Пользователь не найден"));
// final List<PullRequest> pullRequests = pullRequestsService.getAllByAuthorAndReviewerStatus(person.getLogin(), ReviewerStatus.UNAPPROVED);
@ -24,7 +26,7 @@ public class PullRequestNeedWorkProcessing implements ProcessingData<Message> {
// MessageUtils.pullRequestForNeedWork(pullRequests)
// .orElse("Не найдено ПРов, которые нуждаются в доработке :)")
// );
return null;
return Optional.empty();
}
}

View File

@ -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<Message> {
private final MergeRequestsService mergeRequestsService;
@Override
public BoxAnswer processing(Message message) {
public Optional<BoxAnswer> processing(Message message) {
// final Person person = personService.getByTelegramId(message.getPersonId())
// .orElseThrow(() -> new NotFoundException("Пользователь не найден"));
// final List<PullRequest> pullRequests = pullRequestsService.getAllByReviewerAndStatuses(
@ -28,7 +30,7 @@ public class PullRequestReviewProcessing implements ProcessingData<Message> {
// MessageUtils.pullRequestForReview(pullRequests)
// .orElse("Все ПР проверены :)")
// );
return null;
return Optional.empty();
}
}

View File

@ -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<Message> menu(
AppSettingService settingService,
AnswerText<Message> settings,
AnswerText<Message> textAddNewProject,
AnswerText<Message> getTasks,
AnswerText<Message> 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<Mail> menu(
@Unit(SETTINGS) MainUnit<Mail> settings,
@Unit(TEXT_ADD_NEW_PROJECT) MainUnit<Mail> textAddNewProject,
@Unit(GET_TASKS) MainUnit<Mail> getTasks,
@Unit(GET_ASSIGNEE_MERGE_REQUEST) MainUnit<Mail> 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.<Mail>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<Message> textAddNewProject(
AppSettingService settingService,
AnswerText<Message> addNewProject
@Unit(TEXT_ADD_NEW_PROJECT)
public AnswerText<Mail> textAddNewProject(
@Unit(ADD_NEW_PROJECT) MainUnit<Mail> 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.<Mail>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<Message> addNewProject(
AppSettingService settingService,
ProjectParser projectParser,
GitlabProperty gitlabProperty
) {
return AnswerText.builder()
.boxAnswer(message -> {
final List<String> urlList = Arrays.stream(message.getText().split("/")).toList();
@Unit(ADD_NEW_PROJECT)
public AnswerText<Mail> addNewProject() {
return AnswerText.<Mail>builder()
.answer(mail -> {
final List<String> 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<Message> settings(
AppSettingService settingService,
AnswerText<Message> 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<Mail> settings() {
return AnswerText.<Mail>builder()
.triggerPhrase(SETTINGS)
.answer(
boxAnswer("This is the settings menu")
)
.build();
}
@Bean
public AnswerText<Message> 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<Mail> getTasks() {
return AnswerText.<Mail>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<Message> getAssigneeMergeRequest(
MergeRequestsService mergeRequestsService,
PersonInformation personInformation,
AppSettingService settingService
) {
return AnswerText.builder()
.boxAnswer(message -> {
@Unit(UnitName.GET_ASSIGNEE_MERGE_REQUEST)
public AnswerText<Mail> getAssigneeMergeRequest() {
return AnswerText.<Mail>builder()
.triggerPhrase(GET_ASSIGNEE_MERGE_REQUEST)
.answer(() -> {
final Long userId = personInformation.getId();
final Sheet<MergeRequest> sheet = mergeRequestsService.getAll(getAssigneeFilter(userId), PaginationImpl.of(0, 20));
final Page<MergeRequest> sheet = mergeRequestsService.getAll(getAssigneeFilter(userId), PageRequest.of(0, 20));
if (sheet.hasContent()) {
final List<MergeRequest> 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();
}

View File

@ -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<Message> 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<Mail> checkFirstStart(
@Unit(TEXT_PARSER_PRIVATE_PROJECT) MainUnit<Mail> textParserPrivateProject,
@Unit(CHECK_MENU_OR_ANSWER) MainUnit<Mail> checkMenuOrAnswer
) {
return AnswerCheck.builder()
.check(
message -> settingService.isFirstStart()
)
return AnswerCheck.<Mail>builder()
.check(message -> settingService.isFirstStart())
.unitFalse(checkMenuOrAnswer)
.unitTrue(textCheckLanguage)
.unitTrue(textParserPrivateProject)
.build();
}
@Bean
public AnswerCheck checkMenuOrAnswer(
AnswerText<Message> menu,
AnswerText<Message> answerNote
@Unit(value = CHECK_MENU_OR_ANSWER)
public AnswerCheck<Mail> checkMenuOrAnswer(
@Unit(GENERAL_MENU) MainUnit<Mail> menu,
@Unit(ANSWER_NOTE) MainUnit<Mail> answerNote
) {
return AnswerCheck.builder()
return AnswerCheck.<Mail>builder()
.check(
message -> {
Mail mail = (Mail) message;
mail -> {
final List<Mail> 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<Message> answerNote(
NoteService noteService,
DiscussionService discussionService
) {
return AnswerText.builder()
.boxAnswer(
message -> {
final List<Attachment> attachments = ((Mail) message).getForwardMail().get(0).getAttachments();
@Unit(ANSWER_NOTE)
public AnswerText<Mail> answerNote() {
return AnswerText.<Mail>builder()
.answer(
mail -> {
final List<Attachment> 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<Message> textCheckLanguage(
AnswerProcessing checkLanguage
@Unit(TEXT_PARSER_PRIVATE_PROJECT)
public AnswerText<Mail> textParserPrivateProject(
@Unit(CHECK_PARSER_PRIVATE_PROJECT) MainUnit<Mail> 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<Message> 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<Message> 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.<Mail>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<Message> textParseOwnerProject
@Unit(CHECK_PARSER_PRIVATE_PROJECT)
public AnswerCheck<Mail> checkParserPrivateProject(
@Unit(PARSER_PRIVATE_PROJECT) AnswerText<Mail> parserPrivateProject,
@Unit(TEXT_PARSE_OWNER_PROJECT) MainUnit<Mail> textParseOwnerProject
) {
return AnswerCheck.builder()
.check(
message -> appSettingService.getMessage("main.yes").equalsIgnoreCase(message.getText())
)
return AnswerCheck.<Mail>builder()
.check(mail -> "YES".equalsIgnoreCase(mail.getText()))
.unitTrue(parserPrivateProject)
.unitFalse(textParseOwnerProject)
.build();
}
@Bean
public AnswerProcessing parserPrivateProject(
ProjectParser projectParser,
AppSettingService settingService,
AnswerText<Message> textParseOwnerProject
@Unit(PARSER_PRIVATE_PROJECT)
public AnswerText<Mail> parserPrivateProject(
@Unit(TEXT_PARSE_OWNER_PROJECT) MainUnit<Mail> textParseOwnerProject
) {
return AnswerProcessing.builder()
.processingData(message -> {
return AnswerText.<Mail>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<Message> textParseOwnerProject(
AppSettingService settingService,
AnswerCheck checkParseOwnerProject
@Unit(TEXT_PARSE_OWNER_PROJECT)
public AnswerText<Mail> textParseOwnerProject(
@Unit(CHECK_PARSE_OWNER_PROJECT) MainUnit<Mail> 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.<Mail>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<Mail> checkParseOwnerProject(
@Unit(PARSE_OWNER_PROJECT) MainUnit<Mail> parseOwnerProject,
@Unit(END_SETTING) MainUnit<Mail> endSetting
) {
return AnswerCheck.builder()
.check(
message -> appSettingService.getMessage("main.yes").equalsIgnoreCase(message.getText())
)
return AnswerCheck.<Mail>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<Mail> parseOwnerProject(
@Unit(END_SETTING) MainUnit<Mail> endSetting
) {
return AnswerProcessing.builder()
.processingData(message -> {
return AnswerText.<Mail>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<Mail> endSetting() {
return AnswerText.<Mail>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)

View File

@ -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<Message> settingsLanguage(
AppSettingService settingService,
AnswerText<Message> 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<Message> 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();
}
}

View File

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