use of org.graylog.plugins.views.search.views.ViewStateDTO 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.ViewStateDTO in project graylog2-server by Graylog2.
the class DashboardV1FacadeTest method viewDTOShouldHaveACorrectViewState.
@Test
@MongoDBFixtures("DashboardV1FacadeTest.json")
public void viewDTOShouldHaveACorrectViewState() {
assertThat(viewDTO.type()).isEqualByComparingTo(ViewDTO.Type.DASHBOARD);
assertThat(viewDTO.state()).isNotNull();
assertThat(viewDTO.state().size()).isEqualTo(1);
ViewStateDTO viewState = viewDTO.state().values().iterator().next();
assertThat(viewState.widgets().size()).isEqualTo(12);
final Set<String> widgetIds = viewState.widgets().stream().map(WidgetDTO::id).collect(Collectors.toSet());
final Set<String> widgetPositionIds = viewState.widgetPositions().keySet();
assertThat(widgetIds).containsAll(widgetPositionIds);
widgetIds.forEach(widgetId -> assertThat(viewState.titles().widgetTitle(widgetId)).isPresent());
widgetIds.forEach(widgetId -> assertThat(viewState.widgetMapping().get(widgetId)).isNotEmpty());
}
Aggregations