Search in sources :

Example 1 with Query

use of org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.search.Query in project graylog2-server by Graylog2.

the class V20191203120602_MigrateSavedSearchesToViews method migrateSavedSearch.

private Map.Entry<View, Search> migrateSavedSearch(SavedSearch savedSearch) {
    final String histogramId = randomUUIDProvider.get();
    final String messageListId = randomUUIDProvider.get();
    final Set<ViewWidget> widgets = ImmutableSet.of(AggregationWidget.create(histogramId), savedSearch.query().toMessagesWidget(messageListId));
    final Map<String, Set<String>> widgetMapping = new HashMap<>(widgets.size());
    final Set<SearchType> searchTypes = widgets.stream().flatMap(widget -> {
        final Set<SearchType> widgetSearchTypes = widget.toSearchTypes(randomUUIDProvider);
        widgetMapping.put(widget.id(), widgetSearchTypes.stream().map(SearchType::id).collect(Collectors.toSet()));
        return widgetSearchTypes.stream();
    }).collect(Collectors.toSet());
    final Query.Builder queryBuilder = Query.builder().id(randomUUIDProvider.get()).timerange(savedSearch.query().toTimeRange()).query(savedSearch.query().query()).searchTypes(searchTypes);
    final Query query = savedSearch.query().streamId().map(queryBuilder::streamId).orElse(queryBuilder).build();
    final Search newSearch = Search.create(randomObjectIdProvider.get(), Collections.singleton(query), savedSearch.creatorUserId(), savedSearch.createdAt());
    final Titles titles = Titles.ofWidgetTitles(ImmutableMap.of(histogramId, "Message Count", messageListId, "All Messages"));
    final Map<String, ViewWidgetPosition> widgetPositions = ImmutableMap.of(histogramId, ViewWidgetPosition.builder().col(Position.fromInt(1)).row(Position.fromInt(1)).height(Position.fromInt(2)).width(Position.infinity()).build(), messageListId, ViewWidgetPosition.builder().col(Position.fromInt(1)).row(Position.fromInt(3)).height(Position.fromInt(6)).width(Position.infinity()).build());
    final ViewState viewState = ViewState.create(titles, widgets, widgetMapping, widgetPositions);
    final View newView = View.create(randomObjectIdProvider.get(), "Saved Search: " + savedSearch.title(), "This Search was migrated automatically from the \"" + savedSearch.title() + "\" saved search.", "", newSearch.id(), Collections.singletonMap(query.id(), viewState), Optional.of(savedSearch.creatorUserId()), savedSearch.createdAt());
    return new AbstractMap.SimpleEntry<>(newView, newSearch);
}
Also used : ViewService(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.view.ViewService) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ViewWidgetPosition(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.view.ViewWidgetPosition) ViewState(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.view.ViewState) Inject(javax.inject.Inject) ClusterConfigService(org.graylog2.plugin.cluster.ClusterConfigService) Map(java.util.Map) Migration(org.graylog2.migrations.Migration) RandomObjectIdProvider(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.view.RandomObjectIdProvider) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) SearchType(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.search.SearchType) View(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.view.View) SavedSearch(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.savedsearch.SavedSearch) Query(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.search.Query) Set(java.util.Set) ViewWidget(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.view.ViewWidget) Collectors(java.util.stream.Collectors) SavedSearchService(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.savedsearch.SavedSearchService) Search(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.search.Search) AbstractMap(java.util.AbstractMap) RandomUUIDProvider(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.view.RandomUUIDProvider) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator) AutoValue(com.google.auto.value.AutoValue) Position(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.view.Position) Optional(java.util.Optional) AggregationWidget(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.view.AggregationWidget) Titles(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.view.Titles) Collections(java.util.Collections) SearchService(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.search.SearchService) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Query(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.search.Query) HashMap(java.util.HashMap) ViewState(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.view.ViewState) View(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.view.View) Titles(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.view.Titles) ViewWidget(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.view.ViewWidget) ViewWidgetPosition(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.view.ViewWidgetPosition) SavedSearch(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.savedsearch.SavedSearch) Search(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.search.Search) SearchType(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.search.SearchType)

Aggregations

JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 AutoValue (com.google.auto.value.AutoValue)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ZonedDateTime (java.time.ZonedDateTime)1 AbstractMap (java.util.AbstractMap)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 SavedSearch (org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.savedsearch.SavedSearch)1 SavedSearchService (org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.savedsearch.SavedSearchService)1 Query (org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.search.Query)1 Search (org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.search.Search)1 SearchService (org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.search.SearchService)1 SearchType (org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.search.SearchType)1