use of org.graylog2.contentpacks.model.entities.LookupCacheEntity in project graylog2-server by Graylog2.
the class LookupCacheFacade method findExisting.
private Optional<NativeEntity<CacheDto>> findExisting(EntityV1 entity, Map<String, ValueReference> parameters) {
final LookupCacheEntity cacheEntity = objectMapper.convertValue(entity.data(), LookupCacheEntity.class);
final String name = cacheEntity.name().asString(parameters);
final Optional<CacheDto> existingCache = cacheService.get(name);
return existingCache.map(cache -> NativeEntity.create(entity.id(), cache.id(), TYPE_V1, cache.title(), cache));
}
use of org.graylog2.contentpacks.model.entities.LookupCacheEntity in project graylog2-server by Graylog2.
the class LookupCacheFacade method decode.
private NativeEntity<CacheDto> decode(EntityV1 entity, Map<String, ValueReference> parameters) {
final LookupCacheEntity lookupCacheEntity = objectMapper.convertValue(entity.data(), LookupCacheEntity.class);
final LookupCacheConfiguration configuration = objectMapper.convertValue(toValueMap(lookupCacheEntity.configuration(), parameters), LookupCacheConfiguration.class);
final CacheDto cacheDto = CacheDto.builder().name(lookupCacheEntity.name().asString(parameters)).title(lookupCacheEntity.title().asString(parameters)).description(lookupCacheEntity.description().asString(parameters)).config(configuration).build();
final CacheDto savedCacheDto = cacheService.save(cacheDto);
return NativeEntity.create(entity.id(), savedCacheDto.id(), TYPE_V1, savedCacheDto.title(), savedCacheDto);
}
use of org.graylog2.contentpacks.model.entities.LookupCacheEntity in project graylog2-server by Graylog2.
the class LookupCacheFacadeTest method collectEntity.
@Test
@MongoDBFixtures("LookupCacheFacadeTest.json")
public void collectEntity() {
final EntityDescriptor descriptor = EntityDescriptor.create("5adf24b24b900a0fdb4e52dd", ModelTypes.LOOKUP_CACHE_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
final Optional<Entity> collectedEntity = facade.exportEntity(descriptor, entityDescriptorIds);
assertThat(collectedEntity).isPresent().containsInstanceOf(EntityV1.class);
final EntityV1 entity = (EntityV1) collectedEntity.orElseThrow(AssertionError::new);
assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
assertThat(entity.type()).isEqualTo(ModelTypes.LOOKUP_CACHE_V1);
final LookupCacheEntity lookupCacheEntity = objectMapper.convertValue(entity.data(), LookupCacheEntity.class);
assertThat(lookupCacheEntity.name()).isEqualTo(ValueReference.of("no-op-cache"));
assertThat(lookupCacheEntity.title()).isEqualTo(ValueReference.of("No-op cache"));
assertThat(lookupCacheEntity.description()).isEqualTo(ValueReference.of("No-op cache"));
}
use of org.graylog2.contentpacks.model.entities.LookupCacheEntity in project graylog2-server by Graylog2.
the class LookupCacheFacadeTest method exportNativeEntity.
@Test
public void exportNativeEntity() {
final CacheDto cacheDto = CacheDto.builder().id("1234567890").name("cache-name").title("Cache Title").description("Cache Description").config(new FallbackCacheConfig()).build();
final EntityDescriptor descriptor = EntityDescriptor.create(cacheDto.id(), ModelTypes.LOOKUP_CACHE_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
final Entity entity = facade.exportNativeEntity(cacheDto, entityDescriptorIds);
assertThat(entity).isInstanceOf(EntityV1.class);
assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
assertThat(entity.type()).isEqualTo(ModelTypes.LOOKUP_CACHE_V1);
final EntityV1 entityV1 = (EntityV1) entity;
final LookupCacheEntity lookupCacheEntity = objectMapper.convertValue(entityV1.data(), LookupCacheEntity.class);
assertThat(lookupCacheEntity.name()).isEqualTo(ValueReference.of("cache-name"));
assertThat(lookupCacheEntity.title()).isEqualTo(ValueReference.of("Cache Title"));
assertThat(lookupCacheEntity.description()).isEqualTo(ValueReference.of("Cache Description"));
assertThat(lookupCacheEntity.configuration()).containsEntry("type", ValueReference.of("FallbackCacheConfig"));
}
use of org.graylog2.contentpacks.model.entities.LookupCacheEntity in project graylog2-server by Graylog2.
the class LookupCacheFacadeTest method exportEntity.
@Test
@MongoDBFixtures("LookupCacheFacadeTest.json")
public void exportEntity() {
final EntityDescriptor descriptor = EntityDescriptor.create("5adf24b24b900a0fdb4e52dd", ModelTypes.LOOKUP_CACHE_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_CACHE_V1);
final EntityV1 entityV1 = (EntityV1) entity;
final LookupCacheEntity lookupCacheEntity = objectMapper.convertValue(entityV1.data(), LookupCacheEntity.class);
assertThat(lookupCacheEntity.name()).isEqualTo(ValueReference.of("no-op-cache"));
assertThat(lookupCacheEntity.title()).isEqualTo(ValueReference.of("No-op cache"));
assertThat(lookupCacheEntity.description()).isEqualTo(ValueReference.of("No-op cache"));
assertThat(lookupCacheEntity.configuration()).containsEntry("type", ValueReference.of("none"));
}
Aggregations