From 08256dadc36db24db034a07737be8e4f0364cbe9 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Fri, 29 Apr 2022 01:21:34 +0300 Subject: [PATCH] =?UTF-8?q?=D0=91=D0=BE=D0=BB=D1=8C=D1=88=D0=BE=D0=B9=20?= =?UTF-8?q?=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=BD?= =?UTF-8?q?=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot-context/pom.xml | 18 +- .../godfather/context/domain/BasicEntity.java | 15 +- .../godfather/context/domain/BoxAnswer.java | 75 ++++++- .../context/domain/content/BoardComment.java | 14 -- .../context/domain/content/Comment.java | 22 -- .../context/domain/content/EmptyMessage.java | 2 - .../context/domain/content/Mail.java | 40 +++- .../context/domain/content/Message.java | 66 +++++- .../domain/content/attachment/Attachment.java | 11 +- .../content/attachment/AudioMessage.java | 14 +- .../domain/content/attachment/Geo.java | 20 +- .../content/attachment/GeoCoordinate.java | 28 ++- .../domain/content/attachment/Link.java | 17 +- .../domain/keyboard/button/SimpleButton.java | 37 +++- .../keyboard/simple/SimpleKeyBoard.java | 44 +++- .../keyboard/simple/SimpleKeyBoardLine.java | 37 +++- .../context/exception/NotFoundException.java | 14 -- .../exception/UnitConfigException.java | 23 +++ .../context/repository/ContentRepository.java | 14 +- .../impl/local/MailRepositoryList.java | 18 +- .../context/service/MessageService.java | 16 +- .../godfather/context/service/Modifiable.java | 4 +- .../context/service/impl/MailServiceImpl.java | 20 +- .../context/service/sender/Sending.java | 6 +- .../service/sender/email/EmailConfig.java | 68 ------- .../service/sender/email/EmailSending.java | 57 ------ .../godfather/context/utils/InsertWords.java | 12 +- .../godfather/context/utils/KeyBoards.java | 41 ++-- .../godfather/context/utils/Sender.java | 12 +- bot-core/pom.xml | 8 +- .../godfather/core/GeneralAutoResponder.java | 12 +- .../godfather/core/domain/Clarification.java | 17 +- .../godfather/core/domain/Timer.java | 142 ++++++++++++- .../core/domain/question/Question.java | 64 +++--- .../core/domain/question/QuestionAnswer.java | 70 +++---- .../core/domain/question/QuestionResult.java | 64 +++--- .../core/domain/unit/AnswerCheck.java | 121 ++++++++--- .../core/domain/unit/AnswerProcessing.java | 103 ++++++++-- .../core/domain/unit/AnswerSave.java | 158 ++++++++++++--- .../core/domain/unit/AnswerText.java | 140 ++++++++++--- .../core/domain/unit/AnswerTimer.java | 134 +++++++++--- .../core/domain/unit/AnswerValidity.java | 141 ++++++++++--- .../godfather/core/domain/unit/MainUnit.java | 45 +++-- .../service/action/AnswerCheckAction.java | 6 +- .../action/AnswerProcessingAction.java | 2 +- .../core/service/action/AnswerTextAction.java | 32 +-- .../service/action/AnswerTimerAction.java | 2 +- .../service/action/AnswerValidityAction.java | 2 +- .../save/data/PreservableDataSimple.java | 2 +- .../core/service/save/jpa/PreservableJpa.java | 23 --- .../core/service/save/jpa/SaveObjectJpa.java | 25 --- .../core/service/save/push/EmailPusher.java | 125 ------------ .../core/service/timer/TimerActionTask.java | 8 +- .../core/service/timer/TimerServiceImpl.java | 12 +- .../struchkov/godfather/core/utils/Pair.java | 17 -- .../godfather/core/utils/QuestionUtils.java | 190 +++++++++--------- pom.xml | 66 +++--- 57 files changed, 1486 insertions(+), 1010 deletions(-) delete mode 100644 bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/BoardComment.java delete mode 100644 bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/Comment.java delete mode 100644 bot-context/src/main/java/dev/struchkov/godfather/context/exception/NotFoundException.java create mode 100644 bot-context/src/main/java/dev/struchkov/godfather/context/exception/UnitConfigException.java delete mode 100644 bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/email/EmailConfig.java delete mode 100644 bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/email/EmailSending.java delete mode 100644 bot-core/src/main/java/dev/struchkov/godfather/core/service/save/jpa/PreservableJpa.java delete mode 100644 bot-core/src/main/java/dev/struchkov/godfather/core/service/save/jpa/SaveObjectJpa.java delete mode 100644 bot-core/src/main/java/dev/struchkov/godfather/core/service/save/push/EmailPusher.java delete mode 100644 bot-core/src/main/java/dev/struchkov/godfather/core/utils/Pair.java diff --git a/bot-context/pom.xml b/bot-context/pom.xml index 7c13ad4..8a06388 100644 --- a/bot-context/pom.xml +++ b/bot-context/pom.xml @@ -6,7 +6,7 @@ dev.struchkov.godfather godfather-bot - 0.0.4-SNAPSHOT + 0.0.4 bot-context @@ -14,18 +14,10 @@ Bot Context Доменные сущности, интерфейсы, для библиотеки Godfather - - false - - - org.projectlombok - lombok - - - javax.mail - javax.mail-api + dev.struchkov.haiti + haiti-utils @@ -41,6 +33,10 @@ org.slf4j slf4j-api + + org.jetbrains + annotations + \ No newline at end of file diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/BasicEntity.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/BasicEntity.java index 2d72cd1..f175800 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/BasicEntity.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/BasicEntity.java @@ -1,9 +1,5 @@ package dev.struchkov.godfather.context.domain; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.MappedSuperclass; @@ -13,9 +9,6 @@ import javax.persistence.MappedSuperclass; * * @author upagge [28/07/2019] */ -@Getter -@Setter -@ToString @MappedSuperclass public class BasicEntity { @@ -23,4 +16,12 @@ public class BasicEntity { @GeneratedValue protected Long id; + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + } diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/BoxAnswer.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/BoxAnswer.java index 6bcf9b3..d859fbb 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/BoxAnswer.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/BoxAnswer.java @@ -3,27 +3,17 @@ package dev.struchkov.godfather.context.domain; import dev.struchkov.godfather.context.domain.content.Message; import dev.struchkov.godfather.context.domain.keyboard.KeyBoard; import dev.struchkov.godfather.context.service.usercode.ProcessingData; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; /** * Контейнер, которые содержит данные, которые будут отправлены пользователю как ответ на его запрос. * * @author upagge [08/07/2019] */ -@Getter -@ToString -@EqualsAndHashCode -@Builder(toBuilder = true) public class BoxAnswer { /** * Обычное текстовое сообщение. */ - @Setter private String message; /** @@ -33,12 +23,75 @@ public class BoxAnswer { private boolean replace; + private BoxAnswer(Builder builder) { + setMessage(builder.message); + keyBoard = builder.keyBoard; + replace = builder.replace; + } + public static BoxAnswer of(String message) { return BoxAnswer.builder().message(message).build(); } public static ProcessingData processing(String messageText) { - return message -> builder().message(messageText).build(); + return message -> of(messageText); } + public static Builder builder() { + return new Builder(); + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public KeyBoard getKeyBoard() { + return keyBoard; + } + + public boolean isReplace() { + return replace; + } + + @Override + public String toString() { + return "BoxAnswer{" + + "message='" + message + '\'' + + ", keyBoard=" + keyBoard + + ", replace=" + replace + + '}'; + } + + + public static final class Builder { + private String message; + private KeyBoard keyBoard; + private boolean replace; + + private Builder() { + } + + public Builder message(String val) { + message = val; + return this; + } + + public Builder keyBoard(KeyBoard val) { + keyBoard = val; + return this; + } + + public Builder replace(boolean val) { + replace = val; + return this; + } + + public BoxAnswer build() { + return new BoxAnswer(this); + } + } } diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/BoardComment.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/BoardComment.java deleted file mode 100644 index 6d34d7b..0000000 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/BoardComment.java +++ /dev/null @@ -1,14 +0,0 @@ -package dev.struchkov.godfather.context.domain.content; - -/** - * Сообщение от пользователя типа "Комментарий к обсуждению группы". - * - * @author upagge [08/07/2019] - */ -public class BoardComment extends Comment { - - public BoardComment() { - type = ContentType.BOARD_COMMENT; - } - -} diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/Comment.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/Comment.java deleted file mode 100644 index 5438179..0000000 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/Comment.java +++ /dev/null @@ -1,22 +0,0 @@ -package dev.struchkov.godfather.context.domain.content; - -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -/** - * Абстрактная сущность для сообщений от пользователей с привязкой к какому-то контенту (картинка, видео). - * - * @author upagge [08/07/2019] - */ -@Getter -@Setter -@EqualsAndHashCode(callSuper = true) -public abstract class Comment extends Message { - - /** - * Идентификатор контента, к которому ставлено сообщение. - */ - private Long contentId; - -} diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/EmptyMessage.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/EmptyMessage.java index 5aa597e..d828343 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/EmptyMessage.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/EmptyMessage.java @@ -1,14 +1,12 @@ package dev.struchkov.godfather.context.domain.content; import dev.struchkov.godfather.context.exception.AppBotException; -import lombok.ToString; /** * Заглушка для сообщения от пользователя. * * @author upagge [08/07/2019] */ -@ToString public class EmptyMessage extends Message { public EmptyMessage() { diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/Mail.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/Mail.java index 73ad0b7..1eafa1d 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/Mail.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/Mail.java @@ -1,10 +1,6 @@ package dev.struchkov.godfather.context.domain.content; import dev.struchkov.godfather.context.domain.content.attachment.Attachment; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; import javax.persistence.Column; import javax.persistence.Entity; @@ -19,11 +15,7 @@ import java.util.List; * @author upagge [08/07/2019] */ @Entity -@Getter -@Setter @Table(name = "mail") -@ToString(callSuper = true) -@EqualsAndHashCode(callSuper = true) public class Mail extends Message { /** @@ -56,4 +48,36 @@ public class Mail extends Message { type = ContentType.MAIL; } + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public List getAttachments() { + return attachments; + } + + public void setAttachments(List attachments) { + this.attachments = attachments; + } + + public List getForwardMail() { + return forwardMail; + } + + public void setForwardMail(List forwardMail) { + this.forwardMail = forwardMail; + } + } diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/Message.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/Message.java index acfde16..2c6487f 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/Message.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/Message.java @@ -1,10 +1,6 @@ package dev.struchkov.godfather.context.domain.content; import dev.struchkov.godfather.context.domain.BasicEntity; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; import javax.persistence.Column; import javax.persistence.EnumType; @@ -12,18 +8,14 @@ import javax.persistence.Enumerated; import javax.persistence.MappedSuperclass; import javax.validation.constraints.NotNull; import java.time.LocalDateTime; +import java.util.Objects; /** * Абстрактная сущность - Сообщение от пользователя. * * @author upagge [08/07/2019] */ - -@Getter -@Setter @MappedSuperclass -@NoArgsConstructor -@EqualsAndHashCode(callSuper = true) public abstract class Message extends BasicEntity { /** @@ -67,4 +59,60 @@ public abstract class Message extends BasicEntity { this.type = source.getType(); } + public Message() { + } + + public ContentType getType() { + return type; + } + + public void setType(ContentType type) { + this.type = type; + } + + public LocalDateTime getCreateDate() { + return createDate; + } + + public void setCreateDate(LocalDateTime createDate) { + this.createDate = createDate; + } + + public LocalDateTime getAddDate() { + return addDate; + } + + public void setAddDate(LocalDateTime addDate) { + this.addDate = addDate; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Message message = (Message) o; + return type == message.type && Objects.equals(createDate, message.createDate) && Objects.equals(addDate, message.addDate) && Objects.equals(personId, message.personId) && Objects.equals(text, message.text); + } + + @Override + public int hashCode() { + return Objects.hash(type, createDate, addDate, personId, text); + } + } diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/Attachment.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/Attachment.java index edbde4a..7605b66 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/Attachment.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/Attachment.java @@ -1,13 +1,11 @@ package dev.struchkov.godfather.context.domain.content.attachment; -import lombok.EqualsAndHashCode; +import dev.struchkov.godfather.context.domain.BasicEntity; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; /** * Абстрактная сущность, для всех вложений к сообщениям от пользователей. @@ -15,12 +13,7 @@ import javax.persistence.Id; * @author upagge [08/07/2019] */ @Entity -@EqualsAndHashCode -public abstract class Attachment { - - @Id - @GeneratedValue - private Integer id; +public abstract class Attachment extends BasicEntity { /** * Тип сущности. diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/AudioMessage.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/AudioMessage.java index a40613a..d833434 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/AudioMessage.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/AudioMessage.java @@ -1,22 +1,12 @@ package dev.struchkov.godfather.context.domain.content.attachment; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - import java.net.URL; - /** * Вложение типа "Аудиосообщение". * * @author upagge [08/07/2019] */ -@Getter -@EqualsAndHashCode(callSuper = true) -@ToString -@Setter public class AudioMessage extends Attachment { /** @@ -28,4 +18,8 @@ public class AudioMessage extends Attachment { type = AttachmentType.AUDIO_MESSAGE; } + public AudioMessage(URL linkOdd) { + this.linkOdd = linkOdd; + } + } diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/Geo.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/Geo.java index 77f722e..7f04300 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/Geo.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/Geo.java @@ -1,17 +1,10 @@ package dev.struchkov.godfather.context.domain.content.attachment; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; - /** * Вложение типа "Карта". * * @author upagge [08/07/2019] */ -@Getter -@ToString -@EqualsAndHashCode(callSuper = true) public class Geo extends Attachment { /** @@ -37,9 +30,20 @@ public class Geo extends Attachment { return new Geo().new Builder(); } + public GeoCoordinate getGeoCoordinate() { + return geoCoordinate; + } + + public String getCountry() { + return country; + } + + public String getCity() { + return city; + } + public class Builder { private Builder() { - } public Builder coordinate(Float lat, Float aLong) { diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/GeoCoordinate.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/GeoCoordinate.java index 3109a97..d0ac11d 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/GeoCoordinate.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/GeoCoordinate.java @@ -1,17 +1,10 @@ package dev.struchkov.godfather.context.domain.content.attachment; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; - /** * Сущность для хранения географических координат. * * @author upagge [08/07/2019] */ -@Getter -@Setter -@AllArgsConstructor public class GeoCoordinate { /** @@ -24,4 +17,25 @@ public class GeoCoordinate { */ private Float longitude; + public GeoCoordinate(Float latitude, Float longitude) { + this.latitude = latitude; + this.longitude = longitude; + } + + public Float getLatitude() { + return latitude; + } + + public void setLatitude(Float latitude) { + this.latitude = latitude; + } + + public Float getLongitude() { + return longitude; + } + + public void setLongitude(Float longitude) { + this.longitude = longitude; + } + } diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/Link.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/Link.java index fa350c9..3dd78ff 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/Link.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/Link.java @@ -1,14 +1,5 @@ package dev.struchkov.godfather.context.domain.content.attachment; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -@Getter -@Setter -@ToString -@EqualsAndHashCode(callSuper = true) public class Link extends Attachment { private String url; @@ -17,4 +8,12 @@ public class Link extends Attachment { this.type = AttachmentType.LINK; } + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + } diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/SimpleButton.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/SimpleButton.java index 5ffd775..bd98769 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/SimpleButton.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/SimpleButton.java @@ -1,20 +1,15 @@ package dev.struchkov.godfather.context.domain.keyboard.button; import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NonNull; -import lombok.ToString; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; /** * Абстрактная сущность кнопки для клавиатуры. * * @author upagge [08/07/2019] */ -@Getter -@ToString -@EqualsAndHashCode public class SimpleButton implements KeyBoardButton { public static final String TYPE = "SIMPLE"; @@ -28,20 +23,40 @@ public class SimpleButton implements KeyBoardButton { */ protected String callbackData; - @Builder(builderMethodName = "simpleBuilder", buildMethodName = "simpleBuild") protected SimpleButton(String label, String callbackData) { this.label = label; this.callbackData = callbackData; } - public static SimpleButton of(@NonNull String label, @NonNull String callbackData) { + public static SimpleButton of(@NotNull String label, @NotNull String callbackData) { return new SimpleButton(label, callbackData); } - public static SimpleButton of(@NonNull String label) { + public static SimpleButton of(@NotNull String label) { return new SimpleButton(label, label); } + public String getLabel() { + return label; + } + + public String getCallbackData() { + return callbackData; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SimpleButton that = (SimpleButton) o; + return Objects.equals(label, that.label) && Objects.equals(callbackData, that.callbackData); + } + + @Override + public int hashCode() { + return Objects.hash(label, callbackData); + } + @Override public String getType() { return TYPE; diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/simple/SimpleKeyBoard.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/simple/SimpleKeyBoard.java index 6634f18..fc39d17 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/simple/SimpleKeyBoard.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/simple/SimpleKeyBoard.java @@ -3,11 +3,6 @@ package dev.struchkov.godfather.context.domain.keyboard.simple; import dev.struchkov.godfather.context.domain.keyboard.KeyBoard; import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton; import dev.struchkov.godfather.context.domain.keyboard.KeyBoardLine; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Singular; -import lombok.ToString; import java.util.ArrayList; import java.util.List; @@ -17,9 +12,6 @@ import java.util.List; * * @author upagge [08/07/2019] */ -@Getter -@ToString -@EqualsAndHashCode public class SimpleKeyBoard implements KeyBoard { public static final String TYPE = "SIMPLE"; @@ -29,15 +21,22 @@ public class SimpleKeyBoard implements KeyBoard { */ protected List lines = new ArrayList<>(); - @Builder(builderMethodName = "simpleBuilder", buildMethodName = "simpleBuild") - public SimpleKeyBoard(@Singular("line") List lines) { + public SimpleKeyBoard(List lines) { this.lines = lines; } + private SimpleKeyBoard(Builder builder) { + lines = builder.lines; + } + public static SimpleKeyBoard single(KeyBoardLine line) { return new SimpleKeyBoard(List.of(line)); } + public static Builder build() { + return new Builder(); + } + public SimpleKeyBoard single(KeyBoardButton keyBoardButton) { return single(SimpleKeyBoardLine.single(keyBoardButton)); } @@ -47,4 +46,29 @@ public class SimpleKeyBoard implements KeyBoard { return TYPE; } + @Override + public List getLines() { + return lines; + } + + public static final class Builder { + private List lines = new ArrayList<>(); + + private Builder() { + } + + public Builder lines(List val) { + lines = val; + return this; + } + + public Builder line(KeyBoardLine val) { + lines.add(val); + return this; + } + + public SimpleKeyBoard build() { + return new SimpleKeyBoard(this); + } + } } diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/simple/SimpleKeyBoardLine.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/simple/SimpleKeyBoardLine.java index 07893cf..b55a0fe 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/simple/SimpleKeyBoardLine.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/simple/SimpleKeyBoardLine.java @@ -2,10 +2,6 @@ package dev.struchkov.godfather.context.domain.keyboard.simple; import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton; import dev.struchkov.godfather.context.domain.keyboard.KeyBoardLine; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Singular; -import lombok.ToString; import java.util.ArrayList; import java.util.List; @@ -15,8 +11,6 @@ import java.util.List; * * @author upagge [08/07/2019] */ -@ToString -@EqualsAndHashCode public class SimpleKeyBoardLine implements KeyBoardLine { /** @@ -24,18 +18,45 @@ public class SimpleKeyBoardLine implements KeyBoardLine { */ protected List buttons = new ArrayList<>(); - @Builder(builderMethodName = "simpleBuilder", buildMethodName = "simpleBuild") - public SimpleKeyBoardLine(@Singular(value = "button") List buttons) { + public SimpleKeyBoardLine(List buttons) { this.buttons = buttons; } + private SimpleKeyBoardLine(Builder builder) { + buttons = builder.buttons; + } + public static SimpleKeyBoardLine single(KeyBoardButton keyBoardButton) { return new SimpleKeyBoardLine(List.of(keyBoardButton)); } + public static Builder builder() { + return new Builder(); + } + @Override public List getButtons() { return buttons; } + public static final class Builder { + private List buttons = new ArrayList<>(); + + private Builder() { + } + + public Builder buttons(List val) { + buttons = val; + return this; + } + + public Builder button(KeyBoardButton val) { + buttons.add(val); + return this; + } + + public SimpleKeyBoardLine build() { + return new SimpleKeyBoardLine(this); + } + } } diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/exception/NotFoundException.java b/bot-context/src/main/java/dev/struchkov/godfather/context/exception/NotFoundException.java deleted file mode 100644 index a5b9b49..0000000 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/exception/NotFoundException.java +++ /dev/null @@ -1,14 +0,0 @@ -package dev.struchkov.godfather.context.exception; - -/** - * Ошибка, когда что-то не найдено. - * - * @author upagge [08/07/2019] - */ -public class NotFoundException extends AppBotException { - - public NotFoundException(String message) { - super(message); - } - -} diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/exception/UnitConfigException.java b/bot-context/src/main/java/dev/struchkov/godfather/context/exception/UnitConfigException.java new file mode 100644 index 0000000..a88c6a5 --- /dev/null +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/exception/UnitConfigException.java @@ -0,0 +1,23 @@ +package dev.struchkov.godfather.context.exception; + +import dev.struchkov.haiti.context.exception.NotFoundException; + +import java.text.MessageFormat; +import java.util.function.Supplier; + +/** + * Иключения связанные с настройками юнитов. + * + * @author upagge 28.04.2022 + */ +public class UnitConfigException extends AppBotException{ + + public UnitConfigException(String message) { + super(message); + } + + public static Supplier unitConfigException(String message, Object... objects) { + return () -> new NotFoundException(MessageFormat.format(message, objects)); + } + +} diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/repository/ContentRepository.java b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/ContentRepository.java index 5215f90..45679d8 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/repository/ContentRepository.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/ContentRepository.java @@ -1,7 +1,7 @@ package dev.struchkov.godfather.context.repository; -import lombok.NonNull; import dev.struchkov.godfather.context.domain.content.Message; +import org.jetbrains.annotations.NotNull; import java.time.LocalDateTime; import java.util.List; @@ -19,7 +19,7 @@ public interface ContentRepository { * @param content Объект сообщени * @return Идентификатор сообщения в хранилище */ - T add(@NonNull T content); + T add(@NotNull T content); /** * Получить все сообщения за определенный временной диапазон @@ -28,9 +28,9 @@ public interface ContentRepository { * @param dateTo Конец диапазона * @return Список сообщений */ - List betweenByCreateDateTime(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo); + List betweenByCreateDateTime(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo); - List betweenByAddDateTime(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo); + List betweenByAddDateTime(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo); /** * Удаляет данные за указанный период @@ -38,10 +38,10 @@ public interface ContentRepository { * @param dateFrom Дата начала * @param dateTo Дата окончания */ - void deleteAllByAddDateBetween(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo); + void deleteAllByAddDateBetween(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo); - void deleteAllByAddDateBefore(@NonNull LocalDateTime date); + void deleteAllByAddDateBefore(@NotNull LocalDateTime date); - void deleteAllByAddDateAfter(@NonNull LocalDateTime date); + void deleteAllByAddDateAfter(@NotNull LocalDateTime date); } diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/local/MailRepositoryList.java b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/local/MailRepositoryList.java index c77df88..a52744d 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/local/MailRepositoryList.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/local/MailRepositoryList.java @@ -1,9 +1,8 @@ package dev.struchkov.godfather.context.repository.impl.local; -import dev.struchkov.godfather.context.repository.ContentRepository; -import lombok.NonNull; -import lombok.extern.slf4j.Slf4j; import dev.struchkov.godfather.context.domain.content.Mail; +import dev.struchkov.godfather.context.repository.ContentRepository; +import org.jetbrains.annotations.NotNull; import java.time.LocalDateTime; import java.util.ArrayList; @@ -14,7 +13,6 @@ import java.util.List; * * @author upagge [27/07/2019] */ -@Slf4j public class MailRepositoryList implements ContentRepository { private final List mails = new ArrayList<>(); @@ -28,7 +26,7 @@ public class MailRepositoryList implements ContentRepository { } @Override - public List betweenByCreateDateTime(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo) { + public List betweenByCreateDateTime(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo) { ArrayList rezultMails = new ArrayList<>(); for (int i = mails.size() - 1; i >= 0; i--) { Mail mail = mails.get(i); @@ -42,7 +40,7 @@ public class MailRepositoryList implements ContentRepository { } @Override - public List betweenByAddDateTime(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo) { + public List betweenByAddDateTime(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo) { ArrayList rezultMails = new ArrayList<>(); for (int i = mails.size() - 1; i >= 0; i--) { Mail mail = mails.get(i); @@ -57,21 +55,21 @@ public class MailRepositoryList implements ContentRepository { } @Override - public void deleteAllByAddDateBetween(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo) { + public void deleteAllByAddDateBetween(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo) { mails.removeIf(mail -> dateFrom.isBefore(mail.getAddDate()) && dateTo.isAfter(mail.getAddDate())); } @Override - public void deleteAllByAddDateBefore(LocalDateTime date) { + public void deleteAllByAddDateBefore(@NotNull LocalDateTime date) { mails.removeIf(mail -> date.isBefore(mail.getAddDate())); } @Override - public void deleteAllByAddDateAfter(LocalDateTime date) { + public void deleteAllByAddDateAfter(@NotNull LocalDateTime date) { mails.removeIf(mail -> date.isAfter(mail.getAddDate())); } - private boolean isTimePeriod(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo, @NonNull LocalDateTime dateTime) { + private boolean isTimePeriod(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo, @NotNull LocalDateTime dateTime) { return dateFrom.isBefore(dateTime) && dateTo.isAfter(dateTime); } diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/service/MessageService.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/MessageService.java index f37a647..7293f23 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/service/MessageService.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/service/MessageService.java @@ -1,7 +1,7 @@ package dev.struchkov.godfather.context.service; -import lombok.NonNull; import dev.struchkov.godfather.context.domain.content.Message; +import org.jetbrains.annotations.NotNull; import java.time.LocalDateTime; import java.util.List; @@ -13,7 +13,7 @@ import java.util.List; */ public interface MessageService { - void add(@NonNull T event); + void add(@NotNull T event); /** * Получить список сообщений за заданный временной интервал @@ -22,7 +22,7 @@ public interface MessageService { * @param dateTo Конец интервала * @return Список сообщений */ - List getByAddDateTime(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo); + List getByAddDateTime(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo); /** * Получить список ПОСЛЕДНИХ сообщений для каждого пользователя за заданных временной интервал @@ -31,19 +31,19 @@ public interface MessageService { * @param dateTo Конец интервала * @return Список сообщений */ - List getLastEventByCreateDateTime(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo); + List getLastEventByCreateDateTime(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo); - List getLastEventByAddDateTime(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo); + List getLastEventByAddDateTime(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo); /** * Возвращает новые сообщения от последнего запроса. */ List getNewMessage(); - void deleteAllByAddDateBetween(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo); + void deleteAllByAddDateBetween(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo); - void deleteAllByAddDateBefore(@NonNull LocalDateTime date); + void deleteAllByAddDateBefore(@NotNull LocalDateTime date); - void deleteAllByAddDateAfter(@NonNull LocalDateTime date); + void deleteAllByAddDateAfter(@NotNull LocalDateTime date); } diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/service/Modifiable.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/Modifiable.java index c2a696e..dd4231c 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/service/Modifiable.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/service/Modifiable.java @@ -1,7 +1,7 @@ package dev.struchkov.godfather.context.service; -import lombok.NonNull; import dev.struchkov.godfather.context.domain.content.Message; +import org.jetbrains.annotations.NotNull; /** * Интерфес для изменения запроса пользователя перед тем, как он попадет в подсистему обработки. @@ -12,6 +12,6 @@ import dev.struchkov.godfather.context.domain.content.Message; @FunctionalInterface public interface Modifiable { - void change(@NonNull T content); + void change(@NotNull T content); } diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/service/impl/MailServiceImpl.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/impl/MailServiceImpl.java index 45e8c05..b9e0e08 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/service/impl/MailServiceImpl.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/service/impl/MailServiceImpl.java @@ -3,9 +3,9 @@ package dev.struchkov.godfather.context.service.impl; import dev.struchkov.godfather.context.domain.content.Mail; import dev.struchkov.godfather.context.repository.ContentRepository; import dev.struchkov.godfather.context.service.MailService; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; +import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.time.Clock; import java.time.LocalDateTime; @@ -16,14 +16,18 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -@Slf4j -@RequiredArgsConstructor public class MailServiceImpl implements MailService { + private static final Logger log = LoggerFactory.getLogger(MailServiceImpl.class); + private final ContentRepository mailRepository; private boolean newMessage = false; private LocalDateTime oldDateTime = LocalDateTime.now(Clock.tickSeconds(ZoneId.systemDefault())); + public MailServiceImpl(ContentRepository mailRepository) { + this.mailRepository = mailRepository; + } + //TODO [13.04.2022]: Подобная реализация с newMessage вызовет проблемы с несколькими инстансами. @Override public void add(Mail mail) { @@ -73,17 +77,17 @@ public class MailServiceImpl implements MailService { } @Override - public void deleteAllByAddDateBetween(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo) { + public void deleteAllByAddDateBetween(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo) { mailRepository.deleteAllByAddDateBetween(dateFrom, dateTo); } @Override - public void deleteAllByAddDateBefore(@NonNull LocalDateTime date) { + public void deleteAllByAddDateBefore(@NotNull LocalDateTime date) { mailRepository.deleteAllByAddDateBefore(date); } @Override - public void deleteAllByAddDateAfter(@NonNull LocalDateTime date) { + public void deleteAllByAddDateAfter(@NotNull LocalDateTime date) { mailRepository.deleteAllByAddDateAfter(date); } diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/Sending.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/Sending.java index d21bf15..c9a016a 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/Sending.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/Sending.java @@ -1,7 +1,7 @@ package dev.struchkov.godfather.context.service.sender; -import lombok.NonNull; import dev.struchkov.godfather.context.domain.BoxAnswer; +import org.jetbrains.annotations.NotNull; /** * Интерфейс для отправки ответов пользователю. @@ -16,9 +16,9 @@ public interface Sending { * @param personId Идентификатор пользователя * @param boxAnswer Объект с данными, которые необходимо отправить */ - void send(@NonNull Long personId, @NonNull BoxAnswer boxAnswer); + void send(@NotNull Long personId, @NotNull BoxAnswer boxAnswer); - void send(@NonNull Long contentId, @NonNull Long personId, @NonNull BoxAnswer boxAnswer); + void send(@NotNull Long contentId, @NotNull Long personId, @NotNull BoxAnswer boxAnswer); /** * Возвращает тип объекта отправляющего ответ пользователя. В зависимости от типа ответ будет отправлен с помощью diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/email/EmailConfig.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/email/EmailConfig.java deleted file mode 100644 index 5bcdd5e..0000000 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/email/EmailConfig.java +++ /dev/null @@ -1,68 +0,0 @@ -package dev.struchkov.godfather.context.service.sender.email; - -import lombok.Getter; - -import java.util.Properties; - -@Getter -public class EmailConfig { - - private Properties props = new Properties(); - private String username; - private String password; - - private EmailConfig() { - - } - - public static Builder builder() { - return new EmailConfig().new Builder(); - } - - public class Builder { - - private Builder() { - - } - - public Builder smtpHost(String smtpHost) { - EmailConfig.this.props.setProperty("mail.smtp.host", smtpHost); - return this; - } - - public Builder smtpSocketFactoryPort(Integer smtpSocketFactoryPortort) { - EmailConfig.this.props.setProperty("mail.smtp.socketFactory.port", smtpSocketFactoryPortort.toString()); - return this; - } - - public Builder smtpSocketFactoryClass(String smtpSocketFactoryClass) { - EmailConfig.this.props.setProperty("mail.smtp.socketFactory.class", smtpSocketFactoryClass); - return this; - } - - public Builder smtpAuth(Boolean smtpAuth) { - EmailConfig.this.props.setProperty("mail.smtp.auth", (smtpAuth) ? "true" : "false"); - return this; - } - - public Builder smtpPort(Integer smtpPort) { - EmailConfig.this.props.setProperty("mail.smtp.port", smtpPort.toString()); - return this; - } - - public Builder email(String username) { - EmailConfig.this.username = username; - return this; - } - - public Builder password(String password) { - EmailConfig.this.password = password; - return this; - } - - public EmailConfig build() { - return EmailConfig.this; - } - - } -} diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/email/EmailSending.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/email/EmailSending.java deleted file mode 100644 index a6b0a7b..0000000 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/email/EmailSending.java +++ /dev/null @@ -1,57 +0,0 @@ -package dev.struchkov.godfather.context.service.sender.email; - -import dev.struchkov.godfather.context.exception.MailSendException; -import dev.struchkov.godfather.context.service.sender.SendType; -import dev.struchkov.godfather.context.service.sender.Sending; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import dev.struchkov.godfather.context.domain.BoxAnswer; - -import javax.mail.Authenticator; -import javax.mail.Message; -import javax.mail.MessagingException; -import javax.mail.PasswordAuthentication; -import javax.mail.Session; -import javax.mail.Transport; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeMessage; - -@Slf4j -@RequiredArgsConstructor -public class EmailSending implements Sending { - - private final EmailConfig emailConfig; - - @Override - public void send(@NonNull Long personId, @NonNull BoxAnswer boxAnswer) { - Session session = Session.getDefaultInstance(emailConfig.getProps(), new Authenticator() { - @Override - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication(emailConfig.getUsername(), emailConfig.getPassword()); - } - }); - - try { - Message message = new MimeMessage(session); - message.setFrom(new InternetAddress(emailConfig.getUsername())); - message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(emailConfig.getUsername())); - message.setContent(boxAnswer.getMessage(), "text/html; charset=utf-8"); - Transport.send(message); - } catch (MessagingException e) { - log.error(e.getMessage()); - throw new MailSendException(); - } - } - - @Override - public void send(@NonNull Long contentId, @NonNull Long personId, @NonNull BoxAnswer boxAnswer) { - throw new MailSendException(); - } - - @Override - public SendType getType() { - return SendType.PUBLIC; - } - -} diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/utils/InsertWords.java b/bot-context/src/main/java/dev/struchkov/godfather/context/utils/InsertWords.java index 136ec10..fa120ae 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/utils/InsertWords.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/utils/InsertWords.java @@ -1,11 +1,13 @@ package dev.struchkov.godfather.context.utils; -import lombok.NonNull; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static dev.struchkov.haiti.utils.Exceptions.utilityClass; + /** * Класс для вставки слов в текстовую строку вместо подстрок - шаблонов маркеров. * @@ -16,7 +18,7 @@ public class InsertWords { private static final Pattern pattern = Pattern.compile("\\{(\\d+)}"); private InsertWords() { - throw new IllegalStateException(Messages.UTILITY_CLASS); + utilityClass(); } /** @@ -26,9 +28,9 @@ public class InsertWords { * @param words Список слов, которые необходимо поместить вместо шаблона * @return Модифицированная строка */ - public static String insert(@NonNull String text, List words) { - Matcher m = pattern.matcher(text); - StringBuffer result = new StringBuffer(); + public static String insert(@NotNull String text, List words) { + final Matcher m = pattern.matcher(text); + final StringBuilder result = new StringBuilder(); while (m.find()) { if (Integer.parseInt(m.group(1)) < words.size()) { m.appendReplacement(result, words.get(Integer.parseInt(m.group(1)))); diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/utils/KeyBoards.java b/bot-context/src/main/java/dev/struchkov/godfather/context/utils/KeyBoards.java index d0844fe..a163c4f 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/utils/KeyBoards.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/utils/KeyBoards.java @@ -27,9 +27,9 @@ public class KeyBoards { * @return {@link SimpleKeyBoard} */ public static SimpleKeyBoard keyBoardYesNo() { - return SimpleKeyBoard.simpleBuilder().line( - SimpleKeyBoardLine.simpleBuilder().button(YES_BUTTON).button(NO_BUTTON).simpleBuild() - ).simpleBuild(); + return SimpleKeyBoard.build().line( + SimpleKeyBoardLine.builder().button(YES_BUTTON).button(NO_BUTTON).build() + ).build(); } /** @@ -39,12 +39,12 @@ public class KeyBoards { * @return {@link SimpleKeyBoard} */ public static SimpleKeyBoard verticalMenuString(List labelButtons) { - final SimpleKeyBoard.SimpleKeyBoardBuilder keyBoard = SimpleKeyBoard.simpleBuilder(); + final SimpleKeyBoard.Builder keyBoard = SimpleKeyBoard.build(); for (String labelButton : labelButtons) { final SimpleButton simpleButton = SimpleButton.of(labelButton, "{\"button\": \"" + labelButton + "\"}"); - keyBoard.line(SimpleKeyBoardLine.simpleBuilder().button(simpleButton).simpleBuild()); + keyBoard.line(SimpleKeyBoardLine.builder().button(simpleButton).build()); } - return keyBoard.simpleBuild(); + return keyBoard.build(); } /** @@ -74,25 +74,25 @@ public class KeyBoards { * @return {@link SimpleKeyBoard} */ public static SimpleKeyBoard verticalDuoMenuString(List labelButton) { - final SimpleKeyBoard.SimpleKeyBoardBuilder keyBoard = SimpleKeyBoard.simpleBuilder(); + final SimpleKeyBoard.Builder keyBoard = SimpleKeyBoard.build(); boolean flag = true; - SimpleKeyBoardLine.SimpleKeyBoardLineBuilder keyBoardLine = SimpleKeyBoardLine.simpleBuilder(); + SimpleKeyBoardLine.Builder keyBoardLine = SimpleKeyBoardLine.builder(); for (int i = 0; i <= labelButton.size() - 1; i++) { String label = labelButton.get(i); keyBoardLine.button(SimpleButton.of(label)); if (flag) { if (i == labelButton.size() - 1) { - keyBoard.line(keyBoardLine.simpleBuild()); + keyBoard.line(keyBoardLine.build()); } else { flag = false; } } else { - keyBoard.line(keyBoardLine.simpleBuild()); - keyBoardLine = SimpleKeyBoardLine.simpleBuilder(); + keyBoard.line(keyBoardLine.build()); + keyBoardLine = SimpleKeyBoardLine.builder(); flag = true; } } - return keyBoard.simpleBuild(); + return keyBoard.build(); } /** @@ -102,22 +102,11 @@ public class KeyBoards { * @return {@link SimpleKeyBoard} */ public static SimpleKeyBoard verticalMenuButton(List simpleButtons) { - final SimpleKeyBoard.SimpleKeyBoardBuilder keyBoard = SimpleKeyBoard.simpleBuilder(); + final SimpleKeyBoard.Builder keyBoard = SimpleKeyBoard.build(); for (SimpleButton simpleButton : simpleButtons) { - keyBoard.line(SimpleKeyBoardLine.simpleBuilder().button(simpleButton).simpleBuild()); + keyBoard.line(SimpleKeyBoardLine.builder().button(simpleButton).build()); } - return keyBoard.simpleBuild(); - } - - /** - * Возвращает клавиатуру из одной кнопки - * - * @param simpleButton Кнопка - * @return {@link SimpleKeyBoard} - */ - public static SimpleKeyBoard singleton(SimpleButton simpleButton) { - final SimpleKeyBoardLine line = SimpleKeyBoardLine.simpleBuilder().button(simpleButton).simpleBuild(); - return SimpleKeyBoard.simpleBuilder().line(line).simpleBuild(); + return keyBoard.build(); } } diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/utils/Sender.java b/bot-context/src/main/java/dev/struchkov/godfather/context/utils/Sender.java index c2470c7..eb7b518 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/utils/Sender.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/utils/Sender.java @@ -3,7 +3,8 @@ package dev.struchkov.godfather.context.utils; import dev.struchkov.godfather.context.domain.BoxAnswer; import dev.struchkov.godfather.context.domain.content.Message; import dev.struchkov.godfather.context.service.sender.Sending; -import dev.struchkov.godfather.context.domain.content.Comment; + +import static dev.struchkov.haiti.utils.Exceptions.utilityClass; /** * Используется для отправки сообщений определенного типа. @@ -13,13 +14,12 @@ import dev.struchkov.godfather.context.domain.content.Comment; public class Sender { private Sender() { - throw new IllegalStateException(Messages.UTILITY_CLASS); + utilityClass(); } public static void sends(Message message, BoxAnswer boxAnswer, Sending sending) { switch (sending.getType()) { case PUBLIC: - publicSend(message, boxAnswer, sending); break; case PRIVATE: privateSend(message, boxAnswer, sending); @@ -27,12 +27,6 @@ public class Sender { } } - private static void publicSend(Message message, BoxAnswer boxAnswer, Sending sending) { - if (message instanceof Comment) { - sending.send(((Comment) message).getContentId(), message.getPersonId(), boxAnswer); - } - } - private static void privateSend(Message message, BoxAnswer boxAnswer, Sending sending) { sending.send(message.getPersonId(), boxAnswer); } diff --git a/bot-core/pom.xml b/bot-core/pom.xml index 15d83d7..fd9a331 100644 --- a/bot-core/pom.xml +++ b/bot-core/pom.xml @@ -6,7 +6,7 @@ dev.struchkov.godfather godfather-bot - 0.0.4-SNAPSHOT + 0.0.4 bot-core @@ -14,10 +14,6 @@ Bot Core Реализация основной логики для создания ботов без привязки к конкретным социальным сетям. - - false - - dev.struchkov.godfather @@ -25,7 +21,7 @@ - org.sadtech.autoresponder + dev.struchkov autoresponder diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/GeneralAutoResponder.java b/bot-core/src/main/java/dev/struchkov/godfather/core/GeneralAutoResponder.java index f566cdc..b3c8e40 100644 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/GeneralAutoResponder.java +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/GeneralAutoResponder.java @@ -1,8 +1,11 @@ package dev.struchkov.godfather.core; +import dev.struchkov.autoresponder.AutoResponder; +import dev.struchkov.autoresponder.entity.UnitPointer; +import dev.struchkov.autoresponder.repository.UnitPointerRepository; +import dev.struchkov.autoresponder.service.UnitPointerServiceImpl; import dev.struchkov.godfather.context.domain.content.Message; import dev.struchkov.godfather.context.exception.ConfigAppException; -import dev.struchkov.godfather.context.exception.NotFoundException; import dev.struchkov.godfather.context.service.MessageService; import dev.struchkov.godfather.context.service.Modifiable; import dev.struchkov.godfather.context.service.sender.Sending; @@ -17,10 +20,7 @@ import dev.struchkov.godfather.core.service.action.AnswerTimerAction; import dev.struchkov.godfather.core.service.action.AnswerValidityAction; import dev.struchkov.godfather.core.service.timer.TimerService; import dev.struchkov.godfather.core.utils.TypeUnit; -import org.sadtech.autoresponder.AutoResponder; -import org.sadtech.autoresponder.entity.UnitPointer; -import org.sadtech.autoresponder.repository.UnitPointerRepository; -import org.sadtech.autoresponder.service.UnitPointerServiceImpl; +import dev.struchkov.haiti.context.exception.NotFoundException; import java.util.HashMap; import java.util.List; @@ -130,7 +130,7 @@ public class GeneralAutoResponder extends TimerTask { MainUnit mainUnit = actionUnit.action(unitAnswer, event); return !unitAnswer.equals(mainUnit) ? getAction(event, mainUnit) : mainUnit; } else { - throw new NotFoundException("ActionUnit для типа " + unitAnswer.getType() + " не зарегистрирован"); + throw new NotFoundException("ActionUnit для типа {0} не зарегистрирован", unitAnswer.getType()); } } diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/Clarification.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/Clarification.java index bb259dc..626d440 100644 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/Clarification.java +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/Clarification.java @@ -1,14 +1,23 @@ package dev.struchkov.godfather.core.domain; import dev.struchkov.godfather.context.domain.BoxAnswer; -import lombok.Builder; -import lombok.Getter; -@Builder -@Getter public class Clarification { private BoxAnswer question; private String value; + public Clarification(BoxAnswer question, String value) { + this.question = question; + this.value = value; + } + + public BoxAnswer getQuestion() { + return question; + } + + public String getValue() { + return value; + } + } diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/Timer.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/Timer.java index 98b0305..ca4ccce 100644 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/Timer.java +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/Timer.java @@ -2,9 +2,6 @@ package dev.struchkov.godfather.core.domain; import dev.struchkov.godfather.context.service.usercode.CheckData; import dev.struchkov.godfather.core.domain.unit.MainUnit; -import lombok.Builder; -import lombok.Getter; -import lombok.Setter; import java.time.LocalDateTime; @@ -13,9 +10,6 @@ import java.time.LocalDateTime; * * @author upagge [11/07/2019] */ -@Getter -@Setter -@Builder public class Timer { /** @@ -58,4 +52,140 @@ public class Timer { */ private CheckData checkLoop; + private Timer(Builder builder) { + id = builder.id; + unitAnswer = builder.unitAnswer; + unitDeath = builder.unitDeath; + personId = builder.personId; + timeActive = builder.timeActive; + timeDeath = builder.timeDeath; + periodSec = builder.periodSec; + checkLoop = builder.checkLoop; + } + + public static Builder builder() { + return new Builder(); + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public MainUnit getUnitAnswer() { + return unitAnswer; + } + + public void setUnitAnswer(MainUnit unitAnswer) { + this.unitAnswer = unitAnswer; + } + + public MainUnit getUnitDeath() { + return unitDeath; + } + + public void setUnitDeath(MainUnit unitDeath) { + this.unitDeath = unitDeath; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public LocalDateTime getTimeActive() { + return timeActive; + } + + public void setTimeActive(LocalDateTime timeActive) { + this.timeActive = timeActive; + } + + public LocalDateTime getTimeDeath() { + return timeDeath; + } + + public void setTimeDeath(LocalDateTime timeDeath) { + this.timeDeath = timeDeath; + } + + public Integer getPeriodSec() { + return periodSec; + } + + public void setPeriodSec(Integer periodSec) { + this.periodSec = periodSec; + } + + public CheckData getCheckLoop() { + return checkLoop; + } + + public void setCheckLoop(CheckData checkLoop) { + this.checkLoop = checkLoop; + } + + public static final class Builder { + private Integer id; + private MainUnit unitAnswer; + private MainUnit unitDeath; + private Long personId; + private LocalDateTime timeActive; + private LocalDateTime timeDeath; + private Integer periodSec; + private CheckData checkLoop; + + private Builder() { + } + + public Builder id(Integer val) { + id = val; + return this; + } + + public Builder unitAnswer(MainUnit val) { + unitAnswer = val; + return this; + } + + public Builder unitDeath(MainUnit val) { + unitDeath = val; + return this; + } + + public Builder personId(Long val) { + personId = val; + return this; + } + + public Builder timeActive(LocalDateTime val) { + timeActive = val; + return this; + } + + public Builder timeDeath(LocalDateTime val) { + timeDeath = val; + return this; + } + + public Builder periodSec(Integer val) { + periodSec = val; + return this; + } + + public Builder checkLoop(CheckData val) { + checkLoop = val; + return this; + } + + public Timer build() { + return new Timer(this); + } + } } diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/question/Question.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/question/Question.java index e6a4e5c..66a83a2 100644 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/question/Question.java +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/question/Question.java @@ -1,32 +1,32 @@ -package dev.struchkov.godfather.core.domain.question; - -import dev.struchkov.godfather.context.domain.BoxAnswer; -import lombok.Builder; -import lombok.Getter; -import lombok.Setter; -import lombok.Singular; - -import java.util.List; - -/** - * Используется для конфигурации генерации цепочки Unit-ов в виде тестов для прохождения пользователем. - * - * @author upagge [14/07/2019] - */ -@Getter -@Setter -@Builder -public class Question { - - /** - * Вопрос. - */ - private BoxAnswer boxAnswer; - - /** - * Список предполагаемых ответов. - */ - @Singular - private List questionAnswers; - -} +//package dev.struchkov.godfather.core.domain.question; +// +//import dev.struchkov.godfather.context.domain.BoxAnswer; +//import lombok.Builder; +//import lombok.Getter; +//import lombok.Setter; +//import lombok.Singular; +// +//import java.util.List; +// +///** +// * Используется для конфигурации генерации цепочки Unit-ов в виде тестов для прохождения пользователем. +// * +// * @author upagge [14/07/2019] +// */ +//@Getter +//@Setter +//@Builder +//public class Question { +// +// /** +// * Вопрос. +// */ +// private BoxAnswer boxAnswer; +// +// /** +// * Список предполагаемых ответов. +// */ +// @Singular +// private List questionAnswers; +// +//} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/question/QuestionAnswer.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/question/QuestionAnswer.java index 5790b15..1f07e80 100644 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/question/QuestionAnswer.java +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/question/QuestionAnswer.java @@ -1,35 +1,35 @@ -package dev.struchkov.godfather.core.domain.question; - -import lombok.Getter; -import lombok.Setter; - -/** - * Используется для конфигурации генерации цепочки Unit-ов в виде тестов для прохождения пользователем. - * Отвечает за варианты ответов. - * - * @author upagge [14/07/2019] - */ -@Getter -@Setter -public class QuestionAnswer { - - /** - * Текстовый ответ. - */ - private String text; - - /** - * Количество балов за ответ. - */ - private int points; - - public QuestionAnswer(String text, Integer points) { - this.text = text; - this.points = points; - } - - public QuestionAnswer(String text) { - this.text = text; - } - -} +//package dev.struchkov.godfather.core.domain.question; +// +//import lombok.Getter; +//import lombok.Setter; +// +///** +// * Используется для конфигурации генерации цепочки Unit-ов в виде тестов для прохождения пользователем. +// * Отвечает за варианты ответов. +// * +// * @author upagge [14/07/2019] +// */ +//@Getter +//@Setter +//public class QuestionAnswer { +// +// /** +// * Текстовый ответ. +// */ +// private String text; +// +// /** +// * Количество балов за ответ. +// */ +// private int points; +// +// public QuestionAnswer(String text, Integer points) { +// this.text = text; +// this.points = points; +// } +// +// public QuestionAnswer(String text) { +// this.text = text; +// } +// +//} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/question/QuestionResult.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/question/QuestionResult.java index 3e34e4e..683ccb2 100644 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/question/QuestionResult.java +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/question/QuestionResult.java @@ -1,32 +1,32 @@ -package dev.struchkov.godfather.core.domain.question; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; - -/** - * Используется для сохранения результатов ответов на вопросы. - * - * @author upagge [14/07/2019] - */ -@Getter -@Setter -@AllArgsConstructor -public class QuestionResult { - - /** - * Вопрос. - */ - private String question; - - /** - * Ответ. - */ - private String answer; - - /** - * Количество баллов за ответ. - */ - private Integer points; - -} +//package dev.struchkov.godfather.core.domain.question; +// +//import lombok.AllArgsConstructor; +//import lombok.Getter; +//import lombok.Setter; +// +///** +// * Используется для сохранения результатов ответов на вопросы. +// * +// * @author upagge [14/07/2019] +// */ +//@Getter +//@Setter +//@AllArgsConstructor +//public class QuestionResult { +// +// /** +// * Вопрос. +// */ +// private String question; +// +// /** +// * Ответ. +// */ +// private String answer; +// +// /** +// * Количество баллов за ответ. +// */ +// private Integer points; +// +//} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerCheck.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerCheck.java index 19c7187..19a8359 100644 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerCheck.java +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerCheck.java @@ -3,21 +3,20 @@ package dev.struchkov.godfather.core.domain.unit; import dev.struchkov.godfather.context.domain.content.Message; import dev.struchkov.godfather.context.service.usercode.CheckData; import dev.struchkov.godfather.core.utils.TypeUnit; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Singular; +import java.util.HashSet; import java.util.Set; import java.util.regex.Pattern; +import static dev.struchkov.godfather.context.exception.UnitConfigException.unitConfigException; +import static dev.struchkov.haiti.utils.Inspector.isAnyNotNull; +import static dev.struchkov.haiti.utils.Inspector.isNotNull; + /** * Обработчик запроса, который реализует конструкцию IF в сценарии. * * @author upagge [08/07/2019] */ -@Getter -@EqualsAndHashCode(callSuper = true) public class AnswerCheck extends MainUnit { /** @@ -35,23 +34,99 @@ public class AnswerCheck extends MainUnit { */ private final CheckData check; - @Builder - protected AnswerCheck( - @Singular Set keyWords, - String phrase, - Pattern pattern, - Integer matchThreshold, - Integer priority, - @Singular Set nextUnits, - UnitActiveType activeType, - MainUnit unitTrue, - MainUnit unitFalse, - CheckData check - ) { - super(keyWords, phrase, pattern, matchThreshold, priority, nextUnits, activeType, TypeUnit.CHECK); - this.unitTrue = unitTrue; - this.unitFalse = unitFalse; - this.check = check; + private AnswerCheck(Builder builder) { + super(builder.keyWords, builder.phrase, builder.pattern, builder.matchThreshold, builder.priority, null, builder.activeType, TypeUnit.CHECK); + unitTrue = builder.unitTrue; + unitFalse = builder.unitFalse; + check = builder.check; + } + + public static Builder builder() { + return new Builder(); + } + + public MainUnit getUnitTrue() { + return unitTrue; + } + + public MainUnit getUnitFalse() { + return unitFalse; + } + + public CheckData getCheck() { + return check; + } + + public static final class Builder { + private Set keyWords = new HashSet<>(); + private String phrase; + private Pattern pattern; + private Integer matchThreshold; + private Integer priority; + private MainUnit unitTrue; + private MainUnit unitFalse; + private CheckData check; + private UnitActiveType activeType; + + private Builder() { + } + + public Builder keyWords(Set val) { + keyWords = val; + return this; + } + + public Builder keyWord(String val) { + keyWords.add(val); + return this; + } + + public Builder phrase(String val) { + phrase = val; + return this; + } + + public Builder pattern(Pattern val) { + pattern = val; + return this; + } + + public Builder matchThreshold(Integer val) { + matchThreshold = val; + return this; + } + + public Builder priority(Integer val) { + priority = val; + return this; + } + + public Builder unitTrue(MainUnit unitTrue) { + this.unitTrue = unitTrue; + return this; + } + + public Builder unitFalse(MainUnit unitFalse) { + this.unitFalse = unitFalse; + return this; + } + + public Builder check(CheckData check) { + this.check = check; + return this; + } + + public Builder activeType(UnitActiveType val) { + activeType = val; + return this; + } + + public AnswerCheck build() { + isNotNull(check, unitConfigException("Необходимо установить параметр проверки.")); + isAnyNotNull(unitConfigException("Необходимо задать хотя бы один unit результата проверки.")); + return new AnswerCheck(this); + } + } } diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerProcessing.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerProcessing.java index f8abb07..dffc576 100644 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerProcessing.java +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerProcessing.java @@ -4,11 +4,8 @@ import dev.struchkov.godfather.context.domain.content.Message; import dev.struchkov.godfather.context.service.sender.Sending; import dev.struchkov.godfather.context.service.usercode.ProcessingData; import dev.struchkov.godfather.core.utils.TypeUnit; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Singular; +import java.util.HashSet; import java.util.Set; import java.util.regex.Pattern; @@ -17,8 +14,6 @@ import java.util.regex.Pattern; * * @author upagge [08/07/2019] */ -@Getter -@EqualsAndHashCode(callSuper = true) public class AnswerProcessing extends MainUnit { /** @@ -31,21 +26,87 @@ public class AnswerProcessing extends MainUnit { */ private final Sending sending; - @Builder - private AnswerProcessing( - @Singular Set keyWords, - String phrase, - Pattern pattern, - Integer matchThreshold, - Integer priority, - @Singular Set nextUnits, - UnitActiveType activeType, - ProcessingData processingData, - Sending sending - ) { - super(keyWords, phrase, pattern, matchThreshold, priority, nextUnits, activeType, TypeUnit.PROCESSING); - this.processingData = processingData; - this.sending = sending; + private AnswerProcessing(Builder builder) { + super(builder.keyWords, builder.phrase, builder.pattern, builder.matchThreshold, builder.priority, builder.nextUnits, builder.activeType, TypeUnit.PROCESSING); + processingData = builder.processingData; + sending = builder.sending; + } + + public static Builder builder() { + return new Builder<>(); + } + + public ProcessingData getProcessingData() { + return processingData; + } + + public Sending getSending() { + return sending; + } + + public static final class Builder { + private Set keyWords = new HashSet<>(); + private String phrase; + private Pattern pattern; + private Integer matchThreshold; + private Integer priority; + private Set nextUnits = new HashSet<>(); + private ProcessingData processingData; + private Sending sending; + private UnitActiveType activeType; + + private Builder() { + } + + public Builder keyWords(Set val) { + keyWords = val; + return this; + } + + public Builder keyWord(String val) { + keyWords.add(val); + return this; + } + + public Builder phrase(String val) { + phrase = val; + return this; + } + + public Builder pattern(Pattern val) { + pattern = val; + return this; + } + + public Builder matchThreshold(Integer val) { + matchThreshold = val; + return this; + } + + public Builder priority(Integer val) { + priority = val; + return this; + } + + public Builder nextUnits(Set val) { + nextUnits = val; + return this; + } + + public Builder nextUnit(MainUnit val) { + nextUnits.add(val); + return this; + } + + public Builder activeType(UnitActiveType val) { + activeType = val; + return this; + } + + public AnswerProcessing build() { + return new AnswerProcessing<>(this); + } + } } diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerSave.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerSave.java index ef3b08a..65bdb38 100644 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerSave.java +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerSave.java @@ -6,13 +6,8 @@ import dev.struchkov.godfather.core.service.save.Preservable; import dev.struchkov.godfather.core.service.save.data.PreservableData; import dev.struchkov.godfather.core.service.save.push.Pusher; import dev.struchkov.godfather.core.utils.TypeUnit; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Singular; import java.util.Collection; -import java.util.Optional; import java.util.Set; import java.util.regex.Pattern; @@ -21,8 +16,6 @@ import java.util.regex.Pattern; * * @author upagge [08/07/2019] */ -@Getter -@EqualsAndHashCode(callSuper = true) public class AnswerSave extends MainUnit { /** @@ -52,29 +45,19 @@ public class AnswerSave extends MainUnit { private final CheckSave checkSave; - @Builder - private AnswerSave( - @Singular Set keyWords, - String phrase, - Pattern pattern, - Integer matchThreshold, - Integer priority, - @Singular Set nextUnits, - Preservable preservable, - String key, - Pusher pusher, - PreservableData preservableData, - CheckSave checkSave, - boolean hidden - ) { - super(keyWords, phrase, pattern, matchThreshold, priority, nextUnits, (hidden) ? UnitActiveType.AFTER : UnitActiveType.DEFAULT, TypeUnit.SAVE); - this.key = key; - this.pusher = pusher; + private AnswerSave(Builder builder) { + super(builder.keyWords, builder.phrase, builder.pattern, builder.matchThreshold, builder.priority, builder.nextUnits, (builder.hidden) ? UnitActiveType.AFTER : UnitActiveType.DEFAULT, TypeUnit.SAVE); maintenanceNextUnit(nextUnits); - this.preservable = preservable; - this.preservableData = preservableData; - this.hidden = Optional.of(hidden).orElse(false); - this.checkSave = checkSave; + preservable = builder.preservable; + key = builder.key; + pusher = builder.pusher; + preservableData = builder.preservableData; + hidden = builder.hidden; + checkSave = builder.checkSave; + } + + public static Builder builder() { + return new Builder<>(); } private void maintenanceNextUnit(Collection units) { @@ -83,4 +66,121 @@ public class AnswerSave extends MainUnit { } } + public Preservable getPreservable() { + return preservable; + } + + public String getKey() { + return key; + } + + public Pusher getPusher() { + return pusher; + } + + public PreservableData getPreservableData() { + return preservableData; + } + + public boolean isHidden() { + return hidden; + } + + public CheckSave getCheckSave() { + return checkSave; + } + + public static final class Builder { + private Set keyWords; + private String phrase; + private Pattern pattern; + private Integer matchThreshold; + private Integer priority; + private Set nextUnits; + private Preservable preservable; + private String key; + private Pusher pusher; + private PreservableData preservableData; + private boolean hidden; + private CheckSave checkSave; + + private Builder() { + } + + public Builder keyWords(Set val) { + keyWords = val; + return this; + } + + public Builder keyWord(String val) { + keyWords.add(val); + return this; + } + + public Builder phrase(String val) { + phrase = val; + return this; + } + + public Builder pattern(Pattern val) { + pattern = val; + return this; + } + + public Builder matchThreshold(Integer val) { + matchThreshold = val; + return this; + } + + public Builder priority(Integer val) { + priority = val; + return this; + } + + public Builder nextUnits(Set val) { + nextUnits = val; + return this; + } + + public Builder nextUnit(MainUnit val) { + nextUnits.add(val); + return this; + } + + public Builder preservable(Preservable val) { + this.preservable = val; + return this; + } + + public Builder key(String val) { + this.key = val; + return this; + } + + public Builder pusher(Pusher val) { + this.pusher = val; + return this; + } + + public Builder preservableData(PreservableData val) { + this.preservableData = val; + return this; + } + + public Builder hidden(boolean val) { + this.hidden = val; + return this; + } + + public Builder checkSave(CheckSave val) { + this.checkSave = val; + return this; + } + + public AnswerSave build() { + return new AnswerSave<>(this); + } + + } + } diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerText.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerText.java index 69466b1..37769b9 100644 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerText.java +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerText.java @@ -2,25 +2,23 @@ package dev.struchkov.godfather.core.domain.unit; import dev.struchkov.godfather.context.domain.BoxAnswer; import dev.struchkov.godfather.context.domain.content.Message; +import dev.struchkov.godfather.context.exception.UnitConfigException; import dev.struchkov.godfather.context.service.sender.Sending; import dev.struchkov.godfather.context.service.usercode.Insert; import dev.struchkov.godfather.context.service.usercode.ProcessingData; import dev.struchkov.godfather.core.utils.TypeUnit; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Singular; +import java.util.HashSet; import java.util.Set; import java.util.regex.Pattern; +import static dev.struchkov.haiti.utils.Inspector.isNotNull; + /** * Используется для отправки ответа пользователю. * * @author upagge [08/07/2019] */ -@Getter -@EqualsAndHashCode(callSuper = true) public class AnswerText extends MainUnit { /** @@ -31,34 +29,122 @@ public class AnswerText extends MainUnit { /** * Информация, которую необходимо вставить вместо маркеров в строку ответа. */ - private final Insert insert; + private Insert insert; /** * Объект нестандартной отправки ответа. */ - private final Sending sending; + private Sending sending; - @Builder(toBuilder = true) - private AnswerText( - @Singular Set keyWords, - String phrase, - Pattern pattern, - Integer matchThreshold, - Integer priority, - @Singular Set nextUnits, - UnitActiveType activeType, - ProcessingData boxAnswer, - Insert insert, - Sending sending - ) { - super(keyWords, phrase, pattern, matchThreshold, priority, nextUnits, activeType, TypeUnit.TEXT); - this.boxAnswer = boxAnswer; - this.insert = insert; - this.sending = sending; + private AnswerText(Builder builder) { + super(builder.keyWords, builder.phrase, builder.pattern, builder.matchThreshold, builder.priority, builder.nextUnits, builder.activeType, TypeUnit.TEXT); + keyWords = builder.keyWords; + phrase = builder.phrase; + pattern = builder.pattern; + matchThreshold = builder.matchThreshold; + priority = builder.priority; + nextUnits = builder.nextUnits; + boxAnswer = builder.boxAnswer; + insert = builder.insert; + sending = builder.sending; + activeType = builder.activeType; } - public static AnswerText of(String message) { - return builder().boxAnswer(BoxAnswer.processing(message)).build(); + public static AnswerText of(String message) { + return AnswerText.builder().boxAnswer(BoxAnswer.processing(message)).build(); } + public static Builder builder() { + return new Builder<>(); + } + + public ProcessingData getBoxAnswer() { + return boxAnswer; + } + + public Insert getInsert() { + return insert; + } + + public Sending getSending() { + return sending; + } + + public static final class Builder { + private ProcessingData boxAnswer; + private Insert insert; + private Sending sending; + private Set keyWords; + private String phrase; + private Pattern pattern; + private Integer matchThreshold; + private Integer priority; + private Set nextUnits = new HashSet<>(); + private UnitActiveType activeType; + + private Builder() { + + } + + public Builder boxAnswer(ProcessingData boxAnswer) { + this.boxAnswer = boxAnswer; + return this; + } + + public Builder insert(Insert insert) { + this.insert = insert; + return this; + } + + public Builder sending(Sending sending) { + this.sending = sending; + return this; + } + + public Builder keyWords(Set val) { + keyWords = val; + return this; + } + + public Builder phrase(String val) { + phrase = val; + return this; + } + + public Builder pattern(Pattern val) { + pattern = val; + return this; + } + + public Builder matchThreshold(Integer val) { + matchThreshold = val; + return this; + } + + public Builder priority(Integer val) { + priority = val; + return this; + } + + public Builder nextUnits(Set val) { + nextUnits = val; + return this; + } + + public Builder nextUnit(MainUnit val) { + nextUnits.add(val); + return this; + } + + public Builder activeType(UnitActiveType val) { + activeType = val; + return this; + } + + public AnswerText build() { + isNotNull(boxAnswer, UnitConfigException.unitConfigException("BoxAnswer обязательный параметр юнита")); + return new AnswerText<>(this); + } + + } } diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerTimer.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerTimer.java index de077c2..ff4638a 100644 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerTimer.java +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerTimer.java @@ -1,25 +1,21 @@ package dev.struchkov.godfather.core.domain.unit; +import dev.struchkov.godfather.context.domain.content.Message; import dev.struchkov.godfather.context.service.usercode.CheckData; import dev.struchkov.godfather.core.utils.TypeUnit; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Singular; -import lombok.ToString; import java.util.Set; import java.util.regex.Pattern; +import static dev.struchkov.godfather.context.exception.UnitConfigException.unitConfigException; +import static dev.struchkov.haiti.utils.Inspector.isNotNull; + /** * Обработчик таймер, позволяющий отложить обработку других Unit-ов. * * @author upagge [08/07/2019] */ -@Getter -@ToString -@EqualsAndHashCode(callSuper = true) -public class AnswerTimer extends MainUnit { +public class AnswerTimer extends MainUnit { /** * Unit обработку которого необходимо отложить. @@ -39,27 +35,107 @@ public class AnswerTimer extends MainUnit { /** * Условие срабатывания отложенного Unit. */ - private final CheckData checkLoop; + private final CheckData checkLoop; + + private AnswerTimer(Builder builder) { + super(builder.keyWords, builder.phrase, builder.pattern, builder.matchThreshold, builder.priority, null, builder.activeType, TypeUnit.TIMER); + unitAnswer = builder.unitAnswer; + timeDelaySec = builder.timeDelaySec; + timeDeathSec = builder.timeDeathSec; + checkLoop = builder.checkLoop; + } + + public static Builder builder() { + return new Builder<>(); + } + + public MainUnit getUnitAnswer() { + return unitAnswer; + } + + public Integer getTimeDelaySec() { + return timeDelaySec; + } + + public Integer getTimeDeathSec() { + return timeDeathSec; + } + + public CheckData getCheckLoop() { + return checkLoop; + } + + public static final class Builder { + private MainUnit unitAnswer; + private Integer timeDelaySec; + private Integer timeDeathSec; + private CheckData checkLoop; + private Set keyWords; + private String phrase; + private Pattern pattern; + private Integer matchThreshold; + private Integer priority; + private UnitActiveType activeType = UnitActiveType.AFTER; + + private Builder() { + + } + + public Builder unitAnswer(MainUnit val) { + unitAnswer = val; + return this; + } + + public Builder timeDelaySec(Integer val) { + timeDelaySec = val; + return this; + } + + public Builder timeDeathSec(Integer val) { + timeDeathSec = val; + return this; + } + + public Builder checkLoop(CheckData val) { + checkLoop = val; + return this; + } + + public Builder keyWords(Set val) { + keyWords = val; + return this; + } + + public Builder phrase(String val) { + phrase = val; + return this; + } + + public Builder pattern(Pattern val) { + pattern = val; + return this; + } + + public Builder matchThreshold(Integer val) { + matchThreshold = val; + return this; + } + + public Builder priority(Integer val) { + priority = val; + return this; + } + + public Builder activeType(UnitActiveType val) { + activeType = val; + return this; + } + + public AnswerTimer build() { + isNotNull(unitAnswer, unitConfigException("Необходимо указать юнит, обработка которого будет отложена.")); + return new AnswerTimer<>(this); + } - @Builder - private AnswerTimer( - @Singular Set keyWords, - String phrase, - Pattern pattern, - Integer matchThreshold, - Integer priority, - @Singular Set nextUnits, - UnitActiveType activeType, - MainUnit unitAnswer, - Integer timeDelaySec, - Integer timeDeathSec, - CheckData checkLoop - ) { - super(keyWords, phrase, pattern, matchThreshold, priority, nextUnits, (activeType == null) ? UnitActiveType.AFTER : activeType, TypeUnit.TIMER); - this.unitAnswer = unitAnswer; - this.timeDelaySec = timeDelaySec; - this.timeDeathSec = timeDeathSec; - this.checkLoop = checkLoop; } } diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerValidity.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerValidity.java index 3701378..2453c06 100644 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerValidity.java +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerValidity.java @@ -4,11 +4,6 @@ import dev.struchkov.godfather.core.service.ClarificationQuestion; import dev.struchkov.godfather.core.service.save.LocalPreservable; import dev.struchkov.godfather.core.service.save.Preservable; import dev.struchkov.godfather.core.utils.TypeUnit; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Singular; -import lombok.ToString; import java.util.Set; import java.util.regex.Pattern; @@ -18,9 +13,6 @@ import java.util.regex.Pattern; * * @author upagge [11/07/2019] */ -@Getter -@ToString -@EqualsAndHashCode(callSuper = true) public class AnswerValidity extends MainUnit { /** @@ -42,24 +34,121 @@ public class AnswerValidity extends MainUnit { private final ClarificationQuestion clarificationQuestion; - @Builder(toBuilder = true) - private AnswerValidity( - @Singular Set keyWords, - String phrase, - Pattern pattern, - Integer matchThreshold, - Integer priority, - @Singular Set nextUnits, - MainUnit unitYes, - MainUnit unitNo, - MainUnit unitNull, - ClarificationQuestion clarificationQuestion - ) { - super(keyWords, phrase, pattern, matchThreshold, priority, nextUnits, UnitActiveType.DEFAULT, TypeUnit.VALIDITY); - this.unitYes = unitYes; - this.unitNo = unitNo; - this.unitNull = unitNull; - this.clarificationQuestion = clarificationQuestion; + private AnswerValidity(Builder builder) { + super(builder.keyWords, builder.phrase, builder.pattern, builder.matchThreshold, builder.priority, builder.nextUnits, UnitActiveType.DEFAULT, TypeUnit.VALIDITY); + unitYes = builder.unitYes; + unitNo = builder.unitNo; + unitNull = builder.unitNull; + clarificationQuestion = builder.clarificationQuestion; + } + + public static Builder builder() { + return new Builder(); + } + + public MainUnit getUnitYes() { + return unitYes; + } + + public MainUnit getUnitNo() { + return unitNo; + } + + public MainUnit getUnitNull() { + return unitNull; + } + + public Preservable getTempSave() { + return tempSave; + } + + public ClarificationQuestion getClarificationQuestion() { + return clarificationQuestion; + } + + public static final class Builder { + private MainUnit unitYes; + private MainUnit unitNo; + private MainUnit unitNull; + private ClarificationQuestion clarificationQuestion; + private Set keyWords; + private String phrase; + private Pattern pattern; + private Integer matchThreshold; + private Integer priority; + private Set nextUnits; + + private Builder() { + } + + public Builder unitYes(MainUnit val) { + unitYes = val; + return this; + } + + public Builder unitNo(MainUnit val) { + unitNo = val; + return this; + } + + public Builder unitNull(MainUnit val) { + unitNull = val; + return this; + } + + public Builder clarificationQuestion(ClarificationQuestion val) { + clarificationQuestion = val; + return this; + } + + public Builder keyWords(Set val) { + keyWords = val; + return this; + } + + public Builder keyWord(String val) { + keyWords.add(val); + return this; + } + + public Builder phrase(String val) { + phrase = val; + return this; + } + + public Builder pattern(Pattern val) { + pattern = val; + return this; + } + + public Builder matchThreshold(Integer val) { + matchThreshold = val; + return this; + } + + public Builder priority(Integer val) { + priority = val; + return this; + } + + public Builder nextUnits(Set val) { + nextUnits = val; + return this; + } + + public Builder nextUnit(MainUnit val) { + nextUnits.add(val); + return this; + } + + public Builder clearKeyWords() { + nextUnits.clear(); + return this; + } + + public AnswerValidity build() { + return new AnswerValidity(this); + } } } diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/MainUnit.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/MainUnit.java index 558e0e3..44249ac 100644 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/MainUnit.java +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/MainUnit.java @@ -1,11 +1,8 @@ package dev.struchkov.godfather.core.domain.unit; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import org.sadtech.autoresponder.entity.Unit; +import dev.struchkov.autoresponder.entity.Unit; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.UUID; @@ -16,25 +13,19 @@ import java.util.regex.Pattern; * * @author upagge [08/07/2019] */ -@ToString -@EqualsAndHashCode(callSuper = true) public abstract class MainUnit extends Unit { /** * Тип Unit-а. */ - @Getter protected final String type; /** * Режим срабатывания Unit-а. */ - @Getter - @Setter protected UnitActiveType activeType; - @Getter - private String uuid = UUID.randomUUID().toString(); + private final String uuid = UUID.randomUUID().toString(); protected MainUnit( Set keyWords, @@ -51,4 +42,34 @@ public abstract class MainUnit extends Unit { this.type = type; } + public String getType() { + return type; + } + + public void setActiveType(UnitActiveType activeType) { + this.activeType = activeType; + } + + public UnitActiveType getActiveType() { + return activeType; + } + + public String getUuid() { + return uuid; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + MainUnit mainUnit = (MainUnit) o; + return Objects.equals(type, mainUnit.type) && activeType == mainUnit.activeType && Objects.equals(uuid, mainUnit.uuid); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), type, activeType, uuid); + } + } diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerCheckAction.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerCheckAction.java index a6de446..6757452 100644 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerCheckAction.java +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerCheckAction.java @@ -3,7 +3,8 @@ package dev.struchkov.godfather.core.service.action; import dev.struchkov.godfather.context.domain.content.Message; import dev.struchkov.godfather.core.domain.unit.AnswerCheck; import dev.struchkov.godfather.core.domain.unit.MainUnit; -import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Optional; @@ -12,9 +13,10 @@ import java.util.Optional; * * @author upagge [11/07/2019] */ -@Slf4j public class AnswerCheckAction implements ActionUnit { + private static final Logger log = LoggerFactory.getLogger(AnswerCheckAction.class); + @Override public MainUnit action(AnswerCheck answerCheck, Message mail) { MainUnit unitAnswer; diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerProcessingAction.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerProcessingAction.java index 3cb4600..08b09e2 100644 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerProcessingAction.java +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerProcessingAction.java @@ -22,7 +22,7 @@ public class AnswerProcessingAction implements ActionUnit answerProcessing, Message message) { - BoxAnswer boxAnswer = answerProcessing.getProcessingData().processing(message); + final BoxAnswer boxAnswer = answerProcessing.getProcessingData().processing(message); Sending answerProcessingSending = answerProcessing.getSending(); if (answerProcessingSending != null) { diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerTextAction.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerTextAction.java index c0d3d0b..a94d01b 100644 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerTextAction.java +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerTextAction.java @@ -7,8 +7,6 @@ import dev.struchkov.godfather.context.utils.InsertWords; import dev.struchkov.godfather.context.utils.Sender; import dev.struchkov.godfather.core.domain.unit.AnswerText; import dev.struchkov.godfather.core.domain.unit.MainUnit; -import lombok.AllArgsConstructor; -import lombok.NoArgsConstructor; import java.util.List; @@ -17,22 +15,20 @@ import java.util.List; * * @author upagge [11/07/2019] */ -@AllArgsConstructor -@NoArgsConstructor -public class AnswerTextAction implements ActionUnit { +public class AnswerTextAction implements ActionUnit, Message> { - private Sending sending; + private final Sending sending; + + public AnswerTextAction(Sending sending) { + this.sending = sending; + } @Override - public MainUnit action(AnswerText answerText, Message message) { - BoxAnswer boxAnswer = answerText.getBoxAnswer().processing(message); - if (answerText.getInsert() != null) { - List words = answerText.getInsert().insert(message.getPersonId()); - String newMessage = InsertWords.insert(boxAnswer.getMessage(), words); - boxAnswer.setMessage(newMessage); - } + public MainUnit action(AnswerText answerText, Message message) { + final BoxAnswer boxAnswer = answerText.getBoxAnswer().processing(message); + replaceMarkers(answerText, message, boxAnswer); - Sending answerTextSending = answerText.getSending(); + final Sending answerTextSending = answerText.getSending(); if (answerTextSending != null) { Sender.sends(message, boxAnswer, answerTextSending); } else { @@ -42,5 +38,13 @@ public class AnswerTextAction implements ActionUnit { return answerText; } + private void replaceMarkers(AnswerText answerText, Message message, BoxAnswer boxAnswer) { + if (answerText.getInsert() != null) { + final List words = answerText.getInsert().insert(message.getPersonId()); + final String newMessage = InsertWords.insert(boxAnswer.getMessage(), words); + boxAnswer.setMessage(newMessage); + } + } + } diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerTimerAction.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerTimerAction.java index 47850f8..f37fa7a 100644 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerTimerAction.java +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerTimerAction.java @@ -47,7 +47,7 @@ public class AnswerTimerAction implements ActionUnit { .ofNullable(answerTimer.getTimeDelaySec()) .orElseThrow(() -> new TimerSettingException("Не установлена временная задержка таймера"))); - Timer.TimerBuilder timer = Timer.builder() + Timer.Builder timer = Timer.builder() .personId(message.getPersonId()) .unitAnswer(answerTimer.getUnitAnswer()) .timeActive(timeActive) diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerValidityAction.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerValidityAction.java index d07b20a..1a88003 100644 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerValidityAction.java +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerValidityAction.java @@ -39,7 +39,7 @@ public class AnswerValidityAction implements ActionUnit return unit.getUnitNull(); } else { unit.getTempSave().save(personId, "temp", value); - AnswerValidity newValidity = unit.toBuilder() + AnswerValidity newValidity = unit.builder() .clearKeyWords().keyWords(WORDS_YES_NO) .build(); return AnswerText.builder() diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/data/PreservableDataSimple.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/data/PreservableDataSimple.java index b9a9d97..e11b026 100644 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/data/PreservableDataSimple.java +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/data/PreservableDataSimple.java @@ -1,7 +1,7 @@ package dev.struchkov.godfather.core.service.save.data; import dev.struchkov.godfather.context.domain.content.Message; -import dev.struchkov.godfather.core.utils.Pair; +import dev.struchkov.haiti.utils.Pair; /** * TODO: Добавить описание класса. diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/jpa/PreservableJpa.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/jpa/PreservableJpa.java deleted file mode 100644 index bb93656..0000000 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/jpa/PreservableJpa.java +++ /dev/null @@ -1,23 +0,0 @@ -package dev.struchkov.godfather.core.service.save.jpa;//package org.sadtech.social.bot.service.save.jpa; -// -//import lombok.RequiredArgsConstructor; -//import org.sadtech.social.bot.service.save.Preservable; -//import org.springframework.data.jpa.repository.JpaRepository; -// -///** -// * TODO: Добавить описание класса. -// * -// * @author upagge [01/08/2019] -// */ -//@RequiredArgsConstructor -//public abstract class PreservableJpa, D extends SaveObjectJpa> implements Preservable { -// -// protected final R jpaRepository; -// -// @Override -// public void save(Long personId, String key, R save) { -// save.setPersonId(personId); -// jpaRepository.save(save); -// } -// -//} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/jpa/SaveObjectJpa.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/jpa/SaveObjectJpa.java deleted file mode 100644 index b4e9dd2..0000000 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/jpa/SaveObjectJpa.java +++ /dev/null @@ -1,25 +0,0 @@ -package dev.struchkov.godfather.core.service.save.jpa; - -import dev.struchkov.godfather.context.domain.BasicEntity; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -import javax.persistence.Column; -import javax.persistence.MappedSuperclass; - -/** - * TODO: Добавить описание класса. - * - * @author upagge [01/08/2019] - */ -@Getter -@Setter -@MappedSuperclass -@EqualsAndHashCode(callSuper = true) -public abstract class SaveObjectJpa extends BasicEntity { - - @Column(name = "personId") - private Long personId; - -} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/push/EmailPusher.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/push/EmailPusher.java deleted file mode 100644 index 50c155f..0000000 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/push/EmailPusher.java +++ /dev/null @@ -1,125 +0,0 @@ -package dev.struchkov.godfather.core.service.save.push; - -import dev.struchkov.godfather.context.exception.MailSendException; -import dev.struchkov.godfather.context.service.sender.email.EmailConfig; -import lombok.extern.slf4j.Slf4j; - -import javax.mail.Authenticator; -import javax.mail.Message; -import javax.mail.MessagingException; -import javax.mail.PasswordAuthentication; -import javax.mail.Session; -import javax.mail.Transport; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeMessage; -import java.util.Map; - -/** - * Сохранение результатов анкеты на Email. - * - * @author upagge [11/07/2019] - */ -// todo [upagge] [11/07/2019]: Отрефакторить -@Slf4j -public class EmailPusher implements Pusher { - - private final EmailConfig emailConfig; - private final String nameForm; - - public EmailPusher(EmailConfig emailConfig, String nameForm) { - this.emailConfig = emailConfig; - this.nameForm = nameForm; - } - - @Override - public void push(Map saveElement) { - - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - "
\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - "
  
\n" + - "
\n" + - "
\n" + - "

") - .append(nameForm) - .append("

\n" + - "
\n" + - " \n" + - " "); - for (Map.Entry element : saveElement.entrySet()) { - stringBuilder.append("\n" + - " \n" + - " "); - } - stringBuilder.append("\n" + - "
") - .append(element.getKey()) - .append(":\n" + - " ") - .append(element.getValue()) - .append("
\n" + - " \n" + - "
\n" + - "
\n" + - "
\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - "
\n" + - "
\n" + - "
\n" + - "
\n" + - "
 
\n" + - "
\n" + - "
\n" + - "
\n" + - "
\n" + - "
"); - - Session session = Session.getDefaultInstance(emailConfig.getProps(), new Authenticator() { - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication(emailConfig.getUsername(), emailConfig.getPassword()); - } - }); - - try { - Message message = new MimeMessage(session); - message.setFrom(new InternetAddress(emailConfig.getUsername())); - message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(emailConfig.getUsername())); - message.setSubject(nameForm); - message.setContent(stringBuilder.toString(), "text/html; charset=utf-8"); - Transport.send(message); - } catch (MessagingException e) { - log.error(e.getMessage()); - throw new MailSendException(); - } - - } - -} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/timer/TimerActionTask.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/timer/TimerActionTask.java index 5b4a1cc..a8760ad 100644 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/service/timer/TimerActionTask.java +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/timer/TimerActionTask.java @@ -1,11 +1,12 @@ package dev.struchkov.godfather.core.service.timer; import dev.struchkov.godfather.context.domain.content.Message; +import dev.struchkov.godfather.context.service.usercode.CheckData; import dev.struchkov.godfather.context.utils.MessageUtils; import dev.struchkov.godfather.core.GeneralAutoResponder; import dev.struchkov.godfather.core.domain.Timer; -import dev.struchkov.godfather.context.service.usercode.CheckData; -import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.time.Clock; import java.time.LocalDateTime; @@ -17,9 +18,10 @@ import java.util.TimerTask; * * @author upagge [11/07/2019] */ -@Slf4j public class TimerActionTask extends TimerTask { + private static final Logger log = LoggerFactory.getLogger(TimerActionTask.class); + private final TimerService timerService; private final GeneralAutoResponder generalAutoresponder; diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/timer/TimerServiceImpl.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/timer/TimerServiceImpl.java index eac6133..83914f2 100644 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/service/timer/TimerServiceImpl.java +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/timer/TimerServiceImpl.java @@ -2,19 +2,23 @@ package dev.struchkov.godfather.core.service.timer; import dev.struchkov.godfather.core.domain.Timer; import dev.struchkov.godfather.core.repository.TimerRepository; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; -@Slf4j -@RequiredArgsConstructor public class TimerServiceImpl implements TimerService { + private static final Logger log = LoggerFactory.getLogger(TimerServiceImpl.class); + private final TimerRepository timerRepository; + public TimerServiceImpl(TimerRepository timerRepository) { + this.timerRepository = timerRepository; + } + public TimerRepository getTimerRepository() { return timerRepository; } diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/utils/Pair.java b/bot-core/src/main/java/dev/struchkov/godfather/core/utils/Pair.java deleted file mode 100644 index 9e14895..0000000 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/utils/Pair.java +++ /dev/null @@ -1,17 +0,0 @@ -package dev.struchkov.godfather.core.utils; - -import lombok.AllArgsConstructor; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@EqualsAndHashCode -@AllArgsConstructor -public class Pair { - - private K key; - private D value; - -} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/utils/QuestionUtils.java b/bot-core/src/main/java/dev/struchkov/godfather/core/utils/QuestionUtils.java index d66114c..93ad6e9 100644 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/utils/QuestionUtils.java +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/utils/QuestionUtils.java @@ -1,95 +1,95 @@ -package dev.struchkov.godfather.core.utils; - -import dev.struchkov.godfather.context.domain.BoxAnswer; -import dev.struchkov.godfather.context.utils.KeyBoards; -import dev.struchkov.godfather.core.domain.question.Question; -import dev.struchkov.godfather.core.domain.question.QuestionAnswer; -import dev.struchkov.godfather.core.domain.question.QuestionResult; -import dev.struchkov.godfather.core.domain.unit.AnswerSave; -import dev.struchkov.godfather.core.domain.unit.AnswerText; -import dev.struchkov.godfather.core.domain.unit.MainUnit; -import dev.struchkov.godfather.core.domain.unit.UnitActiveType; -import dev.struchkov.godfather.core.service.save.Preservable; -import dev.struchkov.godfather.core.service.save.push.Pusher; - -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -/** - * Утилита для быстрой генерации цепочки Unit-ов, образующих сценарий "Тестирование". - * - * @author upagge [14/07/2019] - */ -public class QuestionUtils { - - private final Preservable preservable; - private final List questions; - private Pusher pusher; - - private QuestionUtils(List questions, Preservable preservable) { - this.questions = questions; - this.preservable = preservable; - } - - private QuestionUtils(List questions, Preservable preservable, Pusher pusher) { - this.questions = questions; - this.preservable = preservable; - this.pusher = pusher; - } - - public static QuestionUtils builder(Preservable preservable, List questions) { - return new QuestionUtils(questions, preservable); - } - - public static QuestionUtils builder(Preservable preservable, Pusher pusher, List list) { - return new QuestionUtils(list, preservable, pusher); - } - - public MainUnit build(MainUnit finishUnit) { - return generateTest(finishUnit); - } - - public MainUnit build() { - return generateTest(null); - } - - private MainUnit generateTest(MainUnit finishUnit) { - AnswerText previousUnit = null; - for (int i = questions.size() - 1; i >= 0; i--) { - Question question = this.questions.get(i); - List collectAnswer = question.getQuestionAnswers().stream() - .map(QuestionAnswer::getText) - .collect(Collectors.toList()); - BoxAnswer boxAnswer = question.getBoxAnswer().toBuilder() - .keyBoard(KeyBoards.verticalDuoMenuString(collectAnswer)).build(); - - AnswerText.AnswerTextBuilder answerTextBuilder = AnswerText.builder() - .boxAnswer(message -> boxAnswer); - - for (QuestionAnswer questionAnswer : question.getQuestionAnswers()) { - AnswerSave.AnswerSaveBuilder answerSaveBuilder = AnswerSave.builder() - .preservable(preservable) - .preservableData( - message -> new QuestionResult( - question.getBoxAnswer().getMessage(), - questionAnswer.getText(), - questionAnswer.getPoints() - ) - ) - .phrase(questionAnswer.getText()); - if (i != this.questions.size() - 1) { - answerSaveBuilder.nextUnit(previousUnit).build(); - } else { - answerSaveBuilder.pusher(pusher); - Optional.of(finishUnit).ifPresent(answerSaveBuilder::nextUnit); - } - answerTextBuilder.nextUnit(answerSaveBuilder.build()); - } - if (i == 0) answerTextBuilder.activeType(UnitActiveType.AFTER); - previousUnit = answerTextBuilder.build(); - } - return previousUnit; - } - -} +//package dev.struchkov.godfather.core.utils; +// +//import dev.struchkov.godfather.context.domain.BoxAnswer; +//import dev.struchkov.godfather.context.utils.KeyBoards; +//import dev.struchkov.godfather.core.domain.question.Question; +//import dev.struchkov.godfather.core.domain.question.QuestionAnswer; +//import dev.struchkov.godfather.core.domain.question.QuestionResult; +//import dev.struchkov.godfather.core.domain.unit.AnswerSave; +//import dev.struchkov.godfather.core.domain.unit.AnswerText; +//import dev.struchkov.godfather.core.domain.unit.MainUnit; +//import dev.struchkov.godfather.core.domain.unit.UnitActiveType; +//import dev.struchkov.godfather.core.service.save.Preservable; +//import dev.struchkov.godfather.core.service.save.push.Pusher; +// +//import java.util.List; +//import java.util.Optional; +//import java.util.stream.Collectors; +// +///** +// * Утилита для быстрой генерации цепочки Unit-ов, образующих сценарий "Тестирование". +// * +// * @author upagge [14/07/2019] +// */ +//public class QuestionUtils { +// +// private final Preservable preservable; +// private final List questions; +// private Pusher pusher; +// +// private QuestionUtils(List questions, Preservable preservable) { +// this.questions = questions; +// this.preservable = preservable; +// } +// +// private QuestionUtils(List questions, Preservable preservable, Pusher pusher) { +// this.questions = questions; +// this.preservable = preservable; +// this.pusher = pusher; +// } +// +// public static QuestionUtils builder(Preservable preservable, List questions) { +// return new QuestionUtils(questions, preservable); +// } +// +// public static QuestionUtils builder(Preservable preservable, Pusher pusher, List list) { +// return new QuestionUtils(list, preservable, pusher); +// } +// +// public MainUnit build(MainUnit finishUnit) { +// return generateTest(finishUnit); +// } +// +// public MainUnit build() { +// return generateTest(null); +// } +// +// private MainUnit generateTest(MainUnit finishUnit) { +// AnswerText previousUnit = null; +// for (int i = questions.size() - 1; i >= 0; i--) { +// Question question = this.questions.get(i); +// List collectAnswer = question.getQuestionAnswers().stream() +// .map(QuestionAnswer::getText) +// .collect(Collectors.toList()); +// BoxAnswer boxAnswer = question.getBoxAnswer().toBuilder() +// .keyBoard(KeyBoards.verticalDuoMenuString(collectAnswer)).build(); +// +// AnswerText.Builder answerTextBuilder = AnswerText.builder() +// .boxAnswer(message -> boxAnswer); +// +// for (QuestionAnswer questionAnswer : question.getQuestionAnswers()) { +// AnswerSave.AnswerSaveBuilder answerSaveBuilder = AnswerSave.builder() +// .preservable(preservable) +// .preservableData( +// message -> new QuestionResult( +// question.getBoxAnswer().getMessage(), +// questionAnswer.getText(), +// questionAnswer.getPoints() +// ) +// ) +// .phrase(questionAnswer.getText()); +// if (i != this.questions.size() - 1) { +// answerSaveBuilder.nextUnit(previousUnit).build(); +// } else { +// answerSaveBuilder.pusher(pusher); +// Optional.of(finishUnit).ifPresent(answerSaveBuilder::nextUnit); +// } +// answerTextBuilder.nextUnit(answerSaveBuilder.build()); +// } +// if (i == 0) answerTextBuilder.activeType(UnitActiveType.AFTER); +// previousUnit = answerTextBuilder.build(); +// } +// return previousUnit; +// } +// +//} diff --git a/pom.xml b/pom.xml index 7eb8e5f..8160820 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ dev.struchkov.godfather godfather-bot - 0.0.4-SNAPSHOT + 0.0.4 pom @@ -32,41 +32,46 @@ UTF-8 UTF-8 - 0.0.4-SNAPSHOT - 0.0.4-SNAPSHOT - 1.9.4-RELEASE + 0.0.4 + + ${godfather.ver} + ${godfather.ver} + + 2.0.0 + 1.0.2 - 2.9.0 - 1.6.2 - 1.18.22 2.2 2.0.1.Final 1.7.36 + 23.0.0 - 3.9.0 - 1.6.12 + 3.10.1 + 1.6.13 3.2.1 - 3.3.2 + 3.4.0 3.0.1 - com.google.code.gson - gson - ${gson.ver} + dev.struchkov.godfather + bot-context + ${godfather.core.ver} + + + + + dev.struchkov + autoresponder + ${autoresponder.ver} - javax.mail - javax.mail-api - ${mail.ver} - - - org.projectlombok - lombok - ${lombok.ver} + dev.struchkov.haiti + haiti-utils + ${haiti.utils} + javax.persistence javax.persistence-api @@ -78,15 +83,9 @@ ${validation.api.ver} - dev.struchkov.godfather - bot-context - ${godfather.core.ver} - - - - org.sadtech.autoresponder - autoresponder - ${autoresponder.ver} + org.jetbrains + annotations + ${jetbrains.annotations.ver} @@ -118,13 +117,6 @@ ${java.version} ${java.version} - - - org.projectlombok - lombok - ${lombok.ver} - -