org.khasanof.executors.matcher.SimpleDocumentMatcher 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.executors.matcher;
import org.khasanof.annotation.methods.HandleDocument;
import org.khasanof.enums.scopes.DocumentScope;
import org.khasanof.models.matcher.MatcherParameters;
import org.khasanof.models.matcher.MatcherProperty;
import org.khasanof.models.matcher.function.PropertyFunction;
import org.khasanof.service.expression.ExpressionMatcherService;
import org.springframework.stereotype.Component;
import org.telegram.telegrambots.meta.api.objects.Message;
import java.util.HashSet;
import java.util.Set;
/**
* @author Nurislom
* @see org.khasanof.executors.matcher
* @since 28.06.2023 10:27
*/
@Component
public class SimpleDocumentMatcher extends GenericMatcher {
private final Set matcherProperties = new HashSet<>();
public SimpleDocumentMatcher(ExpressionMatcherService expressionMatcherService) {
super(expressionMatcherService);
fillMatcherProperties();
}
@Override
public boolean matcher(HandleDocument annotation, Message value) {
return expressionMatcherService.match(createParameter(annotation, value));
}
private MatcherParameters createParameter(HandleDocument annotation, Message value) {
return new MatcherParameters(value, annotation.property(), annotation.match(), annotation.value(), matcherProperties);
}
private void fillMatcherProperties() {
matcherProperties.add(new MatcherProperty(DocumentScope.CAPTION, (PropertyFunction) Message::getCaption));
matcherProperties.add(new MatcherProperty(DocumentScope.FILE_NAME, (PropertyFunction) msg -> msg.getDocument().getFileName()));
matcherProperties.add(new MatcherProperty(DocumentScope.MIME_TYPE, (PropertyFunction) msg -> msg.getDocument().getMimeType()));
matcherProperties.add(new MatcherProperty(DocumentScope.FILE_SIZE, (PropertyFunction) msg -> msg.getDocument().getFileSize()));
}
}