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

org.graylog.plugins.views.ViewsModule Maven / Gradle / Ivy

There is a newer version: 6.0.5
Show newest version
/**
 * This file is part of Graylog.
 *
 * Graylog is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Graylog is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Graylog.  If not, see .
 */
package org.graylog.plugins.views;

import com.google.inject.TypeLiteral;
import com.google.inject.binder.ScopedBindingBuilder;
import com.google.inject.multibindings.MapBinder;
import com.google.inject.multibindings.Multibinder;
import io.searchbox.core.search.aggregation.Aggregation;
import org.graylog.plugins.views.search.Search;
import org.graylog.plugins.views.search.SearchType;
import org.graylog.plugins.views.search.elasticsearch.ESQueryDecorator;
import org.graylog.plugins.views.search.elasticsearch.QueryMetadataDecorator;
import org.graylog.plugins.views.search.elasticsearch.searchtypes.ESSearchTypeHandler;
import org.graylog.plugins.views.search.elasticsearch.searchtypes.pivot.ESPivotBucketSpecHandler;
import org.graylog.plugins.views.search.elasticsearch.searchtypes.pivot.ESPivotSeriesSpecHandler;
import org.graylog.plugins.views.search.engine.GeneratedQueryContext;
import org.graylog.plugins.views.search.engine.QueryBackend;
import org.graylog.plugins.views.search.rest.SeriesDescription;
import org.graylog.plugins.views.search.searchtypes.pivot.BucketSpec;
import org.graylog.plugins.views.search.searchtypes.pivot.SeriesSpec;
import org.graylog.plugins.views.search.views.ViewDTO;
import org.graylog.plugins.views.search.views.sharing.SharingStrategy;
import org.graylog.plugins.views.search.Search;
import org.graylog.plugins.views.search.SearchType;
import org.graylog2.plugin.PluginMetaData;
import org.graylog2.plugin.PluginModule;

public abstract class ViewsModule extends PluginModule {
    protected void registerQueryMetadataDecorator(Class queryMetadataDecorator) {
        queryMetadataDecoratorBinder().addBinding().to(queryMetadataDecorator);
    }

    protected Multibinder queryMetadataDecoratorBinder() {
        return Multibinder.newSetBinder(binder(), QueryMetadataDecorator.class);
    }

    protected void registerProvidedViewsCapability(String capability, PluginMetaData plugin) {
        viewsCapabilityBinder().addBinding(capability).toInstance(plugin);
    }

    protected MapBinder viewsCapabilityBinder() {
        return MapBinder.newMapBinder(binder(), String.class, PluginMetaData.class);
    }

    protected void registerViewRequirement(Class> viewRequirement) {
        viewRequirementBinder().addBinding().to(viewRequirement);
    }

    protected Multibinder> viewRequirementBinder() {
        return Multibinder.newSetBinder(binder(), new TypeLiteral>() {});
    }

    protected void registerSearchRequirement(Class> searchRequirement) {
        searchRequirementBinder().addBinding().to(searchRequirement);
    }

    protected Multibinder> searchRequirementBinder() {
        return Multibinder.newSetBinder(binder(), new TypeLiteral>() {});
    }

    protected void registerESQueryDecorator(Class esQueryDecorator) {
        esQueryDecoratorBinder().addBinding().to(esQueryDecorator);
    }

    protected Multibinder esQueryDecoratorBinder() {
        return Multibinder.newSetBinder(binder(), ESQueryDecorator.class);
    }

    protected MapBinder seriesSpecBinder() {
        return MapBinder.newMapBinder(binder(), String.class, SeriesDescription.class);
    }

    protected void registerPivotAggregationFunction(String name, Class seriesSpecClass) {
        registerJacksonSubtype(seriesSpecClass);
        seriesSpecBinder().addBinding(name).toInstance(SeriesDescription.create(name));
    }

    protected MapBinder sharingStrategyBinder() {
        return MapBinder.newMapBinder(binder(), String.class, SharingStrategy.class);
    }

    protected ScopedBindingBuilder registerSharingStrategy(String type, Class sharingStrategy) {
        return sharingStrategyBinder().addBinding(type).to(sharingStrategy);
    }

    protected MapBinder> pivotBucketHandlerBinder() {
        return MapBinder.newMapBinder(binder(),
                TypeLiteral.get(String.class),
                new TypeLiteral>() {});

    }

    protected ScopedBindingBuilder registerPivotBucketHandler(
            String name,
            Class> implementation
    ) {
        return pivotBucketHandlerBinder().addBinding(name).to(implementation);
    }

    protected MapBinder> pivotSeriesHandlerBinder() {
        return MapBinder.newMapBinder(binder(),
                TypeLiteral.get(String.class),
                new TypeLiteral>() {});

    }

    protected ScopedBindingBuilder registerPivotSeriesHandler(
            String name,
            Class> implementation
    ) {
        return pivotSeriesHandlerBinder().addBinding(name).to(implementation);
    }

    protected MapBinder> queryBackendBinder() {
        return MapBinder.newMapBinder(binder(),
                TypeLiteral.get(String.class),
                new TypeLiteral>() {});

    }

    protected ScopedBindingBuilder registerQueryBackend(String name, Class> implementation) {
        return queryBackendBinder().addBinding(name).to(implementation);
    }

    protected MapBinder> esSearchTypeHandlerBinder() {
        return MapBinder.newMapBinder(binder(),
                TypeLiteral.get(String.class),
                new TypeLiteral>() {});
    }

    protected ScopedBindingBuilder registerESSearchTypeHandler(String name, Class> implementation) {
        return esSearchTypeHandlerBinder().addBinding(name).to(implementation);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy