org.khasanof.service.interceptor.DefaultFluentInterceptorService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-boot-starter-fluent Show documentation
Show all versions of spring-boot-starter-fluent Show documentation
Fluent - Easy Telegram Bots with Spring
The newest version!
package org.khasanof.service.interceptor;
import org.khasanof.feature.interceptor.FluentInterceptor;
import org.khasanof.registry.interceptor.FluentInterceptorRegistryContainer;
import org.springframework.stereotype.Service;
import org.telegram.telegrambots.meta.api.objects.Update;
import java.util.Set;
/**
* @author Nurislom
* @see org.khasanof.service.interceptor
* @since 2/3/2024 6:29 PM
*/
@Service
public class DefaultFluentInterceptorService implements FluentInterceptorService {
private final FluentInterceptorRegistryContainer registryContainer;
public DefaultFluentInterceptorService(FluentInterceptorRegistryContainer registryContainer) {
this.registryContainer = registryContainer;
}
@Override
public boolean preIntercept(Update update) {
return getInterceptors()
.stream()
.allMatch(fluentInterceptor -> fluentInterceptor.preHandle(update));
}
@Override
public void postIntercept(Update update) {
getInterceptors()
.forEach(fluentInterceptor -> fluentInterceptor.postHandle(update));
}
private Set getInterceptors() {
return registryContainer.getFluentInterceptors();
}
}