Добавил идентификатор в объект Message. Упростил SentBox
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
222c272526
commit
5a630282f6
@ -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);
|
||||
|
||||
/**
|
||||
* Возвращает тип объекта отправляющего ответ пользователя. В зависимости от типа ответ будет отправлен с помощью
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
/**
|
||||
* Возвращает тип объекта отправляющего ответ пользователя. В зависимости от типа ответ будет отправлен с помощью
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
@ -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());
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
@ -103,16 +118,18 @@ public class BoxAnswer {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BoxAnswer{" +
|
||||
"message='" + message + '\'' +
|
||||
", keyBoard=" + keyBoard +
|
||||
", replace=" + replace +
|
||||
'}';
|
||||
"message='" + message + '\'' +
|
||||
", keyBoard=" + keyBoard +
|
||||
", replace=" + replace +
|
||||
'}';
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user