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

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> <parent>
<groupId>dev.struchkov.bot.gitlab</groupId> <groupId>dev.struchkov.bot.gitlab</groupId>
<artifactId>gitlab-bot</artifactId> <artifactId>gitlab-bot</artifactId>
<version>1.0.0</version> <version>1.1.0</version>
</parent> </parent>
<artifactId>bot-context</artifactId> <artifactId>bot-context</artifactId>
<version>${gitlab.context.version}</version>
<dependencies> <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> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
@ -20,7 +29,7 @@
<dependency> <dependency>
<groupId>dev.struchkov.haiti</groupId> <groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-context</artifactId> <artifactId>haiti-utils</artifactId>
</dependency> </dependency>
<dependency> <dependency>
@ -32,11 +41,6 @@
<groupId>javax.persistence</groupId> <groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId> <artifactId>javax.persistence-api</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </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 username;
private String name; private String name;
private Long id; private Long id;
private Long telegramId; private String telegramId;
} }

View File

@ -1,14 +1,10 @@
package dev.struchkov.bot.gitlab.context.domain.entity; package dev.struchkov.bot.gitlab.context.domain.entity;
import dev.struchkov.haiti.context.domain.BasicEntity;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import dev.struchkov.bot.gitlab.context.domain.AppLocale;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Table; import javax.persistence.Table;
@ -21,16 +17,12 @@ import javax.persistence.Table;
@Getter @Getter
@Setter @Setter
@Table(name = "app_setting") @Table(name = "app_setting")
public class AppSetting implements BasicEntity<Long> { public class AppSetting {
@Id @Id
@Column(name = "id") @Column(name = "id")
private Long id; private Long id;
@Column(name = "language")
@Enumerated(EnumType.STRING)
private AppLocale appLocale;
@Column(name = "first_start") @Column(name = "first_start")
private boolean firstStart; private boolean firstStart;

View File

@ -1,6 +1,5 @@
package dev.struchkov.bot.gitlab.context.domain.entity; package dev.struchkov.bot.gitlab.context.domain.entity;
import dev.struchkov.haiti.context.domain.BasicEntity;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -25,7 +24,7 @@ import java.util.List;
@Entity @Entity
@Table(name = "discussion") @Table(name = "discussion")
@EqualsAndHashCode(onlyExplicitlyIncluded = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class Discussion implements BasicEntity<String> { public class Discussion {
@Id @Id
@Column(name = "id") @Column(name = "id")

View File

@ -1,10 +1,10 @@
package dev.struchkov.bot.gitlab.context.domain.entity; 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.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import dev.struchkov.bot.gitlab.context.domain.MergeRequestState;
import javax.persistence.CollectionTable; import javax.persistence.CollectionTable;
import javax.persistence.Column; import javax.persistence.Column;
@ -28,9 +28,10 @@ import java.util.Set;
@Getter @Getter
@Setter @Setter
@Entity @Entity
@FieldNames
@Table(name = "merge_request") @Table(name = "merge_request")
@EqualsAndHashCode(onlyExplicitlyIncluded = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class MergeRequest implements BasicEntity<Long> { public class MergeRequest {
@Id @Id
@Column(name = "id") @Column(name = "id")

View File

@ -1,6 +1,5 @@
package dev.struchkov.bot.gitlab.context.domain.entity; package dev.struchkov.bot.gitlab.context.domain.entity;
import dev.struchkov.haiti.context.domain.BasicEntity;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -18,7 +17,7 @@ import java.time.LocalDateTime;
@Entity @Entity
@Table(name = "note") @Table(name = "note")
@EqualsAndHashCode(onlyExplicitlyIncluded = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class Note implements BasicEntity<Long> { public class Note {
@Id @Id
@Column @Column

View File

@ -1,6 +1,5 @@
package dev.struchkov.bot.gitlab.context.domain.entity; package dev.struchkov.bot.gitlab.context.domain.entity;
import dev.struchkov.haiti.context.domain.BasicEntity;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -16,7 +15,7 @@ import javax.persistence.Table;
@Getter @Getter
@Setter @Setter
@Table(name = "person") @Table(name = "person")
public class Person implements BasicEntity<Long> { public class Person {
@Id @Id
@Column(name = "id") @Column(name = "id")

View File

@ -1,7 +1,7 @@
package dev.struchkov.bot.gitlab.context.domain.entity; package dev.struchkov.bot.gitlab.context.domain.entity;
import dev.struchkov.bot.gitlab.context.domain.PipelineStatus; 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.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -23,9 +23,10 @@ import java.time.LocalDateTime;
@Entity @Entity
@Getter @Getter
@Setter @Setter
@FieldNames
@Table(name = "pipeline") @Table(name = "pipeline")
@EqualsAndHashCode(onlyExplicitlyIncluded = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class Pipeline implements BasicEntity<Long> { public class Pipeline {
@Id @Id
@Column(name = "id") @Column(name = "id")

View File

@ -1,6 +1,5 @@
package dev.struchkov.bot.gitlab.context.domain.entity; package dev.struchkov.bot.gitlab.context.domain.entity;
import dev.struchkov.haiti.context.domain.BasicEntity;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -19,7 +18,7 @@ import java.time.LocalDateTime;
@Entity @Entity
@Table(name = "project") @Table(name = "project")
@EqualsAndHashCode(onlyExplicitlyIncluded = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class Project implements BasicEntity<Long> { public class Project {
@Id @Id
@Column(name = "id") @Column(name = "id")

View File

@ -27,7 +27,7 @@ public record GoodMorningNotify(
} }
@Override @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); final StringBuilder message = new StringBuilder().append(Smile.SUN).append(" *Доброе утро, ").append(personName).append("* ").append(Smile.SUN).append(Smile.TWO_BR);
if (!mergeRequestsReviews.isEmpty()) { if (!mergeRequestsReviews.isEmpty()) {
message.append("Необходимо проверить ").append(mergeRequestsReviews.size()).append(" ПР:").append(Smile.BR); message.append("Необходимо проверить ").append(mergeRequestsReviews.size()).append(" ПР:").append(Smile.BR);

View File

@ -1,16 +1,16 @@
package dev.struchkov.bot.gitlab.context.domain.notify; 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.bot.gitlab.context.utils.Smile;
import dev.struchkov.haiti.utils.Strings; import dev.struchkov.haiti.utils.Strings;
import lombok.Builder; import lombok.Builder;
import java.text.MessageFormat;
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
/** /**
* @author upagge 15.01.2021 * @author upagge 15.01.2021
*/ */
public record NewProjectNotify( public record NewProjectNotify(
String projectName, String projectName,
String projectUrl, String projectUrl,
@ -23,9 +23,9 @@ public record NewProjectNotify(
} }
@Override @Override
public String generateMessage(AppSettingService settingService) { public String generateMessage() {
return settingService.getMessage( return MessageFormat.format(
"notify.project.new", "{0} *New project*{1}[{2}]({3}){1}{4}{5}: {6}",
Smile.FUN.getValue(), Smile.HR.getValue(), projectName, projectUrl, Smile.FUN.getValue(), Smile.HR.getValue(), projectName, projectUrl,
(projectDescription != null && !"".equals(projectDescription)) ? escapeMarkdown(projectDescription) + Smile.HR : Strings.EMPTY, (projectDescription != null && !"".equals(projectDescription)) ? escapeMarkdown(projectDescription) + Smile.HR : Strings.EMPTY,
Smile.AUTHOR.getValue(), authorName Smile.AUTHOR.getValue(), authorName

View File

@ -1,9 +1,7 @@
package dev.struchkov.bot.gitlab.context.domain.notify; package dev.struchkov.bot.gitlab.context.domain.notify;
import dev.struchkov.bot.gitlab.context.service.AppSettingService;
public interface Notify { public interface Notify {
String generateMessage(AppSettingService appSettingService); String generateMessage();
} }

View File

@ -1,6 +1,5 @@
package dev.struchkov.bot.gitlab.context.domain.notify; package dev.struchkov.bot.gitlab.context.domain.notify;
import dev.struchkov.bot.gitlab.context.service.AppSettingService;
import lombok.Builder; import lombok.Builder;
/** /**
@ -13,7 +12,7 @@ public record SimpleTextNotify(String message) implements Notify {
} }
@Override @Override
public String generateMessage(AppSettingService appSettingService) { public String generateMessage() {
return message; return message;
} }

View File

@ -34,7 +34,7 @@ public class AnswerCommentNotify implements Notify {
} }
@Override @Override
public String generateMessage(AppSettingService settingService) { public String generateMessage() {
final String answerText = answers.stream() final String answerText = answers.stream()
.map(answer -> answer.getAuthorName() + ": " + answer.getMessage().substring(0, Math.min(answer.getMessage().length(), 500))) .map(answer -> answer.getAuthorName() + ": " + answer.getMessage().substring(0, Math.min(answer.getMessage().length(), 500)))
.collect(Collectors.joining(TWO_NEW_LINE)); .collect(Collectors.joining(TWO_NEW_LINE));

View File

@ -1,10 +1,11 @@
package dev.struchkov.bot.gitlab.context.domain.notify.comment; package dev.struchkov.bot.gitlab.context.domain.notify.comment;
import dev.struchkov.bot.gitlab.context.domain.notify.Notify; 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 dev.struchkov.bot.gitlab.context.utils.Smile;
import lombok.Builder; import lombok.Builder;
import java.text.MessageFormat;
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
public record CommentNotify( public record CommentNotify(
@ -18,9 +19,9 @@ public record CommentNotify(
} }
@Override @Override
public String generateMessage(AppSettingService settingService) { public String generateMessage() {
return settingService.getMessage( return MessageFormat.format(
"notify.comment.bell", "{0} *New mention* | [MR]({1}){2}*{3}*: {4}",
Smile.COMMENT.getValue(), url, Smile.HR.getValue(), authorName, escapeMarkdown(message) 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; package dev.struchkov.bot.gitlab.context.domain.notify.pipeline;
import dev.struchkov.bot.gitlab.context.domain.notify.Notify; 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 dev.struchkov.bot.gitlab.context.utils.Smile;
import lombok.Builder; import lombok.Builder;
@ -26,9 +25,9 @@ public record PipelineNotify(
} }
@Override @Override
public String generateMessage(AppSettingService appSettingService) { public String generateMessage() {
return MessageFormat.format( return MessageFormat.format(
appSettingService.getMessage("notify.pipeline"), "{0} *Pipeline {1,number,#}* | {2}{3}[{4}]({5}){3}{6} {7} {8}",
Smile.BUILD, Smile.BUILD,
pipelineId, pipelineId,
escapeMarkdown(projectName), escapeMarkdown(projectName),

View File

@ -1,9 +1,10 @@
package dev.struchkov.bot.gitlab.context.domain.notify.pullrequest; package dev.struchkov.bot.gitlab.context.domain.notify.pullrequest;
import dev.struchkov.bot.gitlab.context.utils.Smile;
import lombok.Builder; import lombok.Builder;
import lombok.Getter; import lombok.Getter;
import dev.struchkov.bot.gitlab.context.service.AppSettingService;
import dev.struchkov.bot.gitlab.context.utils.Smile; import java.text.MessageFormat;
@Getter @Getter
public class ConflictPrNotify extends PrNotify { public class ConflictPrNotify extends PrNotify {
@ -22,9 +23,9 @@ public class ConflictPrNotify extends PrNotify {
} }
@Override @Override
public String generateMessage(AppSettingService settingService) { public String generateMessage() {
return settingService.getMessage( return MessageFormat.format(
"notify.pr.conflict", "{0} *Attention! MergeRequest conflict | {4}*{1}[{2}]({3})",
Smile.DANGEROUS.getValue(), Smile.HR.getValue(), title, url, projectName, sourceBranch 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 dev.struchkov.bot.gitlab.context.utils.Smile;
import lombok.Builder; import lombok.Builder;
import lombok.Getter; import lombok.Getter;
import dev.struchkov.bot.gitlab.context.service.AppSettingService;
import java.text.MessageFormat;
/** /**
* // TODO: 11.10.2020 Добавить описание. * // TODO: 11.10.2020 Добавить описание.
@ -25,9 +26,9 @@ public class ForgottenSmartPrNotify extends PrNotify {
} }
@Override @Override
public String generateMessage(AppSettingService appSettingService) { public String generateMessage() {
return appSettingService.getMessage( return MessageFormat.format(
"notify.pr.forgotten", "{0} *MergeRequest Review Reminder | {4}*{3}[{1}]({2})",
Smile.SMART.getValue(), title, url, Smile.HR.getValue(), projectName Smile.SMART.getValue(), title, url, Smile.HR.getValue(), projectName
); );
} }

View File

@ -1,11 +1,11 @@
package dev.struchkov.bot.gitlab.context.domain.notify.pullrequest; package dev.struchkov.bot.gitlab.context.domain.notify.pullrequest;
import dev.struchkov.bot.gitlab.context.utils.Smile;
import dev.struchkov.haiti.utils.Strings; import dev.struchkov.haiti.utils.Strings;
import lombok.Builder; import lombok.Builder;
import lombok.Getter; 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.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -40,15 +40,15 @@ public class NewPrNotify extends PrNotify {
} }
@Override @Override
public String generateMessage(AppSettingService settingService) { public String generateMessage() {
String labelText = labels.stream() String labelText = labels.stream()
.map(label -> "#" + label) .map(label -> "#" + label)
.collect(Collectors.joining(" ")); .collect(Collectors.joining(" "));
if (!labelText.isEmpty()) { if (!labelText.isEmpty()) {
labelText = "\n\n" + labelText; labelText = "\n\n" + labelText;
} }
return settingService.getMessage( return MessageFormat.format(
"notify.pr.new", "{0} *New MergeRequest | {1}*{2}[{3}]({4}){5}{2}{9}: {10} {12} {11}",
Smile.FUN.getValue(), Smile.FUN.getValue(),
projectName, projectName,
Smile.HR.getValue(), 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.service.AppSettingService;
import dev.struchkov.bot.gitlab.context.utils.Smile; import dev.struchkov.bot.gitlab.context.utils.Smile;
import java.text.MessageFormat;
@Getter @Getter
public class StatusPrNotify extends PrNotify { public class StatusPrNotify extends PrNotify {
@ -26,9 +28,9 @@ public class StatusPrNotify extends PrNotify {
} }
@Override @Override
public String generateMessage(AppSettingService settingService) { public String generateMessage() {
return settingService.getMessage( return MessageFormat.format(
"notify.pr.state", "{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 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 dev.struchkov.bot.gitlab.context.utils.Smile;
import lombok.Builder; import lombok.Builder;
import lombok.Getter; import lombok.Getter;
import dev.struchkov.bot.gitlab.context.service.AppSettingService;
import java.text.MessageFormat;
@Getter @Getter
public class UpdatePrNotify extends PrNotify { public class UpdatePrNotify extends PrNotify {
@ -34,9 +35,9 @@ public class UpdatePrNotify extends PrNotify {
} }
@Override @Override
public String generateMessage(AppSettingService settingService) { public String generateMessage() {
return settingService.getMessage( return MessageFormat.format(
"notify.pr.update", "{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 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; 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 dev.struchkov.bot.gitlab.context.utils.Smile;
import lombok.Builder; import lombok.Builder;
import java.text.MessageFormat;
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
/** /**
@ -28,9 +29,9 @@ public class TaskCloseNotify extends TaskNotify {
} }
@Override @Override
public String generateMessage(AppSettingService settingService) { public String generateMessage() {
return settingService.getMessage( return MessageFormat.format(
"notify.task.close", "{0} *Closed [task]({1}){2}*{3}*: {4}",
Smile.TASK.getValue(), url, Smile.HR.getValue(), authorName, escapeMarkdown(messageTask), personTasks, personResolvedTasks 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; 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 dev.struchkov.bot.gitlab.context.utils.Smile;
import lombok.Builder; import lombok.Builder;
import lombok.Getter; import lombok.Getter;
import java.text.MessageFormat;
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
/** /**
@ -23,9 +24,9 @@ public class TaskNewNotify extends TaskNotify {
} }
@Override @Override
public String generateMessage(AppSettingService settingService) { public String generateMessage() {
return settingService.getMessage( return MessageFormat.format(
"notify.task.new", "{0} *New [task]({1}) assigned{2}*{3}*: {4}",
Smile.TASK.getValue(), url, Smile.HR.getValue(), authorName, escapeMarkdown(messageTask) Smile.TASK.getValue(), url, Smile.HR.getValue(), authorName, escapeMarkdown(messageTask)
); );
} }

View File

@ -1,11 +1,15 @@
package dev.struchkov.bot.gitlab.context.repository; package dev.struchkov.bot.gitlab.context.repository;
import dev.struchkov.bot.gitlab.context.domain.entity.AppSetting; 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 * @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; package dev.struchkov.bot.gitlab.context.repository;
import dev.struchkov.bot.gitlab.context.domain.entity.Discussion; import dev.struchkov.bot.gitlab.context.domain.entity.Discussion;
import dev.struchkov.haiti.context.repository.SimpleManagerRepository; import org.springframework.data.domain.Page;
import lombok.NonNull; import org.springframework.data.domain.Pageable;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.Set;
/** /**
* @author upagge 11.02.2021 * @author upagge 11.02.2021
*/ */
public interface DiscussionRepository extends SimpleManagerRepository<Discussion, String> { public interface DiscussionRepository {
/** /**
* Вернуть все дискусии для MR * Вернуть все дискусии для 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.IdAndStatusPr;
import dev.struchkov.bot.gitlab.context.domain.MergeRequestState; import dev.struchkov.bot.gitlab.context.domain.MergeRequestState;
import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest; import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest;
import dev.struchkov.haiti.context.repository.SimpleManagerRepository; import dev.struchkov.haiti.filter.Filter;
import dev.struchkov.haiti.filter.FilterOperation;
import lombok.NonNull; import lombok.NonNull;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.Set; import java.util.Set;
public interface MergeRequestRepository extends SimpleManagerRepository<MergeRequest, Long>, FilterOperation<MergeRequest> { public interface MergeRequestRepository {
Set<IdAndStatusPr> findAllIdByStateIn(@NonNull Set<MergeRequestState> states); Set<IdAndStatusPr> findAllIdByStateIn(@NonNull Set<MergeRequestState> states);
//TODO [28.01.2022]: Решить, нужно ли оставить //TODO [28.01.2022]: Решить, нужно ли оставить
List<MergeRequest> findAllByAssignee(@NonNull Long userId); 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; package dev.struchkov.bot.gitlab.context.repository;
import dev.struchkov.bot.gitlab.context.domain.entity.Note; import dev.struchkov.bot.gitlab.context.domain.entity.Note;
import dev.struchkov.haiti.context.page.Pagination; import org.springframework.data.domain.Page;
import dev.struchkov.haiti.context.page.Sheet; import org.springframework.data.domain.Pageable;
import dev.struchkov.haiti.context.repository.SimpleManagerRepository;
import lombok.NonNull;
import java.util.List; import java.util.List;
import java.util.Optional;
/** /**
* @author upagge 08.09.2020 * @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; package dev.struchkov.bot.gitlab.context.repository;
import dev.struchkov.bot.gitlab.context.domain.entity.Person; 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 * @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.PipelineStatus;
import dev.struchkov.bot.gitlab.context.domain.entity.Pipeline; import dev.struchkov.bot.gitlab.context.domain.entity.Pipeline;
import dev.struchkov.haiti.context.page.Pagination; import dev.struchkov.haiti.filter.Filter;
import dev.struchkov.haiti.context.page.Sheet; import org.springframework.data.domain.Page;
import dev.struchkov.haiti.context.repository.SimpleManagerRepository; import org.springframework.data.domain.Pageable;
import dev.struchkov.haiti.filter.FilterOperation;
import lombok.NonNull;
import java.util.List;
import java.util.Optional;
import java.util.Set; import java.util.Set;
/** /**
* @author upagge 17.01.2021 * @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; package dev.struchkov.bot.gitlab.context.repository;
import dev.struchkov.bot.gitlab.context.domain.entity.Project; 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 * @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; 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(); 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; 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.bot.gitlab.context.domain.entity.Discussion;
import dev.struchkov.haiti.context.service.SimpleManagerService;
import lombok.NonNull; import lombok.NonNull;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* @author upagge 11.02.2021 * @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); 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; 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.IdAndStatusPr;
import dev.struchkov.bot.gitlab.context.domain.MergeRequestState; import dev.struchkov.bot.gitlab.context.domain.MergeRequestState;
import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest; 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 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; 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); 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; package dev.struchkov.bot.gitlab.context.service;
import dev.struchkov.bot.gitlab.context.domain.entity.Note; 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 lombok.NonNull;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.List; import java.util.List;
public interface NoteService extends SimpleManagerService<Note, Long> { public interface NoteService {
List<Note> getAllPersonTask(@NonNull Long userId, boolean resolved); List<Note> getAllPersonTask(@NonNull Long userId, boolean resolved);
//TODO [28.01.2022]: Решить нужно ли оставлять //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; 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.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 * @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.PipelineStatus;
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.filter.PipelineFilter; import dev.struchkov.bot.gitlab.context.domain.filter.PipelineFilter;
import dev.struchkov.haiti.context.page.Pagination; import dev.struchkov.haiti.context.domain.ExistsContainer;
import dev.struchkov.haiti.context.page.Sheet;
import dev.struchkov.haiti.context.service.SimpleManagerService;
import dev.struchkov.haiti.context.service.simple.FilterService;
import lombok.NonNull; import lombok.NonNull;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.Set; import java.util.Set;
@ -16,8 +15,18 @@ import java.util.Set;
* *
* @author upagge 17.01.2021 * @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; 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.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 * @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> <parent>
<groupId>dev.struchkov.bot.gitlab</groupId> <groupId>dev.struchkov.bot.gitlab</groupId>
<artifactId>gitlab-bot</artifactId> <artifactId>gitlab-bot</artifactId>
<version>1.0.0</version> <version>1.1.0</version>
</parent> </parent>
<artifactId>bot-core</artifactId> <artifactId>bot-core</artifactId>
<version>${gitlab.core.version}</version>
<dependencies> <dependencies>
<dependency> <dependency>
@ -23,16 +22,6 @@
<artifactId>bot-context</artifactId> <artifactId>bot-context</artifactId>
</dependency> </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> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId> <artifactId>spring-boot-configuration-processor</artifactId>

View File

@ -16,6 +16,6 @@ import org.springframework.context.annotation.Configuration;
public class PersonProperty { public class PersonProperty {
private String token; 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.context.domain.entity.MergeRequest;
import dev.struchkov.bot.gitlab.sdk.domain.MergeRequestJson; import dev.struchkov.bot.gitlab.sdk.domain.MergeRequestJson;
import dev.struchkov.bot.gitlab.sdk.domain.MergeRequestStateJson; import dev.struchkov.bot.gitlab.sdk.domain.MergeRequestStateJson;
import dev.struchkov.haiti.context.exception.ConvertException;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component; 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 * @author upagge 15.01.2021
*/ */
@ -31,7 +35,7 @@ public class MergeRequestJsonConverter implements Converter<MergeRequestJson, Me
mergeRequest.setState(convertState(source.getState())); mergeRequest.setState(convertState(source.getState()));
mergeRequest.setProjectId(source.getProjectId()); mergeRequest.setProjectId(source.getProjectId());
mergeRequest.setWebUrl(source.getWebUrl()); mergeRequest.setWebUrl(source.getWebUrl());
mergeRequest.setLabels(source.getLabels()); mergeRequest.setLabels(convertLabels(source.getLabels()));
if (source.getAssignee() != null) { if (source.getAssignee() != null) {
mergeRequest.setAssignee(convertPerson.convert(source.getAssignee())); mergeRequest.setAssignee(convertPerson.convert(source.getAssignee()));
} }
@ -41,13 +45,21 @@ public class MergeRequestJsonConverter implements Converter<MergeRequestJson, Me
return mergeRequest; 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) { private MergeRequestState convertState(MergeRequestStateJson state) {
return switch (state) { return switch (state) {
case CLOSED -> MergeRequestState.CLOSED; case CLOSED -> MergeRequestState.CLOSED;
case LOCKED -> MergeRequestState.LOCKED; case LOCKED -> MergeRequestState.LOCKED;
case MERGED -> MergeRequestState.MERGED; case MERGED -> MergeRequestState.MERGED;
case OPENED -> MergeRequestState.OPENED; case OPENED -> MergeRequestState.OPENED;
default -> throw new ConvertException("Статус ПР не найден");
}; };
} }

View File

@ -1,19 +1,17 @@
package dev.struchkov.bot.gitlab.core.service.impl; 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.domain.entity.AppSetting;
import dev.struchkov.bot.gitlab.context.repository.AppSettingRepository; import dev.struchkov.bot.gitlab.context.repository.AppSettingRepository;
import dev.struchkov.bot.gitlab.context.service.AppSettingService; import dev.struchkov.bot.gitlab.context.service.AppSettingService;
import dev.struchkov.haiti.context.exception.NotFoundException; import dev.struchkov.haiti.context.exception.NotFoundException;
import lombok.NonNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.Locale;
import java.util.function.Supplier; 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 { public class AppSettingServiceImpl implements AppSettingService {
private static final Long KEY = 1L; 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 AppSettingRepository appSettingRepository;
private final MessageSource messageSource; private final MessageSource messageSource;
@ -41,29 +39,6 @@ public class AppSettingServiceImpl implements AppSettingService {
appSettingRepository.save(appSetting); 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() { private AppSetting getAppSetting() {
return appSettingRepository.findById(KEY) return appSettingRepository.findById(KEY)
.orElseThrow(NOT_FOUND_SETTINGS); .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.CleanService;
import dev.struchkov.bot.gitlab.context.service.MergeRequestsService; import dev.struchkov.bot.gitlab.context.service.MergeRequestsService;
import dev.struchkov.bot.gitlab.context.service.PipelineService; 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 lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -39,7 +39,7 @@ public class CleanServiceImpl implements CleanService {
@Override @Override
public void cleanOldMergedRequests() { public void cleanOldMergedRequests() {
int page = 0; 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()) { while (mergeRequestSheet.hasContent()) {
final Set<Long> ids = mergeRequestSheet.getContent().stream() final Set<Long> ids = mergeRequestSheet.getContent().stream()
@ -48,7 +48,7 @@ public class CleanServiceImpl implements CleanService {
mergeRequestsService.deleteAllById(ids); 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() { public void cleanOldPipelines() {
int page = 0; int page = 0;
final PipelineFilter filter = cleanPipelineFilter(); 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()) { while (sheet.hasContent()) {
final Set<Long> ids = sheet.getContent().stream() final Set<Long> ids = sheet.getContent().stream()
@ -65,7 +65,7 @@ public class CleanServiceImpl implements CleanService {
pipelineService.deleteAllById(ids); 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; 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.PersonInformation;
import dev.struchkov.bot.gitlab.context.domain.entity.Discussion; 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.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.GitlabProperty;
import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty; import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty;
import dev.struchkov.bot.gitlab.core.utils.StringUtils; 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.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import okhttp3.FormBody; import okhttp3.FormBody;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.RequestBody; import okhttp3.RequestBody;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.IOException; import java.io.IOException;
@ -35,6 +37,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static dev.struchkov.haiti.context.exception.NotFoundException.notFoundException;
import static java.lang.Boolean.FALSE; import static java.lang.Boolean.FALSE;
/** /**
@ -44,12 +47,13 @@ import static java.lang.Boolean.FALSE;
*/ */
@Slf4j @Slf4j
@Service @Service
public class DiscussionServiceImpl extends AbstractSimpleManagerService<Discussion, String> implements DiscussionService { @RequiredArgsConstructor
public class DiscussionServiceImpl implements DiscussionService {
protected static final Pattern PATTERN = Pattern.compile("@[\\w]+"); protected static final Pattern PATTERN = Pattern.compile("@[\\w]+");
private final PersonService personService; private final PersonService personService;
private final DiscussionRepository discussionRepository; private final DiscussionRepository repository;
private final PersonInformation personInformation; private final PersonInformation personInformation;
private final OkHttpClient client = new OkHttpClient(); private final OkHttpClient client = new OkHttpClient();
@ -57,16 +61,6 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService<Discussi
private final PersonProperty personProperty; private final PersonProperty personProperty;
private final NotifyService notifyService; 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 @Override
public Discussion create(@NonNull Discussion discussion) { public Discussion create(@NonNull Discussion discussion) {
discussion.getNotes().forEach(note -> personService.create(note.getAuthor())); discussion.getNotes().forEach(note -> personService.create(note.getAuthor()));
@ -76,7 +70,7 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService<Discussi
final boolean resolved = discussion.getNotes().stream() final boolean resolved = discussion.getNotes().stream()
.allMatch(note -> note.isResolvable() && note.getResolved()); .allMatch(note -> note.isResolvable() && note.getResolved());
discussion.setResolved(resolved); discussion.setResolved(resolved);
return discussionRepository.save(discussion); return repository.save(discussion);
} }
/** /**
@ -104,8 +98,8 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService<Discussi
@Override @Override
public Discussion update(@NonNull Discussion discussion) { public Discussion update(@NonNull Discussion discussion) {
final Discussion oldDiscussion = discussionRepository.findById(discussion.getId()) final Discussion oldDiscussion = repository.findById(discussion.getId())
.orElseThrow(NotFoundException.supplier("Дискуссия не найдена")); .orElseThrow(notFoundException("Дискуссия не найдена"));
final Map<Long, Note> idAndNoteMap = oldDiscussion final Map<Long, Note> idAndNoteMap = oldDiscussion
.getNotes().stream() .getNotes().stream()
.collect(Collectors.toMap(Note::getId, note -> note)); .collect(Collectors.toMap(Note::getId, note -> note));
@ -122,7 +116,7 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService<Discussi
.allMatch(note -> note.isResolvable() && note.getResolved()); .allMatch(note -> note.isResolvable() && note.getResolved());
discussion.setResolved(resolved); discussion.setResolved(resolved);
return discussionRepository.save(discussion); return repository.save(discussion);
} }
private void updateNote(Note note, Map<Long, Note> noteMap, boolean inDiscussion) { private void updateNote(Note note, Map<Long, Note> noteMap, boolean inDiscussion) {
@ -189,8 +183,8 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService<Discussi
@Override @Override
public void answer(@NonNull String discussionId, @NonNull String text) { public void answer(@NonNull String discussionId, @NonNull String text) {
final Discussion discussion = discussionRepository.findById(discussionId) final Discussion discussion = repository.findById(discussionId)
.orElseThrow(NotFoundException.supplier("Дисскусия {0} не найдена", discussionId)); .orElseThrow(notFoundException("Дисскусия {0} не найдена", discussionId));
final MergeRequest mergeRequest = discussion.getMergeRequest(); final MergeRequest mergeRequest = discussion.getMergeRequest();
final Long projectId = mergeRequest.getProjectId(); final Long projectId = mergeRequest.getProjectId();
@ -214,7 +208,38 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService<Discussi
@Override @Override
public List<Discussion> getAllByMergeRequestId(@NonNull Long mergeRequestId) { 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; 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.IdAndStatusPr;
import dev.struchkov.bot.gitlab.context.domain.MergeRequestState; import dev.struchkov.bot.gitlab.context.domain.MergeRequestState;
import dev.struchkov.bot.gitlab.context.domain.PersonInformation; 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.NotifyService;
import dev.struchkov.bot.gitlab.context.service.PersonService; import dev.struchkov.bot.gitlab.context.service.PersonService;
import dev.struchkov.bot.gitlab.context.service.ProjectService; import dev.struchkov.bot.gitlab.context.service.ProjectService;
import dev.struchkov.haiti.context.exception.NotFoundException; import dev.struchkov.bot.gitlab.core.service.impl.filter.MergeRequestFilterService;
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 lombok.NonNull; 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 org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import java.util.Set; 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 @Service
public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<MergeRequest, Long> implements MergeRequestsService { @RequiredArgsConstructor
public class MergeRequestsServiceImpl implements MergeRequestsService {
private final NotifyService notifyService; private final NotifyService notifyService;
private final MergeRequestRepository mergeRequestRepository; private final MergeRequestRepository repository;
private final PersonService personService; private final PersonService personService;
private final FilterService<MergeRequest, MergeRequestFilter> filterService; private final MergeRequestFilterService filterService;
private final ProjectService projectService; private final ProjectService projectService;
private final DiscussionService discussionService; private final DiscussionService discussionService;
private final PersonInformation personInformation; 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 @Override
public MergeRequest create(@NonNull MergeRequest mergeRequest) { public MergeRequest create(@NonNull MergeRequest mergeRequest) {
if (mergeRequest.getAssignee() != null) { if (mergeRequest.getAssignee() != null) {
@ -70,7 +55,7 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
mergeRequest.setNotification(true); mergeRequest.setNotification(true);
final MergeRequest newMergeRequest = mergeRequestRepository.save(mergeRequest); final MergeRequest newMergeRequest = repository.save(mergeRequest);
notifyNewPr(newMergeRequest); notifyNewPr(newMergeRequest);
@ -80,9 +65,7 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
private void notifyNewPr(MergeRequest newMergeRequest) { private void notifyNewPr(MergeRequest newMergeRequest) {
if (!personInformation.getId().equals(newMergeRequest.getAuthor().getId())) { if (!personInformation.getId().equals(newMergeRequest.getAuthor().getId())) {
final String projectName = projectService.getById(newMergeRequest.getProjectId()) final String projectName = projectService.getByIdOrThrow(newMergeRequest.getProjectId()).getName();
.orElseThrow(NotFoundException.supplier("Проект не найден"))
.getName();
if (!newMergeRequest.isConflict()) { if (!newMergeRequest.isConflict()) {
notifyService.send( notifyService.send(
NewPrNotify.builder() NewPrNotify.builder()
@ -108,24 +91,23 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
} }
personService.create(mergeRequest.getAuthor()); personService.create(mergeRequest.getAuthor());
final MergeRequest oldMergeRequest = mergeRequestRepository.findById(mergeRequest.getId()) final MergeRequest oldMergeRequest = repository.findById(mergeRequest.getId())
.orElseThrow(NotFoundException.supplier("МержРеквест не найден")); .orElseThrow(notFoundException("МержРеквест не найден"));
if (mergeRequest.getNotification() == null) { if (mergeRequest.getNotification() == null) {
mergeRequest.setNotification(oldMergeRequest.getNotification()); mergeRequest.setNotification(oldMergeRequest.getNotification());
} }
if (!oldMergeRequest.getUpdatedDate().equals(mergeRequest.getUpdatedDate()) || oldMergeRequest.isConflict() != mergeRequest.isConflict()) { if (!oldMergeRequest.getUpdatedDate().equals(mergeRequest.getUpdatedDate()) || oldMergeRequest.isConflict() != mergeRequest.isConflict()) {
final Project project = projectService.getById(mergeRequest.getProjectId()) final Project project = projectService.getByIdOrThrow(mergeRequest.getProjectId());
.orElseThrow(NotFoundException.supplier("Проект не найден"));
if (Boolean.TRUE.equals(oldMergeRequest.getNotification())) { if (TRUE.equals(oldMergeRequest.getNotification())) {
notifyStatus(oldMergeRequest, mergeRequest, project); notifyStatus(oldMergeRequest, mergeRequest, project);
notifyConflict(oldMergeRequest, mergeRequest, project); notifyConflict(oldMergeRequest, mergeRequest, project);
notifyUpdate(oldMergeRequest, mergeRequest, project); notifyUpdate(oldMergeRequest, mergeRequest, project);
} }
return mergeRequestRepository.save(mergeRequest); return repository.save(mergeRequest);
} }
return oldMergeRequest; return oldMergeRequest;
} }
@ -204,27 +186,43 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
@Override @Override
public Set<IdAndStatusPr> getAllId(Set<MergeRequestState> statuses) { public Set<IdAndStatusPr> getAllId(Set<MergeRequestState> statuses) {
return mergeRequestRepository.findAllIdByStateIn(statuses); return repository.findAllIdByStateIn(statuses);
} }
@Override @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); return filterService.getAll(filter, pagination);
} }
@Override @Override
public Optional<MergeRequest> getFirst(@NonNull MergeRequestFilter mergeRequestFilter) { public ExistsContainer<MergeRequest, Long> existsById(@NonNull Set<Long> mergeRequestIds) {
return filterService.getFirst(mergeRequestFilter); 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 @Override
public boolean exists(@NonNull MergeRequestFilter filter) { public List<MergeRequest> createAll(List<MergeRequest> newMergeRequests) {
return filterService.exists(filter); return newMergeRequests.stream()
.map(this::create)
.toList();
} }
@Override @Override
public long count(@NonNull MergeRequestFilter mergeRequestFilter) { public void deleteAllById(@NonNull Set<Long> mergeRequestIds) {
return filterService.count(mergeRequestFilter); repository.deleteByIds(mergeRequestIds);
} }
} }

View File

@ -1,33 +1,63 @@
package dev.struchkov.bot.gitlab.core.service.impl; 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.domain.entity.Person;
import dev.struchkov.bot.gitlab.context.repository.PersonRepository; import dev.struchkov.bot.gitlab.context.repository.PersonRepository;
import dev.struchkov.bot.gitlab.context.service.PersonService; import dev.struchkov.bot.gitlab.context.service.PersonService;
import dev.struchkov.haiti.core.service.AbstractSimpleManagerService;
import lombok.NonNull; import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; 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 * @author upagge 15.01.2021
*/ */
@Service @Service
public class PersonServiceImpl extends AbstractSimpleManagerService<Person, Long> implements PersonService { @RequiredArgsConstructor
public class PersonServiceImpl implements PersonService {
private final PersonRepository personRepository; private final PersonRepository repository;
public PersonServiceImpl(PersonRepository personRepository) {
super(personRepository);
this.personRepository = personRepository;
}
@Override @Override
public Person create(@NonNull Person person) { public Person create(@NonNull Person person) {
return personRepository.save(person); return repository.save(person);
} }
@Override @Override
public Person update(@NonNull Person person) { 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.PersonService;
import dev.struchkov.bot.gitlab.context.service.PipelineService; import dev.struchkov.bot.gitlab.context.service.PipelineService;
import dev.struchkov.bot.gitlab.core.service.impl.filter.PipelineFilterService; import dev.struchkov.bot.gitlab.core.service.impl.filter.PipelineFilterService;
import dev.struchkov.haiti.context.exception.NotFoundException; import dev.struchkov.haiti.context.domain.ExistsContainer;
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.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Optional; import java.util.List;
import java.util.Set; 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.CANCELED;
import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.FAILED; 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.SKIPPED;
import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.SUCCESS; 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 * @author upagge 17.01.2021
*/ */
@Service @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 static final Set<PipelineStatus> notificationStatus = Set.of(FAILED, SUCCESS, CANCELED, SKIPPED);
private final NotifyService notifyService; private final NotifyService notifyService;
private final PipelineRepository pipelineRepository; private final PipelineRepository repository;
private final PersonService personService; private final PersonService personService;
private final PipelineFilterService pipelineFilterService; private final PipelineFilterService pipelineFilterService;
private final PersonInformation personInformation; 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 @Override
public Pipeline create(@NonNull Pipeline pipeline) { public Pipeline create(@NonNull Pipeline pipeline) {
personService.create(pipeline.getPerson()); personService.create(pipeline.getPerson());
final Pipeline newPipeline = pipelineRepository.save(pipeline); final Pipeline newPipeline = repository.save(pipeline);
notifyNewPipeline(pipeline, "n/a"); notifyNewPipeline(pipeline, "n/a");
return newPipeline; return newPipeline;
} }
@ -84,13 +72,13 @@ public class PipelineServiceImpl extends AbstractSimpleManagerService<Pipeline,
@Override @Override
public Pipeline update(@NonNull Pipeline pipeline) { public Pipeline update(@NonNull Pipeline pipeline) {
final Pipeline oldPipeline = pipelineRepository.findById(pipeline.getId()) final Pipeline oldPipeline = repository.findById(pipeline.getId())
.orElseThrow(NotFoundException.supplier("Pipeline не найден")); .orElseThrow(notFoundException("Pipeline не найден"));
if (!oldPipeline.getUpdated().equals(pipeline.getUpdated())) { if (!oldPipeline.getUpdated().equals(pipeline.getUpdated())) {
pipeline.setProject(oldPipeline.getProject()); pipeline.setProject(oldPipeline.getProject());
notifyNewPipeline(pipeline, oldPipeline.getStatus().name()); notifyNewPipeline(pipeline, oldPipeline.getStatus().name());
return pipelineRepository.save(pipeline); return repository.save(pipeline);
} }
return oldPipeline; return oldPipeline;
@ -104,28 +92,32 @@ public class PipelineServiceImpl extends AbstractSimpleManagerService<Pipeline,
} }
@Override @Override
public Sheet<Pipeline> getAllByStatuses(@NonNull Set<PipelineStatus> statuses, @NonNull Pagination pagination) { public Page<Pipeline> getAllByStatuses(@NonNull Set<PipelineStatus> statuses, @NonNull Pageable pagination) {
return pipelineRepository.findAllByStatuses(statuses, pagination); return repository.findAllByStatuses(statuses, pagination);
} }
@Override @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); return pipelineFilterService.getAll(filter, pagination);
} }
@Override @Override
public Optional<Pipeline> getFirst(@NonNull PipelineFilter filter) { public ExistsContainer<Pipeline, Long> existsById(@NonNull Set<Long> pipelineIds) {
return pipelineFilterService.getFirst(filter); 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 @Override
public boolean exists(@NonNull PipelineFilter filter) { public void deleteAllById(Set<Long> pipelineIds) {
return pipelineFilterService.exists(filter); repository.deleteAllByIds(pipelineIds);
}
@Override
public long count(@NonNull PipelineFilter filter) {
return pipelineFilterService.count(filter);
} }
} }

View File

@ -1,5 +1,6 @@
package dev.struchkov.bot.gitlab.core.service.impl; 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.PersonInformation;
import dev.struchkov.bot.gitlab.context.domain.entity.Project; import dev.struchkov.bot.gitlab.context.domain.entity.Project;
import dev.struchkov.bot.gitlab.context.domain.notify.NewProjectNotify; 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.NotifyService;
import dev.struchkov.bot.gitlab.context.service.PersonService; import dev.struchkov.bot.gitlab.context.service.PersonService;
import dev.struchkov.bot.gitlab.context.service.ProjectService; 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.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; 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 * @author upagge 14.01.2021
*/ */
@Service @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 NotifyService notifyService;
private final PersonService personService; private final PersonService personService;
private final PersonInformation personInformation; 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 @Override
public Project create(@NonNull Project project) { public Project create(@NonNull Project project) {
final Project newProject = projectRepository.save(project); final Project newProject = repository.save(project);
if (!personInformation.getId().equals(newProject.getCreatorId())) { if (!personInformation.getId().equals(newProject.getCreatorId())) {
final String authorName = personService.getById(newProject.getCreatorId()) final String authorName = personService.getByIdOrThrown(newProject.getCreatorId()).getName();
.orElseThrow(NotFoundException.supplier("Пользователь не найден"))
.getName();
sendNotifyNewProject(newProject, authorName); sendNotifyNewProject(newProject, authorName);
} }
return newProject; 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) { private void sendNotifyNewProject(Project newProject, String authorName) {
notifyService.send( notifyService.send(
NewProjectNotify.builder() 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; 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.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.domain.filter.MergeRequestFilter;
import dev.struchkov.bot.gitlab.context.repository.MergeRequestRepository; 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.Filter;
import dev.struchkov.haiti.filter.FilterQuery; import dev.struchkov.haiti.filter.FilterQuery;
import dev.struchkov.haiti.filter.criteria.CriteriaFilter; import dev.struchkov.haiti.filter.criteria.CriteriaFilter;
import dev.struchkov.haiti.filter.criteria.CriteriaQuery; import dev.struchkov.haiti.filter.criteria.CriteriaQuery;
import lombok.NonNull; import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
public class MergeRequestFilterService extends AbstractFilterService<MergeRequest, MergeRequestFilter> { @RequiredArgsConstructor
public class MergeRequestFilterService {
public MergeRequestFilterService(MergeRequestRepository filterOperation) { private final MergeRequestRepository repository;
super(filterOperation);
public Page<MergeRequest> getAll(MergeRequestFilter filter, Pageable pagination) {
return repository.filter(createFilter(filter), pagination);
} }
@Override private Filter createFilter(@NonNull MergeRequestFilter filter) {
protected Filter createFilter(@NonNull MergeRequestFilter filter) {
return CriteriaFilter.<MergeRequest>create() return CriteriaFilter.<MergeRequest>create()
.and(convertFilter(filter)) .and(convertFilter(filter))
.or(convertFilterOr(filter)); .or(convertFilterOr(filter));
@ -28,12 +32,12 @@ public class MergeRequestFilterService extends AbstractFilterService<MergeReques
private FilterQuery convertFilterOr(MergeRequestFilter filter) { private FilterQuery convertFilterOr(MergeRequestFilter filter) {
return CriteriaQuery.<MergeRequest>create() return CriteriaQuery.<MergeRequest>create()
.matchPhrase(MergeRequest_.STATE, filter.getStates()); .matchPhrase(MergeRequestFields.state, filter.getStates());
} }
private FilterQuery convertFilter(@NonNull MergeRequestFilter filter) { private FilterQuery convertFilter(@NonNull MergeRequestFilter filter) {
return CriteriaQuery.<MergeRequest>create() 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; 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.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.domain.filter.PipelineFilter;
import dev.struchkov.bot.gitlab.context.repository.PipelineRepository; 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.Filter;
import dev.struchkov.haiti.filter.FilterQuery; import dev.struchkov.haiti.filter.FilterQuery;
import dev.struchkov.haiti.filter.criteria.CriteriaFilter; import dev.struchkov.haiti.filter.criteria.CriteriaFilter;
import dev.struchkov.haiti.filter.criteria.CriteriaQuery; import dev.struchkov.haiti.filter.criteria.CriteriaQuery;
import lombok.NonNull; import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
@ -18,20 +20,24 @@ import org.springframework.stereotype.Service;
* @author upagge 08.02.2021 * @author upagge 08.02.2021
*/ */
@Service @Service
public class PipelineFilterService extends AbstractFilterService<Pipeline, PipelineFilter> { @RequiredArgsConstructor
public class PipelineFilterService {
public PipelineFilterService(PipelineRepository pipelineRepository) { private final PipelineRepository pipelineRepository;
super(pipelineRepository);
public Page<Pipeline> getAll(PipelineFilter filter, Pageable pagination) {
return pipelineRepository.filter(createFilter(filter), pagination);
} }
@Override private Filter createFilter(@NonNull PipelineFilter pipelineFilter) {
protected Filter createFilter(@NonNull PipelineFilter pipelineFilter) {
return CriteriaFilter.<Pipeline>create() return CriteriaFilter.<Pipeline>create()
.and(convertAnd(pipelineFilter)); .and(convertAnd(pipelineFilter));
} }
private FilterQuery convertAnd(PipelineFilter pipelineFilter) { private FilterQuery convertAnd(PipelineFilter pipelineFilter) {
return CriteriaQuery.<Pipeline>create() 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.domain.entity.Note;
import dev.struchkov.bot.gitlab.context.repository.NoteRepository; import dev.struchkov.bot.gitlab.context.repository.NoteRepository;
import dev.struchkov.bot.gitlab.context.service.NoteService; 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.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
import static dev.struchkov.haiti.context.exception.NotFoundException.notFoundException;
@Slf4j @Slf4j
@Service @Service
public class NoteServiceImpl extends AbstractSimpleManagerService<Note, Long> implements NoteService { @RequiredArgsConstructor
public class NoteServiceImpl implements NoteService {
private final NoteRepository noteRepository; private final NoteRepository noteRepository;
public NoteServiceImpl(NoteRepository noteRepository) {
super(noteRepository);
this.noteRepository = noteRepository;
}
@Override @Override
public Note create(@NonNull Note note) { public Page<Note> getAllByResolved(boolean resolved, @NonNull Pageable pagination) {
throw new UnsupportedOperationException();
}
@Override
public Note update(@NonNull Note note) {
throw new UnsupportedOperationException();
}
@Override
public Sheet<Note> getAllByResolved(boolean resolved, @NonNull Pagination pagination) {
return noteRepository.findAllByResolved(resolved, pagination); return noteRepository.findAllByResolved(resolved, pagination);
} }
@Override
public Note getByIdOrThrow(@NonNull Long noteId) {
return noteRepository.findById(noteId)
.orElseThrow(notFoundException("Note не найдено"));
}
@Override @Override
public List<Note> getAllPersonTask(@NonNull Long userId, boolean resolved) { public List<Note> getAllPersonTask(@NonNull Long userId, boolean resolved) {
return noteRepository.findAllByResponsibleIdAndResolved(userId, resolved); return noteRepository.findAllByResponsibleIdAndResolved(userId, resolved);

View File

@ -1,5 +1,6 @@
package dev.struchkov.bot.gitlab.core.service.parser; 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.Discussion;
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.Note; 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.GitlabProperty;
import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty; import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty;
import dev.struchkov.bot.gitlab.sdk.domain.DiscussionJson; 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 dev.struchkov.haiti.utils.network.HttpParse;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.text.MessageFormat; import java.text.MessageFormat;
@ -49,12 +49,12 @@ public class DiscussionParser {
*/ */
public void scanNewDiscussion() { public void scanNewDiscussion() {
int page = 0; int page = 0;
Sheet<MergeRequest> mergeRequestSheet = mergeRequestsService.getAll(PaginationImpl.of(page, COUNT)); Page<MergeRequest> mergeRequestSheet = mergeRequestsService.getAll(PageRequest.of(page, COUNT));
while (mergeRequestSheet.hasContent()) { while (mergeRequestSheet.hasContent()) {
mergeRequestSheet.getContent() mergeRequestSheet.getContent()
.forEach(this::processingMergeRequest); .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() { public void scanOldDiscussions() {
int page = 0; int page = 0;
Sheet<Discussion> discussionSheet = discussionService.getAll(PaginationImpl.of(page, COUNT)); Page<Discussion> discussionSheet = discussionService.getAll(PageRequest.of(page, COUNT));
while (discussionSheet.hasContent()) { while (discussionSheet.hasContent()) {
final List<Discussion> discussions = discussionSheet.getContent(); 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; 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.IdAndStatusPr;
import dev.struchkov.bot.gitlab.context.domain.MergeRequestState; import dev.struchkov.bot.gitlab.context.domain.MergeRequestState;
import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest; 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.core.utils.StringUtils;
import dev.struchkov.bot.gitlab.sdk.domain.CommitJson; import dev.struchkov.bot.gitlab.sdk.domain.CommitJson;
import dev.struchkov.bot.gitlab.sdk.domain.MergeRequestJson; 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 dev.struchkov.haiti.utils.network.HttpParse;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.text.MessageFormat; import java.text.MessageFormat;
@ -66,7 +66,7 @@ public class MergeRequestParser {
public void parsingNewMergeRequest() { public void parsingNewMergeRequest() {
int page = 0; int page = 0;
Sheet<Project> projectSheet = projectService.getAll(PaginationImpl.of(page, COUNT)); Page<Project> projectSheet = projectService.getAll(PageRequest.of(page, COUNT));
while (projectSheet.hasContent()) { while (projectSheet.hasContent()) {
final List<Project> projects = projectSheet.getContent(); final List<Project> projects = projectSheet.getContent();
@ -75,7 +75,7 @@ public class MergeRequestParser {
projectProcessing(project); 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.core.utils.StringUtils;
import dev.struchkov.bot.gitlab.sdk.domain.PipelineJson; import dev.struchkov.bot.gitlab.sdk.domain.PipelineJson;
import dev.struchkov.haiti.context.domain.ExistsContainer; 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 dev.struchkov.haiti.utils.network.HttpParse;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.text.MessageFormat; 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.PREPARING;
import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.RUNNING; 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.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; import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT;
/** /**
@ -56,7 +56,7 @@ public class PipelineParser {
public void scanNewPipeline() { public void scanNewPipeline() {
int page = 0; int page = 0;
Sheet<Project> projectSheet = projectService.getAll(PaginationImpl.of(page, COUNT)); Page<Project> projectSheet = projectService.getAll(PageRequest.of(page, COUNT));
while (projectSheet.hasContent()) { while (projectSheet.hasContent()) {
final List<Project> projects = projectSheet.getContent(); final List<Project> projects = projectSheet.getContent();
@ -65,7 +65,7 @@ public class PipelineParser {
processingProject(project); 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); pipeline.setProject(project);
return pipeline; return pipeline;
}) })
.orElseThrow(ConvertException.supplier("Ошибка обновления Pipelines")); .orElseThrow(convertException("Ошибка обновления Pipelines"));
pipelineService.create(newPipeline); pipelineService.create(newPipeline);
} }
@ -121,7 +121,7 @@ public class PipelineParser {
public void scanOldPipeline() { public void scanOldPipeline() {
int page = 0; 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()) { while (pipelineSheet.hasContent()) {
final List<Pipeline> pipelines = pipelineSheet.getContent(); final List<Pipeline> pipelines = pipelineSheet.getContent();
@ -134,12 +134,12 @@ public class PipelineParser {
.header(StringUtils.H_PRIVATE_TOKEN, personProperty.getToken()) .header(StringUtils.H_PRIVATE_TOKEN, personProperty.getToken())
.execute(PipelineJson.class) .execute(PipelineJson.class)
.map(json -> conversionService.convert(json, Pipeline.class)) .map(json -> conversionService.convert(json, Pipeline.class))
.orElseThrow(ConvertException.supplier("Ошибка обновления Pipelines")); .orElseThrow(convertException("Ошибка обновления Pipelines"));
pipelineService.update(newPipeline); 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; 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.Person;
import dev.struchkov.bot.gitlab.context.domain.entity.Project; import dev.struchkov.bot.gitlab.context.domain.entity.Project;
import dev.struchkov.bot.gitlab.context.service.PersonService; 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.core.utils.StringUtils;
import dev.struchkov.bot.gitlab.sdk.domain.PersonJson; import dev.struchkov.bot.gitlab.sdk.domain.PersonJson;
import dev.struchkov.bot.gitlab.sdk.domain.ProjectJson; 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 dev.struchkov.haiti.utils.network.HttpParse;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -23,6 +22,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static dev.struchkov.haiti.context.exception.ConvertException.convertException;
import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT; import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT;
/** /**
@ -97,7 +97,7 @@ public class ProjectParser {
.header(StringUtils.H_PRIVATE_TOKEN, personProperty.getToken()) .header(StringUtils.H_PRIVATE_TOKEN, personProperty.getToken())
.execute(PersonJson.class) .execute(PersonJson.class)
.map(json -> conversionService.convert(json, Person.class)) .map(json -> conversionService.convert(json, Person.class))
.orElseThrow(ConvertException.supplier("Ошибка преобразования нового пользователя")) .orElseThrow(convertException("Ошибка преобразования нового пользователя"))
).toList(); ).toList();
personService.createAll(newPersons); personService.createAll(newPersons);
@ -119,7 +119,7 @@ public class ProjectParser {
.header(StringUtils.H_PRIVATE_TOKEN, personProperty.getToken()) .header(StringUtils.H_PRIVATE_TOKEN, personProperty.getToken())
.execute(ProjectJson.class) .execute(ProjectJson.class)
.map(json -> conversionService.convert(json, Project.class)) .map(json -> conversionService.convert(json, Project.class))
.orElseThrow(ConvertException.supplier("Ошибка получения проекта")); .orElseThrow(convertException("Ошибка получения проекта"));
if (!projectService.existsById(project.getId())) { if (!projectService.existsById(project.getId())) {
projectService.create(project); projectService.create(project);
} }

View File

@ -6,21 +6,16 @@
<parent> <parent>
<groupId>dev.struchkov.bot.gitlab</groupId> <groupId>dev.struchkov.bot.gitlab</groupId>
<artifactId>gitlab-bot</artifactId> <artifactId>gitlab-bot</artifactId>
<version>1.0.0</version> <version>1.1.0</version>
</parent> </parent>
<artifactId>bot-data</artifactId> <artifactId>bot-data</artifactId>
<version>${gitlab.data.version}</version>
<name>GitLab Server Data</name> <name>GitLab Server Data</name>
<description>Implementation of the Bitbucket server version repository layer</description> <description>Implementation of the Bitbucket server version repository layer</description>
<url>https://github.com/uPagge/bitbucketbot</url> <url>https://github.com/uPagge/bitbucketbot</url>
<dependencies> <dependencies>
<dependency>
<groupId>dev.struchkov.haiti.data</groupId>
<artifactId>haiti-database</artifactId>
</dependency>
<dependency> <dependency>
<groupId>dev.struchkov.bot.gitlab</groupId> <groupId>dev.struchkov.bot.gitlab</groupId>
<artifactId>bot-context</artifactId> <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.domain.entity.AppSetting;
import dev.struchkov.bot.gitlab.context.repository.AppSettingRepository; import dev.struchkov.bot.gitlab.context.repository.AppSettingRepository;
import dev.struchkov.haiti.database.repository.manager.AbstractSimpleManagerRepository; import dev.struchkov.bot.gitlab.data.jpa.AppSettingJpaRepository;
import org.springframework.data.jpa.repository.JpaRepository; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.Optional;
/** /**
* @author upagge 16.01.2021 * @author upagge 16.01.2021
*/ */
@Repository @Repository
public class AppSettingRepositoryImpl extends AbstractSimpleManagerRepository<AppSetting, Long> implements AppSettingRepository { @RequiredArgsConstructor
public class AppSettingRepositoryImpl implements AppSettingRepository {
public AppSettingRepositoryImpl(JpaRepository<AppSetting, Long> jpaRepository) { private final AppSettingJpaRepository jpaRepository;
super(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.domain.entity.Discussion;
import dev.struchkov.bot.gitlab.context.repository.DiscussionRepository; import dev.struchkov.bot.gitlab.context.repository.DiscussionRepository;
import dev.struchkov.bot.gitlab.data.jpa.DiscussionJpaRepository; import dev.struchkov.bot.gitlab.data.jpa.DiscussionJpaRepository;
import dev.struchkov.haiti.database.repository.manager.AbstractSimpleManagerRepository;
import lombok.NonNull; import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.Set;
/** /**
* @author upagge 11.02.2021 * @author upagge 11.02.2021
*/ */
@Repository @Repository
public class DiscussionRepositoryImpl extends AbstractSimpleManagerRepository<Discussion, String> implements DiscussionRepository { @RequiredArgsConstructor
public class DiscussionRepositoryImpl implements DiscussionRepository {
private final DiscussionJpaRepository jpaRepository; private final DiscussionJpaRepository jpaRepository;
public DiscussionRepositoryImpl(DiscussionJpaRepository jpaRepository) {
super(jpaRepository);
this.jpaRepository = jpaRepository;
}
@Override @Override
public List<Discussion> findAllByMergeRequestId(@NonNull Long mergeRequestId) { public List<Discussion> findAllByMergeRequestId(@NonNull Long mergeRequestId) {
return jpaRepository.findAllByMergeRequestId(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.domain.entity.MergeRequest;
import dev.struchkov.bot.gitlab.context.repository.MergeRequestRepository; import dev.struchkov.bot.gitlab.context.repository.MergeRequestRepository;
import dev.struchkov.bot.gitlab.data.jpa.MergeRequestJpaRepository; 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.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 org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.Set; import java.util.Set;
@Repository @Repository
public class MergeRequestRepositoryImpl extends FilterManagerRepository<MergeRequest, Long> implements MergeRequestRepository { @RequiredArgsConstructor
public class MergeRequestRepositoryImpl implements MergeRequestRepository {
private final MergeRequestJpaRepository repositoryJpa; private final MergeRequestJpaRepository jpaRepository;
public MergeRequestRepositoryImpl(MergeRequestJpaRepository jpaRepository) {
super(jpaRepository);
repositoryJpa = jpaRepository;
}
@Override @Override
public Set<IdAndStatusPr> findAllIdByStateIn(@NonNull Set<MergeRequestState> statuses) { public Set<IdAndStatusPr> findAllIdByStateIn(@NonNull Set<MergeRequestState> statuses) {
return repositoryJpa.findAllIdByStateIn(statuses); return jpaRepository.findAllIdByStateIn(statuses);
} }
@Override @Override
public List<MergeRequest> findAllByAssignee(@NonNull Long userId) { 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.domain.entity.Note;
import dev.struchkov.bot.gitlab.context.repository.NoteRepository; import dev.struchkov.bot.gitlab.context.repository.NoteRepository;
import dev.struchkov.bot.gitlab.data.jpa.NoteRepositoryJpa; import dev.struchkov.bot.gitlab.data.jpa.NoteJpaRepository;
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 lombok.NonNull; import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
import java.util.Optional;
/** /**
*
* @author upagge 08.09.2020 * @author upagge 08.09.2020
*/ */
@Repository @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) { @Override
super(repositoryJpa); public Page<Note> findAllByResolved(boolean resolved, @NonNull Pageable pagination) {
this.repositoryJpa = repositoryJpa; return jpaRepository.findAllByResolved(resolved, pagination);
} }
@Override @Override
public Sheet<Note> findAllByResolved(boolean resolved, @NonNull Pagination pagination) { public Optional<Note> findById(Long noteId) {
return Converter.page( return jpaRepository.findById(noteId);
repositoryJpa.findAllByResolved(resolved, Converter.pagination(pagination))
);
} }
@Override @Override
public List<Note> findAllByResponsibleIdAndResolved(@NonNull Long userId, boolean resolved) { 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.domain.entity.Person;
import dev.struchkov.bot.gitlab.context.repository.PersonRepository; import dev.struchkov.bot.gitlab.context.repository.PersonRepository;
import dev.struchkov.haiti.database.repository.manager.AbstractSimpleManagerRepository; import dev.struchkov.bot.gitlab.data.jpa.PersonJpaRepository;
import org.springframework.data.jpa.repository.JpaRepository; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
import java.util.Set;
/** /**
* @author upagge 15.01.2021 * @author upagge 15.01.2021
*/ */
@Repository @Repository
public class PersonRepositoryImpl extends AbstractSimpleManagerRepository<Person, Long> implements PersonRepository { @RequiredArgsConstructor
public class PersonRepositoryImpl implements PersonRepository {
public PersonRepositoryImpl(JpaRepository<Person, Long> jpaRepository) { private final PersonJpaRepository jpaRepository;
super(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.domain.entity.Pipeline;
import dev.struchkov.bot.gitlab.context.repository.PipelineRepository; import dev.struchkov.bot.gitlab.context.repository.PipelineRepository;
import dev.struchkov.bot.gitlab.data.jpa.PipelineJpaRepository; import dev.struchkov.bot.gitlab.data.jpa.PipelineJpaRepository;
import dev.struchkov.haiti.context.page.Pagination; import dev.struchkov.haiti.filter.Filter;
import dev.struchkov.haiti.context.page.Sheet; import lombok.RequiredArgsConstructor;
import dev.struchkov.haiti.database.repository.manager.FilterManagerRepository; import org.springframework.data.domain.Page;
import dev.struchkov.haiti.database.util.Converter; import org.springframework.data.domain.Pageable;
import lombok.NonNull; import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
import java.util.Set; import java.util.Set;
/** /**
* @author upagge 17.01.2021 * @author upagge 17.01.2021
*/ */
@Repository @Repository
public class PipelineRepositoryImpl extends FilterManagerRepository<Pipeline, Long> implements PipelineRepository { @RequiredArgsConstructor
public class PipelineRepositoryImpl implements PipelineRepository {
private final PipelineJpaRepository jpaRepository; private final PipelineJpaRepository jpaRepository;
public PipelineRepositoryImpl(PipelineJpaRepository jpaRepository) { @Override
super(jpaRepository); public Pipeline save(Pipeline pipeline) {
this.jpaRepository = jpaRepository; return jpaRepository.save(pipeline);
} }
@Override @Override
public Sheet<Pipeline> findAllByStatuses(@NonNull Set<PipelineStatus> statuses, @NonNull Pagination pagination) { public Optional<Pipeline> findById(Long pipelineId) {
return Converter.page( return jpaRepository.findById(pipelineId);
jpaRepository.findAllByStatusIn(statuses, Converter.pagination(pagination))
);
} }
@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.domain.entity.Project;
import dev.struchkov.bot.gitlab.context.repository.ProjectRepository; import dev.struchkov.bot.gitlab.context.repository.ProjectRepository;
import dev.struchkov.haiti.database.repository.manager.AbstractSimpleManagerRepository; import dev.struchkov.bot.gitlab.data.jpa.ProjectJpaRepository;
import org.springframework.data.jpa.repository.JpaRepository; import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
import java.util.Set;
/** /**
* @author upagge 14.01.2021 * @author upagge 14.01.2021
*/ */
@Repository @Repository
public class ProjectRepositoryImpl extends AbstractSimpleManagerRepository<Project, Long> implements ProjectRepository { @RequiredArgsConstructor
public class ProjectRepositoryImpl implements ProjectRepository {
public ProjectRepositoryImpl(JpaRepository<Project, Long> jpaRepository) { private final ProjectJpaRepository jpaRepository;
super(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; 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); 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> <parent>
<groupId>dev.struchkov.bot.gitlab</groupId> <groupId>dev.struchkov.bot.gitlab</groupId>
<artifactId>gitlab-bot</artifactId> <artifactId>gitlab-bot</artifactId>
<version>1.0.0</version> <version>1.1.0</version>
</parent> </parent>
<artifactId>gitlab-app</artifactId> <artifactId>gitlab-app</artifactId>
<version>${gitlab.app.version}</version>
<name>Gitlab Notification Bot</name> <name>Gitlab Notification Bot</name>
<description>Notifications about Gitlab Server events in Telegram</description> <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.GitlabProperty;
import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty; import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty;
import dev.struchkov.bot.gitlab.core.utils.StringUtils; import dev.struchkov.bot.gitlab.core.utils.StringUtils;
import dev.struchkov.haiti.context.exception.NotFoundException;
import dev.struchkov.haiti.utils.network.HttpParse; import dev.struchkov.haiti.utils.network.HttpParse;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -19,6 +18,7 @@ import java.util.Arrays;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import static dev.struchkov.haiti.context.exception.NotFoundException.notFoundException;
import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT; import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT;
/** /**
@ -61,7 +61,7 @@ public class AppConfig {
.header(ACCEPT) .header(ACCEPT)
.header(StringUtils.H_PRIVATE_TOKEN, personProperty.getToken()) .header(StringUtils.H_PRIVATE_TOKEN, personProperty.getToken())
.execute(PersonInformation.class) .execute(PersonInformation.class)
.orElseThrow(NotFoundException.supplier("Пользователь не найден")); .orElseThrow(notFoundException("Пользователь не найден"));
personInformation.setTelegramId(personProperty.getTelegramId()); personInformation.setTelegramId(personProperty.getTelegramId());
return personInformation; return personInformation;
} }

View File

@ -7,7 +7,7 @@ spring:
driver-class-name: org.postgresql.Driver driver-class-name: org.postgresql.Driver
password: ${DATASOURCE_PASSWORD} password: ${DATASOURCE_PASSWORD}
liquibase: liquibase:
change-log: classpath:liquibase/change-log.xml change-log: classpath:liquibase/changelog.xml
jpa: jpa:
show-sql: false show-sql: false
hibernate: hibernate:
@ -22,7 +22,7 @@ telegram-config:
bot-username: ${TELEGRAM_BOT_USERNAME} bot-username: ${TELEGRAM_BOT_USERNAME}
bot-token: ${TELEGRAM_BOT_TOKEN} bot-token: ${TELEGRAM_BOT_TOKEN}
gitlab-bot: gitlab-bot:
version: 0.0.6 Beta version: 0.0.7 Beta
person: person:
telegram-id: ${TELEGRAM_PERSON_ID} telegram-id: ${TELEGRAM_PERSON_ID}
token: ${GITLAB_PERSONAL_TOKEN} token: ${GITLAB_PERSONAL_TOKEN}
@ -30,8 +30,8 @@ gitlab-bot:
base-url: ${GITLAB_URL} base-url: ${GITLAB_URL}
replaceUrl: ${GITLAB_REPLACE_URL} replaceUrl: ${GITLAB_REPLACE_URL}
url-project: ${GITLAB_URL}/api/v4/projects?page={0, number, integer}&per_page=100 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-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} 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-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-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} 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" 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-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> </databaseChangeLog>

View File

@ -1,27 +1,18 @@
<databaseChangeLog <databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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"> <createTable tableName="app_setting">
<column name="id" type="int"> <column name="id" type="int">
<constraints primaryKey="true"/> <constraints primaryKey="true"/>
</column> </column>
<column name="language" type="varchar(10)"/>
<column name="first_start" type="boolean"/> <column name="first_start" type="boolean"/>
</createTable> </createTable>
</changeSet> </changeSet>
<changeSet id="2020-01-16" author="uPagge"> <changeSet id="2022-12-03-create-table-project" 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">
<createTable tableName="project"> <createTable tableName="project">
<column name="id" type="int"> <column name="id" type="int">
<constraints nullable="false" primaryKey="true"/> <constraints nullable="false" primaryKey="true"/>
@ -42,7 +33,7 @@
</createTable> </createTable>
</changeSet> </changeSet>
<changeSet id="2020-01-14-create-table-person" author="uPagge"> <changeSet id="2022-12-03-create-table-person" author="uPagge">
<createTable tableName="person"> <createTable tableName="person">
<column name="id" type="int"> <column name="id" type="int">
<constraints nullable="false" primaryKey="true"/> <constraints nullable="false" primaryKey="true"/>
@ -57,7 +48,7 @@
</createTable> </createTable>
</changeSet> </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"> <createTable tableName="merge_request">
<column name="id" type="int"> <column name="id" type="int">
<constraints nullable="false" primaryKey="true"/> <constraints nullable="false" primaryKey="true"/>
@ -105,12 +96,26 @@
<column name="notification" type="boolean"> <column name="notification" type="boolean">
<constraints nullable="false"/> <constraints nullable="false"/>
</column> </column>
<column name="date_last_commit" type="datetime"/>
</createTable> </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>
<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"> <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"/> <constraints nullable="false" primaryKey="true"/>
</column> </column>
<column name="merge_request_id" type="int"> <column name="merge_request_id" type="int">
@ -122,10 +127,13 @@
</column> </column>
</createTable> </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"/> <addUniqueConstraint tableName="merge_request_label" columnNames="merge_request_id, label"/>
</changeSet> </changeSet>
<changeSet id="2021-02-11-create-discussion" author="uPagge"> <changeSet id="2022-12-03-create-discussion" author="uPagge">
<createTable tableName="discussion"> <createTable tableName="discussion">
<column name="id" type="varchar(200)"> <column name="id" type="varchar(200)">
<constraints nullable="false" primaryKey="true"/> <constraints nullable="false" primaryKey="true"/>
@ -136,9 +144,13 @@
</column> </column>
<column name="resolved" type="boolean"/> <column name="resolved" type="boolean"/>
</createTable> </createTable>
<createIndex tableName="discussion" indexName="i_discussion_responsible_id">
<column name="responsible_id"/>
</createIndex>
</changeSet> </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"> <createTable tableName="discussion_merge_request">
<column name="discussion_id" type="varchar(200)"> <column name="discussion_id" type="varchar(200)">
<constraints nullable="false" foreignKeyName="discussion_merge_request_discussion_id" <constraints nullable="false" foreignKeyName="discussion_merge_request_discussion_id"
@ -153,7 +165,7 @@
<addPrimaryKey tableName="discussion_merge_request" columnNames="discussion_id, merge_request_id"/> <addPrimaryKey tableName="discussion_merge_request" columnNames="discussion_id, merge_request_id"/>
</changeSet> </changeSet>
<changeSet id="2020-01-16-create-table-note" author="uPagge"> <changeSet id="2022-12-03-create-table-note" author="uPagge">
<createTable tableName="note"> <createTable tableName="note">
<column name="id" type="int"> <column name="id" type="int">
<constraints nullable="false" primaryKey="true"/> <constraints nullable="false" primaryKey="true"/>
@ -183,9 +195,16 @@
<constraints foreignKeyName="note_discussion_id" references="discussion(id)" deleteCascade="true"/> <constraints foreignKeyName="note_discussion_id" references="discussion(id)" deleteCascade="true"/>
</column> </column>
</createTable> </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>
<changeSet id="2020-01-17-create-table-pipelines" author="uPagge"> <changeSet id="2022-12-03-create-table-pipelines" author="uPagge">
<createTable tableName="pipeline"> <createTable tableName="pipeline">
<column name="id" type="int"> <column name="id" type="int">
<constraints nullable="false" primaryKey="true"/> <constraints nullable="false" primaryKey="true"/>
@ -208,12 +227,13 @@
<constraints foreignKeyName="pipeline_person_id" references="person(id)"/> <constraints foreignKeyName="pipeline_person_id" references="person(id)"/>
</column> </column>
</createTable> </createTable>
</changeSet>
<changeSet id="2020-01-19-create-table-commit" author="uPagge"> <createIndex tableName="pipeline" indexName="i_pipeline_project_id">
<addColumn tableName="merge_request"> <column name="project_id"/>
<column name="date_last_commit" type="datetime"/> </createIndex>
</addColumn> <createIndex tableName="pipeline" indexName="i_pipeline_person_id">
<column name="person_id"/>
</createIndex>
</changeSet> </changeSet>
</databaseChangeLog> </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" 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-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> </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> <parent>
<groupId>dev.struchkov.bot.gitlab</groupId> <groupId>dev.struchkov.bot.gitlab</groupId>
<artifactId>gitlab-bot</artifactId> <artifactId>gitlab-bot</artifactId>
<version>1.0.0</version> <version>1.1.0</version>
</parent> </parent>
<artifactId>gitlab-sdk</artifactId> <artifactId>gitlab-sdk</artifactId>
<version>${gitlab.sdk.version}</version>
<dependencies> <dependencies>
<dependency> <dependency>

86
pom.xml
View File

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

View File

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

View File

@ -1,27 +1,34 @@
package dev.struchkov.bot.gitlab.telegram.config; package dev.struchkov.bot.gitlab.telegram.config;
import dev.struchkov.bot.gitlab.telegram.service.ReplaceUrlLocalhost; import dev.struchkov.bot.gitlab.telegram.service.ReplaceUrlLocalhost;
import dev.struchkov.godfather.context.domain.content.Mail; import dev.struchkov.bot.gitlab.telegram.unit.MenuConfig;
import dev.struchkov.godfather.context.repository.impl.local.MailRepositoryList; import dev.struchkov.bot.gitlab.telegram.unit.UnitConfig;
import dev.struchkov.godfather.context.service.MailService; import dev.struchkov.godfather.main.domain.content.Mail;
import dev.struchkov.godfather.context.service.MessageService; import dev.struchkov.godfather.simple.context.service.EventHandler;
import dev.struchkov.godfather.context.service.impl.MailServiceImpl; import dev.struchkov.godfather.simple.context.service.PersonSettingService;
import dev.struchkov.godfather.context.service.sender.Sending; import dev.struchkov.godfather.simple.context.service.UnitPointerService;
import dev.struchkov.godfather.core.domain.unit.AnswerCheck; import dev.struchkov.godfather.simple.core.provider.StoryLineHandler;
import dev.struchkov.godfather.telegram.autoresponder.MessageAutoresponderTelegram; import dev.struchkov.godfather.simple.core.service.PersonSettingServiceImpl;
import dev.struchkov.godfather.telegram.config.TelegramPollingConfig; import dev.struchkov.godfather.simple.core.service.StorylineMailService;
import dev.struchkov.godfather.telegram.listen.EventDistributor; import dev.struchkov.godfather.simple.core.service.StorylineService;
import dev.struchkov.godfather.telegram.listen.EventDistributorImpl; import dev.struchkov.godfather.simple.core.service.UnitPointerServiceImpl;
import dev.struchkov.godfather.telegram.listen.TelegramConnect; import dev.struchkov.godfather.simple.data.repository.impl.PersonSettingLocalRepository;
import dev.struchkov.godfather.telegram.listen.TelegramSender; import dev.struchkov.godfather.simple.data.repository.impl.StorylineMapRepository;
import org.sadtech.autoresponder.repository.UnitPointerRepository; import dev.struchkov.godfather.simple.data.repository.impl.UnitPointLocalRepository;
import org.sadtech.autoresponder.repository.UnitPointerRepositoryMap; 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.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import java.util.Collections; import java.util.List;
/** /**
* @author upagge [30.01.2020] * @author upagge [30.01.2020]
@ -31,32 +38,46 @@ import java.util.Collections;
public class TelegramBotConfig { public class TelegramBotConfig {
@Bean @Bean
public MailService messageService() { public UnitPointerService unitPointerService() {
return new MailServiceImpl(new MailRepositoryList()); return new UnitPointerServiceImpl(new UnitPointLocalRepository());
} }
@Bean @Bean
public UnitPointerRepository unitPointerRepository() { public PersonSettingService personSettingService() {
return new UnitPointerRepositoryMap(); return new PersonSettingServiceImpl(new PersonSettingLocalRepository());
} }
@Bean @Bean
public MessageAutoresponderTelegram messageAutoresponderTelegram( public StorylineService<Mail> storylineService(
Sending sending, UnitPointerService unitPointerService,
MessageService<Mail> messageService,
UnitPointerRepository unitPointerRepository, MenuConfig menuConfig,
AnswerCheck checkFirstStart UnitConfig unitConfig
) { ) {
return new MessageAutoresponderTelegram( final List<Object> config = List.of(menuConfig, unitConfig);
Collections.singleton(checkFirstStart),
sending, return new StorylineMailService(
messageService, unitPointerService,
unitPointerRepository new StorylineMapRepository(),
config
); );
} }
@Bean @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, TelegramConnect telegramConnect,
ReplaceUrlLocalhost replaceUrlLocalhost ReplaceUrlLocalhost replaceUrlLocalhost
) { ) {
@ -66,22 +87,29 @@ public class TelegramBotConfig {
} }
@Bean @Bean
public TelegramConnect telegramConnect(TelegramPollingConfig telegramConfig) { public TelegramConnectBot telegramConnect(TelegramConnectConfig telegramConfig) {
return new TelegramConnect(telegramConfig); return new TelegramConnectBot(telegramConfig);
} }
@Bean @Bean
@ConfigurationProperties("telegram-config") @ConfigurationProperties("telegram-config")
public TelegramPollingConfig telegramConfig() { public TelegramConnectConfig telegramConfig() {
return new TelegramPollingConfig(); return new TelegramConnectConfig();
}
@Bean
public StoryLineHandler storyLineHandler(
MailAutoresponderTelegram mailAutoresponderTelegram
) {
return new StoryLineHandler(mailAutoresponderTelegram);
} }
@Bean @Bean
public EventDistributor eventDistributor( public EventDistributor eventDistributor(
TelegramConnect telegramConnect, TelegramConnectBot telegramConnect,
MailService mailService 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.PersonInformation;
import dev.struchkov.bot.gitlab.context.domain.notify.Notify; 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.bot.gitlab.context.service.MessageSendService;
import dev.struchkov.godfather.context.domain.BoxAnswer; import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
import dev.struchkov.godfather.context.service.sender.Sending;
import lombok.NonNull; import lombok.NonNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import static dev.struchkov.godfather.main.domain.BoxAnswer.boxAnswer;
/** /**
* Отправляет сообщение в телеграмм. * Отправляет сообщение в телеграмм.
* *
@ -19,14 +19,13 @@ import org.springframework.stereotype.Service;
@RequiredArgsConstructor @RequiredArgsConstructor
public class MessageSendTelegramService implements MessageSendService { public class MessageSendTelegramService implements MessageSendService {
private final Sending sending; private final TelegramSending sending;
private final PersonInformation personInformation; private final PersonInformation personInformation;
private final AppSettingService settingService;
@Override @Override
public void send(@NonNull Notify notify) { 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; package dev.struchkov.bot.gitlab.telegram.service;
import dev.struchkov.bot.gitlab.core.config.properties.GitlabProperty; 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 lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;

View File

@ -27,7 +27,7 @@ public class StartNotify {
SimpleTextNotify.builder() SimpleTextNotify.builder()
.message("Привет. Желаю продуктивного дня :)" + .message("Привет. Желаю продуктивного дня :)" +
"\n-- -- -- -- --\n" + "\n-- -- -- -- --\n" +
"Version " + appProperty.getVersion() + " | Developer: [uPagge](https://struchkov.dev/blog)") "Version " + appProperty.getVersion() + " | Developer: [uPagge](https://mark.struchkov.dev)")
.build() .build()
); );
} }

View File

@ -1,11 +1,13 @@
package dev.struchkov.bot.gitlab.telegram.service.unit.pullrequest; package dev.struchkov.bot.gitlab.telegram.service.unit.pullrequest;
import dev.struchkov.bot.gitlab.context.service.MergeRequestsService; import dev.struchkov.bot.gitlab.context.service.MergeRequestsService;
import dev.struchkov.godfather.context.domain.BoxAnswer; import dev.struchkov.godfather.main.domain.BoxAnswer;
import dev.struchkov.godfather.context.domain.content.Message; import dev.struchkov.godfather.main.domain.content.Message;
import dev.struchkov.godfather.context.service.usercode.ProcessingData; import dev.struchkov.godfather.simple.core.unit.func.ProcessingData;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import java.util.Optional;
/** /**
* @author upagge 17.09.2020 * @author upagge 17.09.2020
*/ */
@ -16,7 +18,7 @@ public class PullRequestNeedWorkProcessing implements ProcessingData<Message> {
private final MergeRequestsService mergeRequestsService; private final MergeRequestsService mergeRequestsService;
@Override @Override
public BoxAnswer processing(Message message) { public Optional<BoxAnswer> processing(Message message) {
// final Person person = personService.getByTelegramId(message.getPersonId()) // final Person person = personService.getByTelegramId(message.getPersonId())
// .orElseThrow(() -> new NotFoundException("Пользователь не найден")); // .orElseThrow(() -> new NotFoundException("Пользователь не найден"));
// final List<PullRequest> pullRequests = pullRequestsService.getAllByAuthorAndReviewerStatus(person.getLogin(), ReviewerStatus.UNAPPROVED); // final List<PullRequest> pullRequests = pullRequestsService.getAllByAuthorAndReviewerStatus(person.getLogin(), ReviewerStatus.UNAPPROVED);
@ -24,7 +26,7 @@ public class PullRequestNeedWorkProcessing implements ProcessingData<Message> {
// MessageUtils.pullRequestForNeedWork(pullRequests) // MessageUtils.pullRequestForNeedWork(pullRequests)
// .orElse("Не найдено ПРов, которые нуждаются в доработке :)") // .orElse("Не найдено ПРов, которые нуждаются в доработке :)")
// ); // );
return null; return Optional.empty();
} }
} }

View File

@ -1,11 +1,13 @@
package dev.struchkov.bot.gitlab.telegram.service.unit.pullrequest; package dev.struchkov.bot.gitlab.telegram.service.unit.pullrequest;
import dev.struchkov.bot.gitlab.context.service.MergeRequestsService; import dev.struchkov.bot.gitlab.context.service.MergeRequestsService;
import dev.struchkov.godfather.context.domain.BoxAnswer; import dev.struchkov.godfather.main.domain.BoxAnswer;
import dev.struchkov.godfather.context.domain.content.Message; import dev.struchkov.godfather.main.domain.content.Message;
import dev.struchkov.godfather.context.service.usercode.ProcessingData; import dev.struchkov.godfather.simple.core.unit.func.ProcessingData;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import java.util.Optional;
/** /**
* @author upagge 17.09.2020 * @author upagge 17.09.2020
*/ */
@ -16,7 +18,7 @@ public class PullRequestReviewProcessing implements ProcessingData<Message> {
private final MergeRequestsService mergeRequestsService; private final MergeRequestsService mergeRequestsService;
@Override @Override
public BoxAnswer processing(Message message) { public Optional<BoxAnswer> processing(Message message) {
// final Person person = personService.getByTelegramId(message.getPersonId()) // final Person person = personService.getByTelegramId(message.getPersonId())
// .orElseThrow(() -> new NotFoundException("Пользователь не найден")); // .orElseThrow(() -> new NotFoundException("Пользователь не найден"));
// final List<PullRequest> pullRequests = pullRequestsService.getAllByReviewerAndStatuses( // final List<PullRequest> pullRequests = pullRequestsService.getAllByReviewerAndStatuses(
@ -28,7 +30,7 @@ public class PullRequestReviewProcessing implements ProcessingData<Message> {
// MessageUtils.pullRequestForReview(pullRequests) // MessageUtils.pullRequestForReview(pullRequests)
// .orElse("Все ПР проверены :)") // .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.PersonInformation;
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.filter.MergeRequestFilter; 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.MergeRequestsService;
import dev.struchkov.bot.gitlab.context.service.NoteService; import dev.struchkov.bot.gitlab.context.service.NoteService;
import dev.struchkov.bot.gitlab.core.config.properties.GitlabProperty; import dev.struchkov.bot.gitlab.core.config.properties.GitlabProperty;
import dev.struchkov.bot.gitlab.core.service.parser.ProjectParser; import dev.struchkov.bot.gitlab.core.service.parser.ProjectParser;
import dev.struchkov.godfather.context.domain.BoxAnswer; import dev.struchkov.bot.gitlab.telegram.utils.UnitName;
import dev.struchkov.godfather.context.domain.content.Message; import dev.struchkov.godfather.main.domain.annotation.Unit;
import dev.struchkov.godfather.context.domain.keyboard.KeyBoard; import dev.struchkov.godfather.main.domain.content.Mail;
import dev.struchkov.godfather.context.domain.keyboard.KeyBoardLine; import dev.struchkov.godfather.simple.core.unit.AnswerText;
import dev.struchkov.godfather.context.domain.keyboard.button.KeyBoardButtonText; import dev.struchkov.godfather.simple.core.unit.MainUnit;
import dev.struchkov.godfather.context.utils.KeyBoards; import lombok.RequiredArgsConstructor;
import dev.struchkov.godfather.core.domain.unit.AnswerText; import org.springframework.data.domain.Page;
import dev.struchkov.haiti.context.page.Sheet; import org.springframework.data.domain.PageRequest;
import dev.struchkov.haiti.context.page.impl.PaginationImpl; import org.springframework.stereotype.Component;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.Arrays; import java.util.Arrays;
@ -27,123 +24,106 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; 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 Добавить описание. * // TODO: 16.01.2021 Добавить описание.
* *
* @author upagge 16.01.2021 * @author upagge 16.01.2021
*/ */
@Configuration @Component
@RequiredArgsConstructor
public class MenuConfig { public class MenuConfig {
@Bean private final ProjectParser projectParser;
public AnswerText<Message> menu( private final GitlabProperty gitlabProperty;
AppSettingService settingService, private final PersonInformation personInformation;
AnswerText<Message> settings, private final NoteService noteService;
AnswerText<Message> textAddNewProject, private final MergeRequestsService mergeRequestsService;
AnswerText<Message> getTasks,
AnswerText<Message> getAssigneeMergeRequest @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() return AnswerText.<Mail>builder()
.boxAnswer(message -> .answer(boxAnswer(
{ "This is the bot menu, select a new item",
final KeyBoardButtonText newMr = KeyBoardButtonText.builder().label(settingService.getMessage("ui.menu.add_mr")).build(); inlineKeyBoard(
final KeyBoardButtonText tasks = KeyBoardButtonText.builder().label(settingService.getMessage("ui.menu.task")).build(); simpleLine(simpleButton("Add project", TEXT_ADD_NEW_PROJECT)),
final KeyBoardButtonText pr = KeyBoardButtonText.builder().label(settingService.getMessage("ui.menu.mr")).build(); simpleLine(
final KeyBoardButtonText settingsKeyBoard = KeyBoardButtonText.builder().label(settingService.getMessage("ui.menu.setting")).build(); simpleButton("My tasks", GET_TASKS),
simpleButton("Merge Request", GET_ASSIGNEE_MERGE_REQUEST)
final KeyBoardLine oneLine = KeyBoardLine.builder() ),
.buttonKeyBoard(newMr) simpleLine(simpleButton("Settings", SETTINGS))
.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();
}
) )
.nextUnit(settings) .next(settings)
.nextUnit(textAddNewProject) .next(textAddNewProject)
.nextUnit(getTasks) .next(getTasks)
.nextUnit(getAssigneeMergeRequest) .next(getAssigneeMergeRequest)
.build(); .build();
} }
@Bean @Unit(TEXT_ADD_NEW_PROJECT)
public AnswerText<Message> textAddNewProject( public AnswerText<Mail> textAddNewProject(
AppSettingService settingService, @Unit(ADD_NEW_PROJECT) MainUnit<Mail> addNewProject
AnswerText<Message> addNewProject
) { ) {
return AnswerText.builder() return AnswerText.<Mail>builder()
.boxAnswer(BoxAnswer.processing(settingService.getMessage("ui.menu.add_mr.text"))) .triggerPhrase(TEXT_ADD_NEW_PROJECT)
.phrase(settingService.getMessage("ui.menu.add_mr")) .answer(boxAnswer("Copy the url of the project and send it to me"))
.nextUnit(addNewProject) .next(addNewProject)
.build(); .build();
} }
@Bean @Unit(ADD_NEW_PROJECT)
public AnswerText<Message> addNewProject( public AnswerText<Mail> addNewProject() {
AppSettingService settingService, return AnswerText.<Mail>builder()
ProjectParser projectParser, .answer(mail -> {
GitlabProperty gitlabProperty final List<String> urlList = Arrays.stream(mail.getText().split("/")).toList();
) {
return AnswerText.builder()
.boxAnswer(message -> {
final List<String> urlList = Arrays.stream(message.getText().split("/")).toList();
int lastElement = urlList.size() - 1; int lastElement = urlList.size() - 1;
final String projectUrl = MessageFormat.format(gitlabProperty.getUrlMergeRequestAdd(), urlList.get(lastElement - 1), urlList.get(lastElement)); final String projectUrl = MessageFormat.format(gitlabProperty.getUrlMergeRequestAdd(), urlList.get(lastElement - 1), urlList.get(lastElement));
projectParser.parseByUrl(projectUrl); projectParser.parseByUrl(projectUrl);
return BoxAnswer.of(settingService.getMessage("menu.add_project_success")); return boxAnswer("Project added successfully");
}) })
.build(); .build();
} }
@Bean @Unit(SETTINGS)
public AnswerText<Message> settings( public AnswerText<Mail> settings() {
AppSettingService settingService, return AnswerText.<Mail>builder()
AnswerText<Message> settingsLanguage .triggerPhrase(SETTINGS)
) { .answer(
return AnswerText.builder() boxAnswer("This is the settings menu")
.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)
.build(); .build();
} }
@Bean @Unit(GET_TASKS)
public AnswerText<Message> getTasks( public AnswerText<Mail> getTasks() {
AppSettingService settingService, return AnswerText.<Mail>builder()
PersonInformation personInformation, .triggerPhrase(GET_TASKS)
NoteService noteService .answer(
) { () -> {
return AnswerText.builder() final Long userId = personInformation.getId();
.boxAnswer(message -> final String text = noteService.getAllPersonTask(userId, false).stream()
{ .map(note -> MessageFormat.format("- [{0}]({1})", trim(note.getBody()).replace("\n", " "), note.getWebUrl()))
final Long userId = personInformation.getId(); .collect(Collectors.joining("\n"));
final String text = noteService.getAllPersonTask(userId, false).stream() return boxAnswer("".equals(text) ? "No tasks found" : text);
.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"))
.build(); .build();
} }
@ -151,26 +131,22 @@ public class MenuConfig {
return body.length() > 31 ? body.substring(0, 30) : body; return body.length() > 31 ? body.substring(0, 30) : body;
} }
@Bean @Unit(UnitName.GET_ASSIGNEE_MERGE_REQUEST)
public AnswerText<Message> getAssigneeMergeRequest( public AnswerText<Mail> getAssigneeMergeRequest() {
MergeRequestsService mergeRequestsService, return AnswerText.<Mail>builder()
PersonInformation personInformation, .triggerPhrase(GET_ASSIGNEE_MERGE_REQUEST)
AppSettingService settingService .answer(() -> {
) {
return AnswerText.builder()
.boxAnswer(message -> {
final Long userId = personInformation.getId(); 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()) { if (sheet.hasContent()) {
final List<MergeRequest> mergeRequests = sheet.getContent(); final List<MergeRequest> mergeRequests = sheet.getContent();
final String text = mergeRequests.stream() final String text = mergeRequests.stream()
.map(mergeRequest -> MessageFormat.format("[{0}]({1})", mergeRequest.getTitle(), mergeRequest.getWebUrl())) .map(mergeRequest -> MessageFormat.format("[{0}]({1})", mergeRequest.getTitle(), mergeRequest.getWebUrl()))
.collect(Collectors.joining("\n")); .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(); .build();
} }

View File

@ -1,72 +1,85 @@
package dev.struchkov.bot.gitlab.telegram.unit; 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.domain.entity.Note;
import dev.struchkov.bot.gitlab.context.service.AppSettingService; import dev.struchkov.bot.gitlab.context.service.AppSettingService;
import dev.struchkov.bot.gitlab.context.service.DiscussionService; import dev.struchkov.bot.gitlab.context.service.DiscussionService;
import dev.struchkov.bot.gitlab.context.service.NoteService; import dev.struchkov.bot.gitlab.context.service.NoteService;
import dev.struchkov.bot.gitlab.core.service.parser.ProjectParser; import dev.struchkov.bot.gitlab.core.service.parser.ProjectParser;
import dev.struchkov.godfather.context.domain.BoxAnswer; import dev.struchkov.godfather.main.core.unit.UnitActiveType;
import dev.struchkov.godfather.context.domain.content.Mail; import dev.struchkov.godfather.main.domain.BoxAnswer;
import dev.struchkov.godfather.context.domain.content.Message; import dev.struchkov.godfather.main.domain.annotation.Unit;
import dev.struchkov.godfather.context.domain.content.attachment.Attachment; import dev.struchkov.godfather.main.domain.content.Attachment;
import dev.struchkov.godfather.context.domain.content.attachment.AttachmentType; import dev.struchkov.godfather.main.domain.content.Mail;
import dev.struchkov.godfather.context.domain.content.attachment.Link; import dev.struchkov.godfather.simple.core.unit.AnswerCheck;
import dev.struchkov.godfather.context.utils.KeyBoards; import dev.struchkov.godfather.simple.core.unit.AnswerText;
import dev.struchkov.godfather.core.domain.unit.AnswerCheck; import dev.struchkov.godfather.simple.core.unit.MainUnit;
import dev.struchkov.godfather.core.domain.unit.AnswerProcessing; import dev.struchkov.godfather.telegram.domain.attachment.LinkAttachment;
import dev.struchkov.godfather.core.domain.unit.AnswerText; import dev.struchkov.godfather.telegram.domain.attachment.TelegramAttachmentType;
import dev.struchkov.godfather.core.domain.unit.UnitActiveType; import dev.struchkov.godfather.telegram.main.core.util.Attachments;
import dev.struchkov.haiti.context.exception.NotFoundException;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean; import org.springframework.stereotype.Component;
import org.springframework.context.annotation.Configuration;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.List; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; 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: Добавить описание класса. * TODO: Добавить описание класса.
* *
* @author upagge [30.01.2020] * @author upagge [30.01.2020]
*/ */
@Configuration @Component
@RequiredArgsConstructor @RequiredArgsConstructor
public class UnitConfig { public class UnitConfig {
private static final Pattern NOTE_LINK = Pattern.compile("#note_\\d+$"); private static final Pattern NOTE_LINK = Pattern.compile("#note_\\d+$");
@Bean private final AppSettingService settingService;
public AnswerCheck checkFirstStart( private final NoteService noteService;
AppSettingService settingService, private final DiscussionService discussionService;
AnswerText<Message> textCheckLanguage, private final ProjectParser projectParser;
AnswerCheck checkMenuOrAnswer
@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() return AnswerCheck.<Mail>builder()
.check( .check(message -> settingService.isFirstStart())
message -> settingService.isFirstStart()
)
.unitFalse(checkMenuOrAnswer) .unitFalse(checkMenuOrAnswer)
.unitTrue(textCheckLanguage) .unitTrue(textParserPrivateProject)
.build(); .build();
} }
@Bean @Unit(value = CHECK_MENU_OR_ANSWER)
public AnswerCheck checkMenuOrAnswer( public AnswerCheck<Mail> checkMenuOrAnswer(
AnswerText<Message> menu, @Unit(GENERAL_MENU) MainUnit<Mail> menu,
AnswerText<Message> answerNote @Unit(ANSWER_NOTE) MainUnit<Mail> answerNote
) { ) {
return AnswerCheck.builder() return AnswerCheck.<Mail>builder()
.check( .check(
message -> { mail -> {
Mail mail = (Mail) message;
final List<Mail> forwardMails = mail.getForwardMail(); final List<Mail> forwardMails = mail.getForwardMail();
if (forwardMails != null && forwardMails.size() == 1) { if (forwardMails != null && forwardMails.size() == 1) {
final Mail forwardMail = forwardMails.get(0); final Mail forwardMail = forwardMails.get(0);
return forwardMail.getAttachments().stream() return Attachments.findFirstLink(forwardMail.getAttachments()).isPresent();
.anyMatch(attachment -> AttachmentType.LINK.equals(attachment.getType()));
} }
return false; return false;
} }
@ -76,177 +89,134 @@ public class UnitConfig {
.build(); .build();
} }
@Bean @Unit(ANSWER_NOTE)
public AnswerText<Message> answerNote( public AnswerText<Mail> answerNote() {
NoteService noteService, return AnswerText.<Mail>builder()
DiscussionService discussionService .answer(
) { mail -> {
return AnswerText.builder() final List<Attachment> attachments = mail.getForwardMail().get(0).getAttachments();
.boxAnswer(
message -> {
final List<Attachment> attachments = ((Mail) message).getForwardMail().get(0).getAttachments();
for (Attachment attachment : attachments) { for (Attachment attachment : attachments) {
if (AttachmentType.LINK.equals(attachment.getType())) { if (TelegramAttachmentType.LINK.name().equals(attachment.getType())) {
final String url = ((Link) attachment).getUrl(); final String url = ((LinkAttachment) attachment).getUrl();
Matcher matcher = NOTE_LINK.matcher(url); final Matcher matcher = NOTE_LINK.matcher(url);
if (matcher.find()) { if (matcher.find()) {
final String noteText = url.substring(matcher.start(), matcher.end()); final String noteText = url.substring(matcher.start(), matcher.end());
Long noteId = Long.valueOf(noteText.replaceAll("#note_", "")); final Long noteId = Long.valueOf(noteText.replaceAll("#note_", ""));
final Note note = noteService.getById(noteId).orElseThrow(NotFoundException.supplier("Note не найдено")); final Note note = noteService.getByIdOrThrow(noteId);
final String discussionId = note.getDiscussion().getId(); 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(); .build();
} }
@Bean @Unit(TEXT_PARSER_PRIVATE_PROJECT)
public AnswerText<Message> textCheckLanguage( public AnswerText<Mail> textParserPrivateProject(
AnswerProcessing checkLanguage @Unit(CHECK_PARSER_PRIVATE_PROJECT) MainUnit<Mail> checkParserPrivateProject
) { ) {
return AnswerText.builder() return AnswerText.<Mail>builder()
.boxAnswer(message -> .answer(
BoxAnswer.builder() boxAnswer(
.message("Hi :)\n\nLet's choose a language for.") "Start tracking private projects?",
.keyBoard(KeyBoards.verticalDuoMenuString("Русский", "English")) inlineKeyBoard(
.build() simpleLine(
) simpleButton("Yes", "YES"),
.nextUnit(checkLanguage) simpleButton("No", "NO")
.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()
) )
.activeType(UnitActiveType.AFTER) .activeType(UnitActiveType.AFTER)
.nextUnit(checkParserPrivateProject) .next(checkParserPrivateProject)
.build(); .build();
} }
@Bean @Unit(CHECK_PARSER_PRIVATE_PROJECT)
public AnswerCheck checkParserPrivateProject( public AnswerCheck<Mail> checkParserPrivateProject(
AppSettingService appSettingService, @Unit(PARSER_PRIVATE_PROJECT) AnswerText<Mail> parserPrivateProject,
AnswerProcessing parserPrivateProject, @Unit(TEXT_PARSE_OWNER_PROJECT) MainUnit<Mail> textParseOwnerProject
AnswerText<Message> textParseOwnerProject
) { ) {
return AnswerCheck.builder() return AnswerCheck.<Mail>builder()
.check( .check(mail -> "YES".equalsIgnoreCase(mail.getText()))
message -> appSettingService.getMessage("main.yes").equalsIgnoreCase(message.getText())
)
.unitTrue(parserPrivateProject) .unitTrue(parserPrivateProject)
.unitFalse(textParseOwnerProject) .unitFalse(textParseOwnerProject)
.build(); .build();
} }
@Bean @Unit(PARSER_PRIVATE_PROJECT)
public AnswerProcessing parserPrivateProject( public AnswerText<Mail> parserPrivateProject(
ProjectParser projectParser, @Unit(TEXT_PARSE_OWNER_PROJECT) MainUnit<Mail> textParseOwnerProject
AppSettingService settingService,
AnswerText<Message> textParseOwnerProject
) { ) {
return AnswerProcessing.builder() return AnswerText.<Mail>builder()
.processingData(message -> { .answer(() -> {
projectParser.parseAllPrivateProject(); 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(); .build();
} }
@Bean @Unit(TEXT_PARSE_OWNER_PROJECT)
public AnswerText<Message> textParseOwnerProject( public AnswerText<Mail> textParseOwnerProject(
AppSettingService settingService, @Unit(CHECK_PARSE_OWNER_PROJECT) MainUnit<Mail> checkParseOwnerProject
AnswerCheck checkParseOwnerProject
) { ) {
return AnswerText.builder() return AnswerText.<Mail>builder()
.boxAnswer(message -> .answer(
BoxAnswer.builder() boxAnswer(
.message(settingService.getMessage("ui.monitor_owner_projects")) "Start tracking public projects that you own?",
.keyBoard(KeyBoards.verticalDuoMenuString( inlineKeyBoard(
settingService.getMessage("main.yes"), settingService.getMessage("main.no") simpleLine(
)) simpleButton("Yes", "YES"),
.build() simpleButton("No", "NO")
)
)
)
) )
.activeType(UnitActiveType.AFTER) .activeType(UnitActiveType.AFTER)
.nextUnit(checkParseOwnerProject) .next(checkParseOwnerProject)
.build(); .build();
} }
@Bean @Unit(CHECK_PARSE_OWNER_PROJECT)
public AnswerCheck checkParseOwnerProject( public AnswerCheck<Mail> checkParseOwnerProject(
AppSettingService appSettingService, @Unit(PARSE_OWNER_PROJECT) MainUnit<Mail> parseOwnerProject,
AnswerProcessing parseOwnerProject, @Unit(END_SETTING) MainUnit<Mail> endSetting
AnswerProcessing endSetting
) { ) {
return AnswerCheck.builder() return AnswerCheck.<Mail>builder()
.check( .check(message -> "YES".equalsIgnoreCase(message.getText()))
message -> appSettingService.getMessage("main.yes").equalsIgnoreCase(message.getText())
)
.unitTrue(parseOwnerProject) .unitTrue(parseOwnerProject)
.unitFalse(endSetting) .unitFalse(endSetting)
.build(); .build();
} }
@Bean @Unit(PARSE_OWNER_PROJECT)
public AnswerProcessing parseOwnerProject( public AnswerText<Mail> parseOwnerProject(
ProjectParser projectParser, @Unit(END_SETTING) MainUnit<Mail> endSetting
AppSettingService settingService,
AnswerProcessing endSetting
) { ) {
return AnswerProcessing.builder() return AnswerText.<Mail>builder()
.processingData(message -> { .answer(() -> {
projectParser.parseAllProjectOwner(); 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(); .build();
} }
@Bean @Unit(END_SETTING)
public AnswerProcessing endSetting( public AnswerText<Mail> endSetting() {
AppSettingService settingService return AnswerText.<Mail>builder()
) { .answer(
return AnswerProcessing.builder() () -> {
.processingData(
message -> {
settingService.disableFirstStart(); settingService.disableFirstStart();
return BoxAnswer.of(settingService.getMessage("ui.setup_finished")); return boxAnswer("""
Configuration completed successfully
Developer: [uPagge](https://mark.struchkov.dev)
""");
} }
) )
.activeType(UnitActiveType.AFTER) .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();
}
}