Сделал personSettingService необязательным
This commit is contained in:
parent
420c700581
commit
ed0d50777f
@ -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())
|
||||
message -> {
|
||||
if (checkNotNull(personSettingService)) {
|
||||
return personSettingService.getStateProcessingByPersonId(newMessage.getFromPersonId())
|
||||
.replaceIfNullWith(TRUE)
|
||||
.chain(
|
||||
.flatMap(
|
||||
state -> {
|
||||
if (TRUE.equals(state)) {
|
||||
return processing(newMessage);
|
||||
}
|
||||
return Uni.createFrom().voidItem();
|
||||
}
|
||||
);
|
||||
} else {
|
||||
return processing(newMessage);
|
||||
}
|
||||
}
|
||||
)
|
||||
).replaceWithVoid();
|
||||
.replaceWithVoid();
|
||||
}
|
||||
|
||||
public Uni<Void> processingNewMessages(List<M> newMessages) {
|
||||
@ -89,6 +96,7 @@ public class GeneralAutoResponder<M extends Message> {
|
||||
final Set<String> personIds = newMessages.stream()
|
||||
.map(Message::getFromPersonId)
|
||||
.collect(Collectors.toSet());
|
||||
if (checkNotNull(personSettingService)) {
|
||||
return personSettingService.getAllPersonIdDisableMessages(personIds)
|
||||
.replaceIfNullWith(emptySet())
|
||||
.onItem().transformToMulti(
|
||||
@ -100,7 +108,12 @@ public class GeneralAutoResponder<M extends Message> {
|
||||
}
|
||||
)
|
||||
.onItem().transform(this::processing)
|
||||
.toUni().replaceWithVoid();
|
||||
.collect().asList().replaceWithVoid();
|
||||
} else {
|
||||
return Multi.createFrom().iterable(newMessages)
|
||||
.onItem().transform(this::processing)
|
||||
.collect().asList().replaceWithVoid();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user