Сделал 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> {
|
public class GeneralAutoResponder<M extends Message> {
|
||||||
|
|
||||||
protected final PersonSettingService personSettingService;
|
protected PersonSettingService personSettingService;
|
||||||
protected final StorylineService<M> storyLineService;
|
protected final StorylineService<M> storyLineService;
|
||||||
protected Map<String, List<ActionUnit>> actionUnitMap = new HashMap<>();
|
protected Map<String, List<ActionUnit>> actionUnitMap = new HashMap<>();
|
||||||
protected List<Modifiable<M>> modifiable;
|
protected List<Modifiable<M>> modifiable;
|
||||||
protected ErrorHandler errorHandler;
|
protected ErrorHandler errorHandler;
|
||||||
|
|
||||||
protected GeneralAutoResponder(
|
protected GeneralAutoResponder(StorylineService<M> storyLineService) {
|
||||||
PersonSettingService personSettingService,
|
|
||||||
StorylineService<M> storyLineService
|
|
||||||
) {
|
|
||||||
this.personSettingService = personSettingService;
|
|
||||||
this.storyLineService = storyLineService;
|
this.storyLineService = storyLineService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPersonSettingService(PersonSettingService personSettingService) {
|
||||||
|
this.personSettingService = personSettingService;
|
||||||
|
}
|
||||||
|
|
||||||
public void registrationActionUnit(ActionUnit actionUnit) {
|
public void registrationActionUnit(ActionUnit actionUnit) {
|
||||||
actionUnitMap.computeIfAbsent(actionUnit.getUnitType(), k -> new ArrayList<>());
|
actionUnitMap.computeIfAbsent(actionUnit.getUnitType(), k -> new ArrayList<>());
|
||||||
actionUnitMap.get(actionUnit.getUnitType()).add(actionUnit);
|
actionUnitMap.get(actionUnit.getUnitType()).add(actionUnit);
|
||||||
@ -67,17 +67,24 @@ public class GeneralAutoResponder<M extends Message> {
|
|||||||
public Uni<Void> processingNewMessage(M newMessage) {
|
public Uni<Void> processingNewMessage(M newMessage) {
|
||||||
return Uni.createFrom().item(newMessage)
|
return Uni.createFrom().item(newMessage)
|
||||||
.onItem().ifNotNull().transformToUni(
|
.onItem().ifNotNull().transformToUni(
|
||||||
message -> personSettingService.getStateProcessingByPersonId(newMessage.getFromPersonId())
|
message -> {
|
||||||
.replaceIfNullWith(TRUE)
|
if (checkNotNull(personSettingService)) {
|
||||||
.chain(
|
return personSettingService.getStateProcessingByPersonId(newMessage.getFromPersonId())
|
||||||
state -> {
|
.replaceIfNullWith(TRUE)
|
||||||
if (TRUE.equals(state)) {
|
.flatMap(
|
||||||
return processing(newMessage);
|
state -> {
|
||||||
}
|
if (TRUE.equals(state)) {
|
||||||
return Uni.createFrom().voidItem();
|
return processing(newMessage);
|
||||||
}
|
}
|
||||||
)
|
return Uni.createFrom().voidItem();
|
||||||
).replaceWithVoid();
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return processing(newMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.replaceWithVoid();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Uni<Void> processingNewMessages(List<M> newMessages) {
|
public Uni<Void> processingNewMessages(List<M> newMessages) {
|
||||||
@ -89,18 +96,24 @@ public class GeneralAutoResponder<M extends Message> {
|
|||||||
final Set<String> personIds = newMessages.stream()
|
final Set<String> personIds = newMessages.stream()
|
||||||
.map(Message::getFromPersonId)
|
.map(Message::getFromPersonId)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
return personSettingService.getAllPersonIdDisableMessages(personIds)
|
if (checkNotNull(personSettingService)) {
|
||||||
.replaceIfNullWith(emptySet())
|
return personSettingService.getAllPersonIdDisableMessages(personIds)
|
||||||
.onItem().transformToMulti(
|
.replaceIfNullWith(emptySet())
|
||||||
disableIds -> {
|
.onItem().transformToMulti(
|
||||||
final List<M> allowedMessages = newMessages.stream()
|
disableIds -> {
|
||||||
.filter(message -> !disableIds.contains(message.getFromPersonId()))
|
final List<M> allowedMessages = newMessages.stream()
|
||||||
.toList();
|
.filter(message -> !disableIds.contains(message.getFromPersonId()))
|
||||||
return Multi.createFrom().iterable(allowedMessages);
|
.toList();
|
||||||
}
|
return Multi.createFrom().iterable(allowedMessages);
|
||||||
)
|
}
|
||||||
.onItem().transform(this::processing)
|
)
|
||||||
.toUni().replaceWithVoid();
|
.onItem().transform(this::processing)
|
||||||
|
.collect().asList().replaceWithVoid();
|
||||||
|
} else {
|
||||||
|
return Multi.createFrom().iterable(newMessages)
|
||||||
|
.onItem().transform(this::processing)
|
||||||
|
.collect().asList().replaceWithVoid();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user