Search in sources :

Example 1 with ViewSummaryDTO

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

the class SearchesCleanUpJobTest method testForMixedReferencedNonReferencedExpiredAndNonexpiredSearches.

@Test
public void testForMixedReferencedNonReferencedExpiredAndNonexpiredSearches() {
    final String searchId = "This search is in use";
    final ViewSummaryDTO view = mock(ViewSummaryDTO.class);
    when(view.searchId()).thenReturn(searchId);
    when(viewService.streamAll()).thenReturn(Stream.of(view));
    final SearchSummary search1 = mock(SearchSummary.class);
    when(search1.createdAt()).thenReturn(DateTime.now(DateTimeZone.UTC).minus(Duration.standardDays(30)));
    when(search1.id()).thenReturn(searchId);
    final SearchSummary search2 = mock(SearchSummary.class);
    when(search2.createdAt()).thenReturn(DateTime.now(DateTimeZone.UTC).minus(Duration.standardHours(2)));
    final SearchSummary search3 = mock(SearchSummary.class);
    when(search3.createdAt()).thenReturn(DateTime.now(DateTimeZone.UTC).minus(Duration.standardDays(30)));
    when(search3.id()).thenReturn("This search is expired and should be deleted");
    when(searchDbService.findSummaries()).thenReturn(Stream.of(search1, search2, search3));
    when(searchDbService.getExpiredSearches(any(), any())).thenCallRealMethod();
    this.searchesCleanUpJob.doRun();
    final ArgumentCaptor<String> deletedSearchId = ArgumentCaptor.forClass(String.class);
    verify(searchDbService, times(1)).delete(deletedSearchId.capture());
    assertThat(deletedSearchId.getValue()).isEqualTo("This search is expired and should be deleted");
}
Also used : SearchSummary(org.graylog.plugins.views.search.SearchSummary) ViewSummaryDTO(org.graylog.plugins.views.search.views.ViewSummaryDTO) Test(org.junit.Test)

Example 2 with ViewSummaryDTO

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

the class ViewFacadeTest method itShouldCreateAEntityExcerpt.

@Test
@MongoDBFixtures("ViewFacadeTest.json")
public void itShouldCreateAEntityExcerpt() {
    final ViewSummaryDTO viewSummaryDTO = viewSummaryService.get(viewId).orElseThrow(() -> new NotFoundException("Missing view with id: " + viewId));
    final EntityExcerpt entityExcerpt = facade.createExcerpt(viewSummaryDTO);
    assertThat(entityExcerpt.id().id()).isEqualTo(viewId);
    assertThat(entityExcerpt.type()).isEqualTo(ModelTypes.SEARCH_V1);
    assertThat(entityExcerpt.title()).isEqualTo(viewSummaryDTO.title());
}
Also used : EntityExcerpt(org.graylog2.contentpacks.model.entities.EntityExcerpt) ViewSummaryDTO(org.graylog.plugins.views.search.views.ViewSummaryDTO) NotFoundException(javax.ws.rs.NotFoundException) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 3 with ViewSummaryDTO

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

the class SavedSearchesResource method views.

@GET
@ApiOperation("Get a list of all searches")
public PaginatedResponse<ViewSummaryDTO> views(@ApiParam(name = "page") @QueryParam("page") @DefaultValue("1") int page, @ApiParam(name = "per_page") @QueryParam("per_page") @DefaultValue("50") int perPage, @ApiParam(name = "sort", value = "The field to sort the result on", required = true, allowableValues = "id,title,created_at") @DefaultValue(ViewDTO.FIELD_TITLE) @QueryParam("sort") String sortField, @ApiParam(name = "order", value = "The sort direction", allowableValues = "asc, desc") @DefaultValue("asc") @QueryParam("order") String order, @ApiParam(name = "query") @QueryParam("query") String query, @Context SearchUser searchUser) {
    if (!ViewDTO.SORT_FIELDS.contains(sortField.toLowerCase(ENGLISH))) {
        sortField = ViewDTO.FIELD_TITLE;
    }
    try {
        final SearchQuery searchQuery = searchQueryParser.parse(query);
        final PaginatedList<ViewSummaryDTO> result = dbService.searchSummariesPaginatedByType(ViewDTO.Type.SEARCH, searchQuery, searchUser::canReadView, order, sortField, page, perPage);
        return PaginatedResponse.create("views", result, query);
    } catch (IllegalArgumentException e) {
        throw new BadRequestException(e.getMessage(), e);
    }
}
Also used : SearchQuery(org.graylog2.search.SearchQuery) ViewSummaryDTO(org.graylog.plugins.views.search.views.ViewSummaryDTO) BadRequestException(javax.ws.rs.BadRequestException) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 4 with ViewSummaryDTO

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

the class DashboardsResource method views.

@GET
@ApiOperation("Get a list of all dashboards")
@Timed
public PaginatedResponse<ViewSummaryDTO> views(@ApiParam(name = "page") @QueryParam("page") @DefaultValue("1") int page, @ApiParam(name = "per_page") @QueryParam("per_page") @DefaultValue("50") int perPage, @ApiParam(name = "sort", value = "The field to sort the result on", required = true, allowableValues = "id,title,created_at") @DefaultValue(ViewDTO.FIELD_TITLE) @QueryParam("sort") String sortField, @ApiParam(name = "order", value = "The sort direction", allowableValues = "asc, desc") @DefaultValue("asc") @QueryParam("order") String order, @ApiParam(name = "query") @QueryParam("query") String query, @Context SearchUser searchUser) {
    if (!ViewDTO.SORT_FIELDS.contains(sortField.toLowerCase(ENGLISH))) {
        sortField = ViewDTO.FIELD_TITLE;
    }
    try {
        final SearchQuery searchQuery = searchQueryParser.parse(query);
        final PaginatedList<ViewSummaryDTO> result = dbService.searchSummariesPaginatedByType(ViewDTO.Type.DASHBOARD, searchQuery, searchUser::canReadView, order, sortField, page, perPage);
        return PaginatedResponse.create("views", result, query);
    } catch (IllegalArgumentException e) {
        throw new BadRequestException(e.getMessage(), e);
    }
}
Also used : SearchQuery(org.graylog2.search.SearchQuery) ViewSummaryDTO(org.graylog.plugins.views.search.views.ViewSummaryDTO) BadRequestException(javax.ws.rs.BadRequestException) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with ViewSummaryDTO

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

the class ViewFacade method resolveNativeEntity.

@SuppressWarnings("UnstableApiUsage")
@Override
public Graph<EntityDescriptor> resolveNativeEntity(EntityDescriptor entityDescriptor) {
    final MutableGraph<EntityDescriptor> mutableGraph = GraphBuilder.directed().build();
    mutableGraph.addNode(entityDescriptor);
    final ModelId modelId = entityDescriptor.id();
    final ViewSummaryDTO viewSummaryDTO = viewSummaryService.get(modelId.id()).orElseThrow(() -> new NoSuchElementException("Could not find view with id " + modelId.id()));
    final Search search = searchDbService.get(viewSummaryDTO.searchId()).orElseThrow(() -> new NoSuchElementException("Could not find search with id " + viewSummaryDTO.searchId()));
    search.usedStreamIds().stream().map(s -> EntityDescriptor.create(s, ModelTypes.STREAM_V1)).forEach(streamDescriptor -> mutableGraph.putEdge(entityDescriptor, streamDescriptor));
    return ImmutableGraph.copyOf(mutableGraph);
}
Also used : EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) ImmutableGraph(com.google.common.graph.ImmutableGraph) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) LoggerFactory(org.slf4j.LoggerFactory) Entity(org.graylog2.contentpacks.model.entities.Entity) ModelType(org.graylog2.contentpacks.model.ModelType) ViewDTO(org.graylog.plugins.views.search.views.ViewDTO) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) Inject(javax.inject.Inject) LinkedHashMap(java.util.LinkedHashMap) SearchEntity(org.graylog2.contentpacks.model.entities.SearchEntity) ViewStateEntity(org.graylog2.contentpacks.model.entities.ViewStateEntity) EntityExcerpt(org.graylog2.contentpacks.model.entities.EntityExcerpt) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) Search(org.graylog.plugins.views.search.Search) ViewSummaryService(org.graylog.plugins.views.search.views.ViewSummaryService) NoSuchElementException(java.util.NoSuchElementException) Logger(org.slf4j.Logger) ModelId(org.graylog2.contentpacks.model.ModelId) MutableGraph(com.google.common.graph.MutableGraph) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) ViewSummaryDTO(org.graylog.plugins.views.search.views.ViewSummaryDTO) Collectors(java.util.stream.Collectors) GraphBuilder(com.google.common.graph.GraphBuilder) ViewEntity(org.graylog2.contentpacks.model.entities.ViewEntity) EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) Objects(java.util.Objects) Stream(java.util.stream.Stream) UserService(org.graylog2.shared.users.UserService) ViewStateDTO(org.graylog.plugins.views.search.views.ViewStateDTO) Optional(java.util.Optional) ViewService(org.graylog.plugins.views.search.views.ViewService) SearchDbService(org.graylog.plugins.views.search.db.SearchDbService) User(org.graylog2.plugin.database.users.User) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) Graph(com.google.common.graph.Graph) ModelTypes(org.graylog2.contentpacks.model.ModelTypes) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) Search(org.graylog.plugins.views.search.Search) ViewSummaryDTO(org.graylog.plugins.views.search.views.ViewSummaryDTO) ModelId(org.graylog2.contentpacks.model.ModelId) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

ViewSummaryDTO (org.graylog.plugins.views.search.views.ViewSummaryDTO)7 Test (org.junit.Test)4 ApiOperation (io.swagger.annotations.ApiOperation)2 BadRequestException (javax.ws.rs.BadRequestException)2 GET (javax.ws.rs.GET)2 Search (org.graylog.plugins.views.search.Search)2 EntityExcerpt (org.graylog2.contentpacks.model.entities.EntityExcerpt)2 SearchQuery (org.graylog2.search.SearchQuery)2 Timed (com.codahale.metrics.annotation.Timed)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Graph (com.google.common.graph.Graph)1 GraphBuilder (com.google.common.graph.GraphBuilder)1 ImmutableGraph (com.google.common.graph.ImmutableGraph)1 MutableGraph (com.google.common.graph.MutableGraph)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1