Search in sources :

Example 6 with LookupCacheEntity

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

the class LookupCacheFacade method exportNativeEntity.

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

Aggregations

LookupCacheEntity (org.graylog2.contentpacks.model.entities.LookupCacheEntity)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 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)3 CacheDto (org.graylog2.lookup.dto.CacheDto)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 FallbackCacheConfig (org.graylog2.plugin.lookup.FallbackCacheConfig)1 LookupCacheConfiguration (org.graylog2.plugin.lookup.LookupCacheConfiguration)1