use of org.graylog2.contentpacks.exceptions.MissingNativeEntityException in project graylog2-server by Graylog2.
the class LookupTableFacade method decode.
private NativeEntity<LookupTableDto> decode(EntityV1 entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Object> nativeEntities) {
final LookupTableEntity lookupTableEntity = objectMapper.convertValue(entity.data(), LookupTableEntity.class);
final String referencedDataAdapterName = lookupTableEntity.dataAdapterName().asString(parameters);
final EntityDescriptor dataAdapterDescriptor = adapterDescriptor(referencedDataAdapterName);
final Object dataAdapter = nativeEntities.get(dataAdapterDescriptor);
final String dataAdapterId;
if (dataAdapter instanceof DataAdapterDto) {
dataAdapterId = ((DataAdapterDto) dataAdapter).id();
} else {
throw new MissingNativeEntityException(dataAdapterDescriptor);
}
final String referencedCacheName = lookupTableEntity.cacheName().asString(parameters);
final EntityDescriptor cacheDescriptor = cacheDescriptor(referencedCacheName);
final Object cache = nativeEntities.get(cacheDescriptor);
final String cacheId;
if (cache instanceof CacheDto) {
cacheId = ((CacheDto) cache).id();
} else {
throw new MissingNativeEntityException(cacheDescriptor);
}
final LookupTableDto lookupTableDto = LookupTableDto.builder().name(lookupTableEntity.name().asString(parameters)).title(lookupTableEntity.title().asString(parameters)).description(lookupTableEntity.description().asString(parameters)).dataAdapterId(dataAdapterId).cacheId(cacheId).defaultSingleValue(lookupTableEntity.defaultSingleValue().asString(parameters)).defaultSingleValueType(lookupTableEntity.defaultSingleValueType().asEnum(parameters, LookupDefaultSingleValue.Type.class)).defaultMultiValue(lookupTableEntity.defaultMultiValue().asString(parameters)).defaultMultiValueType(lookupTableEntity.defaultMultiValueType().asEnum(parameters, LookupDefaultMultiValue.Type.class)).build();
final LookupTableDto savedLookupTableDto = lookupTableService.save(lookupTableDto);
return NativeEntity.create(entity.id(), savedLookupTableDto.id(), TYPE_V1, lookupTableDto.title(), savedLookupTableDto);
}
Aggregations