Сделал personSettingService необязательным

This commit is contained in:
Struchkov Mark 2023-04-23 03:19:08 +03:00
parent 420c700581
commit ed0d50777f
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6

View File

@ -30,20 +30,20 @@ import static java.util.Collections.emptySet;
public class GeneralAutoResponder<M extends Message> {
protected final PersonSettingService personSettingService;
protected PersonSettingService personSettingService;
protected final StorylineService<M> storyLineService;
protected Map<String, List<ActionUnit>> actionUnitMap = new HashMap<>();
protected List<Modifiable<M>> modifiable;
protected ErrorHandler errorHandler;
protected GeneralAutoResponder(
PersonSettingService personSettingService,
StorylineService<M> storyLineService
) {
this.personSettingService = personSettingService;
protected GeneralAutoResponder(StorylineService<M> storyLineService) {
this.storyLineService = storyLineService;
}
public void setPersonSettingService(PersonSettingService personSettingService) {
this.personSettingService = personSettingService;
}
public void registrationActionUnit(ActionUnit actionUnit) {
actionUnitMap.computeIfAbsent(actionUnit.getUnitType(), k -> new ArrayList<>());
actionUnitMap.get(actionUnit.getUnitType()).add(actionUnit);
@ -67,17 +67,24 @@ public class GeneralAutoResponder<M extends Message> {
public Uni<Void> processingNewMessage(M newMessage) {
return Uni.createFrom().item(newMessage)
.onItem().ifNotNull().transformToUni(
message -> personSettingService.getStateProcessingByPersonId(newMessage.getFromPersonId())
.replaceIfNullWith(TRUE)
.chain(
state -> {
if (TRUE.equals(state)) {
return processing(newMessage);
}
return Uni.createFrom().voidItem();
}
)
).replaceWithVoid();
message -> {
if (checkNotNull(personSettingService)) {
return personSettingService.getStateProcessingByPersonId(newMessage.getFromPersonId())
.replaceIfNullWith(TRUE)
.flatMap(
state -> {
if (TRUE.equals(state)) {
return processing(newMessage);
}
return Uni.createFrom().voidItem();
}
);
} else {
return processing(newMessage);
}
}
)
.replaceWithVoid();
}
public Uni<Void> processingNewMessages(List<M> newMessages) {
@ -89,18 +96,24 @@ public class GeneralAutoResponder<M extends Message> {
final Set<String> personIds = newMessages.stream()
.map(Message::getFromPersonId)
.collect(Collectors.toSet());
return personSettingService.getAllPersonIdDisableMessages(personIds)
.replaceIfNullWith(emptySet())
.onItem().transformToMulti(
disableIds -> {
final List<M> allowedMessages = newMessages.stream()
.filter(message -> !disableIds.contains(message.getFromPersonId()))
.toList();
return Multi.createFrom().iterable(allowedMessages);
}
)
.onItem().transform(this::processing)
.toUni().replaceWithVoid();
if (checkNotNull(personSettingService)) {
return personSettingService.getAllPersonIdDisableMessages(personIds)
.replaceIfNullWith(emptySet())
.onItem().transformToMulti(
disableIds -> {
final List<M> allowedMessages = newMessages.stream()
.filter(message -> !disableIds.contains(message.getFromPersonId()))
.toList();
return Multi.createFrom().iterable(allowedMessages);
}
)
.onItem().transform(this::processing)
.collect().asList().replaceWithVoid();
} else {
return Multi.createFrom().iterable(newMessages)
.onItem().transform(this::processing)
.collect().asList().replaceWithVoid();
}
}
);
}