From dc567ad410f3ee286edafa421b30db550b0e2c27 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Thu, 30 Mar 2023 19:33:06 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2=20=D0=B8=20UniPre?= =?UTF-8?q?dicate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../godfather/quarkus/domain/BoxAnswer.java | 18 +++-- .../godfather/quarkus/domain/SentBox.java | 41 ++++------ .../domain/unit/func/UniPredicate.java | 6 ++ .../godfather/simple/domain/BoxAnswer.java | 74 ++++++++----------- .../godfather/simple/domain/SentBox.java | 39 ++++------ .../domain/content/send/SendAttachment.java | 9 +++ .../simple/domain/content/send/SendFile.java | 23 ++++++ pom.xml | 3 +- 8 files changed, 112 insertions(+), 101 deletions(-) create mode 100644 bot-domain/bot-domain-simple/src/main/java/dev/struchkov/godfather/simple/domain/content/send/SendAttachment.java create mode 100644 bot-domain/bot-domain-simple/src/main/java/dev/struchkov/godfather/simple/domain/content/send/SendFile.java diff --git a/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/BoxAnswer.java b/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/BoxAnswer.java index abd064a..43fb1c7 100644 --- a/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/BoxAnswer.java +++ b/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/BoxAnswer.java @@ -1,5 +1,9 @@ package dev.struchkov.godfather.quarkus.domain; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import dev.struchkov.godfather.main.domain.jackson.TelegramPayloadDeserializer; +import dev.struchkov.godfather.main.domain.jackson.TelegramPayloadSerializer; import dev.struchkov.godfather.main.domain.keyboard.KeyBoard; import dev.struchkov.haiti.utils.container.ContextKey; import lombok.Getter; @@ -51,7 +55,9 @@ public class BoxAnswer { /** * Полезная нагрузка для реализаций. */ - protected Map payload; + @JsonSerialize(using = TelegramPayloadSerializer.class) + @JsonDeserialize(using = TelegramPayloadDeserializer.class) + protected Map payload = new HashMap<>(); private BoxAnswer(Builder builder) { message = builder.message; @@ -112,13 +118,13 @@ public class BoxAnswer { } } - public Map getPayload() { + public Map getPayload() { return payload; } public void setPayload(ContextKey key, T value) { if (checkNotNull(value)) { - payload.put(key.getValue(), value); + payload.put(key, value); } } @@ -137,7 +143,7 @@ public class BoxAnswer { private boolean replace; private String replaceMessageId; private String recipientPersonId; - private Map payload = new HashMap<>(); + private Map payload = new HashMap<>(); private Builder() { } @@ -169,14 +175,14 @@ public class BoxAnswer { public Builder payload(ContextKey key, T value) { if (checkNotNull(value)) { - payload.put(key.getValue(), value); + payload.put(key, value); } return this; } public Builder payload(ContextKey key) { if (checkNotNull(key)) { - payload.put(key.getValue(), true); + payload.put(key, true); } return this; } diff --git a/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/SentBox.java b/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/SentBox.java index 71307ea..682ff08 100644 --- a/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/SentBox.java +++ b/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/SentBox.java @@ -1,39 +1,30 @@ package dev.struchkov.godfather.quarkus.domain; +import dev.struchkov.godfather.main.domain.content.Mail; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + import java.util.Optional; +@Getter +@Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor(access = AccessLevel.PRIVATE) public class SentBox { private String personId; private String messageId; + private Mail sentMail; private BoxAnswer sentAnswer; private BoxAnswer originalAnswer; - public SentBox(String personId, String messageId, BoxAnswer sentAnswer, BoxAnswer originalAnswer) { - this.personId = personId; - this.messageId = messageId; - this.sentAnswer = sentAnswer; - this.originalAnswer = originalAnswer; - } - - public static Optional optional(String personId, String messageId, BoxAnswer sentAnswer, BoxAnswer originalAnswer) { - return Optional.of(new SentBox(personId, messageId, sentAnswer, originalAnswer)); - } - - public String getPersonId() { - return personId; - } - - public String getMessageId() { - return messageId; - } - - public BoxAnswer getSentAnswer() { - return sentAnswer; - } - - public BoxAnswer getOriginalAnswer() { - return originalAnswer; + public Optional getMail() { + return Optional.ofNullable(sentMail); } } diff --git a/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/unit/func/UniPredicate.java b/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/unit/func/UniPredicate.java index 98c257e..6f7e582 100644 --- a/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/unit/func/UniPredicate.java +++ b/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/unit/func/UniPredicate.java @@ -2,8 +2,14 @@ package dev.struchkov.godfather.quarkus.domain.unit.func; import io.smallrye.mutiny.Uni; +import java.util.function.Predicate; + public interface UniPredicate { Uni test(T t); + static UniPredicate predicate(Predicate predicate) { + return t -> Uni.createFrom().item(predicate.test(t)); + } + } diff --git a/bot-domain/bot-domain-simple/src/main/java/dev/struchkov/godfather/simple/domain/BoxAnswer.java b/bot-domain/bot-domain-simple/src/main/java/dev/struchkov/godfather/simple/domain/BoxAnswer.java index 8e07ea7..d1c9e81 100644 --- a/bot-domain/bot-domain-simple/src/main/java/dev/struchkov/godfather/simple/domain/BoxAnswer.java +++ b/bot-domain/bot-domain-simple/src/main/java/dev/struchkov/godfather/simple/domain/BoxAnswer.java @@ -1,7 +1,15 @@ package dev.struchkov.godfather.simple.domain; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import dev.struchkov.godfather.main.domain.jackson.TelegramPayloadDeserializer; +import dev.struchkov.godfather.main.domain.jackson.TelegramPayloadSerializer; import dev.struchkov.godfather.main.domain.keyboard.KeyBoard; +import dev.struchkov.godfather.simple.domain.content.send.SendAttachment; import dev.struchkov.haiti.utils.container.ContextKey; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; import java.util.HashMap; import java.util.Map; @@ -15,6 +23,9 @@ import static dev.struchkov.haiti.utils.Checker.checkNull; * * @author upagge [08/07/2019] */ +@Getter +@Setter +@NoArgsConstructor public class BoxAnswer { /** @@ -25,17 +36,17 @@ public class BoxAnswer { /** * Идентификатор сообщения, которое нужно заменить. */ - private final String replaceMessageId; + private String replaceMessageId; /** * Клавиатура - меню. */ - private final KeyBoard keyBoard; + private KeyBoard keyBoard; /** * Флаг означающий, что надо перезаписать наше последнее отправленное сообщение, вместо отправки нового. */ - private final boolean replace; + private boolean replace; /** * Обычное текстовое сообщение. @@ -45,7 +56,11 @@ public class BoxAnswer { /** * Полезная нагрузка для реализаций. */ - protected Map payload; + @JsonSerialize(using = TelegramPayloadSerializer.class) + @JsonDeserialize(using = TelegramPayloadDeserializer.class) + private Map payload = new HashMap<>(); + + private SendAttachment attachment; private BoxAnswer(Builder builder) { message = builder.message; @@ -54,6 +69,7 @@ public class BoxAnswer { replaceMessageId = builder.replaceMessageId; recipientPersonId = builder.recipientPersonId; payload = builder.payload; + attachment = builder.attachment; } public static BoxAnswer boxAnswer(boolean replace, String message) { @@ -96,30 +112,6 @@ public class BoxAnswer { return new Builder().replace(true); } - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public KeyBoard getKeyBoard() { - return keyBoard; - } - - public boolean isReplace() { - return replace; - } - - public String getReplaceMessageId() { - return replaceMessageId; - } - - public String getRecipientPersonId() { - return recipientPersonId; - } - public void setRecipientPersonId(String recipientPersonId) { this.recipientPersonId = recipientPersonId; } @@ -130,28 +122,14 @@ public class BoxAnswer { } } - public Map getPayload() { - return payload; - } - - public void setPayload(ContextKey key, T value) { + public void addPayload(ContextKey key, T value) { if (checkNotNull(value)) { payload.put(key, value); } } public Optional getPayLoad(ContextKey contextKey) { - return Optional.ofNullable(payload.get(contextKey)) - .map(value -> (T) value); - } - - @Override - public String toString() { - return "BoxAnswer{" + - "message='" + message + '\'' + - ", keyBoard=" + keyBoard + - ", replace=" + replace + - '}'; + return Optional.ofNullable(payload.get(contextKey)).map(value -> (T) value); } public static final class Builder { @@ -162,6 +140,7 @@ public class BoxAnswer { private String replaceMessageId; private String recipientPersonId; private Map payload = new HashMap<>(); + private SendAttachment attachment; private Builder() { } @@ -205,6 +184,13 @@ public class BoxAnswer { return this; } + public Builder attachment(SendAttachment attachment) { + if (checkNotNull(attachment)) { + this.attachment = attachment; + } + return this; + } + public BoxAnswer build() { return new BoxAnswer(this); } diff --git a/bot-domain/bot-domain-simple/src/main/java/dev/struchkov/godfather/simple/domain/SentBox.java b/bot-domain/bot-domain-simple/src/main/java/dev/struchkov/godfather/simple/domain/SentBox.java index fe7161f..d810e75 100644 --- a/bot-domain/bot-domain-simple/src/main/java/dev/struchkov/godfather/simple/domain/SentBox.java +++ b/bot-domain/bot-domain-simple/src/main/java/dev/struchkov/godfather/simple/domain/SentBox.java @@ -1,39 +1,28 @@ package dev.struchkov.godfather.simple.domain; +import dev.struchkov.godfather.main.domain.content.Mail; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + import java.util.Optional; +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor(access = AccessLevel.PRIVATE) public class SentBox { private String personId; private String messageId; + private Mail sentMail; private BoxAnswer sentAnswer; private BoxAnswer originalAnswer; - public SentBox(String personId, String messageId, BoxAnswer sentAnswer, BoxAnswer originalAnswer) { - this.personId = personId; - this.messageId = messageId; - this.sentAnswer = sentAnswer; - this.originalAnswer = originalAnswer; - } - - public static Optional optional(String personId, String messageId, BoxAnswer sentAnswer, BoxAnswer originalAnswer) { - return Optional.of(new SentBox(personId, messageId, sentAnswer, originalAnswer)); - } - - public String getPersonId() { - return personId; - } - - public String getMessageId() { - return messageId; - } - - public BoxAnswer getSentAnswer() { - return sentAnswer; - } - - public BoxAnswer getOriginalAnswer() { - return originalAnswer; + public Optional getMail() { + return Optional.ofNullable(sentMail); } } diff --git a/bot-domain/bot-domain-simple/src/main/java/dev/struchkov/godfather/simple/domain/content/send/SendAttachment.java b/bot-domain/bot-domain-simple/src/main/java/dev/struchkov/godfather/simple/domain/content/send/SendAttachment.java new file mode 100644 index 0000000..b6f74df --- /dev/null +++ b/bot-domain/bot-domain-simple/src/main/java/dev/struchkov/godfather/simple/domain/content/send/SendAttachment.java @@ -0,0 +1,9 @@ +package dev.struchkov.godfather.simple.domain.content.send; + +public interface SendAttachment { + + String getType(); + + SendFile getSendFile(); + +} diff --git a/bot-domain/bot-domain-simple/src/main/java/dev/struchkov/godfather/simple/domain/content/send/SendFile.java b/bot-domain/bot-domain-simple/src/main/java/dev/struchkov/godfather/simple/domain/content/send/SendFile.java new file mode 100644 index 0000000..81e226b --- /dev/null +++ b/bot-domain/bot-domain-simple/src/main/java/dev/struchkov/godfather/simple/domain/content/send/SendFile.java @@ -0,0 +1,23 @@ +package dev.struchkov.godfather.simple.domain.content.send; + +import lombok.Getter; +import lombok.Setter; + +import java.io.File; +import java.io.InputStream; + +@Getter +@Setter +public class SendFile { + + private String fileId; + + private String url; + + private String fileName; + + private File data; + + private InputStream fileStream; + +} diff --git a/pom.xml b/pom.xml index d812dc6..56936e5 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 dev.struchkov.godfather