diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java index b09c1e8149c..0f966baf3bf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java @@ -26,6 +26,7 @@ import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; +import org.wso2.carbon.email.sender.core.service.EmailSenderService; import org.wso2.carbon.ntask.core.service.TaskService; import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.user.core.service.RealmService; @@ -36,6 +37,7 @@ import java.util.HashMap; public class DeviceManagementDataHolder { + private static DeviceManagementDataHolder thisInstance = new DeviceManagementDataHolder(); private RealmService realmService; private TenantManager tenantManager; private DeviceManagementProviderService deviceManagerProvider; @@ -49,12 +51,8 @@ public class DeviceManagementDataHolder { private HashMap requireDeviceAuthorization = new HashMap<>(); private DeviceAccessAuthorizationService deviceAccessAuthorizationService; private GroupManagementProviderService groupManagementProviderService; - private TaskService taskService; - //private EmailSenderService emailSenderService; - - - private static DeviceManagementDataHolder thisInstance = new DeviceManagementDataHolder(); + private EmailSenderService emailSenderService; private DeviceManagementDataHolder() {} @@ -74,6 +72,10 @@ public class DeviceManagementDataHolder { this.setTenantManager(realmService); } + public TenantManager getTenantManager() { + return tenantManager; + } + private void setTenantManager(RealmService realmService) { if (realmService == null) { throw new IllegalStateException("Realm service is not initialized properly"); @@ -81,10 +83,6 @@ public class DeviceManagementDataHolder { this.tenantManager = realmService.getTenantManager(); } - public TenantManager getTenantManager() { - return tenantManager; - } - public DeviceManagementProviderService getDeviceManagementProvider() { return deviceManagerProvider; } @@ -189,13 +187,13 @@ public class DeviceManagementDataHolder { public void setTaskService(TaskService taskService) { this.taskService = taskService; } -// -// public EmailSenderService getEmailSenderService() { -// return emailSenderService; -// } -// -// public void setEmailSenderService(EmailSenderService emailSenderService) { -// this.emailSenderService = emailSenderService; -// } + + public EmailSenderService getEmailSenderService() { + return emailSenderService; + } + + public void setEmailSenderService(EmailSenderService emailSenderService) { + this.emailSenderService = emailSenderService; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index 35f7e50f006..09ac3fcd903 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -54,6 +54,7 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceIm import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceImpl; import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer; +import org.wso2.carbon.email.sender.core.service.EmailSenderService; import org.wso2.carbon.ndatasource.core.DataSourceService; import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.user.core.service.RealmService; @@ -100,6 +101,12 @@ import java.util.List; * policy="dynamic" * bind="setConfigurationContextService" * unbind="unsetConfigurationContextService" + * @scr.reference name="email.sender.service" + * interface="org.wso2.carbon.email.sender.core.service.EmailSenderService" + * cardinality="0..1" + * policy="dynamic" + * bind="setEmailSenderService" + * unbind="unsetEmailSenderService" */ public class DeviceManagementServiceComponent { @@ -360,4 +367,18 @@ public class DeviceManagementServiceComponent { DeviceManagementDataHolder.getInstance().setConfigurationContextService(null); } + protected void setEmailSenderService(EmailSenderService emailSenderService) { + if (log.isDebugEnabled()) { + log.debug("Setting Email Sender Service"); + } + DeviceManagementDataHolder.getInstance().setEmailSenderService(emailSenderService); + } + + protected void unsetEmailSenderService(EmailSenderService emailSenderService) { + if (log.isDebugEnabled()) { + log.debug("Un-setting Email Sender Service"); + } + DeviceManagementDataHolder.getInstance().setEmailSenderService(null); + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 9d5e6b46d5c..3324da66ac3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -47,6 +47,9 @@ import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent; import org.wso2.carbon.device.mgt.core.internal.PluginInitializationListener; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; +import org.wso2.carbon.email.sender.core.ContentProviderInfo; +import org.wso2.carbon.email.sender.core.EmailContext; +import org.wso2.carbon.email.sender.core.EmailSendingFailedException; import org.wso2.carbon.email.sender.core.TypedValue; import org.wso2.carbon.user.api.UserStoreException; @@ -540,14 +543,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv new TypedValue, Object>(String.class, DeviceManagerUtil.getServerBaseHttpsUrl())); params.put(org.wso2.carbon.device.mgt.core.DeviceManagementConstants.EmailAttributes.SERVER_BASE_URL_HTTP, new TypedValue, Object>(String.class, DeviceManagerUtil.getServerBaseHttpUrl())); -// try { -// EmailContext ctx = -// new EmailContext.EmailContextBuilder(new ContentProviderInfo("user-enrollment", params), -// metaInfo.getRecipients()).build(); -//// DeviceManagementDataHolder.getInstance().getEmailSenderService().sendEmail(ctx); -// } catch (EmailSendingFailedException e) { -// throw new DeviceManagementException("Error occurred while sending enrollment invitation", e); -// } + try { + EmailContext ctx = + new EmailContext.EmailContextBuilder(new ContentProviderInfo("user-enrollment", params), + metaInfo.getRecipients()).build(); + DeviceManagementDataHolder.getInstance().getEmailSenderService().sendEmail(ctx); + } catch (EmailSendingFailedException e) { + throw new DeviceManagementException("Error occurred while sending enrollment invitation", e); + } } @Override @@ -565,14 +568,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv new TypedValue, Object>(String.class, DeviceManagerUtil.getServerBaseHttpsUrl())); params.put(org.wso2.carbon.device.mgt.core.DeviceManagementConstants.EmailAttributes.SERVER_BASE_URL_HTTP, new TypedValue, Object>(String.class, DeviceManagerUtil.getServerBaseHttpUrl())); -// try { -// EmailContext ctx = -// new EmailContext.EmailContextBuilder(new ContentProviderInfo("user-registration", params), -// metaInfo.getRecipients()).build(); -// DeviceManagementDataHolder.getInstance().getEmailSenderService().sendEmail(ctx); -// } catch (EmailSendingFailedException e) { -// throw new DeviceManagementException("Error occurred while sending user registration notification", e); -// } + try { + EmailContext ctx = + new EmailContext.EmailContextBuilder(new ContentProviderInfo("user-registration", params), + metaInfo.getRecipients()).build(); + DeviceManagementDataHolder.getInstance().getEmailSenderService().sendEmail(ctx); + } catch (EmailSendingFailedException e) { + throw new DeviceManagementException("Error occurred while sending user registration notification", e); + } } @Override