Search in sources :

Example 1 with ViewStateEntity

use of org.graylog2.contentpacks.model.entities.ViewStateEntity 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 ViewStateEntity

use of org.graylog2.contentpacks.model.entities.ViewStateEntity in project graylog2-server by Graylog2.

the class EntityConverter method convert.

public ViewEntity convert(DashboardEntity dashboardEntity, Map<String, ValueReference> parameters) {
    this.parameters = parameters;
    this.dashboardEntity = dashboardEntity;
    final String queryId = UUID.randomUUID().toString();
    final Map<DashboardWidgetEntity, List<WidgetEntity>> widgets = convertWidgets();
    final Map<String, WidgetPositionDTO> widgetPositionMap = DashboardEntity.positionMap(parameters, widgets);
    final Titles titles = DashboardEntity.widgetTitles(widgets, parameters);
    final Map<String, Set<String>> widgetMapping = new HashMap<>();
    final Set<SearchTypeEntity> searchTypes = new HashSet<>();
    createSearchTypes(widgets, widgetMapping, searchTypes);
    SearchEntity searchEntity;
    try {
        searchEntity = createSearchEntity(queryId, searchTypes);
    } catch (InvalidRangeParametersException e) {
        throw new IllegalArgumentException("The provided entity does not have a valid TimeRange", e);
    }
    final ViewStateEntity viewStateEntity = ViewStateEntity.builder().widgets(widgets.values().stream().flatMap(Collection::stream).collect(Collectors.toSet())).titles(titles).widgetMapping(widgetMapping).widgetPositions(widgetPositionMap).build();
    final Map<String, ViewStateEntity> viewStateEntityMap = ImmutableMap.of(queryId, viewStateEntity);
    return ViewEntity.builder().search(searchEntity).state(viewStateEntityMap).title(dashboardEntity.title()).properties(Collections.emptySet()).description(dashboardEntity.description()).requires(Collections.emptyMap()).summary(ValueReference.of("Converted Dashboard")).createdAt(DateTime.now(DateTimeZone.UTC)).type(ViewEntity.Type.DASHBOARD).build();
}
Also used : ViewStateEntity(org.graylog2.contentpacks.model.entities.ViewStateEntity) SearchTypeEntity(org.graylog2.contentpacks.model.entities.SearchTypeEntity) HashSet(java.util.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) InvalidRangeParametersException(org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException) HashMap(java.util.HashMap) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) Titles(org.graylog.plugins.views.search.views.Titles) SearchEntity(org.graylog2.contentpacks.model.entities.SearchEntity) DashboardWidgetEntity(org.graylog2.contentpacks.model.entities.DashboardWidgetEntity) Collection(java.util.Collection) List(java.util.List) WidgetPositionDTO(org.graylog.plugins.views.search.views.WidgetPositionDTO) HashSet(java.util.HashSet)

Example 3 with ViewStateEntity

use of org.graylog2.contentpacks.model.entities.ViewStateEntity in project graylog2-server by Graylog2.

the class ViewFacadeTest method createViewEntity.

private EntityV1 createViewEntity() throws Exception {
    final QueryEntity query = QueryEntity.builder().id("dead-beef").timerange(KeywordRange.create("last 5 minutes", "Etc/UTC")).filter(OrFilter.or(StreamFilter.ofId(newStreamId))).query(ElasticsearchQueryString.of("author: Mara Jade")).build();
    final SearchEntity searchEntity = SearchEntity.builder().queries(ImmutableSet.of(query)).parameters(ImmutableSet.of()).requires(ImmutableMap.of()).createdAt(DateTime.now(DateTimeZone.UTC)).build();
    final ViewStateEntity viewStateEntity = ViewStateEntity.builder().fields(ImmutableSet.of()).titles(Titles.empty()).widgets(ImmutableSet.of()).widgetMapping(ImmutableMap.of()).widgetPositions(ImmutableMap.of()).formatting(FormattingSettings.builder().highlighting(ImmutableSet.of()).build()).displayModeSettings(DisplayModeSettings.empty()).build();
    final ViewEntity entity = ViewEntity.builder().type(ViewEntity.Type.SEARCH).summary(ValueReference.of("summary")).title(ValueReference.of("title")).description(ValueReference.of("description")).search(searchEntity).properties(ImmutableSet.of()).requires(ImmutableMap.of()).state(ImmutableMap.of(newViewId, viewStateEntity)).createdAt(DateTime.now(DateTimeZone.UTC)).build();
    return EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.SEARCH_V1).data(objectMapper.convertValue(entity, JsonNode.class)).build();
}
Also used : ViewStateEntity(org.graylog2.contentpacks.model.entities.ViewStateEntity) SearchEntity(org.graylog2.contentpacks.model.entities.SearchEntity) ViewEntity(org.graylog2.contentpacks.model.entities.ViewEntity) QueryEntity(org.graylog2.contentpacks.model.entities.QueryEntity)

Example 4 with ViewStateEntity

use of org.graylog2.contentpacks.model.entities.ViewStateEntity in project graylog2-server by Graylog2.

the class ViewDTO method toContentPackEntity.

@Override
public ViewEntity.Builder toContentPackEntity(EntityDescriptorIds entityDescriptorIds) {
    final Map<String, ViewStateEntity> viewStateMap = new LinkedHashMap<>(this.state().size());
    for (Map.Entry<String, ViewStateDTO> entry : this.state().entrySet()) {
        final ViewStateDTO viewStateDTO = entry.getValue();
        final ViewStateEntity viewStateEntity = viewStateDTO.toContentPackEntity(entityDescriptorIds);
        viewStateMap.put(entry.getKey(), viewStateEntity);
    }
    final ViewEntity.Builder viewEntityBuilder = ViewEntity.builder().type(this.type()).title(ValueReference.of(this.title())).summary(ValueReference.of(this.summary())).description(ValueReference.of(this.description())).state(viewStateMap).requires(this.requires()).properties(this.properties()).createdAt(this.createdAt());
    if (this.owner().isPresent()) {
        viewEntityBuilder.owner(this.owner().get());
    }
    return viewEntityBuilder;
}
Also used : ViewStateEntity(org.graylog2.contentpacks.model.entities.ViewStateEntity) ViewEntity(org.graylog2.contentpacks.model.entities.ViewEntity) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ViewStateEntity (org.graylog2.contentpacks.model.entities.ViewStateEntity)4 ViewEntity (org.graylog2.contentpacks.model.entities.ViewEntity)3 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 SearchEntity (org.graylog2.contentpacks.model.entities.SearchEntity)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Search (org.graylog.plugins.views.search.Search)1 ElasticsearchQueryString (org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)1 Titles (org.graylog.plugins.views.search.views.Titles)1 ViewDTO (org.graylog.plugins.views.search.views.ViewDTO)1 ViewStateDTO (org.graylog.plugins.views.search.views.ViewStateDTO)1 WidgetPositionDTO (org.graylog.plugins.views.search.views.WidgetPositionDTO)1 DashboardWidgetEntity (org.graylog2.contentpacks.model.entities.DashboardWidgetEntity)1 QueryEntity (org.graylog2.contentpacks.model.entities.QueryEntity)1 SearchTypeEntity (org.graylog2.contentpacks.model.entities.SearchTypeEntity)1