use of org.graylog2.contentpacks.EntityDescriptorIds in project graylog2-server by Graylog2.
the class EventDefinitionFacade method exportEntity.
@Override
public Optional<Entity> exportEntity(EntityDescriptor entityDescriptor, EntityDescriptorIds entityDescriptorIds) {
final ModelId modelId = entityDescriptor.id();
final Optional<EventDefinitionDto> eventDefinition = eventDefinitionService.get(modelId.id());
if (!eventDefinition.isPresent()) {
LOG.debug("Couldn't find event definition {}", entityDescriptor);
return Optional.empty();
}
return Optional.of(exportNativeEntity(eventDefinition.get(), entityDescriptorIds));
}
use of org.graylog2.contentpacks.EntityDescriptorIds in project graylog2-server by Graylog2.
the class NotificationFacade method exportEntity.
@Override
public Optional<Entity> exportEntity(EntityDescriptor entityDescriptor, EntityDescriptorIds entityDescriptorIds) {
final ModelId modelId = entityDescriptor.id();
final Optional<NotificationDto> notificationDto = notificationService.get(modelId.id());
if (!notificationDto.isPresent()) {
LOG.debug("Couldn't find notification {}", entityDescriptor);
return Optional.empty();
}
final NotificationEntity entity = (NotificationEntity) notificationDto.get().toContentPackEntity(entityDescriptorIds);
final JsonNode data = objectMapper.convertValue(entity, JsonNode.class);
return Optional.of(EntityV1.builder().id(ModelId.of(entityDescriptorIds.getOrThrow(notificationDto.get().id(), ModelTypes.NOTIFICATION_V1))).type(ModelTypes.NOTIFICATION_V1).data(data).build());
}
use of org.graylog2.contentpacks.EntityDescriptorIds in project graylog2-server by Graylog2.
the class InputFacade method exportNativeEntity.
@VisibleForTesting
Entity exportNativeEntity(InputWithExtractors inputWithExtractors, EntityDescriptorIds entityDescriptorIds) {
final Input input = inputWithExtractors.input();
// TODO: Create independent representation of entity?
final Map<String, ValueReference> staticFields = input.getStaticFields().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, kv -> ValueReference.of(kv.getValue())));
final ReferenceMap configuration = toReferenceMap(input.getConfiguration());
final List<ExtractorEntity> extractors = inputWithExtractors.extractors().stream().map(this::encodeExtractor).collect(Collectors.toList());
final InputEntity inputEntity = InputEntity.create(ValueReference.of(input.getTitle()), configuration, staticFields, ValueReference.of(input.getType()), ValueReference.of(input.isGlobal()), extractors);
final JsonNode data = objectMapper.convertValue(inputEntity, JsonNode.class);
final Set<Constraint> constraints = versionConstraints(input);
return EntityV1.builder().id(ModelId.of(entityDescriptorIds.getOrThrow(input.getId(), ModelTypes.INPUT_V1))).type(ModelTypes.INPUT_V1).data(data).constraints(ImmutableSet.copyOf(constraints)).build();
}
use of org.graylog2.contentpacks.EntityDescriptorIds in project graylog2-server by Graylog2.
the class LookupTableFacade method exportNativeEntity.
@VisibleForTesting
Entity exportNativeEntity(LookupTableDto lookupTableDto, EntityDescriptorIds entityDescriptorIds) {
final String tableId = entityDescriptorIds.get(EntityDescriptor.create(lookupTableDto.id(), ModelTypes.LOOKUP_TABLE_V1)).orElseThrow(() -> new ContentPackException("Couldn't find lookup table entity " + lookupTableDto.id()));
final String cacheId = entityDescriptorIds.get(cacheDescriptor(lookupTableDto.cacheId())).orElseThrow(() -> new ContentPackException("Couldn't find lookup cache entity " + lookupTableDto.cacheId()));
final String adapterId = entityDescriptorIds.get(adapterDescriptor(lookupTableDto.dataAdapterId())).orElseThrow(() -> new ContentPackException("Couldn't find lookup data adapter entity " + lookupTableDto.dataAdapterId()));
final LookupTableEntity lookupTableEntity = LookupTableEntity.create(ValueReference.of(lookupTableDto.name()), ValueReference.of(lookupTableDto.title()), ValueReference.of(lookupTableDto.description()), ValueReference.of(cacheId), ValueReference.of(adapterId), ValueReference.of(lookupTableDto.defaultSingleValue()), ValueReference.of(lookupTableDto.defaultSingleValueType()), ValueReference.of(lookupTableDto.defaultMultiValue()), ValueReference.of(lookupTableDto.defaultMultiValueType()));
final JsonNode data = objectMapper.convertValue(lookupTableEntity, JsonNode.class);
return EntityV1.builder().id(ModelId.of(tableId)).type(ModelTypes.LOOKUP_TABLE_V1).data(data).build();
}
use of org.graylog2.contentpacks.EntityDescriptorIds in project graylog2-server by Graylog2.
the class ContentPackService method collectEntities.
public ImmutableSet<Entity> collectEntities(Collection<EntityDescriptor> resolvedEntities) {
// It's important to only compute the EntityDescriptor IDs once per #collectEntities call! Otherwise we
// will get broken references between the entities.
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(resolvedEntities);
final ImmutableSet.Builder<Entity> entities = ImmutableSet.builder();
for (EntityDescriptor entityDescriptor : resolvedEntities) {
if (EntityDescriptorIds.isSystemStreamDescriptor(entityDescriptor)) {
continue;
}
final EntityWithExcerptFacade<?, ?> facade = entityFacades.getOrDefault(entityDescriptor.type(), UnsupportedEntityFacade.INSTANCE);
facade.exportEntity(entityDescriptor, entityDescriptorIds).ifPresent(entities::add);
}
return entities.build();
}
Aggregations