From 55d57f657722c925fb2b15f640f39d0c543b2988 Mon Sep 17 00:00:00 2001 From: manoj Date: Tue, 24 Mar 2015 17:57:58 +0530 Subject: [PATCH] Refactor email functionality --- .../mgt/common/EmailMessageProperties.java | 24 +++++++++++++++++++ .../DeviceManagementServiceProviderImpl.java | 17 ++++++------- .../config/email/EmailConfigurations.java | 3 +-- .../device/mgt/core/email/EmailConstants.java | 1 + .../core/service/DeviceManagementService.java | 2 +- .../service/DeviceManagementServiceImpl.java | 4 ++-- .../resources/conf/notification-messages.xml | 6 ++--- 7 files changed, 41 insertions(+), 16 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EmailMessageProperties.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EmailMessageProperties.java index 0bc87c50871..5b4c331fdc2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EmailMessageProperties.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EmailMessageProperties.java @@ -17,6 +17,7 @@ */ package org.wso2.carbon.device.mgt.common; +import java.util.Arrays; public class EmailMessageProperties { @@ -27,6 +28,7 @@ public class EmailMessageProperties { private String subject; private String firstName; private String enrolmentUrl; + private String title; public String getMessageBody() { return messageBody; @@ -83,4 +85,26 @@ public class EmailMessageProperties { public void setEnrolmentUrl(String enrolmentUrl) { this.enrolmentUrl = enrolmentUrl; } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + @Override + public String toString() { + return "EmailMessageProperties{" + + "messageBody='" + messageBody + '\'' + + ", mailTo=" + Arrays.toString(mailTo) + + ", ccList=" + Arrays.toString(ccList) + + ", bccList=" + Arrays.toString(bccList) + + ", subject='" + subject + '\'' + + ", firstName='" + firstName + '\'' + + ", enrolmentUrl='" + enrolmentUrl + '\'' + + ", title='" + title + '\'' + + '}'; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java index d7a8745b468..ba090b14d3c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java @@ -231,7 +231,7 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ } @Override - public void sendEnrollInvitation(EmailMessageProperties emailMessageProperties) throws DeviceManagementException { + public void sendEnrolmentInvitation(EmailMessageProperties emailMessageProperties) throws DeviceManagementException { EnrolmentNotifications enrolmentNotifications = DeviceConfigurationManager.getInstance() .getNotificationMessagesConfig().getEnrolmentNotifications(); @@ -243,20 +243,19 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ StringBuilder messageBuilder = new StringBuilder(); try { + String title = ""; + if (emailMessageProperties.getTitle() != null){ + title = emailMessageProperties.getTitle(); + } messageHeader = messageHeader.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.TITLE + "\\}", - URLEncoder.encode(emailMessageProperties.getSubject(), - EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); - - messageHeader = - messageHeader.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.USERNAME + "\\}", + URLEncoder.encode(title, EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); + messageHeader = messageHeader.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.USERNAME + "\\}", URLEncoder.encode(emailMessageProperties.getFirstName(), EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); - messageBody = messageBody + System.getProperty("line.separator") + enrolmentNotifications.getUrl() .replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.DOwN_LOAD_URL + "\\}", URLDecoder.decode(emailMessageProperties.getEnrolmentUrl(), EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); - messageBuilder.append(messageHeader).append(System.getProperty("line.separator")).append( System.getProperty("line.separator")); @@ -264,10 +263,12 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ System.getProperty("line.separator")).append(messageFooter); } catch (IOException e) { + log.error("IO error in processing enrol email message "+emailMessageProperties); throw new DeviceManagementException("Error replacing tags in email template '" + emailMessageProperties.getSubject() + "'", e); } emailMessageProperties.setMessageBody(messageBuilder.toString()); + emailMessageProperties.setSubject(EmailConstants.EnrolmentEmailConstants.ENROLMENT_MAIL_SUBJECT); EmailServiceDataHolder.getInstance().getEmailServiceProvider().sendEmail(emailMessageProperties); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/email/EmailConfigurations.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/email/EmailConfigurations.java index ee0393ebc30..b0a242df46a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/email/EmailConfigurations.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/email/EmailConfigurations.java @@ -46,12 +46,11 @@ public class EmailConfigurations { this.maxNumOfThread = maxNumOfThread; } - @XmlElement(name = "maximumThread", required = true) + @XmlElement(name = "keepAliveTime", required = true) public int getKeepAliveTime() { return keepAliveTime; } - @XmlElement(name = "keepAliveTime", required = true) public void setKeepAliveTime(int keepAliveTime) { this.keepAliveTime = keepAliveTime; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/email/EmailConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/email/EmailConstants.java index 2e9babdbdb9..81c2080c911 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/email/EmailConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/email/EmailConstants.java @@ -24,6 +24,7 @@ public final class EmailConstants { public static final String USERNAME = "user-name"; public static final String DOwN_LOAD_URL = "downloadUrl"; public static final String ENCODED_SCHEME = "UTF-8"; + public static final String ENROLMENT_MAIL_SUBJECT = "Enrol Your Device with wso2 MDM"; } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java index cbb826f5429..d9b22c404d1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java @@ -38,7 +38,7 @@ public interface DeviceManagementService extends DeviceManager, LicenseManager, List getDeviceListOfUser(String username) throws DeviceManagementException; - void sendEnrollInvitation(EmailMessageProperties config) throws DeviceManagementException; + void sendEnrolmentInvitation(EmailMessageProperties config) throws DeviceManagementException; FeatureManager getFeatureManager(String type) throws DeviceManagementException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java index 69b9610ed50..e7835abaf9a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java @@ -136,9 +136,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { } @Override - public void sendEnrollInvitation(EmailMessageProperties emailMessageProperties) throws DeviceManagementException { + public void sendEnrolmentInvitation(EmailMessageProperties emailMessageProperties) throws DeviceManagementException { DeviceManagementDataHolder.getInstance().getDeviceManagementProvider() - .sendEnrollInvitation(emailMessageProperties); + .sendEnrolmentInvitation(emailMessageProperties); } } diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/notification-messages.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/notification-messages.xml index 2bb3dae4b83..e642309f2f3 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/notification-messages.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/notification-messages.xml @@ -23,9 +23,9 @@ You have been registered to the WSO2 MDM. Below is the link to enroll. {downloadUrl}
- Best Regards, - WSO2 Carbon Team - http://www.wso2.com +Best Regards, +WSO2 Carbon Team +http://www.wso2.com
Enrol your device