Изменен формат сообщений в ws, рефакторинг
This commit is contained in:
@@ -8,8 +8,10 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.serega6531.packmate.model.FoundPattern;
|
||||
import ru.serega6531.packmate.model.Pattern;
|
||||
import ru.serega6531.packmate.model.PatternType;
|
||||
import ru.serega6531.packmate.model.enums.PatternType;
|
||||
import ru.serega6531.packmate.model.Stream;
|
||||
import ru.serega6531.packmate.model.enums.SubscriptionMessageType;
|
||||
import ru.serega6531.packmate.model.pojo.SubscriptionMessage;
|
||||
import ru.serega6531.packmate.repository.PatternRepository;
|
||||
|
||||
import java.util.*;
|
||||
@@ -22,14 +24,19 @@ public class PatternService {
|
||||
|
||||
private final PatternRepository repository;
|
||||
private final StreamService streamService;
|
||||
private final StreamSubscriptionService subscriptionService;
|
||||
|
||||
private final Map<Integer, Pattern> patterns = new HashMap<>();
|
||||
private final Map<String, java.util.regex.Pattern> compiledPatterns = new HashMap<>();
|
||||
|
||||
@Autowired
|
||||
public PatternService(PatternRepository repository, @Lazy StreamService streamService) {
|
||||
public PatternService(PatternRepository repository,
|
||||
@Lazy StreamService streamService,
|
||||
StreamSubscriptionService subscriptionService) {
|
||||
this.repository = repository;
|
||||
this.streamService = streamService;
|
||||
this.subscriptionService = subscriptionService;
|
||||
|
||||
repository.findAll().forEach(p -> patterns.put(p.getId(), p));
|
||||
log.info("Loaded {} patterns", patterns.size());
|
||||
}
|
||||
@@ -108,6 +115,7 @@ public class PatternService {
|
||||
patterns.remove(id);
|
||||
compiledPatterns.remove(pattern.getValue());
|
||||
repository.delete(pattern);
|
||||
subscriptionService.broadcast(new SubscriptionMessage(SubscriptionMessageType.DELETE_PATTERN, id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +123,7 @@ public class PatternService {
|
||||
log.info("Добавлен новый паттерн {} со значением {}", pattern.getName(), pattern.getValue());
|
||||
final Pattern saved = repository.save(pattern);
|
||||
patterns.put(saved.getId(), pattern);
|
||||
subscriptionService.broadcast(new SubscriptionMessage(SubscriptionMessageType.SAVE_PATTERN, saved));
|
||||
return saved;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user