Search in sources :

Example 1 with NewPortalNotificationEntity

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

the class PortalNotificationServiceImpl method create.

@Override
public void create(Hook hook, List<String> users, Object params) {
    try {
        // get notification template
        String tpl = RELATIVE_TPL_PATH + hook.getScope().name() + "." + hook.name() + ".yml";
        final Template template = freemarkerConfiguration.getTemplate(tpl);
        final String yamlContent = processTemplateIntoString(template, params);
        Yaml yaml = new Yaml();
        Map<String, String> load = yaml.loadAs(yamlContent, HashMap.class);
        List<NewPortalNotificationEntity> notifications = new ArrayList<>(users.size());
        users.forEach(user -> {
            NewPortalNotificationEntity notification = new NewPortalNotificationEntity();
            notification.setUser(user);
            notification.setTitle(load.get("title"));
            notification.setMessage(load.get("message"));
            notifications.add(notification);
        });
        create(notifications);
    } catch (final Exception ex) {
        LOGGER.error("Error while sending notification", ex);
        throw new TechnicalManagementException("Error while sending notification", ex);
    }
}
Also used : FreeMarkerTemplateUtils.processTemplateIntoString(org.springframework.ui.freemarker.FreeMarkerTemplateUtils.processTemplateIntoString) NewPortalNotificationEntity(io.gravitee.management.model.notification.NewPortalNotificationEntity) Yaml(org.yaml.snakeyaml.Yaml) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException) Template(freemarker.template.Template)

Aggregations

Template (freemarker.template.Template)1 NewPortalNotificationEntity (io.gravitee.management.model.notification.NewPortalNotificationEntity)1 TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)1 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 FreeMarkerTemplateUtils.processTemplateIntoString (org.springframework.ui.freemarker.FreeMarkerTemplateUtils.processTemplateIntoString)1 Yaml (org.yaml.snakeyaml.Yaml)1