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();
}
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();
}
Aggregations