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");
}
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());
}
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);
}
}
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);
}
}
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);
}
Aggregations