Search in sources :

Example 1 with ViewStateDTO

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);
}
Also used : ViewStateEntity(org.graylog2.contentpacks.model.entities.ViewStateEntity) ViewDTO(org.graylog.plugins.views.search.views.ViewDTO) ViewStateDTO(org.graylog.plugins.views.search.views.ViewStateDTO) ViewEntity(org.graylog2.contentpacks.model.entities.ViewEntity) Search(org.graylog.plugins.views.search.Search) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with ViewStateDTO

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());
}
Also used : ViewStateDTO(org.graylog.plugins.views.search.views.ViewStateDTO) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Aggregations

ViewStateDTO (org.graylog.plugins.views.search.views.ViewStateDTO)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Search (org.graylog.plugins.views.search.Search)1 ViewDTO (org.graylog.plugins.views.search.views.ViewDTO)1 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)1 ViewEntity (org.graylog2.contentpacks.model.entities.ViewEntity)1 ViewStateEntity (org.graylog2.contentpacks.model.entities.ViewStateEntity)1 Test (org.junit.Test)1