Search in sources :

Example 1 with WidgetDTO

use of org.graylog.plugins.views.search.views.WidgetDTO in project graylog2-server by Graylog2.

the class ViewsResource method validateIntegrity.

private void validateIntegrity(ViewDTO dto, SearchUser searchUser) {
    final Search search = searchDomain.getForUser(dto.searchId(), searchUser).orElseThrow(() -> new BadRequestException("Search " + dto.searchId() + " not available"));
    final Set<String> searchQueries = search.queries().stream().map(Query::id).collect(Collectors.toSet());
    final Set<String> stateQueries = dto.state().keySet();
    if (!searchQueries.containsAll(stateQueries)) {
        final Sets.SetView<String> diff = Sets.difference(searchQueries, stateQueries);
        throw new BadRequestException("Search queries do not correspond to view/state queries, missing query IDs: " + diff);
    }
    final Set<String> searchTypes = search.queries().stream().flatMap(q -> q.searchTypes().stream()).map(SearchType::id).collect(Collectors.toSet());
    final Set<String> stateTypes = dto.state().values().stream().flatMap(v -> v.widgetMapping().values().stream()).flatMap(Collection::stream).collect(Collectors.toSet());
    if (!searchTypes.containsAll(stateTypes)) {
        final Sets.SetView<String> diff = Sets.difference(searchTypes, stateTypes);
        throw new BadRequestException("Search types do not correspond to view/search types, missing searches: " + diff);
    }
    final Set<String> widgetIds = dto.state().values().stream().flatMap(v -> v.widgets().stream()).map(WidgetDTO::id).collect(Collectors.toSet());
    final Set<String> widgetPositions = dto.state().values().stream().flatMap(v -> v.widgetPositions().keySet().stream()).collect(Collectors.toSet());
    if (!widgetPositions.containsAll(widgetIds)) {
        final Sets.SetView<String> diff = Sets.difference(widgetPositions, widgetIds);
        throw new BadRequestException("Widget positions don't correspond to widgets, missing widget possitions: " + diff);
    }
}
Also used : Produces(javax.ws.rs.Produces) ViewsAuditEventTypes(org.graylog.plugins.views.audit.ViewsAuditEventTypes) UserContext(org.graylog.security.UserContext) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) WidgetDTO(org.graylog.plugins.views.search.views.WidgetDTO) ViewDTO(org.graylog.plugins.views.search.views.ViewDTO) NotEmpty(javax.validation.constraints.NotEmpty) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) PaginatedList(org.graylog2.database.PaginatedList) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) SearchQueryField(org.graylog2.search.SearchQueryField) Locale(java.util.Locale) Map(java.util.Map) PluginRestResource(org.graylog2.plugin.rest.PluginRestResource) DefaultValue(javax.ws.rs.DefaultValue) BadRequestException(javax.ws.rs.BadRequestException) ENGLISH(java.util.Locale.ENGLISH) DELETE(javax.ws.rs.DELETE) Context(javax.ws.rs.core.Context) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Set(java.util.Set) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) NotFoundException(javax.ws.rs.NotFoundException) ClusterEventBus(org.graylog2.events.ClusterEventBus) SearchUser(org.graylog.plugins.views.search.permissions.SearchUser) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) PathParam(javax.ws.rs.PathParam) Query(org.graylog.plugins.views.search.Query) SearchQueryParser(org.graylog2.search.SearchQueryParser) GET(javax.ws.rs.GET) ViewResolver(org.graylog.plugins.views.search.views.ViewResolver) SearchDomain(org.graylog.plugins.views.search.SearchDomain) Inject(javax.inject.Inject) ViewResolverDecoder(org.graylog.plugins.views.search.views.ViewResolverDecoder) SearchType(org.graylog.plugins.views.search.SearchType) AuditEvent(org.graylog2.audit.jersey.AuditEvent) Api(io.swagger.annotations.Api) Search(org.graylog.plugins.views.search.Search) SearchQuery(org.graylog2.search.SearchQuery) DashboardDeletedEvent(org.graylog2.dashboards.events.DashboardDeletedEvent) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) ForbiddenException(javax.ws.rs.ForbiddenException) RestResource(org.graylog2.shared.rest.resources.RestResource) ValidationException(org.graylog2.plugin.database.ValidationException) ViewService(org.graylog.plugins.views.search.views.ViewService) PUT(javax.ws.rs.PUT) PaginatedResponse(org.graylog2.rest.models.PaginatedResponse) User(org.graylog2.plugin.database.users.User) Sets(com.google.common.collect.Sets) Search(org.graylog.plugins.views.search.Search) BadRequestException(javax.ws.rs.BadRequestException)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 Sets (com.google.common.collect.Sets)1 Api (io.swagger.annotations.Api)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiParam (io.swagger.annotations.ApiParam)1 Collection (java.util.Collection)1 Locale (java.util.Locale)1 ENGLISH (java.util.Locale.ENGLISH)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Valid (javax.validation.Valid)1 NotEmpty (javax.validation.constraints.NotEmpty)1 NotNull (javax.validation.constraints.NotNull)1 BadRequestException (javax.ws.rs.BadRequestException)1 DELETE (javax.ws.rs.DELETE)1 DefaultValue (javax.ws.rs.DefaultValue)1 ForbiddenException (javax.ws.rs.ForbiddenException)1 GET (javax.ws.rs.GET)1