Search in sources :

Example 1 with QueryEntity

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

the class ViewFacadeTest method itShouldCreateAViewEntity.

@Test
@MongoDBFixtures("ViewFacadeTest.json")
public void itShouldCreateAViewEntity() {
    final ViewDTO viewDTO = viewService.get(viewId).orElseThrow(() -> new NotFoundException("Missing view with id: " + viewId));
    final EntityDescriptor searchDescriptor = EntityDescriptor.create(viewDTO.id(), ModelTypes.SEARCH_V1);
    final EntityDescriptor streamDescriptor = EntityDescriptor.create(streamId, ModelTypes.STREAM_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(searchDescriptor, streamDescriptor);
    final Optional<Entity> optionalEntity = facade.exportEntity(searchDescriptor, entityDescriptorIds);
    assertThat(optionalEntity).isPresent();
    final Entity entity = optionalEntity.get();
    assertThat(entity).isInstanceOf(EntityV1.class);
    final EntityV1 entityV1 = (EntityV1) entity;
    assertThat(entityV1.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(searchDescriptor).orElse(null)));
    assertThat(entityV1.type()).isEqualTo(ModelTypes.SEARCH_V1);
    final ViewEntity viewEntity = objectMapper.convertValue(entityV1.data(), ViewEntity.class);
    assertThat(viewEntity.title().asString()).isEqualTo(viewDTO.title());
    assertThat(viewEntity.type().toString()).isEqualTo(ViewDTO.Type.SEARCH.toString());
    assertThat(viewEntity.search().queries().size()).isEqualTo(1);
    final QueryEntity queryEntity = viewEntity.search().queries().iterator().next();
    assertThat(queryEntity.filter().filters().size()).isEqualTo(1);
    final StreamFilter filter = (StreamFilter) queryEntity.filter().filters().iterator().next();
    assertThat(filter.streamId()).doesNotMatch(streamId);
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) ViewDTO(org.graylog.plugins.views.search.views.ViewDTO) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) PivotEntity(org.graylog2.contentpacks.model.entities.PivotEntity) QueryEntity(org.graylog2.contentpacks.model.entities.QueryEntity) EventListEntity(org.graylog2.contentpacks.model.entities.EventListEntity) ViewEntity(org.graylog2.contentpacks.model.entities.ViewEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) SearchEntity(org.graylog2.contentpacks.model.entities.SearchEntity) ViewStateEntity(org.graylog2.contentpacks.model.entities.ViewStateEntity) StreamEntity(org.graylog2.contentpacks.model.entities.StreamEntity) MessageListEntity(org.graylog2.contentpacks.model.entities.MessageListEntity) ViewEntity(org.graylog2.contentpacks.model.entities.ViewEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) NotFoundException(javax.ws.rs.NotFoundException) QueryEntity(org.graylog2.contentpacks.model.entities.QueryEntity) StreamFilter(org.graylog.plugins.views.search.filter.StreamFilter) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 2 with QueryEntity

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

Aggregations

QueryEntity (org.graylog2.contentpacks.model.entities.QueryEntity)2 SearchEntity (org.graylog2.contentpacks.model.entities.SearchEntity)2 ViewEntity (org.graylog2.contentpacks.model.entities.ViewEntity)2 ViewStateEntity (org.graylog2.contentpacks.model.entities.ViewStateEntity)2 NotFoundException (javax.ws.rs.NotFoundException)1 StreamFilter (org.graylog.plugins.views.search.filter.StreamFilter)1 ViewDTO (org.graylog.plugins.views.search.views.ViewDTO)1 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)1 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)1 Entity (org.graylog2.contentpacks.model.entities.Entity)1 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)1 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)1 EventListEntity (org.graylog2.contentpacks.model.entities.EventListEntity)1 MessageListEntity (org.graylog2.contentpacks.model.entities.MessageListEntity)1 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)1 PivotEntity (org.graylog2.contentpacks.model.entities.PivotEntity)1 StreamEntity (org.graylog2.contentpacks.model.entities.StreamEntity)1 Test (org.junit.Test)1