Отправка файлов и UniPredicate
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Struchkov Mark 2023-03-30 19:33:06 +03:00
parent 54a6d3cbd7
commit dc567ad410
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
8 changed files with 112 additions and 101 deletions

View File

@ -1,5 +1,9 @@
package dev.struchkov.godfather.quarkus.domain; 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.godfather.main.domain.keyboard.KeyBoard;
import dev.struchkov.haiti.utils.container.ContextKey; import dev.struchkov.haiti.utils.container.ContextKey;
import lombok.Getter; import lombok.Getter;
@ -51,7 +55,9 @@ public class BoxAnswer {
/** /**
* Полезная нагрузка для реализаций. * Полезная нагрузка для реализаций.
*/ */
protected Map<String, Object> payload; @JsonSerialize(using = TelegramPayloadSerializer.class)
@JsonDeserialize(using = TelegramPayloadDeserializer.class)
protected Map<ContextKey, Object> payload = new HashMap<>();
private BoxAnswer(Builder builder) { private BoxAnswer(Builder builder) {
message = builder.message; message = builder.message;
@ -112,13 +118,13 @@ public class BoxAnswer {
} }
} }
public Map<String, Object> getPayload() { public Map<ContextKey, Object> getPayload() {
return payload; return payload;
} }
public <T> void setPayload(ContextKey<T> key, T value) { public <T> void setPayload(ContextKey<T> key, T value) {
if (checkNotNull(value)) { if (checkNotNull(value)) {
payload.put(key.getValue(), value); payload.put(key, value);
} }
} }
@ -137,7 +143,7 @@ public class BoxAnswer {
private boolean replace; private boolean replace;
private String replaceMessageId; private String replaceMessageId;
private String recipientPersonId; private String recipientPersonId;
private Map<String, Object> payload = new HashMap<>(); private Map<ContextKey, Object> payload = new HashMap<>();
private Builder() { private Builder() {
} }
@ -169,14 +175,14 @@ public class BoxAnswer {
public <T> Builder payload(ContextKey<T> key, T value) { public <T> Builder payload(ContextKey<T> key, T value) {
if (checkNotNull(value)) { if (checkNotNull(value)) {
payload.put(key.getValue(), value); payload.put(key, value);
} }
return this; return this;
} }
public Builder payload(ContextKey<Boolean> key) { public Builder payload(ContextKey<Boolean> key) {
if (checkNotNull(key)) { if (checkNotNull(key)) {
payload.put(key.getValue(), true); payload.put(key, true);
} }
return this; return this;
} }

View File

@ -1,39 +1,30 @@
package dev.struchkov.godfather.quarkus.domain; 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; import java.util.Optional;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class SentBox { public class SentBox {
private String personId; private String personId;
private String messageId; private String messageId;
private Mail sentMail;
private BoxAnswer sentAnswer; private BoxAnswer sentAnswer;
private BoxAnswer originalAnswer; private BoxAnswer originalAnswer;
public SentBox(String personId, String messageId, BoxAnswer sentAnswer, BoxAnswer originalAnswer) { public Optional<Mail> getMail() {
this.personId = personId; return Optional.ofNullable(sentMail);
this.messageId = messageId;
this.sentAnswer = sentAnswer;
this.originalAnswer = originalAnswer;
}
public static Optional<SentBox> 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;
} }
} }

View File

@ -2,8 +2,14 @@ package dev.struchkov.godfather.quarkus.domain.unit.func;
import io.smallrye.mutiny.Uni; import io.smallrye.mutiny.Uni;
import java.util.function.Predicate;
public interface UniPredicate<T> { public interface UniPredicate<T> {
Uni<Boolean> test(T t); Uni<Boolean> test(T t);
static <D> UniPredicate<D> predicate(Predicate<D> predicate) {
return t -> Uni.createFrom().item(predicate.test(t));
}
} }

View File

@ -1,7 +1,15 @@
package dev.struchkov.godfather.simple.domain; 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.main.domain.keyboard.KeyBoard;
import dev.struchkov.godfather.simple.domain.content.send.SendAttachment;
import dev.struchkov.haiti.utils.container.ContextKey; import dev.struchkov.haiti.utils.container.ContextKey;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -15,6 +23,9 @@ import static dev.struchkov.haiti.utils.Checker.checkNull;
* *
* @author upagge [08/07/2019] * @author upagge [08/07/2019]
*/ */
@Getter
@Setter
@NoArgsConstructor
public class BoxAnswer { 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<ContextKey, Object> payload; @JsonSerialize(using = TelegramPayloadSerializer.class)
@JsonDeserialize(using = TelegramPayloadDeserializer.class)
private Map<ContextKey, Object> payload = new HashMap<>();
private SendAttachment attachment;
private BoxAnswer(Builder builder) { private BoxAnswer(Builder builder) {
message = builder.message; message = builder.message;
@ -54,6 +69,7 @@ public class BoxAnswer {
replaceMessageId = builder.replaceMessageId; replaceMessageId = builder.replaceMessageId;
recipientPersonId = builder.recipientPersonId; recipientPersonId = builder.recipientPersonId;
payload = builder.payload; payload = builder.payload;
attachment = builder.attachment;
} }
public static BoxAnswer boxAnswer(boolean replace, String message) { public static BoxAnswer boxAnswer(boolean replace, String message) {
@ -96,30 +112,6 @@ public class BoxAnswer {
return new Builder().replace(true); 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) { public void setRecipientPersonId(String recipientPersonId) {
this.recipientPersonId = recipientPersonId; this.recipientPersonId = recipientPersonId;
} }
@ -130,28 +122,14 @@ public class BoxAnswer {
} }
} }
public Map<ContextKey, Object> getPayload() { public <T> void addPayload(ContextKey<T> key, T value) {
return payload;
}
public <T> void setPayload(ContextKey<T> key, T value) {
if (checkNotNull(value)) { if (checkNotNull(value)) {
payload.put(key, value); payload.put(key, value);
} }
} }
public <T> Optional<T> getPayLoad(ContextKey<T> contextKey) { public <T> Optional<T> getPayLoad(ContextKey<T> contextKey) {
return Optional.ofNullable(payload.get(contextKey)) return Optional.ofNullable(payload.get(contextKey)).map(value -> (T) value);
.map(value -> (T) value);
}
@Override
public String toString() {
return "BoxAnswer{" +
"message='" + message + '\'' +
", keyBoard=" + keyBoard +
", replace=" + replace +
'}';
} }
public static final class Builder { public static final class Builder {
@ -162,6 +140,7 @@ public class BoxAnswer {
private String replaceMessageId; private String replaceMessageId;
private String recipientPersonId; private String recipientPersonId;
private Map<ContextKey, Object> payload = new HashMap<>(); private Map<ContextKey, Object> payload = new HashMap<>();
private SendAttachment attachment;
private Builder() { private Builder() {
} }
@ -205,6 +184,13 @@ public class BoxAnswer {
return this; return this;
} }
public Builder attachment(SendAttachment attachment) {
if (checkNotNull(attachment)) {
this.attachment = attachment;
}
return this;
}
public BoxAnswer build() { public BoxAnswer build() {
return new BoxAnswer(this); return new BoxAnswer(this);
} }

View File

@ -1,39 +1,28 @@
package dev.struchkov.godfather.simple.domain; 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; import java.util.Optional;
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class SentBox { public class SentBox {
private String personId; private String personId;
private String messageId; private String messageId;
private Mail sentMail;
private BoxAnswer sentAnswer; private BoxAnswer sentAnswer;
private BoxAnswer originalAnswer; private BoxAnswer originalAnswer;
public SentBox(String personId, String messageId, BoxAnswer sentAnswer, BoxAnswer originalAnswer) { public Optional<Mail> getMail() {
this.personId = personId; return Optional.ofNullable(sentMail);
this.messageId = messageId;
this.sentAnswer = sentAnswer;
this.originalAnswer = originalAnswer;
}
public static Optional<SentBox> 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;
} }
} }

View File

@ -0,0 +1,9 @@
package dev.struchkov.godfather.simple.domain.content.send;
public interface SendAttachment {
String getType();
SendFile getSendFile();
}

View File

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

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>dev.struchkov.godfather</groupId> <groupId>dev.struchkov.godfather</groupId>