use of org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.search.SearchType 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);
}
Aggregations