use of org.graylog.events.contentpack.entities.NotificationEntity 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.graylog.events.contentpack.entities.NotificationEntity in project graylog2-server by Graylog2.
the class NotificationFacadeTest method createTestEntity.
private EntityV1 createTestEntity() {
final HttpEventNotificationConfigEntity httpEventNotificationConfigEntity = HttpEventNotificationConfigEntity.builder().url(ValueReference.of("https://hulud.net")).build();
final NotificationEntity notificationEntity = NotificationEntity.builder().title(ValueReference.of("title")).description(ValueReference.of("descriptions")).config(httpEventNotificationConfigEntity).build();
final JsonNode data = objectMapper.convertValue(notificationEntity, JsonNode.class);
return EntityV1.builder().data(data).id(ModelId.of("beef-1337")).type(ModelTypes.NOTIFICATION_V1).build();
}
use of org.graylog.events.contentpack.entities.NotificationEntity in project graylog2-server by Graylog2.
the class EventDefinitionFacadeTest method resolveForInstallation.
@Test
@MongoDBFixtures("EventDefinitionFacadeTest.json")
public void resolveForInstallation() {
EntityV1 eventEntityV1 = createTestEntity();
final NotificationEntity notificationEntity = NotificationEntity.builder().title(ValueReference.of("title")).description(ValueReference.of("description")).config(HttpEventNotificationConfigEntity.builder().url(ValueReference.of("http://url")).build()).build();
final JsonNode data = objectMapper.convertValue(notificationEntity, JsonNode.class);
final EntityV1 notificationV1 = EntityV1.builder().data(data).id(ModelId.of("123123")).type(ModelTypes.EVENT_DEFINITION_V1).build();
final EntityDescriptor entityDescriptor = EntityDescriptor.create("123123", ModelTypes.NOTIFICATION_V1);
Map<String, ValueReference> parameters = ImmutableMap.of();
Map<EntityDescriptor, Entity> entities = ImmutableMap.of(entityDescriptor, notificationV1);
Graph<Entity> graph = facade.resolveForInstallation(eventEntityV1, parameters, entities);
assertThat(graph).isNotNull();
Set<Entity> expectedNodes = ImmutableSet.of(eventEntityV1, notificationV1);
assertThat(graph.nodes()).isEqualTo(expectedNodes);
}
use of org.graylog.events.contentpack.entities.NotificationEntity in project graylog2-server by Graylog2.
the class NotificationFacadeTest method exportEntity.
@Test
@MongoDBFixtures("NotificationFacadeTest.json")
public void exportEntity() {
final ModelId id = ModelId.of("5d4d33753d27460ad18e0c4d");
final EntityDescriptor descriptor = EntityDescriptor.create(id, ModelTypes.NOTIFICATION_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
final Optional<Entity> entity = facade.exportEntity(descriptor, entityDescriptorIds);
assertThat(entity).isPresent();
final EntityV1 entityV1 = (EntityV1) entity.get();
final NotificationEntity notificationEntity = objectMapper.convertValue(entityV1.data(), NotificationEntity.class);
assertThat(notificationEntity.title().asString()).isEqualTo("title");
assertThat(notificationEntity.description().asString()).isEqualTo("description");
assertThat(notificationEntity.config().type()).isEqualTo("email-notification-v1");
}
use of org.graylog.events.contentpack.entities.NotificationEntity in project graylog2-server by Graylog2.
the class NotificationFacade method decode.
private NativeEntity<NotificationDto> decode(EntityV1 entityV1, Map<String, ValueReference> parameters, Map<EntityDescriptor, Object> nativeEntities, User user) {
final NotificationEntity entity = objectMapper.convertValue(entityV1.data(), NotificationEntity.class);
final NotificationDto notificationDto = entity.toNativeEntity(parameters, nativeEntities);
final NotificationDto savedDto = notificationResourceHandler.create(notificationDto, Optional.ofNullable(user));
return NativeEntity.create(entityV1.id(), savedDto.id(), ModelTypes.NOTIFICATION_V1, savedDto.title(), savedDto);
}
Aggregations