Search in sources :

Example 1 with NotificationEntity

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());
}
Also used : NotificationDto(org.graylog.events.notifications.NotificationDto) JsonNode(com.fasterxml.jackson.databind.JsonNode) NotificationEntity(org.graylog.events.contentpack.entities.NotificationEntity) ModelId(org.graylog2.contentpacks.model.ModelId)

Example 2 with NotificationEntity

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();
}
Also used : HttpEventNotificationConfigEntity(org.graylog.events.contentpack.entities.HttpEventNotificationConfigEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode) NotificationEntity(org.graylog.events.contentpack.entities.NotificationEntity)

Example 3 with NotificationEntity

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);
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) EventNotificationHandlerConfigEntity(org.graylog.events.contentpack.entities.EventNotificationHandlerConfigEntity) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) HttpEventNotificationConfigEntity(org.graylog.events.contentpack.entities.HttpEventNotificationConfigEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) NotificationEntity(org.graylog.events.contentpack.entities.NotificationEntity) AggregationEventProcessorConfigEntity(org.graylog.events.contentpack.entities.AggregationEventProcessorConfigEntity) EventDefinitionEntity(org.graylog.events.contentpack.entities.EventDefinitionEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode) NotificationEntity(org.graylog.events.contentpack.entities.NotificationEntity) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 4 with NotificationEntity

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");
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) HttpEventNotificationConfigEntity(org.graylog.events.contentpack.entities.HttpEventNotificationConfigEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) EmailEventNotificationConfigEntity(org.graylog.events.contentpack.entities.EmailEventNotificationConfigEntity) NotificationEntity(org.graylog.events.contentpack.entities.NotificationEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) NotificationEntity(org.graylog.events.contentpack.entities.NotificationEntity) ModelId(org.graylog2.contentpacks.model.ModelId) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 5 with NotificationEntity

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);
}
Also used : NotificationDto(org.graylog.events.notifications.NotificationDto) NotificationEntity(org.graylog.events.contentpack.entities.NotificationEntity)

Aggregations

NotificationEntity (org.graylog.events.contentpack.entities.NotificationEntity)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 HttpEventNotificationConfigEntity (org.graylog.events.contentpack.entities.HttpEventNotificationConfigEntity)3 NotificationDto (org.graylog.events.notifications.NotificationDto)2 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)2 ModelId (org.graylog2.contentpacks.model.ModelId)2 Entity (org.graylog2.contentpacks.model.entities.Entity)2 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)2 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)2 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)2 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)2 Test (org.junit.Test)2 AggregationEventProcessorConfigEntity (org.graylog.events.contentpack.entities.AggregationEventProcessorConfigEntity)1 EmailEventNotificationConfigEntity (org.graylog.events.contentpack.entities.EmailEventNotificationConfigEntity)1 EventDefinitionEntity (org.graylog.events.contentpack.entities.EventDefinitionEntity)1 EventNotificationHandlerConfigEntity (org.graylog.events.contentpack.entities.EventNotificationHandlerConfigEntity)1 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)1 ValueReference (org.graylog2.contentpacks.model.entities.references.ValueReference)1