Удалил ненужный PersonSettingService.java
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Struchkov Mark 2023-04-23 04:12:18 +03:00
parent ed0d50777f
commit 2f2f3319a2
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
10 changed files with 9 additions and 307 deletions

View File

@ -1,17 +0,0 @@
package dev.struchkov.godfather.quarkus.context.repository;
import io.smallrye.mutiny.Uni;
import java.util.Set;
public interface PersonSettingRepository {
Uni<Set<String>> findAllByAllowedProcessing(Set<String> personIds);
Uni<Void> disableMessageProcessing(String personId);
Uni<Void> enableMessageProcessing(String personId);
Uni<Boolean> findStateByPersonId(String personId);
}

View File

@ -1,18 +0,0 @@
package dev.struchkov.godfather.quarkus.context.service;
import io.smallrye.mutiny.Uni;
import org.jetbrains.annotations.NotNull;
import java.util.Set;
public interface PersonSettingService {
Uni<Set<String>> getAllPersonIdDisableMessages(@NotNull Set<String> personIds);
Uni<Boolean> getStateProcessingByPersonId(@NotNull String personId);
Uni<Void> disableMessageProcessing(@NotNull String personId);
Uni<Void> enableMessageProcessing(@NotNull String personId);
}

View File

@ -1,16 +0,0 @@
package dev.struchkov.godfather.simple.context.repository;
import java.util.Optional;
import java.util.Set;
public interface PersonSettingRepository {
Set<String> findAllByAllowedProcessing(Set<String> personIds);
void disableMessageProcessing(String personId);
void enableMessageProcessing(String personId);
Optional<Boolean> findStateByPersonId(String personId);
}

View File

@ -1,18 +0,0 @@
package dev.struchkov.godfather.simple.context.service;
import org.jetbrains.annotations.NotNull;
import java.util.Optional;
import java.util.Set;
public interface PersonSettingService {
Set<String> getAllPersonIdDisableMessages(@NotNull Set<String> personIds);
Optional<Boolean> getStateProcessingByPersonId(@NotNull String personId);
void disableMessageProcessing(@NotNull String personId);
void enableMessageProcessing(@NotNull String personId);
}

View File

@ -4,7 +4,6 @@ import dev.struchkov.godfather.main.domain.content.Message;
import dev.struchkov.godfather.main.domain.unit.UnitActiveType;
import dev.struchkov.godfather.quarkus.context.service.ErrorHandler;
import dev.struchkov.godfather.quarkus.context.service.Modifiable;
import dev.struchkov.godfather.quarkus.context.service.PersonSettingService;
import dev.struchkov.godfather.quarkus.core.action.ActionUnit;
import dev.struchkov.godfather.quarkus.core.service.StorylineService;
import dev.struchkov.godfather.quarkus.domain.unit.MainUnit;
@ -20,17 +19,13 @@ import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import static dev.struchkov.haiti.utils.Checker.checkEmpty;
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;
public class GeneralAutoResponder<M extends Message> {
protected PersonSettingService personSettingService;
protected final StorylineService<M> storyLineService;
protected Map<String, List<ActionUnit>> actionUnitMap = new HashMap<>();
protected List<Modifiable<M>> modifiable;
@ -40,10 +35,6 @@ public class GeneralAutoResponder<M extends Message> {
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,22 +58,7 @@ public class GeneralAutoResponder<M extends Message> {
public Uni<Void> processingNewMessage(M newMessage) {
return Uni.createFrom().item(newMessage)
.onItem().ifNotNull().transformToUni(
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);
}
}
message -> processing(newMessage)
)
.replaceWithVoid();
}
@ -92,28 +68,9 @@ public class GeneralAutoResponder<M extends Message> {
.onItem().ifNotNull().transformToUni(
messages -> {
if (checkEmpty(newMessages)) return Uni.createFrom().voidItem();
final Set<String> personIds = newMessages.stream()
.map(Message::getFromPersonId)
.collect(Collectors.toSet());
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();
}
return Multi.createFrom().iterable(newMessages)
.onItem().transform(this::processing)
.collect().asList().replaceWithVoid();
}
);
}

View File

@ -1,42 +0,0 @@
package dev.struchkov.godfather.quarkus.core.service;
import dev.struchkov.godfather.quarkus.context.repository.PersonSettingRepository;
import dev.struchkov.godfather.quarkus.context.service.PersonSettingService;
import dev.struchkov.haiti.utils.Inspector;
import io.smallrye.mutiny.Uni;
import org.jetbrains.annotations.NotNull;
import java.util.Set;
public class PersonSettingServiceImpl implements PersonSettingService {
private final PersonSettingRepository personSettingRepository;
public PersonSettingServiceImpl(PersonSettingRepository personSettingRepository) {
this.personSettingRepository = personSettingRepository;
}
@Override
public Uni<Set<String>> getAllPersonIdDisableMessages(@NotNull Set<String> personIds) {
Inspector.isNotNull(personIds);
return personSettingRepository.findAllByAllowedProcessing(personIds);
}
@Override
public Uni<Boolean> getStateProcessingByPersonId(@NotNull String personId) {
return personSettingRepository.findStateByPersonId(personId);
}
@Override
public Uni<Void> disableMessageProcessing(@NotNull String personId) {
Inspector.isNotNull(personId);
return personSettingRepository.disableMessageProcessing(personId);
}
@Override
public Uni<Void> enableMessageProcessing(@NotNull String personId) {
Inspector.isNotNull(personId);
return personSettingRepository.enableMessageProcessing(personId);
}
}

View File

@ -5,7 +5,6 @@ import dev.struchkov.godfather.main.domain.unit.UnitActiveType;
import dev.struchkov.godfather.simple.context.service.Accessibility;
import dev.struchkov.godfather.simple.context.service.ErrorHandler;
import dev.struchkov.godfather.simple.context.service.Modifiable;
import dev.struchkov.godfather.simple.context.service.PersonSettingService;
import dev.struchkov.godfather.simple.core.action.ActionUnit;
import dev.struchkov.godfather.simple.core.service.StorylineService;
import dev.struchkov.godfather.simple.domain.unit.MainUnit;
@ -22,7 +21,6 @@ import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;
import static dev.struchkov.haiti.utils.Checker.checkNotEmpty;
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
@ -31,7 +29,6 @@ public class GeneralAutoResponder<M extends Message> {
private static final Logger log = LoggerFactory.getLogger(GeneralAutoResponder.class);
protected final PersonSettingService personSettingService;
protected final StorylineService<M> storyLineService;
protected Map<String, List<ActionUnit>> actionUnitMap = new HashMap<>();
@ -39,11 +36,7 @@ public class GeneralAutoResponder<M extends Message> {
protected ErrorHandler errorHandler;
protected ExecutorService executorService;
protected GeneralAutoResponder(
PersonSettingService personSettingService,
StorylineService<M> storyLineService
) {
this.personSettingService = personSettingService;
protected GeneralAutoResponder(StorylineService<M> storyLineService) {
this.storyLineService = storyLineService;
}
@ -75,42 +68,25 @@ public class GeneralAutoResponder<M extends Message> {
if (checkNotNull(newMessage)) {
if (checkNotNull(executorService)) {
CompletableFuture.runAsync(
() -> {
final boolean state = personSettingService.getStateProcessingByPersonId(newMessage.getFromPersonId())
.orElse(true);
if (state) {
processing(newMessage);
}
}, executorService
() -> processing(newMessage), executorService
).exceptionally(ex -> {
log.error(ex.getMessage(), ex);
return null;
});
} else {
final boolean state = personSettingService.getStateProcessingByPersonId(newMessage.getFromPersonId())
.orElse(true);
if (state) {
processing(newMessage);
}
processing(newMessage);
}
}
}
public void processingNewMessages(List<M> newMessages) {
if (checkNotEmpty(newMessages)) {
final Set<String> personIds = newMessages.stream()
.map(Message::getFromPersonId)
.collect(Collectors.toSet());
final Set<String> disableIds = personSettingService.getAllPersonIdDisableMessages(personIds);
final List<M> allowedMessages = newMessages.stream()
.filter(message -> !disableIds.contains(message.getFromPersonId()))
.toList();
if (checkNotNull(executorService)) {
for (M allowedMessage : allowedMessages) {
for (M allowedMessage : newMessages) {
executorService.submit(() -> processing(allowedMessage));
}
} else {
for (M allowedMessage : allowedMessages) {
for (M allowedMessage : newMessages) {
processing(allowedMessage);
}
}

View File

@ -1,42 +0,0 @@
package dev.struchkov.godfather.simple.core.service;
import dev.struchkov.godfather.simple.context.repository.PersonSettingRepository;
import dev.struchkov.godfather.simple.context.service.PersonSettingService;
import dev.struchkov.haiti.utils.Inspector;
import org.jetbrains.annotations.NotNull;
import java.util.Optional;
import java.util.Set;
public class PersonSettingServiceImpl implements PersonSettingService {
private final PersonSettingRepository personSettingRepository;
public PersonSettingServiceImpl(PersonSettingRepository personSettingRepository) {
this.personSettingRepository = personSettingRepository;
}
@Override
public Set<String> getAllPersonIdDisableMessages(@NotNull Set<String> personIds) {
Inspector.isNotNull(personIds);
return personSettingRepository.findAllByAllowedProcessing(personIds);
}
@Override
public Optional<Boolean> getStateProcessingByPersonId(@NotNull String personId) {
return personSettingRepository.findStateByPersonId(personId);
}
@Override
public void disableMessageProcessing(@NotNull String personId) {
Inspector.isNotNull(personId);
personSettingRepository.disableMessageProcessing(personId);
}
@Override
public void enableMessageProcessing(@NotNull String personId) {
Inspector.isNotNull(personId);
personSettingRepository.enableMessageProcessing(personId);
}
}

View File

@ -1,41 +0,0 @@
package dev.struchkov.godfather.quarkus.data.repository.impl;
import dev.struchkov.godfather.quarkus.context.repository.PersonSettingRepository;
import io.smallrye.mutiny.Uni;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
public class PersonSettingLocalRepository implements PersonSettingRepository {
private final Map<String, Boolean> map = new HashMap<>();
@Override
public Uni<Set<String>> findAllByAllowedProcessing(Set<String> personIds) {
return Uni.createFrom().item(
personIds.stream()
.filter(map::get)
.collect(Collectors.toSet())
);
}
@Override
public Uni<Void> disableMessageProcessing(String personId) {
map.put(personId, false);
return Uni.createFrom().voidItem();
}
@Override
public Uni<Void> enableMessageProcessing(String personId) {
map.put(personId, true);
return Uni.createFrom().voidItem();
}
@Override
public Uni<Boolean> findStateByPersonId(String personId) {
return Uni.createFrom().item(map.get(personId));
}
}

View File

@ -1,37 +0,0 @@
package dev.struchkov.godfather.simple.data.repository.impl;
import dev.struchkov.godfather.simple.context.repository.PersonSettingRepository;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
public class PersonSettingLocalRepository implements PersonSettingRepository {
private final Map<String, Boolean> map = new HashMap<>();
@Override
public Set<String> findAllByAllowedProcessing(Set<String> personIds) {
return personIds.stream()
.filter(map::get)
.collect(Collectors.toSet());
}
@Override
public void disableMessageProcessing(String personId) {
map.put(personId, false);
}
@Override
public void enableMessageProcessing(String personId) {
map.put(personId, true);
}
@Override
public Optional<Boolean> findStateByPersonId(String personId) {
return Optional.ofNullable(map.get(personId));
}
}