use of org.graylog2.contentpacks.model.entities.EntityV1 in project graylog2-server by Graylog2.
the class EventDefinitionFacade method resolveForInstallationV1.
private Graph<Entity> resolveForInstallationV1(EntityV1 entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Entity> entities) {
final MutableGraph<Entity> graph = GraphBuilder.directed().build();
graph.addNode(entity);
final EventDefinitionEntity eventDefinition = objectMapper.convertValue(entity.data(), EventDefinitionEntity.class);
eventDefinition.resolveForInstallation(entity, parameters, entities, graph);
return ImmutableGraph.copyOf(graph);
}
use of org.graylog2.contentpacks.model.entities.EntityV1 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.model.entities.EntityV1 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.model.entities.EntityV1 in project graylog2-server by Graylog2.
the class InputFacade method resolveForInstallationV1.
private Graph<Entity> resolveForInstallationV1(EntityV1 entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Entity> entities) {
final MutableGraph<Entity> graph = GraphBuilder.directed().build();
graph.addNode(entity);
final InputEntity input = objectMapper.convertValue(entity.data(), InputEntity.class);
resolveForInstallationV1LookupTable(entity, input, parameters, entities, graph);
resolveForInstallationV1GrokPattern(entity, input, parameters, entities, graph);
return ImmutableGraph.copyOf(graph);
}
use of org.graylog2.contentpacks.model.entities.EntityV1 in project graylog2-server by Graylog2.
the class InputFacade method decode.
private NativeEntity<InputWithExtractors> decode(EntityV1 entity, Map<String, ValueReference> parameters, String username) {
final InputEntity inputEntity = objectMapper.convertValue(entity.data(), InputEntity.class);
final Map<String, ValueReference> staticFields = inputEntity.staticFields();
final MessageInput messageInput;
try {
messageInput = createMessageInput(inputEntity.title().asString(parameters), inputEntity.type().asString(parameters), inputEntity.global().asBoolean(parameters), toValueMap(inputEntity.configuration(), parameters), username);
} catch (Exception e) {
throw new RuntimeException("Couldn't create input", e);
}
final Input input;
try {
input = inputService.find(messageInput.getPersistId());
} catch (NotFoundException e) {
throw new RuntimeException("Couldn't find persisted input", e);
}
try {
addStaticFields(input, messageInput, staticFields, parameters);
} catch (ValidationException e) {
throw new RuntimeException("Couldn't add static fields to input", e);
}
final List<Extractor> extractors;
try {
extractors = createExtractors(input, inputEntity.extractors(), username, parameters);
} catch (Exception e) {
throw new RuntimeException("Couldn't create extractors", e);
}
return NativeEntity.create(entity.id(), input.getId(), TYPE_V1, input.getTitle(), InputWithExtractors.create(input, extractors));
}
Aggregations