Search in sources :

Example 1 with EmailConnector

use of io.kamax.mxisd.threepid.connector.email.EmailConnector 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));
        }
    }
}
Also used : ThreePidMedium(io.kamax.matrix.ThreePidMedium) GsonUtil(io.kamax.matrix.json.GsonUtil) PhoneNotificationHandler(io.kamax.mxisd.threepid.notification.phone.PhoneNotificationHandler) ConfigurationException(io.kamax.mxisd.exception.ConfigurationException) StringUtils(org.apache.commons.lang3.StringUtils) EmailConfig(io.kamax.mxisd.config.threepid.medium.EmailConfig) Mxisd(io.kamax.mxisd.Mxisd) StreamSupport(java.util.stream.StreamSupport) PhoneConfig(io.kamax.mxisd.config.threepid.medium.PhoneConfig) EmailGeneratorSupplier(io.kamax.mxisd.threepid.generator.email.EmailGeneratorSupplier) NotificationHandlerSupplier(io.kamax.mxisd.notification.NotificationHandlerSupplier) EmailRawNotificationHandler(io.kamax.mxisd.threepid.notification.email.EmailRawNotificationHandler) JsonSyntaxException(com.google.gson.JsonSyntaxException) PhoneGeneratorSupplier(io.kamax.mxisd.threepid.generator.phone.PhoneGeneratorSupplier) ServiceLoader(java.util.ServiceLoader) EmailGenerator(io.kamax.mxisd.threepid.generator.email.EmailGenerator) Collectors(java.util.stream.Collectors) EmailConnector(io.kamax.mxisd.threepid.connector.email.EmailConnector) Objects(java.util.Objects) EmailSendGridConfig(io.kamax.mxisd.config.threepid.connector.EmailSendGridConfig) PhoneConnectorSupplier(io.kamax.mxisd.threepid.connector.phone.PhoneConnectorSupplier) List(java.util.List) PhoneGenerator(io.kamax.mxisd.threepid.generator.phone.PhoneGenerator) NotificationHandlers(io.kamax.mxisd.notification.NotificationHandlers) EmailConnectorSupplier(io.kamax.mxisd.threepid.connector.email.EmailConnectorSupplier) EmailSendGridNotificationHandler(io.kamax.mxisd.threepid.notification.email.EmailSendGridNotificationHandler) Optional(java.util.Optional) PhoneConnector(io.kamax.mxisd.threepid.connector.phone.PhoneConnector) EmailGenerator(io.kamax.mxisd.threepid.generator.email.EmailGenerator) Optional(java.util.Optional) EmailConnector(io.kamax.mxisd.threepid.connector.email.EmailConnector) EmailConfig(io.kamax.mxisd.config.threepid.medium.EmailConfig) JsonSyntaxException(com.google.gson.JsonSyntaxException) ConfigurationException(io.kamax.mxisd.exception.ConfigurationException) EmailSendGridNotificationHandler(io.kamax.mxisd.threepid.notification.email.EmailSendGridNotificationHandler) EmailSendGridConfig(io.kamax.mxisd.config.threepid.connector.EmailSendGridConfig) EmailRawNotificationHandler(io.kamax.mxisd.threepid.notification.email.EmailRawNotificationHandler)

Aggregations

JsonSyntaxException (com.google.gson.JsonSyntaxException)1 ThreePidMedium (io.kamax.matrix.ThreePidMedium)1 GsonUtil (io.kamax.matrix.json.GsonUtil)1 Mxisd (io.kamax.mxisd.Mxisd)1 EmailSendGridConfig (io.kamax.mxisd.config.threepid.connector.EmailSendGridConfig)1 EmailConfig (io.kamax.mxisd.config.threepid.medium.EmailConfig)1 PhoneConfig (io.kamax.mxisd.config.threepid.medium.PhoneConfig)1 ConfigurationException (io.kamax.mxisd.exception.ConfigurationException)1 NotificationHandlerSupplier (io.kamax.mxisd.notification.NotificationHandlerSupplier)1 NotificationHandlers (io.kamax.mxisd.notification.NotificationHandlers)1 EmailConnector (io.kamax.mxisd.threepid.connector.email.EmailConnector)1 EmailConnectorSupplier (io.kamax.mxisd.threepid.connector.email.EmailConnectorSupplier)1 PhoneConnector (io.kamax.mxisd.threepid.connector.phone.PhoneConnector)1 PhoneConnectorSupplier (io.kamax.mxisd.threepid.connector.phone.PhoneConnectorSupplier)1 EmailGenerator (io.kamax.mxisd.threepid.generator.email.EmailGenerator)1 EmailGeneratorSupplier (io.kamax.mxisd.threepid.generator.email.EmailGeneratorSupplier)1 PhoneGenerator (io.kamax.mxisd.threepid.generator.phone.PhoneGenerator)1 PhoneGeneratorSupplier (io.kamax.mxisd.threepid.generator.phone.PhoneGeneratorSupplier)1 EmailRawNotificationHandler (io.kamax.mxisd.threepid.notification.email.EmailRawNotificationHandler)1 EmailSendGridNotificationHandler (io.kamax.mxisd.threepid.notification.email.EmailSendGridNotificationHandler)1