use of io.kamax.mxisd.threepid.generator.email.EmailGenerator in project mxisd by kamax-io.
the class BuiltInNotificationHandlerSupplier method acceptEmail.
private void acceptEmail(String handler, Mxisd mxisd) {
if (StringUtils.equals(EmailRawNotificationHandler.ID, handler)) {
Object o = mxisd.getConfig().getThreepid().getMedium().get(ThreePidMedium.Email.getId());
if (Objects.nonNull(o)) {
EmailConfig emailCfg;
try {
emailCfg = GsonUtil.get().fromJson(GsonUtil.makeObj(o), EmailConfig.class);
} catch (JsonSyntaxException e) {
throw new ConfigurationException("Invalid configuration for threepid email notification");
}
if (StringUtils.isBlank(emailCfg.getGenerator())) {
throw new ConfigurationException("notification.email.generator");
}
if (StringUtils.isBlank(emailCfg.getConnector())) {
throw new ConfigurationException("notification.email.connector");
}
List<EmailGenerator> generators = StreamSupport.stream(ServiceLoader.load(EmailGeneratorSupplier.class).spliterator(), false).map(s -> s.apply(emailCfg, mxisd)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
List<EmailConnector> connectors = StreamSupport.stream(ServiceLoader.load(EmailConnectorSupplier.class).spliterator(), false).map(s -> s.apply(emailCfg, mxisd)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
NotificationHandlers.register(() -> new EmailRawNotificationHandler(emailCfg, generators, connectors));
}
}
if (StringUtils.equals(EmailSendGridNotificationHandler.ID, handler)) {
Object cfgJson = mxisd.getConfig().getNotification().getHandlers().get(EmailSendGridNotificationHandler.ID);
if (Objects.nonNull(cfgJson)) {
EmailSendGridConfig cfg;
try {
cfg = GsonUtil.get().fromJson(GsonUtil.get().toJson(cfgJson), EmailSendGridConfig.class);
} catch (JsonSyntaxException e) {
throw new ConfigurationException("Invalid configuration for threepid email sendgrid handler");
}
NotificationHandlers.register(() -> new EmailSendGridNotificationHandler(mxisd.getConfig(), cfg));
}
}
}
Aggregations