diff --git a/bot-context/pom.xml b/bot-context/pom.xml
index ca2154b..45bc7fa 100644
--- a/bot-context/pom.xml
+++ b/bot-context/pom.xml
@@ -6,13 +6,22 @@
dev.struchkov.bot.gitlab
gitlab-bot
- 1.0.0
+ 1.1.0
bot-context
- ${gitlab.context.version}
+
+ dev.struchkov.haiti.utils
+ haiti-utils-field-constants
+
+
+
+ org.springframework.data
+ spring-data-jpa
+
+
org.projectlombok
lombok
@@ -20,7 +29,7 @@
dev.struchkov.haiti
- haiti-context
+ haiti-utils
@@ -32,11 +41,6 @@
javax.persistence
javax.persistence-api
-
-
- org.hibernate.orm
- hibernate-jpamodelgen
-
\ No newline at end of file
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/AppLocale.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/AppLocale.java
deleted file mode 100644
index f4821de..0000000
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/AppLocale.java
+++ /dev/null
@@ -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());
- }
-
-}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/ExistsContainer.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/ExistsContainer.java
new file mode 100644
index 0000000..be81a33
--- /dev/null
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/ExistsContainer.java
@@ -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 {
+
+ protected final Collection container;
+ protected final boolean allFound;
+ protected final Collection idNoFound;
+
+ protected ExistsContainer(Collection container, boolean allFound, Collection idNoFound) {
+ this.container = container;
+ this.allFound = allFound;
+ this.idNoFound = idNoFound;
+ }
+
+ public static ExistsContainer allFind(@NonNull Collection container) {
+ return new ExistsContainer<>(container, true, Collections.emptyList());
+ }
+
+ public static ExistsContainer notAllFind(@NonNull Collection container, @NonNull Collection idNoFound) {
+ return new ExistsContainer<>(container, false, idNoFound);
+ }
+
+ public Collection getContainer() {
+ return container;
+ }
+
+ public boolean isAllFound() {
+ return allFound;
+ }
+
+ public Collection getIdNoFound() {
+ return idNoFound;
+ }
+
+}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/PersonInformation.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/PersonInformation.java
index 362753e..c95a4ea 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/PersonInformation.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/PersonInformation.java
@@ -13,6 +13,6 @@ public class PersonInformation {
private String username;
private String name;
private Long id;
- private Long telegramId;
+ private String telegramId;
}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/AppSetting.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/AppSetting.java
index 9a6ba7a..cf10d74 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/AppSetting.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/AppSetting.java
@@ -1,14 +1,10 @@
package dev.struchkov.bot.gitlab.context.domain.entity;
-import dev.struchkov.haiti.context.domain.BasicEntity;
import lombok.Getter;
import lombok.Setter;
-import dev.struchkov.bot.gitlab.context.domain.AppLocale;
import javax.persistence.Column;
import javax.persistence.Entity;
-import javax.persistence.EnumType;
-import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Table;
@@ -21,16 +17,12 @@ import javax.persistence.Table;
@Getter
@Setter
@Table(name = "app_setting")
-public class AppSetting implements BasicEntity {
+public class AppSetting {
@Id
@Column(name = "id")
private Long id;
- @Column(name = "language")
- @Enumerated(EnumType.STRING)
- private AppLocale appLocale;
-
@Column(name = "first_start")
private boolean firstStart;
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Discussion.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Discussion.java
index e8f4638..2887848 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Discussion.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Discussion.java
@@ -1,6 +1,5 @@
package dev.struchkov.bot.gitlab.context.domain.entity;
-import dev.struchkov.haiti.context.domain.BasicEntity;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@@ -25,7 +24,7 @@ import java.util.List;
@Entity
@Table(name = "discussion")
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
-public class Discussion implements BasicEntity {
+public class Discussion {
@Id
@Column(name = "id")
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/MergeRequest.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/MergeRequest.java
index 6e207d7..92038d9 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/MergeRequest.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/MergeRequest.java
@@ -1,10 +1,10 @@
package dev.struchkov.bot.gitlab.context.domain.entity;
-import dev.struchkov.haiti.context.domain.BasicEntity;
+import dev.struchkov.bot.gitlab.context.domain.MergeRequestState;
+import dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
-import dev.struchkov.bot.gitlab.context.domain.MergeRequestState;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
@@ -28,9 +28,10 @@ import java.util.Set;
@Getter
@Setter
@Entity
+@FieldNames
@Table(name = "merge_request")
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
-public class MergeRequest implements BasicEntity {
+public class MergeRequest {
@Id
@Column(name = "id")
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Note.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Note.java
index 6982974..504d3d0 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Note.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Note.java
@@ -1,6 +1,5 @@
package dev.struchkov.bot.gitlab.context.domain.entity;
-import dev.struchkov.haiti.context.domain.BasicEntity;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@@ -18,7 +17,7 @@ import java.time.LocalDateTime;
@Entity
@Table(name = "note")
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
-public class Note implements BasicEntity {
+public class Note {
@Id
@Column
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Person.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Person.java
index 5b26571..21ba442 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Person.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Person.java
@@ -1,6 +1,5 @@
package dev.struchkov.bot.gitlab.context.domain.entity;
-import dev.struchkov.haiti.context.domain.BasicEntity;
import lombok.Getter;
import lombok.Setter;
@@ -16,7 +15,7 @@ import javax.persistence.Table;
@Getter
@Setter
@Table(name = "person")
-public class Person implements BasicEntity {
+public class Person {
@Id
@Column(name = "id")
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Pipeline.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Pipeline.java
index 83f9ffe..2270802 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Pipeline.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Pipeline.java
@@ -1,7 +1,7 @@
package dev.struchkov.bot.gitlab.context.domain.entity;
import dev.struchkov.bot.gitlab.context.domain.PipelineStatus;
-import dev.struchkov.haiti.context.domain.BasicEntity;
+import dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@@ -23,9 +23,10 @@ import java.time.LocalDateTime;
@Entity
@Getter
@Setter
+@FieldNames
@Table(name = "pipeline")
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
-public class Pipeline implements BasicEntity {
+public class Pipeline {
@Id
@Column(name = "id")
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Project.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Project.java
index 196cc7e..5780992 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Project.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Project.java
@@ -1,6 +1,5 @@
package dev.struchkov.bot.gitlab.context.domain.entity;
-import dev.struchkov.haiti.context.domain.BasicEntity;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@@ -19,7 +18,7 @@ import java.time.LocalDateTime;
@Entity
@Table(name = "project")
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
-public class Project implements BasicEntity {
+public class Project {
@Id
@Column(name = "id")
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/GoodMorningNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/GoodMorningNotify.java
index acc9539..aad6c68 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/GoodMorningNotify.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/GoodMorningNotify.java
@@ -27,7 +27,7 @@ public record GoodMorningNotify(
}
@Override
- public String generateMessage(AppSettingService settingService) {
+ public String generateMessage() {
final StringBuilder message = new StringBuilder().append(Smile.SUN).append(" *Доброе утро, ").append(personName).append("* ").append(Smile.SUN).append(Smile.TWO_BR);
if (!mergeRequestsReviews.isEmpty()) {
message.append("Необходимо проверить ").append(mergeRequestsReviews.size()).append(" ПР:").append(Smile.BR);
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/NewProjectNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/NewProjectNotify.java
index 524247c..436578d 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/NewProjectNotify.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/NewProjectNotify.java
@@ -1,16 +1,16 @@
package dev.struchkov.bot.gitlab.context.domain.notify;
-import dev.struchkov.bot.gitlab.context.service.AppSettingService;
import dev.struchkov.bot.gitlab.context.utils.Smile;
import dev.struchkov.haiti.utils.Strings;
import lombok.Builder;
+import java.text.MessageFormat;
+
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
/**
* @author upagge 15.01.2021
*/
-
public record NewProjectNotify(
String projectName,
String projectUrl,
@@ -23,9 +23,9 @@ public record NewProjectNotify(
}
@Override
- public String generateMessage(AppSettingService settingService) {
- return settingService.getMessage(
- "notify.project.new",
+ public String generateMessage() {
+ return MessageFormat.format(
+ "{0} *New project*{1}[{2}]({3}){1}{4}{5}: {6}",
Smile.FUN.getValue(), Smile.HR.getValue(), projectName, projectUrl,
(projectDescription != null && !"".equals(projectDescription)) ? escapeMarkdown(projectDescription) + Smile.HR : Strings.EMPTY,
Smile.AUTHOR.getValue(), authorName
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/Notify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/Notify.java
index b09c2ac..6c1bb37 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/Notify.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/Notify.java
@@ -1,9 +1,7 @@
package dev.struchkov.bot.gitlab.context.domain.notify;
-import dev.struchkov.bot.gitlab.context.service.AppSettingService;
-
public interface Notify {
- String generateMessage(AppSettingService appSettingService);
+ String generateMessage();
}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/SimpleTextNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/SimpleTextNotify.java
index dd81239..4c20a25 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/SimpleTextNotify.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/SimpleTextNotify.java
@@ -1,6 +1,5 @@
package dev.struchkov.bot.gitlab.context.domain.notify;
-import dev.struchkov.bot.gitlab.context.service.AppSettingService;
import lombok.Builder;
/**
@@ -13,7 +12,7 @@ public record SimpleTextNotify(String message) implements Notify {
}
@Override
- public String generateMessage(AppSettingService appSettingService) {
+ public String generateMessage() {
return message;
}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/comment/AnswerCommentNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/comment/AnswerCommentNotify.java
index 93fcee8..951e988 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/comment/AnswerCommentNotify.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/comment/AnswerCommentNotify.java
@@ -34,7 +34,7 @@ public class AnswerCommentNotify implements Notify {
}
@Override
- public String generateMessage(AppSettingService settingService) {
+ public String generateMessage() {
final String answerText = answers.stream()
.map(answer -> answer.getAuthorName() + ": " + answer.getMessage().substring(0, Math.min(answer.getMessage().length(), 500)))
.collect(Collectors.joining(TWO_NEW_LINE));
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/comment/CommentNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/comment/CommentNotify.java
index 1ec4191..1f22e22 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/comment/CommentNotify.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/comment/CommentNotify.java
@@ -1,10 +1,11 @@
package dev.struchkov.bot.gitlab.context.domain.notify.comment;
import dev.struchkov.bot.gitlab.context.domain.notify.Notify;
-import dev.struchkov.bot.gitlab.context.service.AppSettingService;
import dev.struchkov.bot.gitlab.context.utils.Smile;
import lombok.Builder;
+import java.text.MessageFormat;
+
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
public record CommentNotify(
@@ -18,9 +19,9 @@ public record CommentNotify(
}
@Override
- public String generateMessage(AppSettingService settingService) {
- return settingService.getMessage(
- "notify.comment.bell",
+ public String generateMessage() {
+ return MessageFormat.format(
+ "{0} *New mention* | [MR]({1}){2}*{3}*: {4}",
Smile.COMMENT.getValue(), url, Smile.HR.getValue(), authorName, escapeMarkdown(message)
);
}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pipeline/PipelineNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pipeline/PipelineNotify.java
index 99f0a63..28e7be1 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pipeline/PipelineNotify.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pipeline/PipelineNotify.java
@@ -1,7 +1,6 @@
package dev.struchkov.bot.gitlab.context.domain.notify.pipeline;
import dev.struchkov.bot.gitlab.context.domain.notify.Notify;
-import dev.struchkov.bot.gitlab.context.service.AppSettingService;
import dev.struchkov.bot.gitlab.context.utils.Smile;
import lombok.Builder;
@@ -26,9 +25,9 @@ public record PipelineNotify(
}
@Override
- public String generateMessage(AppSettingService appSettingService) {
+ public String generateMessage() {
return MessageFormat.format(
- appSettingService.getMessage("notify.pipeline"),
+ "{0} *Pipeline {1,number,#}* | {2}{3}[{4}]({5}){3}{6} {7} {8}",
Smile.BUILD,
pipelineId,
escapeMarkdown(projectName),
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/ConflictPrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/ConflictPrNotify.java
index 66805bf..4dae705 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/ConflictPrNotify.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/ConflictPrNotify.java
@@ -1,9 +1,10 @@
package dev.struchkov.bot.gitlab.context.domain.notify.pullrequest;
+import dev.struchkov.bot.gitlab.context.utils.Smile;
import lombok.Builder;
import lombok.Getter;
-import dev.struchkov.bot.gitlab.context.service.AppSettingService;
-import dev.struchkov.bot.gitlab.context.utils.Smile;
+
+import java.text.MessageFormat;
@Getter
public class ConflictPrNotify extends PrNotify {
@@ -22,9 +23,9 @@ public class ConflictPrNotify extends PrNotify {
}
@Override
- public String generateMessage(AppSettingService settingService) {
- return settingService.getMessage(
- "notify.pr.conflict",
+ public String generateMessage() {
+ return MessageFormat.format(
+ "{0} *Attention! MergeRequest conflict | {4}*{1}[{2}]({3})",
Smile.DANGEROUS.getValue(), Smile.HR.getValue(), title, url, projectName, sourceBranch
);
}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/ForgottenSmartPrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/ForgottenSmartPrNotify.java
index 269025e..a45a6c9 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/ForgottenSmartPrNotify.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/ForgottenSmartPrNotify.java
@@ -3,7 +3,8 @@ package dev.struchkov.bot.gitlab.context.domain.notify.pullrequest;
import dev.struchkov.bot.gitlab.context.utils.Smile;
import lombok.Builder;
import lombok.Getter;
-import dev.struchkov.bot.gitlab.context.service.AppSettingService;
+
+import java.text.MessageFormat;
/**
* // TODO: 11.10.2020 Добавить описание.
@@ -25,9 +26,9 @@ public class ForgottenSmartPrNotify extends PrNotify {
}
@Override
- public String generateMessage(AppSettingService appSettingService) {
- return appSettingService.getMessage(
- "notify.pr.forgotten",
+ public String generateMessage() {
+ return MessageFormat.format(
+ "{0} *MergeRequest Review Reminder | {4}*{3}[{1}]({2})",
Smile.SMART.getValue(), title, url, Smile.HR.getValue(), projectName
);
}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/NewPrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/NewPrNotify.java
index aba542e..5fbd1b2 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/NewPrNotify.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/NewPrNotify.java
@@ -1,11 +1,11 @@
package dev.struchkov.bot.gitlab.context.domain.notify.pullrequest;
+import dev.struchkov.bot.gitlab.context.utils.Smile;
import dev.struchkov.haiti.utils.Strings;
import lombok.Builder;
import lombok.Getter;
-import dev.struchkov.bot.gitlab.context.service.AppSettingService;
-import dev.struchkov.bot.gitlab.context.utils.Smile;
+import java.text.MessageFormat;
import java.util.Set;
import java.util.stream.Collectors;
@@ -40,15 +40,15 @@ public class NewPrNotify extends PrNotify {
}
@Override
- public String generateMessage(AppSettingService settingService) {
+ public String generateMessage() {
String labelText = labels.stream()
.map(label -> "#" + label)
.collect(Collectors.joining(" "));
if (!labelText.isEmpty()) {
labelText = "\n\n" + labelText;
}
- return settingService.getMessage(
- "notify.pr.new",
+ return MessageFormat.format(
+ "{0} *New MergeRequest | {1}*{2}[{3}]({4}){5}{2}{9}: {10} {12} {11}",
Smile.FUN.getValue(),
projectName,
Smile.HR.getValue(),
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/StatusPrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/StatusPrNotify.java
index 650bd14..7c0b2c2 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/StatusPrNotify.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/StatusPrNotify.java
@@ -6,6 +6,8 @@ import dev.struchkov.bot.gitlab.context.domain.MergeRequestState;
import dev.struchkov.bot.gitlab.context.service.AppSettingService;
import dev.struchkov.bot.gitlab.context.utils.Smile;
+import java.text.MessageFormat;
+
@Getter
public class StatusPrNotify extends PrNotify {
@@ -26,9 +28,9 @@ public class StatusPrNotify extends PrNotify {
}
@Override
- public String generateMessage(AppSettingService settingService) {
- return settingService.getMessage(
- "notify.pr.state",
+ public String generateMessage() {
+ return MessageFormat.format(
+ "{0} *MergeRequest status changed | {7}*{1}[{2}]({3}){1}{4} {5} {6}",
Smile.PEN.getValue(), Smile.HR.getValue(), title, url, oldStatus.name(), Smile.ARROW.getValue(), newStatus.name(), projectName
);
}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/UpdatePrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/UpdatePrNotify.java
index 3dbf187..99a30b0 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/UpdatePrNotify.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pullrequest/UpdatePrNotify.java
@@ -3,7 +3,8 @@ package dev.struchkov.bot.gitlab.context.domain.notify.pullrequest;
import dev.struchkov.bot.gitlab.context.utils.Smile;
import lombok.Builder;
import lombok.Getter;
-import dev.struchkov.bot.gitlab.context.service.AppSettingService;
+
+import java.text.MessageFormat;
@Getter
public class UpdatePrNotify extends PrNotify {
@@ -34,9 +35,9 @@ public class UpdatePrNotify extends PrNotify {
}
@Override
- public String generateMessage(AppSettingService settingService) {
- return settingService.getMessage(
- "notify.pr.update",
+ public String generateMessage() {
+ return MessageFormat.format(
+ "{0} *MergeRequest update | {6}*{3}[{1}]({2}){3}{4}: {5}",
Smile.UPDATE.getValue(), title, url, Smile.HR.getValue(), Smile.AUTHOR.getValue(), author, projectName, allTasks, allResolvedTasks, personTasks, personResolvedTasks
);
}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/TaskCloseNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/TaskCloseNotify.java
index b4bfb28..776d5b1 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/TaskCloseNotify.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/TaskCloseNotify.java
@@ -1,9 +1,10 @@
package dev.struchkov.bot.gitlab.context.domain.notify.task;
-import dev.struchkov.bot.gitlab.context.service.AppSettingService;
import dev.struchkov.bot.gitlab.context.utils.Smile;
import lombok.Builder;
+import java.text.MessageFormat;
+
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
/**
@@ -28,9 +29,9 @@ public class TaskCloseNotify extends TaskNotify {
}
@Override
- public String generateMessage(AppSettingService settingService) {
- return settingService.getMessage(
- "notify.task.close",
+ public String generateMessage() {
+ return MessageFormat.format(
+ "{0} *Closed [task]({1}){2}*{3}*: {4}",
Smile.TASK.getValue(), url, Smile.HR.getValue(), authorName, escapeMarkdown(messageTask), personTasks, personResolvedTasks
);
}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/TaskNewNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/TaskNewNotify.java
index 2f56056..8066f57 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/TaskNewNotify.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/TaskNewNotify.java
@@ -1,10 +1,11 @@
package dev.struchkov.bot.gitlab.context.domain.notify.task;
-import dev.struchkov.bot.gitlab.context.service.AppSettingService;
import dev.struchkov.bot.gitlab.context.utils.Smile;
import lombok.Builder;
import lombok.Getter;
+import java.text.MessageFormat;
+
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
/**
@@ -23,9 +24,9 @@ public class TaskNewNotify extends TaskNotify {
}
@Override
- public String generateMessage(AppSettingService settingService) {
- return settingService.getMessage(
- "notify.task.new",
+ public String generateMessage() {
+ return MessageFormat.format(
+ "{0} *New [task]({1}) assigned{2}*{3}*: {4}",
Smile.TASK.getValue(), url, Smile.HR.getValue(), authorName, escapeMarkdown(messageTask)
);
}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/AppSettingRepository.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/AppSettingRepository.java
index 5fba2ef..00aaf16 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/AppSettingRepository.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/AppSettingRepository.java
@@ -1,11 +1,15 @@
package dev.struchkov.bot.gitlab.context.repository;
import dev.struchkov.bot.gitlab.context.domain.entity.AppSetting;
-import dev.struchkov.haiti.context.repository.SimpleManagerRepository;
+
+import java.util.Optional;
/**
* @author upagge 16.01.2021
*/
-public interface AppSettingRepository extends SimpleManagerRepository {
+public interface AppSettingRepository {
+ AppSetting save(AppSetting appSetting);
+
+ Optional findById(Long key);
}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/DiscussionRepository.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/DiscussionRepository.java
index 4bad62d..986d71b 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/DiscussionRepository.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/DiscussionRepository.java
@@ -1,19 +1,31 @@
package dev.struchkov.bot.gitlab.context.repository;
import dev.struchkov.bot.gitlab.context.domain.entity.Discussion;
-import dev.struchkov.haiti.context.repository.SimpleManagerRepository;
-import lombok.NonNull;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import java.util.List;
+import java.util.Optional;
+import java.util.Set;
/**
* @author upagge 11.02.2021
*/
-public interface DiscussionRepository extends SimpleManagerRepository {
+public interface DiscussionRepository {
/**
* Вернуть все дискусии для MR
*/
- List findAllByMergeRequestId(@NonNull Long mergeRequestId);
+ List findAllByMergeRequestId(Long mergeRequestId);
+
+ Discussion save(Discussion discussion);
+
+ Optional findById(String discussionId);
+
+ void deleteById(String discussionId);
+
+ Page findAll(Pageable pagination);
+
+ List findAllById(Set discussionIds);
}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/MergeRequestRepository.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/MergeRequestRepository.java
index e7d5c3a..cbe8d6a 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/MergeRequestRepository.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/MergeRequestRepository.java
@@ -3,18 +3,31 @@ package dev.struchkov.bot.gitlab.context.repository;
import dev.struchkov.bot.gitlab.context.domain.IdAndStatusPr;
import dev.struchkov.bot.gitlab.context.domain.MergeRequestState;
import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest;
-import dev.struchkov.haiti.context.repository.SimpleManagerRepository;
-import dev.struchkov.haiti.filter.FilterOperation;
+import dev.struchkov.haiti.filter.Filter;
import lombok.NonNull;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import java.util.List;
+import java.util.Optional;
import java.util.Set;
-public interface MergeRequestRepository extends SimpleManagerRepository, FilterOperation {
+public interface MergeRequestRepository {
Set findAllIdByStateIn(@NonNull Set states);
//TODO [28.01.2022]: Решить, нужно ли оставить
List findAllByAssignee(@NonNull Long userId);
+ MergeRequest save(MergeRequest mergeRequest);
+
+ Optional findById(Long mergeRequestId);
+
+ Page findAll(Pageable pagination);
+
+ List findAllById(Set mergeRequestIds);
+
+ void deleteByIds(Set mergeRequestIds);
+
+ Page filter(Filter filter, Pageable pageable);
}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/NoteRepository.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/NoteRepository.java
index 940b41a..9fab3b7 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/NoteRepository.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/NoteRepository.java
@@ -1,20 +1,20 @@
package dev.struchkov.bot.gitlab.context.repository;
import dev.struchkov.bot.gitlab.context.domain.entity.Note;
-import dev.struchkov.haiti.context.page.Pagination;
-import dev.struchkov.haiti.context.page.Sheet;
-import dev.struchkov.haiti.context.repository.SimpleManagerRepository;
-import lombok.NonNull;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import java.util.List;
+import java.util.Optional;
/**
* @author upagge 08.09.2020
*/
-public interface NoteRepository extends SimpleManagerRepository {
+public interface NoteRepository {
- List findAllByResponsibleIdAndResolved(@NonNull Long userId, boolean resolved);
+ List findAllByResponsibleIdAndResolved(Long userId, boolean resolved);
- Sheet findAllByResolved(boolean resolved, @NonNull Pagination pagination);
+ Page findAllByResolved(boolean resolved, Pageable pagination);
+ Optional findById(Long noteId);
}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/PersonRepository.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/PersonRepository.java
index 70897ec..1cbe322 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/PersonRepository.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/PersonRepository.java
@@ -1,11 +1,20 @@
package dev.struchkov.bot.gitlab.context.repository;
import dev.struchkov.bot.gitlab.context.domain.entity.Person;
-import dev.struchkov.haiti.context.repository.SimpleManagerRepository;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
/**
* @author upagge 15.01.2021
*/
-public interface PersonRepository extends SimpleManagerRepository {
+public interface PersonRepository {
+
+ Person save(Person person);
+
+ Optional findById(Long personId);
+
+ List findAllById(Set personIds);
}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/PipelineRepository.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/PipelineRepository.java
index a0b43c6..4ec5d97 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/PipelineRepository.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/PipelineRepository.java
@@ -2,19 +2,29 @@ package dev.struchkov.bot.gitlab.context.repository;
import dev.struchkov.bot.gitlab.context.domain.PipelineStatus;
import dev.struchkov.bot.gitlab.context.domain.entity.Pipeline;
-import dev.struchkov.haiti.context.page.Pagination;
-import dev.struchkov.haiti.context.page.Sheet;
-import dev.struchkov.haiti.context.repository.SimpleManagerRepository;
-import dev.struchkov.haiti.filter.FilterOperation;
-import lombok.NonNull;
+import dev.struchkov.haiti.filter.Filter;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import java.util.List;
+import java.util.Optional;
import java.util.Set;
/**
* @author upagge 17.01.2021
*/
-public interface PipelineRepository extends SimpleManagerRepository, FilterOperation {
+public interface PipelineRepository {
- Sheet findAllByStatuses(@NonNull Set statuses, @NonNull Pagination pagination);
+ Pipeline save(Pipeline pipeline);
+
+ Optional findById(Long pipelineId);
+
+ Page findAllByStatuses(Set statuses, Pageable pagination);
+
+ List findAllById(Set pipelineIds);
+
+ void deleteAllByIds(Set pipelineIds);
+
+ Page filter(Filter filter, Pageable pagination);
}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/ProjectRepository.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/ProjectRepository.java
index 114935b..5130554 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/ProjectRepository.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/ProjectRepository.java
@@ -1,11 +1,26 @@
package dev.struchkov.bot.gitlab.context.repository;
import dev.struchkov.bot.gitlab.context.domain.entity.Project;
-import dev.struchkov.haiti.context.repository.SimpleManagerRepository;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
/**
* @author upagge 14.01.2021
*/
-public interface ProjectRepository extends SimpleManagerRepository {
+public interface ProjectRepository {
+
+ Project save(Project project);
+
+ Optional findById(Long projectId);
+
+ List findAllById(Set projectIds);
+
+ boolean existById(Long projectId);
+
+ Page findAllById(Pageable pagination);
}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/AppSettingService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/AppSettingService.java
index ca06ffc..f42eb44 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/AppSettingService.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/AppSettingService.java
@@ -1,8 +1,5 @@
package dev.struchkov.bot.gitlab.context.service;
-import dev.struchkov.bot.gitlab.context.domain.AppLocale;
-import lombok.NonNull;
-
/**
* Сервис отвечает за пользовательские настройки приложения.
*
@@ -24,21 +21,4 @@ public interface AppSettingService {
*/
void disableFirstStart();
- /**
- * Позволяет получить по ключу текст на языке, который установил пользователь
- *
- * @param label ключ сообщений
- * @return Сообщение на языке пользователя
- */
- String getMessage(@NonNull String label);
-
- String getMessage(@NonNull String label, Object... params);
-
- /**
- * Устанавливает язык приложения
- *
- * @param appLocale Язык, который необходимо установить
- */
- void setLocale(@NonNull AppLocale appLocale);
-
}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/DiscussionService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/DiscussionService.java
index b1dc6bf..11707a7 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/DiscussionService.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/DiscussionService.java
@@ -1,15 +1,22 @@
package dev.struchkov.bot.gitlab.context.service;
+import dev.struchkov.bot.gitlab.context.domain.ExistsContainer;
import dev.struchkov.bot.gitlab.context.domain.entity.Discussion;
-import dev.struchkov.haiti.context.service.SimpleManagerService;
import lombok.NonNull;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import java.util.List;
+import java.util.Set;
/**
* @author upagge 11.02.2021
*/
-public interface DiscussionService extends SimpleManagerService {
+public interface DiscussionService {
+
+ Discussion create(@NonNull Discussion discussion);
+
+ Discussion update(@NonNull Discussion discussion);
/**
* Метод отправляющий коментарий в дискуссию.
@@ -24,4 +31,12 @@ public interface DiscussionService extends SimpleManagerService getAllByMergeRequestId(@NonNull Long mergeRequestId);
+ ExistsContainer existsById(@NonNull Set discussionIds);
+
+ List createAll(@NonNull List newDiscussions);
+
+ Page getAll(@NonNull Pageable pagination);
+
+ void deleteById(String discussionId);
+
}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/MergeRequestsService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/MergeRequestsService.java
index ec5453d..91172bc 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/MergeRequestsService.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/MergeRequestsService.java
@@ -1,15 +1,22 @@
package dev.struchkov.bot.gitlab.context.service;
+import dev.struchkov.bot.gitlab.context.domain.ExistsContainer;
import dev.struchkov.bot.gitlab.context.domain.IdAndStatusPr;
import dev.struchkov.bot.gitlab.context.domain.MergeRequestState;
import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest;
-import dev.struchkov.haiti.context.service.SimpleManagerService;
-import dev.struchkov.haiti.context.service.simple.FilterService;
import dev.struchkov.bot.gitlab.context.domain.filter.MergeRequestFilter;
+import lombok.NonNull;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import java.util.List;
import java.util.Set;
-public interface MergeRequestsService extends SimpleManagerService, FilterService {
+public interface MergeRequestsService {
+
+ MergeRequest create(@NonNull MergeRequest mergeRequest);
+
+ MergeRequest update(@NonNull MergeRequest mergeRequest);
/**
* Получить все идентификаторы вместе со статусами.
@@ -19,4 +26,14 @@ public interface MergeRequestsService extends SimpleManagerService getAllId(Set statuses);
+ Page getAll(Pageable pagination);
+
+ Page getAll(@NonNull MergeRequestFilter filter, Pageable pagination);
+
+ ExistsContainer existsById(@NonNull Set mergeRequestIds);
+
+ List createAll(List newMergeRequests);
+
+ void deleteAllById(@NonNull Set mergeRequestIds);
+
}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/NoteService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/NoteService.java
index 7ac56a9..420dd5c 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/NoteService.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/NoteService.java
@@ -1,18 +1,19 @@
package dev.struchkov.bot.gitlab.context.service;
import dev.struchkov.bot.gitlab.context.domain.entity.Note;
-import dev.struchkov.haiti.context.page.Pagination;
-import dev.struchkov.haiti.context.page.Sheet;
-import dev.struchkov.haiti.context.service.SimpleManagerService;
import lombok.NonNull;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import java.util.List;
-public interface NoteService extends SimpleManagerService {
+public interface NoteService {
List getAllPersonTask(@NonNull Long userId, boolean resolved);
//TODO [28.01.2022]: Решить нужно ли оставлять
- Sheet getAllByResolved(boolean resolved, @NonNull Pagination pagination);
+ Page getAllByResolved(boolean resolved, @NonNull Pageable pagination);
+
+ Note getByIdOrThrow(@NonNull Long noteId);
}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PersonService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PersonService.java
index ef59913..2fd6772 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PersonService.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PersonService.java
@@ -1,11 +1,25 @@
package dev.struchkov.bot.gitlab.context.service;
+import dev.struchkov.bot.gitlab.context.domain.ExistsContainer;
import dev.struchkov.bot.gitlab.context.domain.entity.Person;
-import dev.struchkov.haiti.context.service.SimpleManagerService;
+import lombok.NonNull;
+
+import java.util.List;
+import java.util.Set;
/**
* @author upagge 15.01.2021
*/
-public interface PersonService extends SimpleManagerService {
+public interface PersonService {
+
+ Person create(@NonNull Person person);
+
+ Person update(@NonNull Person person);
+
+ Person getByIdOrThrown(@NonNull Long personId);
+
+ ExistsContainer existsById(Set personIds);
+
+ List createAll(List newPersons);
}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PipelineService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PipelineService.java
index 6410855..f2ceacd 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PipelineService.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PipelineService.java
@@ -3,11 +3,10 @@ package dev.struchkov.bot.gitlab.context.service;
import dev.struchkov.bot.gitlab.context.domain.PipelineStatus;
import dev.struchkov.bot.gitlab.context.domain.entity.Pipeline;
import dev.struchkov.bot.gitlab.context.domain.filter.PipelineFilter;
-import dev.struchkov.haiti.context.page.Pagination;
-import dev.struchkov.haiti.context.page.Sheet;
-import dev.struchkov.haiti.context.service.SimpleManagerService;
-import dev.struchkov.haiti.context.service.simple.FilterService;
+import dev.struchkov.haiti.context.domain.ExistsContainer;
import lombok.NonNull;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import java.util.Set;
@@ -16,8 +15,18 @@ import java.util.Set;
*
* @author upagge 17.01.2021
*/
-public interface PipelineService extends SimpleManagerService, FilterService {
+public interface PipelineService {
- Sheet getAllByStatuses(@NonNull Set statuses, @NonNull Pagination pagination);
+ Pipeline create(@NonNull Pipeline pipeline);
+
+ Pipeline update(@NonNull Pipeline pipeline);
+
+ Page getAllByStatuses(@NonNull Set statuses, @NonNull Pageable pagination);
+
+ Page getAll(@NonNull PipelineFilter filter, @NonNull Pageable pagination);
+
+ ExistsContainer existsById(@NonNull Set pipelineIds);
+
+ void deleteAllById(Set pipelineIds);
}
diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/ProjectService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/ProjectService.java
index b6ffd59..8b23c4a 100644
--- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/ProjectService.java
+++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/ProjectService.java
@@ -1,11 +1,31 @@
package dev.struchkov.bot.gitlab.context.service;
+import dev.struchkov.bot.gitlab.context.domain.ExistsContainer;
import dev.struchkov.bot.gitlab.context.domain.entity.Project;
-import dev.struchkov.haiti.context.service.SimpleManagerService;
+import lombok.NonNull;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+
+import java.util.List;
+import java.util.Set;
/**
* @author upagge 14.01.2021
*/
-public interface ProjectService extends SimpleManagerService {
+public interface ProjectService {
+
+ Project create(@NonNull Project project);
+
+ Project update(@NonNull Project project);
+
+ Project getByIdOrThrow(@NonNull Long projectId);
+
+ Page getAll(@NonNull Pageable pagination);
+
+ List createAll(List newProjects);
+
+ boolean existsById(Long projectId);
+
+ ExistsContainer existsById(Set projectIds);
}
diff --git a/bot-core/pom.xml b/bot-core/pom.xml
index ba56b45..8b895f9 100644
--- a/bot-core/pom.xml
+++ b/bot-core/pom.xml
@@ -6,11 +6,10 @@
dev.struchkov.bot.gitlab
gitlab-bot
- 1.0.0
+ 1.1.0
bot-core
- ${gitlab.core.version}
@@ -23,16 +22,6 @@
bot-context
-
- dev.struchkov.haiti.data
- haiti-database
-
-
-
- org.hibernate.orm
- hibernate-jpamodelgen
-
-
org.springframework.boot
spring-boot-configuration-processor
diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/config/properties/PersonProperty.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/config/properties/PersonProperty.java
index 6a66c86..3d9d9f0 100644
--- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/config/properties/PersonProperty.java
+++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/config/properties/PersonProperty.java
@@ -16,6 +16,6 @@ import org.springframework.context.annotation.Configuration;
public class PersonProperty {
private String token;
- private Long telegramId;
+ private String telegramId;
}
diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/convert/MergeRequestJsonConverter.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/convert/MergeRequestJsonConverter.java
index 804aac2..820ffdb 100644
--- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/convert/MergeRequestJsonConverter.java
+++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/convert/MergeRequestJsonConverter.java
@@ -4,11 +4,15 @@ import dev.struchkov.bot.gitlab.context.domain.MergeRequestState;
import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest;
import dev.struchkov.bot.gitlab.sdk.domain.MergeRequestJson;
import dev.struchkov.bot.gitlab.sdk.domain.MergeRequestStateJson;
-import dev.struchkov.haiti.context.exception.ConvertException;
import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static dev.struchkov.haiti.utils.Checker.checkNotEmpty;
+
/**
* @author upagge 15.01.2021
*/
@@ -31,7 +35,7 @@ public class MergeRequestJsonConverter implements Converter convertLabels(Set source) {
+ if (checkNotEmpty(source)) {
+ return source.stream()
+ .map(label -> label.replaceAll("-", "_"))
+ .collect(Collectors.toSet());
+ }
+ return null;
+ }
+
private MergeRequestState convertState(MergeRequestStateJson state) {
return switch (state) {
case CLOSED -> MergeRequestState.CLOSED;
case LOCKED -> MergeRequestState.LOCKED;
case MERGED -> MergeRequestState.MERGED;
case OPENED -> MergeRequestState.OPENED;
- default -> throw new ConvertException("Статус ПР не найден");
};
}
diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/AppSettingServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/AppSettingServiceImpl.java
index fca7932..d9ce143 100644
--- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/AppSettingServiceImpl.java
+++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/AppSettingServiceImpl.java
@@ -1,19 +1,17 @@
package dev.struchkov.bot.gitlab.core.service.impl;
-import dev.struchkov.bot.gitlab.context.domain.AppLocale;
import dev.struchkov.bot.gitlab.context.domain.entity.AppSetting;
import dev.struchkov.bot.gitlab.context.repository.AppSettingRepository;
import dev.struchkov.bot.gitlab.context.service.AppSettingService;
import dev.struchkov.haiti.context.exception.NotFoundException;
-import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Service;
-import java.util.Arrays;
-import java.util.Locale;
import java.util.function.Supplier;
+import static dev.struchkov.haiti.context.exception.NotFoundException.notFoundException;
+
/**
* Сервис отвечает за пользовательские настройки приложения.
*
@@ -24,7 +22,7 @@ import java.util.function.Supplier;
public class AppSettingServiceImpl implements AppSettingService {
private static final Long KEY = 1L;
- public static final Supplier NOT_FOUND_SETTINGS = NotFoundException.supplier("Ошибка, невозможно найти настройки приложения, проверьте базу данных.");
+ public static final Supplier NOT_FOUND_SETTINGS = notFoundException("Ошибка, невозможно найти настройки приложения, проверьте базу данных.");
private final AppSettingRepository appSettingRepository;
private final MessageSource messageSource;
@@ -41,29 +39,6 @@ public class AppSettingServiceImpl implements AppSettingService {
appSettingRepository.save(appSetting);
}
- @Override
- public String getMessage(@NonNull String label) {
- final Locale value = getAppSetting().getAppLocale().getValue();
- return messageSource.getMessage(label, null, value);
- }
-
- @Override
- public String getMessage(@NonNull String label, Object... params) {
- final Object[] paramsArray = Arrays.stream(params).toArray();
- return messageSource.getMessage(
- label,
- paramsArray,
- getAppSetting().getAppLocale().getValue()
- );
- }
-
- @Override
- public void setLocale(@NonNull AppLocale appLocale) {
- final AppSetting appSetting = getAppSetting();
- appSetting.setAppLocale(appLocale);
- appSettingRepository.save(appSetting);
- }
-
private AppSetting getAppSetting() {
return appSettingRepository.findById(KEY)
.orElseThrow(NOT_FOUND_SETTINGS);
diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/CleanServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/CleanServiceImpl.java
index c9a7fb4..e8628e5 100644
--- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/CleanServiceImpl.java
+++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/CleanServiceImpl.java
@@ -7,9 +7,9 @@ import dev.struchkov.bot.gitlab.context.domain.filter.PipelineFilter;
import dev.struchkov.bot.gitlab.context.service.CleanService;
import dev.struchkov.bot.gitlab.context.service.MergeRequestsService;
import dev.struchkov.bot.gitlab.context.service.PipelineService;
-import dev.struchkov.haiti.context.page.Sheet;
-import dev.struchkov.haiti.context.page.impl.PaginationImpl;
import lombok.RequiredArgsConstructor;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
@@ -39,7 +39,7 @@ public class CleanServiceImpl implements CleanService {
@Override
public void cleanOldMergedRequests() {
int page = 0;
- Sheet mergeRequestSheet = mergeRequestsService.getAll(MR_CLEAN_FILTER, PaginationImpl.of(page, COUNT));
+ Page mergeRequestSheet = mergeRequestsService.getAll(MR_CLEAN_FILTER, PageRequest.of(page, COUNT));
while (mergeRequestSheet.hasContent()) {
final Set ids = mergeRequestSheet.getContent().stream()
@@ -48,7 +48,7 @@ public class CleanServiceImpl implements CleanService {
mergeRequestsService.deleteAllById(ids);
- mergeRequestSheet = mergeRequestsService.getAll(MR_CLEAN_FILTER, PaginationImpl.of(++page, COUNT));
+ mergeRequestSheet = mergeRequestsService.getAll(MR_CLEAN_FILTER, PageRequest.of(++page, COUNT));
}
}
@@ -56,7 +56,7 @@ public class CleanServiceImpl implements CleanService {
public void cleanOldPipelines() {
int page = 0;
final PipelineFilter filter = cleanPipelineFilter();
- Sheet sheet = pipelineService.getAll(filter, PaginationImpl.of(page, COUNT));
+ Page sheet = pipelineService.getAll(filter, PageRequest.of(page, COUNT));
while (sheet.hasContent()) {
final Set ids = sheet.getContent().stream()
@@ -65,7 +65,7 @@ public class CleanServiceImpl implements CleanService {
pipelineService.deleteAllById(ids);
- sheet = pipelineService.getAll(filter, PaginationImpl.of(page, COUNT));
+ sheet = pipelineService.getAll(filter, PageRequest.of(page, COUNT));
}
}
diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/DiscussionServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/DiscussionServiceImpl.java
index 32c6d87..31d2084 100644
--- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/DiscussionServiceImpl.java
+++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/DiscussionServiceImpl.java
@@ -1,5 +1,6 @@
package dev.struchkov.bot.gitlab.core.service.impl;
+import dev.struchkov.bot.gitlab.context.domain.ExistsContainer;
import dev.struchkov.bot.gitlab.context.domain.PersonInformation;
import dev.struchkov.bot.gitlab.context.domain.entity.Discussion;
import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest;
@@ -14,14 +15,15 @@ import dev.struchkov.bot.gitlab.context.service.PersonService;
import dev.struchkov.bot.gitlab.core.config.properties.GitlabProperty;
import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty;
import dev.struchkov.bot.gitlab.core.utils.StringUtils;
-import dev.struchkov.haiti.context.exception.NotFoundException;
-import dev.struchkov.haiti.core.service.AbstractSimpleManagerService;
import lombok.NonNull;
+import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.io.IOException;
@@ -35,6 +37,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
+import static dev.struchkov.haiti.context.exception.NotFoundException.notFoundException;
import static java.lang.Boolean.FALSE;
/**
@@ -44,12 +47,13 @@ import static java.lang.Boolean.FALSE;
*/
@Slf4j
@Service
-public class DiscussionServiceImpl extends AbstractSimpleManagerService implements DiscussionService {
+@RequiredArgsConstructor
+public class DiscussionServiceImpl implements DiscussionService {
protected static final Pattern PATTERN = Pattern.compile("@[\\w]+");
private final PersonService personService;
- private final DiscussionRepository discussionRepository;
+ private final DiscussionRepository repository;
private final PersonInformation personInformation;
private final OkHttpClient client = new OkHttpClient();
@@ -57,16 +61,6 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService personService.create(note.getAuthor()));
@@ -76,7 +70,7 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService note.isResolvable() && note.getResolved());
discussion.setResolved(resolved);
- return discussionRepository.save(discussion);
+ return repository.save(discussion);
}
/**
@@ -104,8 +98,8 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService idAndNoteMap = oldDiscussion
.getNotes().stream()
.collect(Collectors.toMap(Note::getId, note -> note));
@@ -122,7 +116,7 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService note.isResolvable() && note.getResolved());
discussion.setResolved(resolved);
- return discussionRepository.save(discussion);
+ return repository.save(discussion);
}
private void updateNote(Note note, Map noteMap, boolean inDiscussion) {
@@ -189,8 +183,8 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService getAllByMergeRequestId(@NonNull Long mergeRequestId) {
- return discussionRepository.findAllByMergeRequestId(mergeRequestId);
+ return repository.findAllByMergeRequestId(mergeRequestId);
+ }
+
+ @Override
+ public ExistsContainer existsById(@NonNull Set discussionIds) {
+ final List existsEntity = repository.findAllById(discussionIds);
+ final Set 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 noExistsId = discussionIds.stream()
+ .filter(id -> !existsIds.contains(id))
+ .collect(Collectors.toSet());
+ return ExistsContainer.notAllFind(existsEntity, noExistsId);
+ }
+ }
+
+ @Override
+ public List createAll(@NonNull List newDiscussions) {
+ return newDiscussions.stream()
+ .map(this::create)
+ .toList();
+ }
+
+ @Override
+ public Page getAll(@NonNull Pageable pagination) {
+ return repository.findAll(pagination);
+ }
+
+ @Override
+ public void deleteById(String discussionId) {
+ repository.deleteById(discussionId);
}
/**
diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java
index d22c380..a3c0f6b 100644
--- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java
+++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java
@@ -1,5 +1,6 @@
package dev.struchkov.bot.gitlab.core.service.impl;
+import dev.struchkov.bot.gitlab.context.domain.ExistsContainer;
import dev.struchkov.bot.gitlab.context.domain.IdAndStatusPr;
import dev.struchkov.bot.gitlab.context.domain.MergeRequestState;
import dev.struchkov.bot.gitlab.context.domain.PersonInformation;
@@ -17,50 +18,34 @@ import dev.struchkov.bot.gitlab.context.service.MergeRequestsService;
import dev.struchkov.bot.gitlab.context.service.NotifyService;
import dev.struchkov.bot.gitlab.context.service.PersonService;
import dev.struchkov.bot.gitlab.context.service.ProjectService;
-import dev.struchkov.haiti.context.exception.NotFoundException;
-import dev.struchkov.haiti.context.page.Pagination;
-import dev.struchkov.haiti.context.page.Sheet;
-import dev.struchkov.haiti.context.service.simple.FilterService;
-import dev.struchkov.haiti.core.service.AbstractSimpleManagerService;
+import dev.struchkov.bot.gitlab.core.service.impl.filter.MergeRequestFilterService;
import lombok.NonNull;
-import org.springframework.beans.factory.annotation.Qualifier;
+import lombok.RequiredArgsConstructor;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
-import java.util.Optional;
import java.util.Set;
+import java.util.stream.Collectors;
+
+import static dev.struchkov.haiti.context.exception.NotFoundException.notFoundException;
+import static java.lang.Boolean.TRUE;
@Service
-public class MergeRequestsServiceImpl extends AbstractSimpleManagerService implements MergeRequestsService {
+@RequiredArgsConstructor
+public class MergeRequestsServiceImpl implements MergeRequestsService {
private final NotifyService notifyService;
- private final MergeRequestRepository mergeRequestRepository;
+ private final MergeRequestRepository repository;
private final PersonService personService;
- private final FilterService filterService;
+ private final MergeRequestFilterService filterService;
private final ProjectService projectService;
private final DiscussionService discussionService;
private final PersonInformation personInformation;
- protected MergeRequestsServiceImpl(
- MergeRequestRepository mergeRequestRepository,
- NotifyService notifyService,
- PersonService personService,
- @Qualifier("mergeRequestFilterService") FilterService filterService,
- ProjectService projectService,
- DiscussionService discussionService, PersonInformation personInformation
- ) {
- super(mergeRequestRepository);
- this.notifyService = notifyService;
- this.mergeRequestRepository = mergeRequestRepository;
- this.personService = personService;
- this.filterService = filterService;
- this.projectService = projectService;
- this.discussionService = discussionService;
- this.personInformation = personInformation;
- }
-
@Override
public MergeRequest create(@NonNull MergeRequest mergeRequest) {
if (mergeRequest.getAssignee() != null) {
@@ -70,7 +55,7 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService getAllId(Set statuses) {
- return mergeRequestRepository.findAllIdByStateIn(statuses);
+ return repository.findAllIdByStateIn(statuses);
}
@Override
- public Sheet getAll(@NonNull MergeRequestFilter filter, Pagination pagination) {
+ public Page getAll(Pageable pagination) {
+ return repository.findAll(pagination);
+ }
+
+ @Override
+ public Page getAll(@NonNull MergeRequestFilter filter, Pageable pagination) {
return filterService.getAll(filter, pagination);
}
@Override
- public Optional getFirst(@NonNull MergeRequestFilter mergeRequestFilter) {
- return filterService.getFirst(mergeRequestFilter);
+ public ExistsContainer existsById(@NonNull Set mergeRequestIds) {
+ final List existsEntity = repository.findAllById(mergeRequestIds);
+ final Set existsIds = existsEntity.stream().map(MergeRequest::getId).collect(Collectors.toSet());
+ if (existsIds.containsAll(mergeRequestIds)) {
+ return ExistsContainer.allFind(existsEntity);
+ } else {
+ final Set noExistsId = mergeRequestIds.stream()
+ .filter(id -> !existsIds.contains(id))
+ .collect(Collectors.toSet());
+ return ExistsContainer.notAllFind(existsEntity, noExistsId);
+ }
}
@Override
- public boolean exists(@NonNull MergeRequestFilter filter) {
- return filterService.exists(filter);
+ public List createAll(List newMergeRequests) {
+ return newMergeRequests.stream()
+ .map(this::create)
+ .toList();
}
@Override
- public long count(@NonNull MergeRequestFilter mergeRequestFilter) {
- return filterService.count(mergeRequestFilter);
+ public void deleteAllById(@NonNull Set mergeRequestIds) {
+ repository.deleteByIds(mergeRequestIds);
}
}
diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PersonServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PersonServiceImpl.java
index f3383c3..0d8632a 100644
--- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PersonServiceImpl.java
+++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PersonServiceImpl.java
@@ -1,33 +1,63 @@
package dev.struchkov.bot.gitlab.core.service.impl;
+import dev.struchkov.bot.gitlab.context.domain.ExistsContainer;
import dev.struchkov.bot.gitlab.context.domain.entity.Person;
import dev.struchkov.bot.gitlab.context.repository.PersonRepository;
import dev.struchkov.bot.gitlab.context.service.PersonService;
-import dev.struchkov.haiti.core.service.AbstractSimpleManagerService;
import lombok.NonNull;
+import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static dev.struchkov.haiti.context.exception.NotFoundException.notFoundException;
+
/**
* @author upagge 15.01.2021
*/
@Service
-public class PersonServiceImpl extends AbstractSimpleManagerService implements PersonService {
+@RequiredArgsConstructor
+public class PersonServiceImpl implements PersonService {
- private final PersonRepository personRepository;
-
- public PersonServiceImpl(PersonRepository personRepository) {
- super(personRepository);
- this.personRepository = personRepository;
- }
+ private final PersonRepository repository;
@Override
public Person create(@NonNull Person person) {
- return personRepository.save(person);
+ return repository.save(person);
}
@Override
public Person update(@NonNull Person person) {
- return personRepository.save(person);
+ return repository.save(person);
+ }
+
+ @Override
+ public Person getByIdOrThrown(@NonNull Long personId) {
+ return repository.findById(personId)
+ .orElseThrow(notFoundException("Пользователь не найден"));
+ }
+
+ @Override
+ public ExistsContainer existsById(Set personIds) {
+ final List existsEntity = repository.findAllById(personIds);
+ final Set existsIds = existsEntity.stream().map(Person::getId).collect(Collectors.toSet());
+ if (existsIds.containsAll(personIds)) {
+ return ExistsContainer.allFind(existsEntity);
+ } else {
+ final Set noExistsId = personIds.stream()
+ .filter(id -> !existsIds.contains(id))
+ .collect(Collectors.toSet());
+ return ExistsContainer.notAllFind(existsEntity, noExistsId);
+ }
+ }
+
+ @Override
+ public List createAll(List newPersons) {
+ return newPersons.stream()
+ .map(this::create)
+ .toList();
}
}
diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PipelineServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PipelineServiceImpl.java
index e3e2dfb..3d145fa 100644
--- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PipelineServiceImpl.java
+++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PipelineServiceImpl.java
@@ -11,20 +11,22 @@ import dev.struchkov.bot.gitlab.context.service.NotifyService;
import dev.struchkov.bot.gitlab.context.service.PersonService;
import dev.struchkov.bot.gitlab.context.service.PipelineService;
import dev.struchkov.bot.gitlab.core.service.impl.filter.PipelineFilterService;
-import dev.struchkov.haiti.context.exception.NotFoundException;
-import dev.struchkov.haiti.context.page.Pagination;
-import dev.struchkov.haiti.context.page.Sheet;
-import dev.struchkov.haiti.core.service.AbstractSimpleManagerService;
+import dev.struchkov.haiti.context.domain.ExistsContainer;
import lombok.NonNull;
+import lombok.RequiredArgsConstructor;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
-import java.util.Optional;
+import java.util.List;
import java.util.Set;
+import java.util.stream.Collectors;
import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.CANCELED;
import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.FAILED;
import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.SKIPPED;
import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.SUCCESS;
+import static dev.struchkov.haiti.context.exception.NotFoundException.notFoundException;
/**
* Реализация сервиса для работы с пайплайнами.
@@ -32,37 +34,23 @@ import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.SUCCESS;
* @author upagge 17.01.2021
*/
@Service
-public class PipelineServiceImpl extends AbstractSimpleManagerService implements PipelineService {
+@RequiredArgsConstructor
+public class PipelineServiceImpl implements PipelineService {
// Статусы пайплайнов, о которых нужно уведомить
private static final Set notificationStatus = Set.of(FAILED, SUCCESS, CANCELED, SKIPPED);
private final NotifyService notifyService;
- private final PipelineRepository pipelineRepository;
+ private final PipelineRepository repository;
private final PersonService personService;
private final PipelineFilterService pipelineFilterService;
private final PersonInformation personInformation;
- public PipelineServiceImpl(
- NotifyService notifyService,
- PipelineRepository pipelineRepository,
- PersonService personService,
- PipelineFilterService pipelineFilterService,
- PersonInformation personInformation
- ) {
- super(pipelineRepository);
- this.notifyService = notifyService;
- this.pipelineRepository = pipelineRepository;
- this.personService = personService;
- this.pipelineFilterService = pipelineFilterService;
- this.personInformation = personInformation;
- }
-
@Override
public Pipeline create(@NonNull Pipeline pipeline) {
personService.create(pipeline.getPerson());
- final Pipeline newPipeline = pipelineRepository.save(pipeline);
+ final Pipeline newPipeline = repository.save(pipeline);
notifyNewPipeline(pipeline, "n/a");
return newPipeline;
}
@@ -84,13 +72,13 @@ public class PipelineServiceImpl extends AbstractSimpleManagerService getAllByStatuses(@NonNull Set statuses, @NonNull Pagination pagination) {
- return pipelineRepository.findAllByStatuses(statuses, pagination);
+ public Page getAllByStatuses(@NonNull Set statuses, @NonNull Pageable pagination) {
+ return repository.findAllByStatuses(statuses, pagination);
}
@Override
- public Sheet getAll(@NonNull PipelineFilter filter, @NonNull Pagination pagination) {
+ public Page getAll(@NonNull PipelineFilter filter, @NonNull Pageable pagination) {
return pipelineFilterService.getAll(filter, pagination);
}
@Override
- public Optional getFirst(@NonNull PipelineFilter filter) {
- return pipelineFilterService.getFirst(filter);
+ public ExistsContainer existsById(@NonNull Set pipelineIds) {
+ final List existsEntity = repository.findAllById(pipelineIds);
+ final Set existsIds = existsEntity.stream().map(Pipeline::getId).collect(Collectors.toSet());
+ if (existsIds.containsAll(pipelineIds)) {
+ return ExistsContainer.allFind(existsEntity);
+ } else {
+ final Set noExistsId = pipelineIds.stream()
+ .filter(id -> !existsIds.contains(id))
+ .collect(Collectors.toSet());
+ return ExistsContainer.notAllFind(existsEntity, noExistsId);
+ }
}
@Override
- public boolean exists(@NonNull PipelineFilter filter) {
- return pipelineFilterService.exists(filter);
- }
-
- @Override
- public long count(@NonNull PipelineFilter filter) {
- return pipelineFilterService.count(filter);
+ public void deleteAllById(Set pipelineIds) {
+ repository.deleteAllByIds(pipelineIds);
}
}
diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/ProjectServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/ProjectServiceImpl.java
index 6c972d6..6633af1 100644
--- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/ProjectServiceImpl.java
+++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/ProjectServiceImpl.java
@@ -1,5 +1,6 @@
package dev.struchkov.bot.gitlab.core.service.impl;
+import dev.struchkov.bot.gitlab.context.domain.ExistsContainer;
import dev.struchkov.bot.gitlab.context.domain.PersonInformation;
import dev.struchkov.bot.gitlab.context.domain.entity.Project;
import dev.struchkov.bot.gitlab.context.domain.notify.NewProjectNotify;
@@ -7,51 +8,85 @@ import dev.struchkov.bot.gitlab.context.repository.ProjectRepository;
import dev.struchkov.bot.gitlab.context.service.NotifyService;
import dev.struchkov.bot.gitlab.context.service.PersonService;
import dev.struchkov.bot.gitlab.context.service.ProjectService;
-import dev.struchkov.haiti.context.exception.NotFoundException;
-import dev.struchkov.haiti.context.repository.SimpleManagerRepository;
-import dev.struchkov.haiti.core.service.AbstractSimpleManagerService;
import lombok.NonNull;
+import lombok.RequiredArgsConstructor;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static dev.struchkov.haiti.context.exception.NotFoundException.notFoundException;
+
/**
* @author upagge 14.01.2021
*/
@Service
-public class ProjectServiceImpl extends AbstractSimpleManagerService implements ProjectService {
+@RequiredArgsConstructor
+public class ProjectServiceImpl implements ProjectService {
+
+ private final ProjectRepository repository;
- private final ProjectRepository projectRepository;
private final NotifyService notifyService;
private final PersonService personService;
private final PersonInformation personInformation;
- public ProjectServiceImpl(
- SimpleManagerRepository repository,
- ProjectRepository projectRepository,
- NotifyService notifyService,
- PersonService personService,
- PersonInformation personInformation
- ) {
- super(repository);
- this.projectRepository = projectRepository;
- this.notifyService = notifyService;
- this.personService = personService;
- this.personInformation = personInformation;
- }
-
@Override
public Project create(@NonNull Project project) {
- final Project newProject = projectRepository.save(project);
+ final Project newProject = repository.save(project);
if (!personInformation.getId().equals(newProject.getCreatorId())) {
- final String authorName = personService.getById(newProject.getCreatorId())
- .orElseThrow(NotFoundException.supplier("Пользователь не найден"))
- .getName();
+ final String authorName = personService.getByIdOrThrown(newProject.getCreatorId()).getName();
sendNotifyNewProject(newProject, authorName);
}
return newProject;
}
+ @Override
+ public Project update(@NonNull Project project) {
+ return repository.save(project);
+ }
+
+ @Override
+ public Project getByIdOrThrow(@NonNull Long projectId) {
+ return repository.findById(projectId)
+ .orElseThrow(notFoundException("Проект не найден"));
+ }
+
+ @Override
+ public Page getAll(@NonNull Pageable pagination) {
+ return repository.findAllById(pagination);
+ }
+
+ @Override
+ public List createAll(List newProjects) {
+ return newProjects.stream()
+ .map(this::create)
+ .toList();
+ }
+
+ @Override
+ public boolean existsById(Long projectId) {
+ return repository.existById(projectId);
+ }
+
+ @Override
+ public ExistsContainer existsById(Set projectIds) {
+ final List existsEntity = repository.findAllById(projectIds);
+ final Set existsIds = existsEntity.stream().map(Project::getId).collect(Collectors.toSet());
+ if (existsIds.containsAll(projectIds)) {
+ return ExistsContainer.allFind(existsEntity);
+ } else {
+ final Set noExistsId = projectIds.stream()
+ .filter(id -> !existsIds.contains(id))
+ .collect(Collectors.toSet());
+ return ExistsContainer.notAllFind(existsEntity, noExistsId);
+ }
+ }
+
private void sendNotifyNewProject(Project newProject, String authorName) {
notifyService.send(
NewProjectNotify.builder()
@@ -63,9 +98,4 @@ public class ProjectServiceImpl extends AbstractSimpleManagerService {
+@RequiredArgsConstructor
+public class MergeRequestFilterService {
- public MergeRequestFilterService(MergeRequestRepository filterOperation) {
- super(filterOperation);
+ private final MergeRequestRepository repository;
+
+ public Page getAll(MergeRequestFilter filter, Pageable pagination) {
+ return repository.filter(createFilter(filter), pagination);
}
- @Override
- protected Filter createFilter(@NonNull MergeRequestFilter filter) {
+ private Filter createFilter(@NonNull MergeRequestFilter filter) {
return CriteriaFilter.create()
.and(convertFilter(filter))
.or(convertFilterOr(filter));
@@ -28,12 +32,12 @@ public class MergeRequestFilterService extends AbstractFilterServicecreate()
- .matchPhrase(MergeRequest_.STATE, filter.getStates());
+ .matchPhrase(MergeRequestFields.state, filter.getStates());
}
private FilterQuery convertFilter(@NonNull MergeRequestFilter filter) {
return CriteriaQuery.create()
- .matchPhrase(MergeRequest_.ASSIGNEE, filter.getAssignee());
+ .matchPhrase(MergeRequestFields.assignee, filter.getAssignee());
}
}
diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/filter/PipelineFilterService.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/filter/PipelineFilterService.java
index fc43fa3..a18afc2 100644
--- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/filter/PipelineFilterService.java
+++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/filter/PipelineFilterService.java
@@ -1,15 +1,17 @@
package dev.struchkov.bot.gitlab.core.service.impl.filter;
import dev.struchkov.bot.gitlab.context.domain.entity.Pipeline;
-import dev.struchkov.bot.gitlab.context.domain.entity.Pipeline_;
+import dev.struchkov.bot.gitlab.context.domain.entity.PipelineFields;
import dev.struchkov.bot.gitlab.context.domain.filter.PipelineFilter;
import dev.struchkov.bot.gitlab.context.repository.PipelineRepository;
-import dev.struchkov.haiti.core.service.AbstractFilterService;
import dev.struchkov.haiti.filter.Filter;
import dev.struchkov.haiti.filter.FilterQuery;
import dev.struchkov.haiti.filter.criteria.CriteriaFilter;
import dev.struchkov.haiti.filter.criteria.CriteriaQuery;
import lombok.NonNull;
+import lombok.RequiredArgsConstructor;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
/**
@@ -18,20 +20,24 @@ import org.springframework.stereotype.Service;
* @author upagge 08.02.2021
*/
@Service
-public class PipelineFilterService extends AbstractFilterService {
+@RequiredArgsConstructor
+public class PipelineFilterService {
- public PipelineFilterService(PipelineRepository pipelineRepository) {
- super(pipelineRepository);
+ private final PipelineRepository pipelineRepository;
+
+ public Page getAll(PipelineFilter filter, Pageable pagination) {
+ return pipelineRepository.filter(createFilter(filter), pagination);
}
- @Override
- protected Filter createFilter(@NonNull PipelineFilter pipelineFilter) {
+ private Filter createFilter(@NonNull PipelineFilter pipelineFilter) {
return CriteriaFilter.create()
.and(convertAnd(pipelineFilter));
}
private FilterQuery convertAnd(PipelineFilter pipelineFilter) {
return CriteriaQuery.create()
- .lessThan(Pipeline_.CREATED, pipelineFilter.getLessThanCreatedDate());
+ .lessThan(PipelineFields.created, pipelineFilter.getLessThanCreatedDate());
}
+
+
}
diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/note/NoteServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/note/NoteServiceImpl.java
index 203bd44..8243f0c 100644
--- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/note/NoteServiceImpl.java
+++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/note/NoteServiceImpl.java
@@ -3,41 +3,35 @@ package dev.struchkov.bot.gitlab.core.service.impl.note;
import dev.struchkov.bot.gitlab.context.domain.entity.Note;
import dev.struchkov.bot.gitlab.context.repository.NoteRepository;
import dev.struchkov.bot.gitlab.context.service.NoteService;
-import dev.struchkov.haiti.context.page.Pagination;
-import dev.struchkov.haiti.context.page.Sheet;
-import dev.struchkov.haiti.core.service.AbstractSimpleManagerService;
import lombok.NonNull;
+import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.List;
+import static dev.struchkov.haiti.context.exception.NotFoundException.notFoundException;
+
@Slf4j
@Service
-public class NoteServiceImpl extends AbstractSimpleManagerService implements NoteService {
+@RequiredArgsConstructor
+public class NoteServiceImpl implements NoteService {
private final NoteRepository noteRepository;
- public NoteServiceImpl(NoteRepository noteRepository) {
- super(noteRepository);
- this.noteRepository = noteRepository;
- }
-
@Override
- public Note create(@NonNull Note note) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Note update(@NonNull Note note) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Sheet getAllByResolved(boolean resolved, @NonNull Pagination pagination) {
+ public Page getAllByResolved(boolean resolved, @NonNull Pageable pagination) {
return noteRepository.findAllByResolved(resolved, pagination);
}
+ @Override
+ public Note getByIdOrThrow(@NonNull Long noteId) {
+ return noteRepository.findById(noteId)
+ .orElseThrow(notFoundException("Note не найдено"));
+ }
+
@Override
public List getAllPersonTask(@NonNull Long userId, boolean resolved) {
return noteRepository.findAllByResponsibleIdAndResolved(userId, resolved);
diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/DiscussionParser.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/DiscussionParser.java
index 2aaf08c..b0b770e 100644
--- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/DiscussionParser.java
+++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/DiscussionParser.java
@@ -1,5 +1,6 @@
package dev.struchkov.bot.gitlab.core.service.parser;
+import dev.struchkov.bot.gitlab.context.domain.ExistsContainer;
import dev.struchkov.bot.gitlab.context.domain.entity.Discussion;
import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest;
import dev.struchkov.bot.gitlab.context.domain.entity.Note;
@@ -8,12 +9,11 @@ import dev.struchkov.bot.gitlab.context.service.MergeRequestsService;
import dev.struchkov.bot.gitlab.core.config.properties.GitlabProperty;
import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty;
import dev.struchkov.bot.gitlab.sdk.domain.DiscussionJson;
-import dev.struchkov.haiti.context.domain.ExistsContainer;
-import dev.struchkov.haiti.context.page.Sheet;
-import dev.struchkov.haiti.context.page.impl.PaginationImpl;
import dev.struchkov.haiti.utils.network.HttpParse;
import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.ConversionService;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Component;
import java.text.MessageFormat;
@@ -49,12 +49,12 @@ public class DiscussionParser {
*/
public void scanNewDiscussion() {
int page = 0;
- Sheet mergeRequestSheet = mergeRequestsService.getAll(PaginationImpl.of(page, COUNT));
+ Page mergeRequestSheet = mergeRequestsService.getAll(PageRequest.of(page, COUNT));
while (mergeRequestSheet.hasContent()) {
mergeRequestSheet.getContent()
.forEach(this::processingMergeRequest);
- mergeRequestSheet = mergeRequestsService.getAll(PaginationImpl.of(++page, COUNT));
+ mergeRequestSheet = mergeRequestsService.getAll(PageRequest.of(++page, COUNT));
}
}
@@ -97,7 +97,7 @@ public class DiscussionParser {
*/
public void scanOldDiscussions() {
int page = 0;
- Sheet discussionSheet = discussionService.getAll(PaginationImpl.of(page, COUNT));
+ Page discussionSheet = discussionService.getAll(PageRequest.of(page, COUNT));
while (discussionSheet.hasContent()) {
final List discussions = discussionSheet.getContent();
@@ -119,7 +119,7 @@ public class DiscussionParser {
}
}
- discussionSheet = discussionService.getAll(PaginationImpl.of(++page, COUNT));
+ discussionSheet = discussionService.getAll(PageRequest.of(++page, COUNT));
}
}
diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/MergeRequestParser.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/MergeRequestParser.java
index bcee415..fef4cca 100644
--- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/MergeRequestParser.java
+++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/MergeRequestParser.java
@@ -1,5 +1,6 @@
package dev.struchkov.bot.gitlab.core.service.parser;
+import dev.struchkov.bot.gitlab.context.domain.ExistsContainer;
import dev.struchkov.bot.gitlab.context.domain.IdAndStatusPr;
import dev.struchkov.bot.gitlab.context.domain.MergeRequestState;
import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest;
@@ -11,13 +12,12 @@ import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty;
import dev.struchkov.bot.gitlab.core.utils.StringUtils;
import dev.struchkov.bot.gitlab.sdk.domain.CommitJson;
import dev.struchkov.bot.gitlab.sdk.domain.MergeRequestJson;
-import dev.struchkov.haiti.context.domain.ExistsContainer;
-import dev.struchkov.haiti.context.page.Sheet;
-import dev.struchkov.haiti.context.page.impl.PaginationImpl;
import dev.struchkov.haiti.utils.network.HttpParse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.convert.ConversionService;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import java.text.MessageFormat;
@@ -66,7 +66,7 @@ public class MergeRequestParser {
public void parsingNewMergeRequest() {
int page = 0;
- Sheet projectSheet = projectService.getAll(PaginationImpl.of(page, COUNT));
+ Page projectSheet = projectService.getAll(PageRequest.of(page, COUNT));
while (projectSheet.hasContent()) {
final List projects = projectSheet.getContent();
@@ -75,7 +75,7 @@ public class MergeRequestParser {
projectProcessing(project);
}
- projectSheet = projectService.getAll(PaginationImpl.of(++page, COUNT));
+ projectSheet = projectService.getAll(PageRequest.of(++page, COUNT));
}
}
diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/PipelineParser.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/PipelineParser.java
index 3ee6c08..b195199 100644
--- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/PipelineParser.java
+++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/PipelineParser.java
@@ -10,12 +10,11 @@ import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty;
import dev.struchkov.bot.gitlab.core.utils.StringUtils;
import dev.struchkov.bot.gitlab.sdk.domain.PipelineJson;
import dev.struchkov.haiti.context.domain.ExistsContainer;
-import dev.struchkov.haiti.context.exception.ConvertException;
-import dev.struchkov.haiti.context.page.Sheet;
-import dev.struchkov.haiti.context.page.impl.PaginationImpl;
import dev.struchkov.haiti.utils.network.HttpParse;
import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.ConversionService;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import java.text.MessageFormat;
@@ -31,6 +30,7 @@ import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.PENDING;
import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.PREPARING;
import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.RUNNING;
import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.WAITING_FOR_RESOURCE;
+import static dev.struchkov.haiti.context.exception.ConvertException.convertException;
import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT;
/**
@@ -56,7 +56,7 @@ public class PipelineParser {
public void scanNewPipeline() {
int page = 0;
- Sheet projectSheet = projectService.getAll(PaginationImpl.of(page, COUNT));
+ Page projectSheet = projectService.getAll(PageRequest.of(page, COUNT));
while (projectSheet.hasContent()) {
final List projects = projectSheet.getContent();
@@ -65,7 +65,7 @@ public class PipelineParser {
processingProject(project);
}
- projectSheet = projectService.getAll(PaginationImpl.of(++page, COUNT));
+ projectSheet = projectService.getAll(PageRequest.of(++page, COUNT));
}
}
@@ -99,7 +99,7 @@ public class PipelineParser {
pipeline.setProject(project);
return pipeline;
})
- .orElseThrow(ConvertException.supplier("Ошибка обновления Pipelines"));
+ .orElseThrow(convertException("Ошибка обновления Pipelines"));
pipelineService.create(newPipeline);
}
@@ -121,7 +121,7 @@ public class PipelineParser {
public void scanOldPipeline() {
int page = 0;
- Sheet pipelineSheet = pipelineService.getAllByStatuses(oldStatus, PaginationImpl.of(page, COUNT));
+ Page pipelineSheet = pipelineService.getAllByStatuses(oldStatus, PageRequest.of(page, COUNT));
while (pipelineSheet.hasContent()) {
final List pipelines = pipelineSheet.getContent();
@@ -134,12 +134,12 @@ public class PipelineParser {
.header(StringUtils.H_PRIVATE_TOKEN, personProperty.getToken())
.execute(PipelineJson.class)
.map(json -> conversionService.convert(json, Pipeline.class))
- .orElseThrow(ConvertException.supplier("Ошибка обновления Pipelines"));
+ .orElseThrow(convertException("Ошибка обновления Pipelines"));
pipelineService.update(newPipeline);
}
- pipelineSheet = pipelineService.getAllByStatuses(oldStatus, PaginationImpl.of(++page, COUNT));
+ pipelineSheet = pipelineService.getAllByStatuses(oldStatus, PageRequest.of(++page, COUNT));
}
}
diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/ProjectParser.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/ProjectParser.java
index 3b70c68..ed4ba01 100644
--- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/ProjectParser.java
+++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/ProjectParser.java
@@ -1,5 +1,6 @@
package dev.struchkov.bot.gitlab.core.service.parser;
+import dev.struchkov.bot.gitlab.context.domain.ExistsContainer;
import dev.struchkov.bot.gitlab.context.domain.entity.Person;
import dev.struchkov.bot.gitlab.context.domain.entity.Project;
import dev.struchkov.bot.gitlab.context.service.PersonService;
@@ -9,8 +10,6 @@ import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty;
import dev.struchkov.bot.gitlab.core.utils.StringUtils;
import dev.struchkov.bot.gitlab.sdk.domain.PersonJson;
import dev.struchkov.bot.gitlab.sdk.domain.ProjectJson;
-import dev.struchkov.haiti.context.domain.ExistsContainer;
-import dev.struchkov.haiti.context.exception.ConvertException;
import dev.struchkov.haiti.utils.network.HttpParse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -23,6 +22,7 @@ import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
+import static dev.struchkov.haiti.context.exception.ConvertException.convertException;
import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT;
/**
@@ -97,7 +97,7 @@ public class ProjectParser {
.header(StringUtils.H_PRIVATE_TOKEN, personProperty.getToken())
.execute(PersonJson.class)
.map(json -> conversionService.convert(json, Person.class))
- .orElseThrow(ConvertException.supplier("Ошибка преобразования нового пользователя"))
+ .orElseThrow(convertException("Ошибка преобразования нового пользователя"))
).toList();
personService.createAll(newPersons);
@@ -119,7 +119,7 @@ public class ProjectParser {
.header(StringUtils.H_PRIVATE_TOKEN, personProperty.getToken())
.execute(ProjectJson.class)
.map(json -> conversionService.convert(json, Project.class))
- .orElseThrow(ConvertException.supplier("Ошибка получения проекта"));
+ .orElseThrow(convertException("Ошибка получения проекта"));
if (!projectService.existsById(project.getId())) {
projectService.create(project);
}
diff --git a/bot-data/pom.xml b/bot-data/pom.xml
index 6f62e3a..fef3d3d 100644
--- a/bot-data/pom.xml
+++ b/bot-data/pom.xml
@@ -6,21 +6,16 @@
dev.struchkov.bot.gitlab
gitlab-bot
- 1.0.0
+ 1.1.0
bot-data
- ${gitlab.data.version}
GitLab Server Data
Implementation of the Bitbucket server version repository layer
https://github.com/uPagge/bitbucketbot
-
- dev.struchkov.haiti.data
- haiti-database
-
dev.struchkov.bot.gitlab
bot-context
diff --git a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/AppSettingRepositoryImpl.java b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/AppSettingRepositoryImpl.java
index 230c68a..dfc4f67 100644
--- a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/AppSettingRepositoryImpl.java
+++ b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/AppSettingRepositoryImpl.java
@@ -2,18 +2,28 @@ package dev.struchkov.bot.gitlab.data.impl;
import dev.struchkov.bot.gitlab.context.domain.entity.AppSetting;
import dev.struchkov.bot.gitlab.context.repository.AppSettingRepository;
-import dev.struchkov.haiti.database.repository.manager.AbstractSimpleManagerRepository;
-import org.springframework.data.jpa.repository.JpaRepository;
+import dev.struchkov.bot.gitlab.data.jpa.AppSettingJpaRepository;
+import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
+import java.util.Optional;
+
/**
* @author upagge 16.01.2021
*/
@Repository
-public class AppSettingRepositoryImpl extends AbstractSimpleManagerRepository implements AppSettingRepository {
+@RequiredArgsConstructor
+public class AppSettingRepositoryImpl implements AppSettingRepository {
- public AppSettingRepositoryImpl(JpaRepository jpaRepository) {
- super(jpaRepository);
+ private final AppSettingJpaRepository jpaRepository;
+
+ @Override
+ public AppSetting save(AppSetting appSetting) {
+ return jpaRepository.save(appSetting);
}
+ @Override
+ public Optional findById(Long key) {
+ return jpaRepository.findById(key);
+ }
}
diff --git a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/DiscussionRepositoryImpl.java b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/DiscussionRepositoryImpl.java
index f690e74..3ed56d5 100644
--- a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/DiscussionRepositoryImpl.java
+++ b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/DiscussionRepositoryImpl.java
@@ -3,28 +3,53 @@ package dev.struchkov.bot.gitlab.data.impl;
import dev.struchkov.bot.gitlab.context.domain.entity.Discussion;
import dev.struchkov.bot.gitlab.context.repository.DiscussionRepository;
import dev.struchkov.bot.gitlab.data.jpa.DiscussionJpaRepository;
-import dev.struchkov.haiti.database.repository.manager.AbstractSimpleManagerRepository;
import lombok.NonNull;
+import lombok.RequiredArgsConstructor;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;
import java.util.List;
+import java.util.Optional;
+import java.util.Set;
/**
* @author upagge 11.02.2021
*/
@Repository
-public class DiscussionRepositoryImpl extends AbstractSimpleManagerRepository implements DiscussionRepository {
+@RequiredArgsConstructor
+public class DiscussionRepositoryImpl implements DiscussionRepository {
private final DiscussionJpaRepository jpaRepository;
- public DiscussionRepositoryImpl(DiscussionJpaRepository jpaRepository) {
- super(jpaRepository);
- this.jpaRepository = jpaRepository;
- }
-
@Override
public List findAllByMergeRequestId(@NonNull Long mergeRequestId) {
return jpaRepository.findAllByMergeRequestId(mergeRequestId);
}
+ @Override
+ public Discussion save(Discussion discussion) {
+ return jpaRepository.save(discussion);
+ }
+
+ @Override
+ public Optional findById(String discussionId) {
+ return jpaRepository.findById(discussionId);
+ }
+
+ @Override
+ public void deleteById(String discussionId) {
+ jpaRepository.deleteById(discussionId);
+ }
+
+ @Override
+ public Page findAll(Pageable pagination) {
+ return jpaRepository.findAll(pagination);
+ }
+
+ @Override
+ public List findAllById(Set discussionIds) {
+ return jpaRepository.findAllById(discussionIds);
+ }
+
}
diff --git a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/MergeRequestRepositoryImpl.java b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/MergeRequestRepositoryImpl.java
index 3af294a..dcb21ef 100644
--- a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/MergeRequestRepositoryImpl.java
+++ b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/MergeRequestRepositoryImpl.java
@@ -5,31 +5,62 @@ import dev.struchkov.bot.gitlab.context.domain.MergeRequestState;
import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest;
import dev.struchkov.bot.gitlab.context.repository.MergeRequestRepository;
import dev.struchkov.bot.gitlab.data.jpa.MergeRequestJpaRepository;
-import dev.struchkov.haiti.database.repository.manager.FilterManagerRepository;
+import dev.struchkov.haiti.filter.Filter;
import lombok.NonNull;
+import lombok.RequiredArgsConstructor;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Repository;
import java.util.List;
+import java.util.Optional;
import java.util.Set;
@Repository
-public class MergeRequestRepositoryImpl extends FilterManagerRepository implements MergeRequestRepository {
+@RequiredArgsConstructor
+public class MergeRequestRepositoryImpl implements MergeRequestRepository {
- private final MergeRequestJpaRepository repositoryJpa;
-
- public MergeRequestRepositoryImpl(MergeRequestJpaRepository jpaRepository) {
- super(jpaRepository);
- repositoryJpa = jpaRepository;
- }
+ private final MergeRequestJpaRepository jpaRepository;
@Override
public Set findAllIdByStateIn(@NonNull Set statuses) {
- return repositoryJpa.findAllIdByStateIn(statuses);
+ return jpaRepository.findAllIdByStateIn(statuses);
}
@Override
public List 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 findById(Long mergeRequestId) {
+ return jpaRepository.findById(mergeRequestId);
+ }
+
+ @Override
+ public Page findAll(Pageable pagination) {
+ return jpaRepository.findAll(pagination);
+ }
+
+ @Override
+ public List findAllById(Set mergeRequestIds) {
+ return jpaRepository.findAllById(mergeRequestIds);
+ }
+
+ @Override
+ public void deleteByIds(Set mergeRequestIds) {
+ jpaRepository.deleteAllByIdIn(mergeRequestIds);
+ }
+
+ @Override
+ public Page filter(Filter filter, Pageable pageable) {
+ return jpaRepository.findAll(filter.>build(), pageable);
}
}
diff --git a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/NoteRepositoryImpl.java b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/NoteRepositoryImpl.java
index 66ce9fb..694bb0c 100644
--- a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/NoteRepositoryImpl.java
+++ b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/NoteRepositoryImpl.java
@@ -2,40 +2,38 @@ package dev.struchkov.bot.gitlab.data.impl;
import dev.struchkov.bot.gitlab.context.domain.entity.Note;
import dev.struchkov.bot.gitlab.context.repository.NoteRepository;
-import dev.struchkov.bot.gitlab.data.jpa.NoteRepositoryJpa;
-import dev.struchkov.haiti.context.page.Pagination;
-import dev.struchkov.haiti.context.page.Sheet;
-import dev.struchkov.haiti.database.repository.manager.AbstractSimpleManagerRepository;
-import dev.struchkov.haiti.database.util.Converter;
+import dev.struchkov.bot.gitlab.data.jpa.NoteJpaRepository;
import lombok.NonNull;
+import lombok.RequiredArgsConstructor;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;
import java.util.List;
+import java.util.Optional;
/**
- *
* @author upagge 08.09.2020
*/
@Repository
-public class NoteRepositoryImpl extends AbstractSimpleManagerRepository implements NoteRepository {
+@RequiredArgsConstructor
+public class NoteRepositoryImpl implements NoteRepository {
- private final NoteRepositoryJpa repositoryJpa;
+ private final NoteJpaRepository jpaRepository;
- public NoteRepositoryImpl(NoteRepositoryJpa repositoryJpa) {
- super(repositoryJpa);
- this.repositoryJpa = repositoryJpa;
+ @Override
+ public Page findAllByResolved(boolean resolved, @NonNull Pageable pagination) {
+ return jpaRepository.findAllByResolved(resolved, pagination);
}
@Override
- public Sheet findAllByResolved(boolean resolved, @NonNull Pagination pagination) {
- return Converter.page(
- repositoryJpa.findAllByResolved(resolved, Converter.pagination(pagination))
- );
+ public Optional findById(Long noteId) {
+ return jpaRepository.findById(noteId);
}
@Override
public List findAllByResponsibleIdAndResolved(@NonNull Long userId, boolean resolved) {
- return repositoryJpa.findAllByDiscussionResponsibleIdAndResolved(userId, resolved);
+ return jpaRepository.findAllByDiscussionResponsibleIdAndResolved(userId, resolved);
}
diff --git a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/PersonRepositoryImpl.java b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/PersonRepositoryImpl.java
index 0818e8f..ad830b6 100644
--- a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/PersonRepositoryImpl.java
+++ b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/PersonRepositoryImpl.java
@@ -2,18 +2,36 @@ package dev.struchkov.bot.gitlab.data.impl;
import dev.struchkov.bot.gitlab.context.domain.entity.Person;
import dev.struchkov.bot.gitlab.context.repository.PersonRepository;
-import dev.struchkov.haiti.database.repository.manager.AbstractSimpleManagerRepository;
-import org.springframework.data.jpa.repository.JpaRepository;
+import dev.struchkov.bot.gitlab.data.jpa.PersonJpaRepository;
+import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+
/**
* @author upagge 15.01.2021
*/
@Repository
-public class PersonRepositoryImpl extends AbstractSimpleManagerRepository implements PersonRepository {
+@RequiredArgsConstructor
+public class PersonRepositoryImpl implements PersonRepository {
- public PersonRepositoryImpl(JpaRepository jpaRepository) {
- super(jpaRepository);
+ private final PersonJpaRepository jpaRepository;
+
+ @Override
+ public Person save(Person person) {
+ return jpaRepository.save(person);
+ }
+
+ @Override
+ public Optional findById(Long personId) {
+ return jpaRepository.findById(personId);
+ }
+
+ @Override
+ public List findAllById(Set personIds) {
+ return jpaRepository.findAllById(personIds);
}
}
diff --git a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/PipelineRepositoryImpl.java b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/PipelineRepositoryImpl.java
index 50eef2c..0872c42 100644
--- a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/PipelineRepositoryImpl.java
+++ b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/PipelineRepositoryImpl.java
@@ -4,32 +4,54 @@ import dev.struchkov.bot.gitlab.context.domain.PipelineStatus;
import dev.struchkov.bot.gitlab.context.domain.entity.Pipeline;
import dev.struchkov.bot.gitlab.context.repository.PipelineRepository;
import dev.struchkov.bot.gitlab.data.jpa.PipelineJpaRepository;
-import dev.struchkov.haiti.context.page.Pagination;
-import dev.struchkov.haiti.context.page.Sheet;
-import dev.struchkov.haiti.database.repository.manager.FilterManagerRepository;
-import dev.struchkov.haiti.database.util.Converter;
-import lombok.NonNull;
+import dev.struchkov.haiti.filter.Filter;
+import lombok.RequiredArgsConstructor;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Repository;
+import java.util.List;
+import java.util.Optional;
import java.util.Set;
/**
* @author upagge 17.01.2021
*/
@Repository
-public class PipelineRepositoryImpl extends FilterManagerRepository implements PipelineRepository {
+@RequiredArgsConstructor
+public class PipelineRepositoryImpl implements PipelineRepository {
private final PipelineJpaRepository jpaRepository;
- public PipelineRepositoryImpl(PipelineJpaRepository jpaRepository) {
- super(jpaRepository);
- this.jpaRepository = jpaRepository;
+ @Override
+ public Pipeline save(Pipeline pipeline) {
+ return jpaRepository.save(pipeline);
}
@Override
- public Sheet findAllByStatuses(@NonNull Set statuses, @NonNull Pagination pagination) {
- return Converter.page(
- jpaRepository.findAllByStatusIn(statuses, Converter.pagination(pagination))
- );
+ public Optional findById(Long pipelineId) {
+ return jpaRepository.findById(pipelineId);
}
+
+ @Override
+ public Page findAllByStatuses(Set statuses, Pageable pagination) {
+ return jpaRepository.findAllByStatusIn(statuses, pagination);
+ }
+
+ @Override
+ public List findAllById(Set pipelineIds) {
+ return jpaRepository.findAllById(pipelineIds);
+ }
+
+ @Override
+ public void deleteAllByIds(Set