Search in sources :

Example 1 with EmailTemplate

use of io.gravitee.rest.api.service.builder.EmailNotificationBuilder.EmailTemplate 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)1 EmailTemplate (io.gravitee.rest.api.service.builder.EmailNotificationBuilder.EmailTemplate)1 UuidString (io.gravitee.rest.api.service.common.UuidString)1