Добавил идентификатор в объект Message. Упростил SentBox
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Struchkov Mark 2023-01-25 11:28:50 +03:00
parent 222c272526
commit 5a630282f6
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
24 changed files with 110 additions and 110 deletions

View File

@ -11,14 +11,14 @@ import org.jetbrains.annotations.NotNull;
*
* @author upagge [08/07/2019]
*/
public interface Sending<MESSAGE_ID> {
public interface Sending {
/**
* Отправляет сообщение пользователю
*
* @param boxAnswer Объект с данными, которые необходимо отправить
*/
Uni<SentBox<MESSAGE_ID>> send(@NotNull BoxAnswer boxAnswer);
Uni<SentBox> send(@NotNull BoxAnswer boxAnswer);
/**
* Возвращает тип объекта отправляющего ответ пользователя. В зависимости от типа ответ будет отправлен с помощью

View File

@ -10,12 +10,12 @@ import org.jetbrains.annotations.NotNull;
*
* @author upagge [08/07/2019]
*/
public interface SendingService<MESSAGE_ID> extends Sending<MESSAGE_ID> {
public interface SendingService extends Sending {
void addPreSendProcess(@NotNull PreSendProcessing processing);
Uni<Void> deleteMessage(@NotNull String personId, @NotNull MESSAGE_ID messageId);
Uni<Void> deleteMessage(@NotNull String personId, @NotNull String messageId);
Uni<SentBox<MESSAGE_ID>> replaceMessage(@NotNull String personId, @NotNull MESSAGE_ID messageId, @NotNull BoxAnswer newAnswer);
Uni<SentBox> replaceMessage(@NotNull String personId, @NotNull String messageId, @NotNull BoxAnswer newAnswer);
}

View File

@ -12,14 +12,14 @@ import java.util.Optional;
*
* @author upagge [08/07/2019]
*/
public interface Sending<MESSAGE_ID> {
public interface Sending {
/**
* Отравляет сообщение пользователю.
*
* @param boxAnswer Объект с данными, которые необходимо отправить
*/
Optional<SentBox<MESSAGE_ID>> send(@NotNull BoxAnswer boxAnswer);
Optional<SentBox> send(@NotNull BoxAnswer boxAnswer);
/**
* Возвращает тип объекта отправляющего ответ пользователя. В зависимости от типа ответ будет отправлен с помощью

View File

@ -11,12 +11,12 @@ import java.util.Optional;
*
* @author upagge [08/07/2019]
*/
public interface SendingService<MESSAGE_ID> extends Sending<MESSAGE_ID> {
public interface SendingService extends Sending {
void addPreSendProcess(@NotNull PreSendProcessing processing);
void deleteMessage(@NotNull String personId, @NotNull MESSAGE_ID messageId);
void deleteMessage(@NotNull String personId, @NotNull String messageId);
Optional<SentBox<MESSAGE_ID>> replaceMessage(@NotNull String personId, @NotNull MESSAGE_ID messageId, @NotNull BoxAnswer newAnswer);
Optional<SentBox> replaceMessage(@NotNull String personId, @NotNull String messageId, @NotNull BoxAnswer newAnswer);
}

View File

@ -43,7 +43,7 @@ public class GeneralAutoResponder<M extends Message> {
protected ErrorHandler errorHandler;
protected GeneralAutoResponder(
Sending<?> sending,
Sending sending,
PersonSettingService personSettingService,
StorylineService<M> storyLineService
) {
@ -52,7 +52,7 @@ public class GeneralAutoResponder<M extends Message> {
init(sending);
}
private void init(Sending<?> sending) {
private void init(Sending sending) {
actionUnitMap.put(TypeUnit.CHECK, new AnswerCheckAction<>(sending));
actionUnitMap.put(TypeUnit.TEXT, new AnswerTextAction(sending));
actionUnitMap.put(TypeUnit.REPLACE_CMD, new ReplaceCmdAction());

View File

@ -20,9 +20,9 @@ import static dev.struchkov.haiti.utils.Checker.checkTrue;
*/
public class AnswerCheckAction<M extends Message> implements ActionUnit<AnswerCheck<M>, M> {
private final Sending<?> sending;
private final Sending sending;
public AnswerCheckAction(Sending<?> sending) {
public AnswerCheckAction(Sending sending) {
this.sending = sending;
}

View File

@ -5,7 +5,7 @@ import dev.struchkov.godfather.quarkus.context.service.Sending;
import dev.struchkov.godfather.quarkus.core.unit.AnswerText;
import dev.struchkov.godfather.quarkus.core.unit.MainUnit;
import dev.struchkov.godfather.quarkus.core.unit.UnitRequest;
import dev.struchkov.godfather.quarkus.core.unit.func.collback.CallBackConsumer;
import dev.struchkov.godfather.quarkus.core.unit.func.CallBackConsumer;
import io.smallrye.mutiny.Uni;
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
@ -17,9 +17,9 @@ import static dev.struchkov.haiti.utils.Checker.checkNotNull;
*/
public class AnswerTextAction implements ActionUnit<AnswerText<Message>, Message> {
private final Sending<?> sending;
private final Sending sending;
public AnswerTextAction(Sending<?> sending) {
public AnswerTextAction(Sending sending) {
this.sending = sending;
}

View File

@ -6,8 +6,8 @@ import dev.struchkov.godfather.main.core.unit.UnitActiveType;
import dev.struchkov.godfather.main.domain.BoxAnswer;
import dev.struchkov.godfather.main.domain.content.Message;
import dev.struchkov.godfather.quarkus.context.service.Accessibility;
import dev.struchkov.godfather.quarkus.core.unit.func.CallBackConsumer;
import dev.struchkov.godfather.quarkus.core.unit.func.ProcessingData;
import dev.struchkov.godfather.quarkus.core.unit.func.collback.CallBackConsumer;
import io.smallrye.mutiny.Uni;
import java.util.HashSet;

View File

@ -0,0 +1,11 @@
package dev.struchkov.godfather.quarkus.core.unit.func;
import dev.struchkov.godfather.main.domain.SentBox;
import io.smallrye.mutiny.Uni;
@FunctionalInterface
public interface CallBackConsumer {
Uni<Void> processing(SentBox sentBox);
}

View File

@ -1,11 +0,0 @@
package dev.struchkov.godfather.quarkus.core.unit.func.collback;
import dev.struchkov.godfather.main.domain.SentBox;
import io.smallrye.mutiny.Uni;
@FunctionalInterface
public interface CallBackConsumer<MESSAGE_ID> {
Uni<Void> processing(SentBox<MESSAGE_ID> sentBox);
}

View File

@ -1,11 +0,0 @@
package dev.struchkov.godfather.quarkus.core.unit.func.collback;
import dev.struchkov.godfather.main.domain.SentBox;
import io.smallrye.mutiny.Uni;
@FunctionalInterface
public interface IntegerCallBack extends CallBackConsumer<Integer> {
Uni<Void> processing(SentBox<Integer> sentBox);
}

View File

@ -1,11 +0,0 @@
package dev.struchkov.godfather.quarkus.core.unit.func.collback;
import dev.struchkov.godfather.main.domain.SentBox;
import io.smallrye.mutiny.Uni;
@FunctionalInterface
public interface StringCallBack extends CallBackConsumer<String> {
Uni<Void> processing(SentBox<String> sentBox);
}

View File

@ -42,7 +42,7 @@ public class GeneralAutoResponder<M extends Message> {
protected ExecutorService executorService;
protected GeneralAutoResponder(
Sending<?> sending,
Sending sending,
PersonSettingService personSettingService,
StorylineService<M> storyLineService
) {
@ -51,7 +51,7 @@ public class GeneralAutoResponder<M extends Message> {
init(sending);
}
private void init(Sending<?> sending) {
private void init(Sending sending) {
actionUnitMap.put(TypeUnit.CHECK, new AnswerCheckAction<>(sending));
actionUnitMap.put(TypeUnit.TEXT, new AnswerTextAction(sending));
actionUnitMap.put(TypeUnit.REPLACE_CMD, new ReplaceCmdAction());

View File

@ -22,9 +22,9 @@ public class AnswerCheckAction<M extends Message> implements ActionUnit<AnswerCh
private static final Logger log = LoggerFactory.getLogger(AnswerCheckAction.class);
private final Sending<?> sending;
private final Sending sending;
public AnswerCheckAction(Sending<?> sending) {
public AnswerCheckAction(Sending sending) {
this.sending = sending;
}
@ -56,4 +56,5 @@ public class AnswerCheckAction<M extends Message> implements ActionUnit<AnswerCh
log.debug("Завершилась обработка unit: {}.", unit.getName());
return UnitRequest.of(Objects.requireNonNullElse(unitAnswer, unit), message);
}
}

View File

@ -7,8 +7,8 @@ import dev.struchkov.godfather.simple.context.service.Sending;
import dev.struchkov.godfather.simple.core.unit.AnswerText;
import dev.struchkov.godfather.simple.core.unit.MainUnit;
import dev.struchkov.godfather.simple.core.unit.UnitRequest;
import dev.struchkov.godfather.simple.core.unit.func.CallBackConsumer;
import dev.struchkov.godfather.simple.core.unit.func.ProcessingData;
import dev.struchkov.godfather.simple.core.unit.func.collback.CallBackConsumer;
import java.util.Optional;
@ -21,9 +21,9 @@ import static dev.struchkov.haiti.utils.Checker.checkNotNull;
*/
public class AnswerTextAction implements ActionUnit<AnswerText<Message>, Message> {
private final Sending<?> sending;
private final Sending sending;
public AnswerTextAction(Sending<?> sending) {
public AnswerTextAction(Sending sending) {
this.sending = sending;
}
@ -39,10 +39,10 @@ public class AnswerTextAction implements ActionUnit<AnswerText<Message>, Message
final BoxAnswer answer = optAnswer.get();
answer.setRecipientIfNull(message.getPersonId());
final Optional<? extends SentBox<?>> optSentBox = sending.send(answer);
final Optional<? extends SentBox> optSentBox = sending.send(answer);
final CallBackConsumer callBack = unit.getCallBack();
if (checkNotNull(callBack) && optAnswer.isPresent()) {
final SentBox<?> sentBox = optSentBox.get();
final SentBox sentBox = optSentBox.get();
callBack.processing(sentBox);
}
}

View File

@ -12,9 +12,9 @@ public class UserSanderPusher implements Pusher<String> {
private final String personId;
private final String nameForm;
private final Sending<?> sending;
private final Sending sending;
public UserSanderPusher(String personId, String nameForm, Sending<?> sending) {
public UserSanderPusher(String personId, String nameForm, Sending sending) {
this.personId = personId;
this.nameForm = nameForm;
this.sending = sending;

View File

@ -6,8 +6,8 @@ import dev.struchkov.godfather.main.core.unit.UnitActiveType;
import dev.struchkov.godfather.main.domain.BoxAnswer;
import dev.struchkov.godfather.main.domain.content.Message;
import dev.struchkov.godfather.simple.context.service.Accessibility;
import dev.struchkov.godfather.simple.core.unit.func.CallBackConsumer;
import dev.struchkov.godfather.simple.core.unit.func.ProcessingData;
import dev.struchkov.godfather.simple.core.unit.func.collback.CallBackConsumer;
import java.util.HashSet;
import java.util.List;
@ -132,7 +132,7 @@ public class AnswerText<M extends Message> extends MainUnit<M> {
return this;
}
public Builder<M> callBack(CallBackConsumer callBack) {
public <T> Builder<M> callBack(CallBackConsumer callBack) {
this.callBack = callBack;
return this;
}

View File

@ -0,0 +1,10 @@
package dev.struchkov.godfather.simple.core.unit.func;
import dev.struchkov.godfather.main.domain.SentBox;
@FunctionalInterface
public interface CallBackConsumer {
void processing(SentBox sentBox);
}

View File

@ -1,10 +0,0 @@
package dev.struchkov.godfather.simple.core.unit.func.collback;
import dev.struchkov.godfather.main.domain.SentBox;
@FunctionalInterface
public interface CallBackConsumer<MESSAGE_ID> {
void processing(SentBox<MESSAGE_ID> sentBox);
}

View File

@ -1,10 +0,0 @@
package dev.struchkov.godfather.simple.core.unit.func.collback;
import dev.struchkov.godfather.main.domain.SentBox;
@FunctionalInterface
public interface IntegerCallBack extends CallBackConsumer<Integer> {
void processing(SentBox<Integer> sentBox);
}

View File

@ -1,10 +0,0 @@
package dev.struchkov.godfather.simple.core.unit.func.collback;
import dev.struchkov.godfather.main.domain.SentBox;
@FunctionalInterface
public interface StringCallBack extends CallBackConsumer<String> {
void processing(SentBox<String> sentBox);
}

View File

@ -21,6 +21,8 @@ public class BoxAnswer {
*/
private final boolean replace;
private final String replaceMessageId;
/**
* Обычное текстовое сообщение.
*/
@ -35,6 +37,7 @@ public class BoxAnswer {
message = builder.message;
keyBoard = builder.keyBoard;
replace = builder.replace;
replaceMessageId = builder.replaceMessageId;
recipientPersonId = builder.recipientPersonId;
}
@ -50,16 +53,24 @@ public class BoxAnswer {
return boxAnswer(false, message);
}
public static BoxAnswer boxAnswer(String messageText, KeyBoard keyBoard) {
return boxAnswer(false, messageText, keyBoard);
public static BoxAnswer boxAnswer(String message, KeyBoard keyBoard) {
return boxAnswer(false, message, keyBoard);
}
public static BoxAnswer replaceBoxAnswer(String message) {
return boxAnswer(true, message);
}
public static BoxAnswer replaceBoxAnswer(String messageText, KeyBoard keyBoard) {
return boxAnswer(true, messageText, keyBoard);
public static BoxAnswer replaceBoxAnswer(String message, KeyBoard keyBoard) {
return boxAnswer(true, message, keyBoard);
}
public static BoxAnswer replaceBoxAnswer(String messageId, String message) {
return BoxAnswer.builder().replace(true).replaceMessageId(messageId).message(message).build();
}
public static BoxAnswer replaceBoxAnswer(String messageId, String message, KeyBoard keyBoard) {
return BoxAnswer.builder().replace(true).replaceMessageId(messageId).message(message).keyBoard(keyBoard).build();
}
public static Builder builder() {
@ -86,6 +97,10 @@ public class BoxAnswer {
return replace;
}
public String getReplaceMessageId() {
return replaceMessageId;
}
public String getRecipientPersonId() {
return recipientPersonId;
}
@ -110,9 +125,11 @@ public class BoxAnswer {
}
public static final class Builder {
private String message;
private KeyBoard keyBoard;
private boolean replace;
private String replaceMessageId;
private String recipientPersonId;
private Builder() {
@ -138,9 +155,15 @@ public class BoxAnswer {
return this;
}
public Builder replaceMessageId(String val) {
replaceMessageId = val;
return this;
}
public BoxAnswer build() {
return new BoxAnswer(this);
}
}
}

View File

@ -2,23 +2,29 @@ package dev.struchkov.godfather.main.domain;
import java.util.Optional;
public class SentBox<T> {
public class SentBox {
private T messageId;
private String personId;
private String messageId;
private BoxAnswer sentAnswer;
private BoxAnswer originalAnswer;
public SentBox(T messageId, BoxAnswer sentAnswer, 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 <T> Optional<SentBox<T>> optional(T messageId, BoxAnswer sentAnswer, BoxAnswer originalAnswer) {
return Optional.of(new SentBox<>(messageId, sentAnswer, originalAnswer));
public static Optional<SentBox> optional(String personId, String messageId, BoxAnswer sentAnswer, BoxAnswer originalAnswer) {
return Optional.of(new SentBox(personId, messageId, sentAnswer, originalAnswer));
}
public T getMessageId() {
public String getPersonId() {
return personId;
}
public String getMessageId() {
return messageId;
}

View File

@ -12,6 +12,8 @@ import java.util.Objects;
*/
public abstract class Message implements DeliverableText {
protected String id;
/**
* Тип сообщения.
*/
@ -33,6 +35,7 @@ public abstract class Message implements DeliverableText {
private String text;
protected Message(Message source) {
this.id = source.getId();
this.personId = source.getPersonId();
this.text = source.getText();
this.createDate = source.getCreateDate();
@ -74,16 +77,25 @@ public abstract class Message implements DeliverableText {
this.text = text;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Message message = (Message) o;
return contentType == message.contentType && Objects.equals(createDate, message.createDate) && Objects.equals(personId, message.personId) && Objects.equals(text, message.text);
return Objects.equals(id, message.id);
}
@Override
public int hashCode() {
return Objects.hash(contentType, createDate, personId, text);
return Objects.hash(id);
}
}