All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.khasanof.feature.method.VarExpressionExtraParam Maven / Gradle / Ivy

The newest version!
package org.khasanof.feature.method;

import org.khasanof.annotation.methods.HandleMessage;
import org.khasanof.context.FluentContextHolder;
import org.khasanof.context.FluentUpdate;
import org.khasanof.enums.DefaultMethodType;
import org.khasanof.executors.expression.ExpressionVariables;
import org.khasanof.feature.HandleMethodExtraParam;
import org.khasanof.models.invoker.InvokerParam;
import org.khasanof.models.invoker.SimpleInvoker;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author Nurislom
 * @see org.khasanof.feature.method
 * @since 2/1/2024 10:32 PM
 */
@Component
public class VarExpressionExtraParam implements HandleMethodExtraParam {

    private final ExpressionVariables matcher;

    public VarExpressionExtraParam(ExpressionVariables matcher) {
        this.matcher = matcher;
    }

    @Override
    public void execute(SimpleInvoker simpleInvoker) {
        FluentUpdate currentUpdate = FluentContextHolder.getCurrentFluentUpdate();
        Map matchVariables = getMatchVariables(simpleInvoker, currentUpdate);
        simpleInvoker.getParams().put(InvokerParam.ADDITIONAL_PARAM, matchVariables);
    }

    private Map getMatchVariables(SimpleInvoker simpleInvoker, FluentUpdate currentUpdate) {
        return matcher.getMatchVariables(((HandleMessage) simpleInvoker.getParams().get(InvokerParam.ANNOTATION)).value(),
                currentUpdate.getUpdate().getMessage().getText());
    }

    @Override
    public MethodType methodType() {
        return DefaultMethodType.VAR_EXPRESSION;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy