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

co.com.sofka.infraestructure.handle.QueryExecutor Maven / Gradle / Ivy

There is a newer version: 1.5.0
Show newest version
package co.com.sofka.infraestructure.handle;

import co.com.sofka.domain.generic.ViewModel;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.logging.Logger;

/**
 * The type Query executor.
 */
public class QueryExecutor implements QueryHandler> {
    private static final Logger logger = Logger.getLogger(QueryExecutor.class.getName());

    /**
     * The Handles.
     */
    protected Map, ?>> handles = new ConcurrentHashMap<>();

    /**
     * Add.
     *
     * @param queryPath the path of the query route
     * @param function  the function
     */
    protected void put(String queryPath, Function, ?> function) {
        handles.put(queryPath, function);
    }

    @Override
    public ViewModel get(String path, Map params) {

        if (!handles.containsKey(path)) {
            throw new ExecutionNoFound(path);
        }
        var result = handles.get(path).apply(params);
        logger.info("View model applied OK --> " + params);

        return (ViewModel) result;
    }

    @Override
    public List find(String path, Map params) {
        if (!handles.containsKey(path)) {
            throw new ExecutionNoFound(path);
        }
        var result = handles.get(path).apply(params);
        logger.info("View model list applied OK --> " + params);

        return (List) result;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy