Search in sources :

Example 1 with NotificationDefinition

use of io.gravitee.node.api.notifier.NotificationDefinition in project gravitee-access-management by gravitee-io.

the class DomainNotifierServiceImpl method buildEmailNotificationDefinition.

private Optional<NotificationDefinition> buildEmailNotificationDefinition(Certificate certificate, Domain domain, User user) {
    if (emailNotifierEnabled && !Strings.isNullOrEmpty(user.getEmail())) {
        try {
            Map<String, Object> data = new NotificationDefinitionUtils.ParametersBuilder().withDomain(domain).withUser(user).withCertificate(certificate).build();
            final Email email = emailService.getFinalEmail(domain, null, Template.CERTIFICATE_EXPIRATION, user, data);
            EmailNotifierConfiguration notifierConfig = new EmailNotifierConfiguration(this.emailConfiguration);
            notifierConfig.setSubject(email.getSubject());
            notifierConfig.setBody(email.getContent());
            notifierConfig.setTo(user.getEmail());
            final NotificationDefinition definition = new NotificationDefinition();
            definition.setType(TYPE_EMAIL_NOTIFIER);
            definition.setConfiguration(mapper.writeValueAsString(notifierConfig));
            definition.setResourceId(certificate.getId());
            definition.setResourceType(RESOURCE_TYPE_CERTIFICATE);
            definition.setAudienceId(user.getId());
            definition.setCron(this.certificateCronExpression);
            definition.setData(data);
            return Optional.of(definition);
        } catch (IOException | TemplateException e) {
            LOGGER.warn("Unable to generate email template for certificate expiration", e);
        }
    } else {
        LOGGER.debug("Ignore email notification for certificate {}, email is disabled or email address is missing", certificate.getId());
    }
    return Optional.empty();
}
Also used : Email(io.gravitee.am.common.email.Email) TemplateException(freemarker.template.TemplateException) NotificationDefinition(io.gravitee.node.api.notifier.NotificationDefinition) IOException(java.io.IOException)

Example 2 with NotificationDefinition

use of io.gravitee.node.api.notifier.NotificationDefinition in project gravitee-access-management by gravitee-io.

the class DomainNotifierServiceImpl method buildUINotificationDefinition.

private Optional<NotificationDefinition> buildUINotificationDefinition(Certificate certificate, Domain domain, User user) {
    if (uiNotifierEnabled) {
        try {
            Map<String, Object> data = new NotificationDefinitionUtils.ParametersBuilder().withDomain(domain).withUser(user).withCertificate(certificate).build();
            ManagementUINotifierConfiguration value = new ManagementUINotifierConfiguration();
            value.setTemplate(CERTIFICATE_EXPIRY_TPL);
            final NotificationDefinition definition = new NotificationDefinition();
            definition.setType(TYPE_UI_NOTIFIER);
            definition.setConfiguration(mapper.writeValueAsString(value));
            definition.setResourceId(certificate.getId());
            definition.setResourceType(RESOURCE_TYPE_CERTIFICATE);
            definition.setAudienceId(user.getId());
            definition.setCron(this.certificateCronExpression);
            definition.setData(data);
            return Optional.of(definition);
        } catch (IOException e) {
            LOGGER.warn("Unable to generate ui configuration for certificate expiration", e);
        }
    } else {
        LOGGER.debug("Ignore email notification for certificate {}, email is disabled or email address is missing", certificate.getId());
    }
    return Optional.empty();
}
Also used : NotificationDefinition(io.gravitee.node.api.notifier.NotificationDefinition) IOException(java.io.IOException)

Aggregations

NotificationDefinition (io.gravitee.node.api.notifier.NotificationDefinition)2 IOException (java.io.IOException)2 TemplateException (freemarker.template.TemplateException)1 Email (io.gravitee.am.common.email.Email)1