From 7c3711ab904dfb942f122c1bb6ed61ad3620eac6 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Wed, 21 Sep 2022 19:15:16 +0300 Subject: [PATCH] Revert "release-0.0.27" This reverts commit 1a2d2d46024e287ccac3a2970641df725fdc0adf. --- bot-context/bot-context-main/pom.xml | 5 +- bot-context/bot-context-quarkus/pom.xml | 2 +- .../quarkus/context/service/ErrorHandler.java | 3 +- bot-context/bot-context-simple/pom.xml | 2 +- bot-context/pom.xml | 2 +- bot-core/bot-core-main/pom.xml | 2 +- bot-core/bot-core-quarkus/pom.xml | 2 +- .../quarkus/core/GeneralAutoResponder.java | 127 ++++++++++-------- .../quarkus/core/action/AnswerTextAction.java | 60 ++++++--- .../quarkus/core/unit/AnswerCheck.java | 2 +- .../godfather/quarkus/core/utils/Sender.java | 19 +-- bot-core/bot-core-simple/pom.xml | 2 +- .../simple/core/unit/AnswerCheck.java | 2 +- bot-core/pom.xml | 2 +- bot-data/bot-data-main/pom.xml | 2 +- bot-data/bot-data-quarkus/pom.xml | 2 +- bot-data/bot-data-simple/pom.xml | 2 +- bot-data/pom.xml | 2 +- bot-domain/bot-domain-main/pom.xml | 2 +- bot-domain/pom.xml | 2 +- bot-exception/pom.xml | 2 +- pom.xml | 2 +- 22 files changed, 136 insertions(+), 112 deletions(-) diff --git a/bot-context/bot-context-main/pom.xml b/bot-context/bot-context-main/pom.xml index 19fc346..0ea62f6 100644 --- a/bot-context/bot-context-main/pom.xml +++ b/bot-context/bot-context-main/pom.xml @@ -3,9 +3,10 @@ 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"> + godfather-bot dev.struchkov.godfather - bot-context - 0.0.27 + 0.0.25 + ../../pom.xml 4.0.0 diff --git a/bot-context/bot-context-quarkus/pom.xml b/bot-context/bot-context-quarkus/pom.xml index b429ef1..b3a3c76 100644 --- a/bot-context/bot-context-quarkus/pom.xml +++ b/bot-context/bot-context-quarkus/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather bot-context - 0.0.27 + 0.0.25 4.0.0 diff --git a/bot-context/bot-context-quarkus/src/main/java/dev/struchkov/godfather/quarkus/context/service/ErrorHandler.java b/bot-context/bot-context-quarkus/src/main/java/dev/struchkov/godfather/quarkus/context/service/ErrorHandler.java index af9c6ee..8a4b986 100644 --- a/bot-context/bot-context-quarkus/src/main/java/dev/struchkov/godfather/quarkus/context/service/ErrorHandler.java +++ b/bot-context/bot-context-quarkus/src/main/java/dev/struchkov/godfather/quarkus/context/service/ErrorHandler.java @@ -1,7 +1,6 @@ package dev.struchkov.godfather.quarkus.context.service; import dev.struchkov.godfather.main.domain.content.Message; -import io.smallrye.mutiny.Uni; /** * Используется для перехвата исключений, которые возникают при обработке юнитов. @@ -14,6 +13,6 @@ public interface ErrorHandler { * @param message Сообщение, после которого возникло исключение. * @param e Объект исключения. */ - Uni handle(Message message, Throwable e); + void handle(Message message, Throwable e); } diff --git a/bot-context/bot-context-simple/pom.xml b/bot-context/bot-context-simple/pom.xml index b2457b8..a651bf3 100644 --- a/bot-context/bot-context-simple/pom.xml +++ b/bot-context/bot-context-simple/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather bot-context - 0.0.27 + 0.0.25 4.0.0 diff --git a/bot-context/pom.xml b/bot-context/pom.xml index 144f5c5..80608ce 100644 --- a/bot-context/pom.xml +++ b/bot-context/pom.xml @@ -6,7 +6,7 @@ dev.struchkov.godfather godfather-bot - 0.0.27 + 0.0.25 bot-context diff --git a/bot-core/bot-core-main/pom.xml b/bot-core/bot-core-main/pom.xml index e1fe13b..23cae53 100644 --- a/bot-core/bot-core-main/pom.xml +++ b/bot-core/bot-core-main/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather bot-core - 0.0.27 + 0.0.25 4.0.0 diff --git a/bot-core/bot-core-quarkus/pom.xml b/bot-core/bot-core-quarkus/pom.xml index 13d0f4c..c13f6bf 100644 --- a/bot-core/bot-core-quarkus/pom.xml +++ b/bot-core/bot-core-quarkus/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather bot-core - 0.0.27 + 0.0.25 4.0.0 diff --git a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/GeneralAutoResponder.java b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/GeneralAutoResponder.java index 7f98eb8..65d2d23 100644 --- a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/GeneralAutoResponder.java +++ b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/GeneralAutoResponder.java @@ -28,11 +28,9 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; -import static dev.struchkov.haiti.utils.Checker.checkEmpty; +import static dev.struchkov.haiti.utils.Checker.checkNotEmpty; import static dev.struchkov.haiti.utils.Checker.checkNotNull; -import static java.lang.Boolean.TRUE; -import static java.util.Collections.emptyList; -import static java.util.Collections.emptySet; +import static dev.struchkov.haiti.utils.Checker.checkNull; public class GeneralAutoResponder { @@ -86,72 +84,87 @@ public class GeneralAutoResponder { } public Uni processingNewMessage(M newMessage) { - return Uni.createFrom().item(newMessage) - .onItem().ifNotNull().transformToUni( - message -> personSettingService.getStateProcessingByPersonId(newMessage.getPersonId()) - .replaceIfNullWith(TRUE) - .chain( - state -> { - if (TRUE.equals(state)) { - return processing(newMessage); - } - return Uni.createFrom().voidItem(); - } - ) - ).replaceWithVoid(); - + if (newMessage != null) { + return personSettingService.getStateProcessingByPersonId(newMessage.getPersonId()) + .onItem().transformToUni( + state -> { + if (checkNull(state) || state) { + return processing(newMessage); + } + return Uni.createFrom().voidItem(); + } + ); + } + return Uni.createFrom().voidItem(); } public Uni processingNewMessages(List newMessages) { - return Uni.createFrom().item(newMessages) - .onItem().ifNotNull().transformToUni( - messages -> { - if (checkEmpty(newMessages)) return Uni.createFrom().voidItem(); - - final Set personIds = newMessages.stream() - .map(Message::getPersonId) - .collect(Collectors.toSet()); - return personSettingService.getAllPersonIdDisableMessages(personIds) - .replaceIfNullWith(emptySet()) - .onItem().transformToMulti( - disableIds -> { - final List allowedMessages = newMessages.stream() - .filter(message -> !disableIds.contains(message.getPersonId())) - .toList(); - return Multi.createFrom().iterable(allowedMessages); - } - ) - .onItem().transform(this::processing) - .toUni().replaceWithVoid(); - } - ); + if (newMessages != null && !newMessages.isEmpty()) { + final Set personIds = newMessages.stream() + .map(Message::getPersonId) + .collect(Collectors.toSet()); + return personSettingService.getAllPersonIdDisableMessages(personIds) + .onItem().transformToMulti( + disableIds -> { + final List allowedMessages = newMessages.stream() + .filter(message -> !disableIds.contains(message.getPersonId())) + .toList(); + return Multi.createFrom().iterable(allowedMessages); + } + ) + .onItem().transform(this::processing) + .toUni().replaceWithVoid(); + } + return Uni.createFrom().voidItem(); } private Uni processing(M message) { return Uni.createFrom().item(message) - .onItem().ifNotNull().transform(m -> modifiable) - .replaceIfNullWith(emptyList()) - .onItem().transformToMulti(modifiables -> Multi.createFrom().iterable(modifiables)) - .onItem().transformToUni(mModifiable -> mModifiable.change(message)) - .concatenate().toUni().replaceWith( - storyLineService.getNextUnitByPersonId(message.getPersonId()) - .onItem().ifNotNull().transformToUni( - nextUnits -> Uni.createFrom().optional( - Responder.nextUnit(message, nextUnits).or(storyLineService::getDefaultUnit) - ) - ).onItem().ifNotNull().transformToUni(answerUnit -> answer(UnitRequest.of(answerUnit, message))) + .onItem().transformToUni( + mail -> { + if (checkNotEmpty(modifiable)) { + return Multi.createFrom().iterable(modifiable) + .onItem().transformToUni(m -> m.change(mail)) + .concatenate().toUni().replaceWith(mail); + } + return Uni.createFrom().item(mail); + } + ).onItem().transformToUni( + mail -> { + final Uni>> uniUnits = storyLineService.getNextUnitByPersonId(mail.getPersonId()); + return Uni.combine().all().unis(uniUnits, Uni.createFrom().item(mail)).asTuple(); + } + ).onItem().transformToUni( + t -> { + final Set> units = t.getItem1(); + final M mail = t.getItem2(); + final Optional> optAnswer = Responder.nextUnit(mail, units).or(storyLineService::getDefaultUnit); + if (optAnswer.isPresent()) { + final MainUnit answer = optAnswer.get(); + //TODO [05.08.2022]: нужно ли проверку встраивать в поток? +// if (checkPermission(answer.getAccessibility(), message)) { + return answer(UnitRequest.of(answer, message)); +// } + } + return Uni.createFrom().voidItem(); + } ); } +// private boolean checkPermission(Optional accessibility, M message) { +// return accessibility.isEmpty() || accessibility.get().check(message); +// } + public Uni answer(UnitRequest unitRequest) { return getAction(unitRequest) - .chain(request -> activeUnitAfter(unitRequest)) - .onFailure().call( + .onItem().transformToUni( + request -> activeUnitAfter(unitRequest) + ) + .onFailure().invoke( throwable -> { - if (checkNotNull(errorHandler)) { - return errorHandler.handle(unitRequest.getMessage(), throwable); + if (errorHandler != null) { + errorHandler.handle(unitRequest.getMessage(), throwable); } - return Uni.createFrom().voidItem(); } ) .replaceWithVoid(); @@ -165,7 +178,7 @@ public class GeneralAutoResponder { .findFirst(); if (first.isPresent()) { return Uni.createFrom().voidItem().onItem().transformToUni( - v -> getAction(UnitRequest.of(first.get(), unitRequest.getMessage())) + v-> getAction(UnitRequest.of(first.get(), unitRequest.getMessage())) ) .onItem().transformToUni( uR -> activeUnitAfter(UnitRequest.of(first.get(), unitRequest.getMessage())) diff --git a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/action/AnswerTextAction.java b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/action/AnswerTextAction.java index 74c8609..e1a9adc 100644 --- a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/action/AnswerTextAction.java +++ b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/action/AnswerTextAction.java @@ -28,32 +28,48 @@ public class AnswerTextAction implements ActionUnit, Message @Override public Uni> action(UnitRequest, Message> unitRequest) { - final Message message = unitRequest.getMessage(); final AnswerText unit = unitRequest.getUnit(); - return Uni.createFrom().voidItem() - .chain(request -> unit.getAnswer().processing(message)) - .onItem().ifNotNull().transformToUni(boxAnswer -> replaceMarkers(unit, message, boxAnswer)) - .onItem().ifNotNull().transformToUni(boxAnswer -> { - final Sending answerTextSending = unit.getSending(); - if (checkNotNull(answerTextSending)) { - return Sender.sends(message, boxAnswer, answerTextSending); - } else { - return Sender.sends(message, boxAnswer, this.sending); - } - }).replaceWith(UnitRequest.of(unit, message)); + final Message message = unitRequest.getMessage(); + + return unit.getAnswer().processing(message) + .onItem().transformToUni( + boxAnswer -> { + if (checkNotNull(boxAnswer)) { + return replaceMarkers(unit, message, boxAnswer); + } + return Uni.createFrom().nullItem(); + } + ).onItem().transformToUni( + boxAnswer -> { + if (checkNotNull(boxAnswer)) { + final Sending answerTextSending = unit.getSending(); + if (answerTextSending != null) { + return Sender.sends(message, boxAnswer, answerTextSending); + } else { + return Sender.sends(message, boxAnswer, this.sending); + } + } + return Uni.createFrom().nullItem(); + } + ).onItem().transform( + v -> UnitRequest.of(unit, message) + ); } private Uni replaceMarkers(AnswerText answerText, Message message, BoxAnswer boxAnswer) { - return Uni.createFrom().item(answerText.getInsert()) - .onItem().ifNotNull().transformToUni(insert -> insert.insert(message.getPersonId())) - .onItem().ifNotNull().transform(words -> { - if (checkNotEmpty(words)) { - final String newMessage = InsertWords.insert(boxAnswer.getMessage(), words); - boxAnswer.setMessage(newMessage); - } - return boxAnswer; - }) - .replaceIfNullWith(boxAnswer); + if (answerText.getInsert() != null) { + return answerText.getInsert().insert(message.getPersonId()) + .onItem().transformToUni( + words -> { + if (checkNotEmpty(words)) { + final String newMessage = InsertWords.insert(boxAnswer.getMessage(), words); + boxAnswer.setMessage(newMessage); + } + return Uni.createFrom().item(boxAnswer); + } + ); + } + return Uni.createFrom().item(boxAnswer); } } diff --git a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/unit/AnswerCheck.java b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/unit/AnswerCheck.java index 244e8b2..dbc4f4c 100644 --- a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/unit/AnswerCheck.java +++ b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/unit/AnswerCheck.java @@ -167,7 +167,7 @@ public class AnswerCheck extends MainUnit { return this; } - public Builder triggerCheck(Predicate trigger) { + private Builder triggerCheck(Predicate trigger) { triggerCheck = trigger; return this; } diff --git a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/utils/Sender.java b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/utils/Sender.java index 5293528..4c862c5 100644 --- a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/utils/Sender.java +++ b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/utils/Sender.java @@ -19,18 +19,13 @@ public class Sender { } public static Uni sends(Message message, BoxAnswer boxAnswer, Sending sending) { - return Uni.createFrom().item(sending) - .onItem().ifNotNull().transformToUni( - sender -> { - switch (sending.getType()) { - case PUBLIC: - break; - case PRIVATE: - return privateSend(message, boxAnswer, sending); - } - return Uni.createFrom().nullItem(); - } - ).replaceWithVoid(); + switch (sending.getType()) { + case PUBLIC: + break; + case PRIVATE: + return privateSend(message, boxAnswer, sending); + } + return Uni.createFrom().voidItem(); } private static Uni privateSend(Message message, BoxAnswer boxAnswer, Sending sending) { diff --git a/bot-core/bot-core-simple/pom.xml b/bot-core/bot-core-simple/pom.xml index 8a6e998..27821d8 100644 --- a/bot-core/bot-core-simple/pom.xml +++ b/bot-core/bot-core-simple/pom.xml @@ -5,7 +5,7 @@ bot-core dev.struchkov.godfather - 0.0.27 + 0.0.25 4.0.0 diff --git a/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/unit/AnswerCheck.java b/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/unit/AnswerCheck.java index d5fbe6c..b25f309 100644 --- a/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/unit/AnswerCheck.java +++ b/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/unit/AnswerCheck.java @@ -164,7 +164,7 @@ public class AnswerCheck extends MainUnit { return this; } - public Builder triggerCheck(Predicate trigger) { + private Builder triggerCheck(Predicate trigger) { triggerCheck = trigger; return this; } diff --git a/bot-core/pom.xml b/bot-core/pom.xml index d0b0665..16cfb0d 100644 --- a/bot-core/pom.xml +++ b/bot-core/pom.xml @@ -6,7 +6,7 @@ dev.struchkov.godfather godfather-bot - 0.0.27 + 0.0.25 bot-core diff --git a/bot-data/bot-data-main/pom.xml b/bot-data/bot-data-main/pom.xml index d6cc961..502d9ca 100644 --- a/bot-data/bot-data-main/pom.xml +++ b/bot-data/bot-data-main/pom.xml @@ -5,7 +5,7 @@ bot-data dev.struchkov.godfather - 0.0.27 + 0.0.25 4.0.0 diff --git a/bot-data/bot-data-quarkus/pom.xml b/bot-data/bot-data-quarkus/pom.xml index 48b923a..16f4883 100644 --- a/bot-data/bot-data-quarkus/pom.xml +++ b/bot-data/bot-data-quarkus/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather bot-data - 0.0.27 + 0.0.25 4.0.0 diff --git a/bot-data/bot-data-simple/pom.xml b/bot-data/bot-data-simple/pom.xml index bdc74ae..717b945 100644 --- a/bot-data/bot-data-simple/pom.xml +++ b/bot-data/bot-data-simple/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather bot-data - 0.0.27 + 0.0.25 4.0.0 diff --git a/bot-data/pom.xml b/bot-data/pom.xml index 7923d6f..d371d92 100644 --- a/bot-data/pom.xml +++ b/bot-data/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather godfather-bot - 0.0.27 + 0.0.25 4.0.0 diff --git a/bot-domain/bot-domain-main/pom.xml b/bot-domain/bot-domain-main/pom.xml index fa00651..2d117e3 100644 --- a/bot-domain/bot-domain-main/pom.xml +++ b/bot-domain/bot-domain-main/pom.xml @@ -5,7 +5,7 @@ bot-domain dev.struchkov.godfather - 0.0.27 + 0.0.25 4.0.0 diff --git a/bot-domain/pom.xml b/bot-domain/pom.xml index e4d5134..f44a2ff 100644 --- a/bot-domain/pom.xml +++ b/bot-domain/pom.xml @@ -5,7 +5,7 @@ godfather-bot dev.struchkov.godfather - 0.0.27 + 0.0.25 4.0.0 diff --git a/bot-exception/pom.xml b/bot-exception/pom.xml index 8dde2cf..c10ac7c 100644 --- a/bot-exception/pom.xml +++ b/bot-exception/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather godfather-bot - 0.0.27 + 0.0.25 4.0.0 diff --git a/pom.xml b/pom.xml index b07d3c9..809961f 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ dev.struchkov.godfather godfather-bot - 0.0.27 + 0.0.25 pom