Search in sources :

Example 11 with LookupTableDto

use of org.graylog2.lookup.dto.LookupTableDto in project graylog2-server by Graylog2.

the class LookupTableFacadeTest method findExistingWithNoExistingEntity.

@Test
@MongoDBFixtures("LookupTableFacadeTest.json")
public void findExistingWithNoExistingEntity() {
    final Entity entity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.LOOKUP_TABLE_V1).data(objectMapper.convertValue(LookupTableEntity.create(ValueReference.of("some-name"), ValueReference.of("Title"), ValueReference.of("Description"), ValueReference.of("cache-id"), ValueReference.of("data-adapter-id"), ValueReference.of("Default single value"), ValueReference.of(LookupDefaultValue.Type.STRING), ValueReference.of("Default multi value"), ValueReference.of(LookupDefaultValue.Type.OBJECT)), JsonNode.class)).build();
    final Optional<NativeEntity<LookupTableDto>> existingEntity = facade.findExisting(entity, Collections.emptyMap());
    assertThat(existingEntity).isEmpty();
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) LookupCacheEntity(org.graylog2.contentpacks.model.entities.LookupCacheEntity) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 12 with LookupTableDto

use of org.graylog2.lookup.dto.LookupTableDto in project graylog2-server by Graylog2.

the class LookupTableFacadeTest method findExisting.

@Test
@MongoDBFixtures("LookupTableFacadeTest.json")
public void findExisting() {
    final Entity entity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.LOOKUP_TABLE_V1).data(objectMapper.convertValue(LookupTableEntity.create(ValueReference.of("http-dsv-no-cache"), ValueReference.of("HTTP DSV without Cache"), ValueReference.of("HTTP DSV without Cache"), ValueReference.of("cache-id"), ValueReference.of("data-adapter-id"), ValueReference.of("Default single value"), ValueReference.of(LookupDefaultValue.Type.STRING), ValueReference.of("Default multi value"), ValueReference.of(LookupDefaultValue.Type.OBJECT)), JsonNode.class)).build();
    final NativeEntity<LookupTableDto> existingEntity = facade.findExisting(entity, Collections.emptyMap()).orElseThrow(AssertionError::new);
    assertThat(existingEntity.descriptor().id()).isEqualTo(ModelId.of("5adf24dd4b900a0fdb4e530d"));
    assertThat(existingEntity.descriptor().type()).isEqualTo(ModelTypes.LOOKUP_TABLE_V1);
    assertThat(existingEntity.entity().name()).isEqualTo("http-dsv-no-cache");
    assertThat(existingEntity.entity().title()).isEqualTo("HTTP DSV without Cache");
    assertThat(existingEntity.entity().description()).isEqualTo("HTTP DSV without Cache");
    assertThat(existingEntity.entity().dataAdapterId()).isEqualTo("5adf24a04b900a0fdb4e52c8");
    assertThat(existingEntity.entity().cacheId()).isEqualTo("5adf24b24b900a0fdb4e52dd");
    assertThat(existingEntity.entity().defaultSingleValue()).isEqualTo("Default single value");
    assertThat(existingEntity.entity().defaultSingleValueType()).isEqualTo(LookupDefaultValue.Type.STRING);
    assertThat(existingEntity.entity().defaultMultiValue()).isEqualTo("Default multi value");
    assertThat(existingEntity.entity().defaultMultiValueType()).isEqualTo(LookupDefaultValue.Type.OBJECT);
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) LookupCacheEntity(org.graylog2.contentpacks.model.entities.LookupCacheEntity) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) LookupTableDto(org.graylog2.lookup.dto.LookupTableDto) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 13 with LookupTableDto

use of org.graylog2.lookup.dto.LookupTableDto in project graylog2-server by Graylog2.

the class LookupTableFacadeTest method createExcerpt.

@Test
public void createExcerpt() {
    final LookupTableDto lookupTableDto = LookupTableDto.builder().id("1234567890").name("lookup-table-name").title("Lookup Table Title").description("Lookup Table Description").dataAdapterId("data-adapter-1234").cacheId("cache-1234").defaultSingleValue("default-single").defaultSingleValueType(LookupDefaultValue.Type.STRING).defaultMultiValue("default-multi").defaultMultiValueType(LookupDefaultValue.Type.STRING).build();
    final EntityExcerpt excerpt = facade.createExcerpt(lookupTableDto);
    assertThat(excerpt.id()).isEqualTo(ModelId.of("1234567890"));
    assertThat(excerpt.type()).isEqualTo(ModelTypes.LOOKUP_TABLE_V1);
    assertThat(excerpt.title()).isEqualTo("Lookup Table Title");
}
Also used : EntityExcerpt(org.graylog2.contentpacks.model.entities.EntityExcerpt) LookupTableDto(org.graylog2.lookup.dto.LookupTableDto) Test(org.junit.Test)

Example 14 with LookupTableDto

use of org.graylog2.lookup.dto.LookupTableDto in project graylog2-server by Graylog2.

the class LookupTableFacadeTest method exportEntity.

@Test
public void exportEntity() {
    final EntityDescriptor tableDescriptor = EntityDescriptor.create("1234567890", ModelTypes.LOOKUP_TABLE_V1);
    final EntityDescriptor adapterDescriptor = EntityDescriptor.create("data-adapter-1234", ModelTypes.LOOKUP_ADAPTER_V1);
    final EntityDescriptor cacheDescriptor = EntityDescriptor.create("cache-1234", ModelTypes.LOOKUP_CACHE_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(tableDescriptor, adapterDescriptor, cacheDescriptor);
    final LookupTableDto lookupTableDto = LookupTableDto.builder().id("1234567890").name("lookup-table-name").title("Lookup Table Title").description("Lookup Table Description").dataAdapterId("data-adapter-1234").cacheId("cache-1234").defaultSingleValue("default-single").defaultSingleValueType(LookupDefaultValue.Type.STRING).defaultMultiValue("default-multi").defaultMultiValueType(LookupDefaultValue.Type.STRING).build();
    final Entity entity = facade.exportNativeEntity(lookupTableDto, entityDescriptorIds);
    assertThat(entity).isInstanceOf(EntityV1.class);
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(tableDescriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.LOOKUP_TABLE_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final LookupTableEntity lookupTableEntity = objectMapper.convertValue(entityV1.data(), LookupTableEntity.class);
    assertThat(lookupTableEntity.name()).isEqualTo(ValueReference.of("lookup-table-name"));
    assertThat(lookupTableEntity.title()).isEqualTo(ValueReference.of("Lookup Table Title"));
    assertThat(lookupTableEntity.description()).isEqualTo(ValueReference.of("Lookup Table Description"));
    assertThat(lookupTableEntity.dataAdapterName()).isEqualTo(ValueReference.of(entityDescriptorIds.get(adapterDescriptor).orElse(null)));
    assertThat(lookupTableEntity.cacheName()).isEqualTo(ValueReference.of(entityDescriptorIds.get(cacheDescriptor).orElse(null)));
    assertThat(lookupTableEntity.defaultSingleValue()).isEqualTo(ValueReference.of("default-single"));
    assertThat(lookupTableEntity.defaultSingleValueType()).isEqualTo(ValueReference.of(LookupDefaultValue.Type.STRING));
    assertThat(lookupTableEntity.defaultMultiValue()).isEqualTo(ValueReference.of("default-multi"));
    assertThat(lookupTableEntity.defaultMultiValueType()).isEqualTo(ValueReference.of(LookupDefaultValue.Type.STRING));
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) LookupCacheEntity(org.graylog2.contentpacks.model.entities.LookupCacheEntity) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) LookupTableDto(org.graylog2.lookup.dto.LookupTableDto) Test(org.junit.Test)

Example 15 with LookupTableDto

use of org.graylog2.lookup.dto.LookupTableDto in project graylog2-server by Graylog2.

the class DBLookupTableService method save.

public LookupTableDto save(LookupTableDto table) {
    WriteResult<LookupTableDto, ObjectId> save = db.save(table);
    final LookupTableDto savedLookupTable = save.getSavedObject();
    clusterEventBus.post(LookupTablesUpdated.create(savedLookupTable));
    return savedLookupTable;
}
Also used : ObjectId(org.bson.types.ObjectId) LookupTableDto(org.graylog2.lookup.dto.LookupTableDto)

Aggregations

LookupTableDto (org.graylog2.lookup.dto.LookupTableDto)14 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)8 Entity (org.graylog2.contentpacks.model.entities.Entity)5 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)5 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)5 Test (org.junit.Test)5 ImmutableSet (com.google.common.collect.ImmutableSet)4 ApiOperation (io.swagger.annotations.ApiOperation)4 Path (javax.ws.rs.Path)4 LookupCacheEntity (org.graylog2.contentpacks.model.entities.LookupCacheEntity)4 LookupDataAdapterEntity (org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity)4 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)3 CacheDto (org.graylog2.lookup.dto.CacheDto)3 DataAdapterDto (org.graylog2.lookup.dto.DataAdapterDto)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Subscribe (com.google.common.eventbus.Subscribe)2 AbstractIdleService (com.google.common.util.concurrent.AbstractIdleService)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 GET (javax.ws.rs.GET)2