use of org.graylog.plugins.views.search.views.ViewDTO in project graylog2-server by Graylog2.
the class ViewFacade method decode.
protected NativeEntity<ViewDTO> decode(EntityV1 entityV1, Map<String, ValueReference> parameters, Map<EntityDescriptor, Object> nativeEntities, User user) {
final ViewEntity viewEntity = objectMapper.convertValue(entityV1.data(), ViewEntity.class);
final Map<String, ViewStateDTO> viewStateMap = new LinkedHashMap<>(viewEntity.state().size());
for (Map.Entry<String, ViewStateEntity> entry : viewEntity.state().entrySet()) {
final ViewStateEntity entity = entry.getValue();
viewStateMap.put(entry.getKey(), entity.toNativeEntity(parameters, nativeEntities));
}
final ViewDTO.Builder viewBuilder = viewEntity.toNativeEntity(parameters, nativeEntities);
viewBuilder.state(viewStateMap);
final Search search = viewEntity.search().toNativeEntity(parameters, nativeEntities);
final Search persistedSearch = searchDbService.save(search);
final ViewDTO persistedView = viewService.saveWithOwner(viewBuilder.searchId(persistedSearch.id()).build(), user);
return NativeEntity.create(entityV1.id(), persistedView.id(), getModelType(), persistedView.title(), persistedView);
}
use of org.graylog.plugins.views.search.views.ViewDTO in project graylog2-server by Graylog2.
the class ViewSharingToGrantsMigration method getTarget.
private GRN getTarget(String viewId) {
final ViewDTO view = viewService.get(viewId).orElseThrow(() -> new IllegalArgumentException("View <" + viewId + "> doesn't exist"));
final GRNType grnType = ViewDTO.Type.DASHBOARD.equals(view.type()) ? GRNTypes.DASHBOARD : GRNTypes.SEARCH;
return grnType.toGRN(viewId);
}
use of org.graylog.plugins.views.search.views.ViewDTO in project graylog2-server by Graylog2.
the class SearchDomainTest method includesSearchesPermittedViaViewsInList.
@Test
public void includesSearchesPermittedViaViewsInList() {
final Search permittedSearch = mockSearchWithOwner("someone else");
mockSearchWithOwner("someone else");
final SearchUser searchUser = mock(SearchUser.class);
final ViewDTO viewDTO = mock(ViewDTO.class);
when(viewService.forSearch(permittedSearch.id())).thenReturn(ImmutableList.of(viewDTO));
when(searchUser.canReadView(viewDTO)).thenReturn(true);
List<Search> result = sut.getAllForUser(searchUser, searchUser::canReadView);
assertThat(result).containsExactly(permittedSearch);
}
use of org.graylog.plugins.views.search.views.ViewDTO in project graylog2-server by Graylog2.
the class SearchDomainTest method loadsSearchIfSearchIsPermittedViaViews.
@Test
public void loadsSearchIfSearchIsPermittedViaViews() {
final Search search = mockSearchWithOwner("someone else");
final SearchUser searchUser = mock(SearchUser.class);
final ViewDTO viewDTO = mock(ViewDTO.class);
when(viewService.forSearch(anyString())).thenReturn(ImmutableList.of(viewDTO));
when(searchUser.canReadView(viewDTO)).thenReturn(true);
final Optional<Search> result = sut.getForUser(search.id(), searchUser);
assertThat(result).isEqualTo(Optional.of(search));
}
use of org.graylog.plugins.views.search.views.ViewDTO in project graylog2-server by Graylog2.
the class ViewsResource method views.
@GET
@ApiOperation("Get a list of all views")
public PaginatedResponse<ViewDTO> 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<ViewDTO> result = dbService.searchPaginated(searchQuery, searchUser::canReadView, order, sortField, page, perPage);
return PaginatedResponse.create("views", result, query);
} catch (IllegalArgumentException e) {
throw new BadRequestException(e.getMessage(), e);
}
}
Aggregations