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

com.enonic.xp.lib.node.QueryNodeHandlerParams Maven / Gradle / Ivy

The newest version!
package com.enonic.xp.lib.node;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.enonic.xp.script.ScriptValue;

@SuppressWarnings("unused")
public class QueryNodeHandlerParams
{
    private Integer start;

    private Integer count;

    private ScriptValue query;

    private ScriptValue sort;

    private Map aggregations;

    private Map suggestions;

    private Map highlight;

    private List> filters;

    private boolean explain;

    List> getFilters()
    {
        return filters;
    }

    @SuppressWarnings("unused")
    public void setFilters( final ScriptValue filters )
    {
        this.filters = doSetFilters( filters );
    }

    private List> doSetFilters( final ScriptValue filters )
    {
        List> filterList = new ArrayList<>();

        if ( filters == null )
        {
            return filterList;
        }

        if ( filters.isObject() )
        {
            filterList.add( filters.getMap() );
        }
        else if ( filters.isArray() )
        {
            filters.getArray().forEach( sv -> {

                if ( !sv.isObject() )
                {
                    throw new IllegalArgumentException( "Array elements not of type objects" );
                }

                filterList.add( sv.getMap() );
            } );
        }

        return filterList;
    }

    Integer getStart()
    {
        return start;
    }

    public boolean isExplain()
    {
        return explain;
    }

    @SuppressWarnings("unused")
    public void setStart( final Integer start )
    {
        this.start = start;
    }

    Integer getCount()
    {
        return count;
    }

    public void setCount( final Integer count )
    {
        this.count = count;
    }

    ScriptValue getQuery()
    {
        return query;
    }

    @SuppressWarnings("unused")
    public void setQuery( final ScriptValue query )
    {
        this.query = query;
    }

    ScriptValue getSort()
    {
        return sort;
    }

    @SuppressWarnings("unused")
    public void setSort( final ScriptValue sort )
    {
        this.sort = sort;
    }

    Map getAggregations()
    {
        return aggregations;
    }

    @SuppressWarnings("unused")
    public void setAggregations( final ScriptValue aggregations )
    {
        this.aggregations = aggregations != null ? aggregations.getMap() : new HashMap<>();
    }

    Map getSuggestions()
    {
        return suggestions;
    }

    @SuppressWarnings("unused")
    public void setSuggestions( final ScriptValue suggestions )
    {
        this.suggestions = suggestions != null ? suggestions.getMap() : new HashMap<>();
    }

    Map getHighlight()
    {
        return highlight;
    }

    @SuppressWarnings("unused")
    public void setHighlight( final ScriptValue highlight )
    {
        this.highlight = highlight != null ? highlight.getMap() : new HashMap<>();
    }

    public void setExplain( final boolean explain )
    {
        this.explain = explain;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy