From cfe9bd5f9fe870a0a05f75f6dace3d25e79451d0 Mon Sep 17 00:00:00 2001 From: manoj Date: Fri, 22 May 2015 13:22:00 +0530 Subject: [PATCH] Email format --- .../DeviceManagementServiceProviderImpl.java | 54 ++++++++++++------- .../config/email/NotificationMessages.java | 41 ++++++++++---- .../resources/conf/notification-messages.xml | 45 ++++++---------- 3 files changed, 83 insertions(+), 57 deletions(-) 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 7eb690c10e7..8e662c75202 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 @@ -255,7 +255,9 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ String messageHeader = ""; String messageBody = ""; - String messageFooter = ""; + String messageFooter1 = ""; + String messageFooter2 = ""; + String messageFooter3 = ""; String url = ""; String subject = ""; @@ -264,7 +266,9 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ equals(notificationMessage.getType())) { messageHeader = notificationMessage.getHeader(); messageBody = notificationMessage.getBody(); - messageFooter = notificationMessage.getFooter(); + messageFooter1 = notificationMessage.getFooterLine1(); + messageFooter2 = notificationMessage.getFooterLine2(); + messageFooter3 = notificationMessage.getFooterLine3(); url = notificationMessage.getUrl(); subject = notificationMessage.getSubject(); break; @@ -277,13 +281,19 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ messageHeader = messageHeader.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.FIRST_NAME + "\\}", URLEncoder.encode(emailMessageProperties.getFirstName(), EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); - messageBody = messageBody + System.getProperty("line.separator") + url.replaceAll("\\{" + messageBody = messageBody.trim() + System.getProperty("line.separator") + + System.getProperty("line.separator") + url.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.DOWNLOAD_URL + "\\}", URLDecoder.decode(emailMessageProperties.getEnrolmentUrl(), EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); - messageBuilder.append(messageHeader).append(System.getProperty("line.separator")); - messageBuilder.append(messageBody).append(System.getProperty("line.separator")).append(messageFooter); + messageBuilder.append(messageHeader).append(System.getProperty("line.separator")) + .append(System.getProperty("line.separator")); + messageBuilder.append(messageBody); + messageBuilder.append(System.getProperty("line.separator")).append(System.getProperty("line.separator")); + messageBuilder.append(messageFooter1.trim()) + .append(System.getProperty("line.separator")).append(messageFooter2.trim()).append(System + .getProperty("line.separator")).append(messageFooter3.trim()); } catch (IOException e) { log.error("IO error in processing enrol email message " + emailMessageProperties); @@ -302,7 +312,9 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ String messageHeader = ""; String messageBody = ""; - String messageFooter = ""; + String messageFooter1 = ""; + String messageFooter2 = ""; + String messageFooter3 = ""; String url = ""; String subject = ""; @@ -311,7 +323,9 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ equals(notificationMessage.getType())) { messageHeader = notificationMessage.getHeader(); messageBody = notificationMessage.getBody(); - messageFooter = notificationMessage.getFooter(); + messageFooter1 = notificationMessage.getFooterLine1(); + messageFooter2 = notificationMessage.getFooterLine2(); + messageFooter3 = notificationMessage.getFooterLine3(); url = notificationMessage.getUrl(); subject = notificationMessage.getSubject(); break; @@ -325,7 +339,9 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ URLEncoder.encode(emailMessageProperties.getFirstName(), EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); - messageBody = messageBody.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.USERNAME + "\\}", + messageBody = messageBody.trim().replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants + .USERNAME + + "\\}", URLEncoder.encode(emailMessageProperties.getUserName(), EmailConstants.EnrolmentEmailConstants .ENCODED_SCHEME)); @@ -339,7 +355,9 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); messageBuilder.append(messageHeader).append(System.getProperty("line.separator")); - messageBuilder.append(messageBody).append(System.getProperty("line.separator")).append(messageFooter); + messageBuilder.append(messageBody).append(System.getProperty("line.separator")).append(messageFooter1.trim()); + messageBuilder.append(System.getProperty("line.separator")).append(messageFooter2.trim()); + messageBuilder.append(System.getProperty("line.separator")).append(messageFooter3.trim()); } catch (IOException e) { log.error("IO error in processing enrol email message " + emailMessageProperties); @@ -488,7 +506,7 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ devicesList = this.getDeviceDAO().getDeviceListOfUser(userName, tenantId); } catch (DeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while obtaining the devices of user '" - + userName + "'", e); + + userName + "'", e); } //Fetch the DeviceList from device plugin dbs & append the properties @@ -509,8 +527,8 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ } devicesOfUser.add(convertedDevice); } catch (DeviceManagementDAOException e) { - log.error("Error occurred while obtaining the device type of DeviceTypeId '"+ - device.getDeviceTypeId() + "'",e); + log.error("Error occurred while obtaining the device type of DeviceTypeId '" + + device.getDeviceTypeId() + "'", e); } } return devicesOfUser; @@ -531,15 +549,15 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ int tenantId = DeviceManagerUtil.getTenantId(); //Obtaining the list of users of role try { - users = DeviceManagementDataHolder.getInstance().getUserManager().getUsersForTenantAndRole( + users = DeviceManagementDataHolder.getInstance().getUserManager().getUsersForTenantAndRole( tenantId, roleName); } catch (org.wso2.carbon.device.mgt.user.common.UserManagementException e) { throw new DeviceManagementException("Error occurred while obtaining the users of role '" - + roleName + "'", e); + + roleName + "'", e); } //Obtaining the devices per user - for(org.wso2.carbon.device.mgt.user.common.User user:users){ + for (org.wso2.carbon.device.mgt.user.common.User user : users) { try { userName = user.getUserName(); devicesList = this.getDeviceDAO().getDeviceListOfUser(userName, tenantId); @@ -560,13 +578,13 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ } devicesOfRole.add(convertedDevice); } catch (DeviceManagementDAOException e) { - log.error("Error occurred while obtaining the device type of DeviceTypeId '"+ - device.getDeviceTypeId() + "'",e); + log.error("Error occurred while obtaining the device type of DeviceTypeId '" + + device.getDeviceTypeId() + "'", e); } } } catch (DeviceManagementDAOException e) { log.error("Error occurred while obtaining the devices of user '" - + userName + "'", e); + + userName + "'", e); } } return devicesOfRole; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/email/NotificationMessages.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/email/NotificationMessages.java index c04b6d04d19..961497030b1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/email/NotificationMessages.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/email/NotificationMessages.java @@ -27,7 +27,9 @@ public class NotificationMessages { private String header; private String body; - private String footer; + private String footerLine1; + private String footerLine2; + private String footerLine3; private String subject; private String url; @@ -60,15 +62,6 @@ public class NotificationMessages { this.body = body; } - @XmlElement(name = "Footer", required = true) - public String getFooter() { - return footer; - } - - public void setFooter(String footer) { - this.footer = footer; - } - @XmlElement(name = "Subject", required = true) public String getSubject() { return subject; @@ -86,4 +79,32 @@ public class NotificationMessages { public void setUrl(String url) { this.url = url; } + + @XmlElement(name = "Footer1") + public String getFooterLine1() { + return footerLine1; + } + + public void setFooterLine1(String footerLine1) { + this.footerLine1 = footerLine1; + } + + @XmlElement(name = "Footer2") + public String getFooterLine2() { + return footerLine2; + } + + public void setFooterLine2(String footerLine2) { + this.footerLine2 = footerLine2; + } + + @XmlElement(name = "Footer3") + public String getFooterLine3() { + return footerLine3; + } + + public void setFooterLine3(String footerLine3) { + this.footerLine3 = footerLine3; + } + } 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 e3aaa462a02..9b13c5d8088 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 @@ -1,22 +1,3 @@ - - - Enroll your Device with WSO2 MDM @@ -25,28 +6,34 @@ You have been registered to the WSO2 MDM. Below is the link to enroll. {downloadUrl} -
+ Best Regards, + + WSO2 MDM Team. + + http://www.wso2.com -
+
Enroll your Device with WSO2 MDM
Dear {first-name},
- You have been registered to WSO2 MDM with following credentials. - - Username: {user-name} - Password: {password} - - Below is the link to enroll. +You have been registered to WSO2 MDM with following credentials. +Username: {user-name} +Password: {password} +Below is the link to enroll. {downloadUrl} - +
\ No newline at end of file