Search in sources :

Example 1 with LookupDataAdapterEntity

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

the class LookupDataAdapterFacade method findExisting.

private Optional<NativeEntity<DataAdapterDto>> findExisting(EntityV1 entity, Map<String, ValueReference> parameters) {
    final LookupDataAdapterEntity dataAdapterEntity = objectMapper.convertValue(entity.data(), LookupDataAdapterEntity.class);
    final String name = dataAdapterEntity.name().asString(parameters);
    final Optional<DataAdapterDto> existingDataAdapter = dataAdapterService.get(name);
    return existingDataAdapter.map(dataAdapter -> NativeEntity.create(entity.id(), dataAdapter.id(), TYPE_V1, dataAdapter.title(), dataAdapter));
}
Also used : LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) DataAdapterDto(org.graylog2.lookup.dto.DataAdapterDto)

Example 2 with LookupDataAdapterEntity

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

the class LookupDataAdapterFacade method exportNativeEntity.

@VisibleForTesting
Entity exportNativeEntity(DataAdapterDto dataAdapterDto, EntityDescriptorIds entityDescriptorIds) {
    // TODO: Create independent representation of entity?
    final Map<String, Object> configuration = objectMapper.convertValue(dataAdapterDto.config(), TypeReferences.MAP_STRING_OBJECT);
    final LookupDataAdapterEntity lookupDataAdapterEntity = LookupDataAdapterEntity.create(ValueReference.of(dataAdapterDto.name()), ValueReference.of(dataAdapterDto.title()), ValueReference.of(dataAdapterDto.description()), toReferenceMap(configuration));
    final JsonNode data = objectMapper.convertValue(lookupDataAdapterEntity, JsonNode.class);
    final Set<Constraint> constraints = versionConstraints(dataAdapterDto);
    return EntityV1.builder().id(ModelId.of(entityDescriptorIds.getOrThrow(dataAdapterDto.id(), ModelTypes.LOOKUP_ADAPTER_V1))).type(ModelTypes.LOOKUP_ADAPTER_V1).constraints(ImmutableSet.copyOf(constraints)).data(data).build();
}
Also used : LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) Constraint(org.graylog2.contentpacks.model.constraints.Constraint) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) JsonNode(com.fasterxml.jackson.databind.JsonNode) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with LookupDataAdapterEntity

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

the class LookupDataAdapterFacade method decode.

private NativeEntity<DataAdapterDto> decode(EntityV1 entity, final Map<String, ValueReference> parameters) {
    final LookupDataAdapterEntity lookupDataAdapterEntity = objectMapper.convertValue(entity.data(), LookupDataAdapterEntity.class);
    final LookupDataAdapterConfiguration configuration = objectMapper.convertValue(toValueMap(lookupDataAdapterEntity.configuration(), parameters), LookupDataAdapterConfiguration.class);
    final DataAdapterDto dataAdapterDto = DataAdapterDto.builder().name(lookupDataAdapterEntity.name().asString(parameters)).title(lookupDataAdapterEntity.title().asString(parameters)).description(lookupDataAdapterEntity.description().asString(parameters)).config(configuration).build();
    final DataAdapterDto savedDataAdapterDto = dataAdapterService.save(dataAdapterDto);
    return NativeEntity.create(entity.id(), savedDataAdapterDto.id(), TYPE_V1, savedDataAdapterDto.title(), savedDataAdapterDto);
}
Also used : LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) DataAdapterDto(org.graylog2.lookup.dto.DataAdapterDto) LookupDataAdapterConfiguration(org.graylog2.plugin.lookup.LookupDataAdapterConfiguration)

Example 4 with LookupDataAdapterEntity

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

the class LookupDataAdapterFacadeTest method exportNativeEntity.

@Test
public void exportNativeEntity() {
    final DataAdapterDto dataAdapterDto = DataAdapterDto.builder().id("1234567890").name("data-adapter-name").title("Data Adapter Title").description("Data Adapter Description").config(new FallbackAdapterConfig()).build();
    final EntityDescriptor descriptor = EntityDescriptor.create(dataAdapterDto.id(), ModelTypes.LOOKUP_ADAPTER_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Entity entity = facade.exportNativeEntity(dataAdapterDto, entityDescriptorIds);
    assertThat(entity).isInstanceOf(EntityV1.class);
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.LOOKUP_ADAPTER_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final LookupDataAdapterEntity lookupDataAdapterEntity = objectMapper.convertValue(entityV1.data(), LookupDataAdapterEntity.class);
    assertThat(lookupDataAdapterEntity.name()).isEqualTo(ValueReference.of("data-adapter-name"));
    assertThat(lookupDataAdapterEntity.title()).isEqualTo(ValueReference.of("Data Adapter Title"));
    assertThat(lookupDataAdapterEntity.description()).isEqualTo(ValueReference.of("Data Adapter Description"));
    assertThat(lookupDataAdapterEntity.configuration()).containsEntry("type", ValueReference.of("FallbackAdapterConfig"));
}
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) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) DataAdapterDto(org.graylog2.lookup.dto.DataAdapterDto) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) FallbackAdapterConfig(org.graylog2.plugin.lookup.FallbackAdapterConfig) Test(org.junit.Test)

Example 5 with LookupDataAdapterEntity

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

the class LookupDataAdapterFacadeTest method exportEntityDescriptor.

@Test
@MongoDBFixtures("LookupDataAdapterFacadeTest.json")
public void exportEntityDescriptor() {
    final EntityDescriptor descriptor = EntityDescriptor.create("5adf24a04b900a0fdb4e52c8", ModelTypes.LOOKUP_ADAPTER_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Entity entity = facade.exportEntity(descriptor, entityDescriptorIds).orElseThrow(AssertionError::new);
    assertThat(entity).isInstanceOf(EntityV1.class);
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.LOOKUP_ADAPTER_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final LookupDataAdapterEntity lookupDataAdapterEntity = objectMapper.convertValue(entityV1.data(), LookupDataAdapterEntity.class);
    assertThat(lookupDataAdapterEntity.name()).isEqualTo(ValueReference.of("http-dsv"));
    assertThat(lookupDataAdapterEntity.title()).isEqualTo(ValueReference.of("HTTP DSV"));
    assertThat(lookupDataAdapterEntity.description()).isEqualTo(ValueReference.of("HTTP DSV"));
}
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) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Aggregations

LookupDataAdapterEntity (org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity)6 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)3 Entity (org.graylog2.contentpacks.model.entities.Entity)3 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)3 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)3 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)3 DataAdapterDto (org.graylog2.lookup.dto.DataAdapterDto)3 Test (org.junit.Test)3 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Constraint (org.graylog2.contentpacks.model.constraints.Constraint)1 PluginVersionConstraint (org.graylog2.contentpacks.model.constraints.PluginVersionConstraint)1 FallbackAdapterConfig (org.graylog2.plugin.lookup.FallbackAdapterConfig)1 LookupDataAdapterConfiguration (org.graylog2.plugin.lookup.LookupDataAdapterConfiguration)1