Сделал 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> { 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 -> {
if (checkNotNull(personSettingService)) {
return personSettingService.getStateProcessingByPersonId(newMessage.getFromPersonId())
.replaceIfNullWith(TRUE) .replaceIfNullWith(TRUE)
.chain( .flatMap(
state -> { state -> {
if (TRUE.equals(state)) { if (TRUE.equals(state)) {
return processing(newMessage); return processing(newMessage);
} }
return Uni.createFrom().voidItem(); return Uni.createFrom().voidItem();
} }
);
} else {
return processing(newMessage);
}
}
) )
).replaceWithVoid(); .replaceWithVoid();
} }
public Uni<Void> processingNewMessages(List<M> newMessages) { public Uni<Void> processingNewMessages(List<M> newMessages) {
@ -89,6 +96,7 @@ 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());
if (checkNotNull(personSettingService)) {
return personSettingService.getAllPersonIdDisableMessages(personIds) return personSettingService.getAllPersonIdDisableMessages(personIds)
.replaceIfNullWith(emptySet()) .replaceIfNullWith(emptySet())
.onItem().transformToMulti( .onItem().transformToMulti(
@ -100,7 +108,12 @@ public class GeneralAutoResponder<M extends Message> {
} }
) )
.onItem().transform(this::processing) .onItem().transform(this::processing)
.toUni().replaceWithVoid(); .collect().asList().replaceWithVoid();
} else {
return Multi.createFrom().iterable(newMessages)
.onItem().transform(this::processing)
.collect().asList().replaceWithVoid();
}
} }
); );
} }