Search in sources :

Example 16 with NotificationTemplateEntity

use of io.gravitee.rest.api.model.notification.NotificationTemplateEntity in project gravitee-management-rest-api by gravitee-io.

the class NotificationTemplateServiceImpl method loadEmailNotificationTemplateFromHook.

private NotificationTemplateEntity loadEmailNotificationTemplateFromHook(Hook hook) {
    String templateName = hook.getTemplate() + "." + io.gravitee.rest.api.model.notification.NotificationTemplateType.EMAIL.name();
    final EmailTemplate emailTemplate = EmailTemplate.fromHook(hook);
    if (emailTemplate != null) {
        File emailTemplateFile = new File(templatesPath + "/" + emailTemplate.getHtmlTemplate());
        try {
            String title = (emailTemplate == null ? "unused title" : emailTemplate.getSubject());
            String content = new String(Files.readAllBytes(emailTemplateFile.toPath()));
            return new NotificationTemplateEntity(hook.name(), hook.getScope().name(), templateName, hook.getLabel(), hook.getDescription(), title, content, io.gravitee.rest.api.model.notification.NotificationTemplateType.EMAIL);
        } catch (IOException e) {
            LOGGER.warn("Problem while getting freemarker template {} from file : {}", hook.getTemplate(), e.getMessage());
        }
    }
    return null;
}
Also used : NotificationTemplateEntity(io.gravitee.rest.api.model.notification.NotificationTemplateEntity) EmailTemplate(io.gravitee.rest.api.service.builder.EmailNotificationBuilder.EmailTemplate) UuidString(io.gravitee.rest.api.service.common.UuidString)

Aggregations

NotificationTemplateEntity (io.gravitee.rest.api.model.notification.NotificationTemplateEntity)16 Test (org.junit.Test)8 NotificationTemplate (io.gravitee.repository.management.model.NotificationTemplate)5 NotificationTemplateEvent (io.gravitee.rest.api.model.notification.NotificationTemplateEvent)4 SimpleEvent (io.gravitee.common.event.impl.SimpleEvent)3 AlertTriggerEntity (io.gravitee.rest.api.model.alert.AlertTriggerEntity)3 ApplicationAlertEventType (io.gravitee.rest.api.model.alert.ApplicationAlertEventType)3 NewAlertTriggerEntity (io.gravitee.rest.api.model.alert.NewAlertTriggerEntity)3 UpdateAlertTriggerEntity (io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity)3 ApplicationListItem (io.gravitee.rest.api.model.application.ApplicationListItem)3 UuidString (io.gravitee.rest.api.service.common.UuidString)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Notification (io.gravitee.notifier.api.Notification)2 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)2 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)2 EmailTemplate (io.gravitee.rest.api.service.builder.EmailNotificationBuilder.EmailTemplate)1 NotificationTemplateNotFoundException (io.gravitee.rest.api.service.exceptions.NotificationTemplateNotFoundException)1 Async (org.springframework.scheduling.annotation.Async)1 Yaml (org.yaml.snakeyaml.Yaml)1