Refactor email functionality

revert-70aa11f8
manoj 10 years ago
parent ee6c067398
commit 55d57f6577

@ -17,6 +17,7 @@
*/ */
package org.wso2.carbon.device.mgt.common; package org.wso2.carbon.device.mgt.common;
import java.util.Arrays;
public class EmailMessageProperties { public class EmailMessageProperties {
@ -27,6 +28,7 @@ public class EmailMessageProperties {
private String subject; private String subject;
private String firstName; private String firstName;
private String enrolmentUrl; private String enrolmentUrl;
private String title;
public String getMessageBody() { public String getMessageBody() {
return messageBody; return messageBody;
@ -83,4 +85,26 @@ public class EmailMessageProperties {
public void setEnrolmentUrl(String enrolmentUrl) { public void setEnrolmentUrl(String enrolmentUrl) {
this.enrolmentUrl = 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 + '\'' +
'}';
}
} }

@ -231,7 +231,7 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
} }
@Override @Override
public void sendEnrollInvitation(EmailMessageProperties emailMessageProperties) throws DeviceManagementException { public void sendEnrolmentInvitation(EmailMessageProperties emailMessageProperties) throws DeviceManagementException {
EnrolmentNotifications enrolmentNotifications = DeviceConfigurationManager.getInstance() EnrolmentNotifications enrolmentNotifications = DeviceConfigurationManager.getInstance()
.getNotificationMessagesConfig().getEnrolmentNotifications(); .getNotificationMessagesConfig().getEnrolmentNotifications();
@ -243,20 +243,19 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
StringBuilder messageBuilder = new StringBuilder(); StringBuilder messageBuilder = new StringBuilder();
try { try {
String title = "";
if (emailMessageProperties.getTitle() != null){
title = emailMessageProperties.getTitle();
}
messageHeader = messageHeader.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.TITLE + "\\}", messageHeader = messageHeader.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.TITLE + "\\}",
URLEncoder.encode(emailMessageProperties.getSubject(), URLEncoder.encode(title, EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); messageHeader = messageHeader.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.USERNAME + "\\}",
messageHeader =
messageHeader.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.USERNAME + "\\}",
URLEncoder.encode(emailMessageProperties.getFirstName(), URLEncoder.encode(emailMessageProperties.getFirstName(),
EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
messageBody = messageBody + System.getProperty("line.separator") + enrolmentNotifications.getUrl() messageBody = messageBody + System.getProperty("line.separator") + enrolmentNotifications.getUrl()
.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.DOwN_LOAD_URL + "\\}", .replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.DOwN_LOAD_URL + "\\}",
URLDecoder.decode(emailMessageProperties.getEnrolmentUrl(), URLDecoder.decode(emailMessageProperties.getEnrolmentUrl(),
EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
messageBuilder.append(messageHeader).append(System.getProperty("line.separator")).append( messageBuilder.append(messageHeader).append(System.getProperty("line.separator")).append(
System.getProperty("line.separator")); System.getProperty("line.separator"));
@ -264,10 +263,12 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
System.getProperty("line.separator")).append(messageFooter); System.getProperty("line.separator")).append(messageFooter);
} catch (IOException e) { } catch (IOException e) {
log.error("IO error in processing enrol email message "+emailMessageProperties);
throw new DeviceManagementException("Error replacing tags in email template '" + throw new DeviceManagementException("Error replacing tags in email template '" +
emailMessageProperties.getSubject() + "'", e); emailMessageProperties.getSubject() + "'", e);
} }
emailMessageProperties.setMessageBody(messageBuilder.toString()); emailMessageProperties.setMessageBody(messageBuilder.toString());
emailMessageProperties.setSubject(EmailConstants.EnrolmentEmailConstants.ENROLMENT_MAIL_SUBJECT);
EmailServiceDataHolder.getInstance().getEmailServiceProvider().sendEmail(emailMessageProperties); EmailServiceDataHolder.getInstance().getEmailServiceProvider().sendEmail(emailMessageProperties);
} }

@ -46,12 +46,11 @@ public class EmailConfigurations {
this.maxNumOfThread = maxNumOfThread; this.maxNumOfThread = maxNumOfThread;
} }
@XmlElement(name = "maximumThread", required = true) @XmlElement(name = "keepAliveTime", required = true)
public int getKeepAliveTime() { public int getKeepAliveTime() {
return keepAliveTime; return keepAliveTime;
} }
@XmlElement(name = "keepAliveTime", required = true)
public void setKeepAliveTime(int keepAliveTime) { public void setKeepAliveTime(int keepAliveTime) {
this.keepAliveTime = keepAliveTime; this.keepAliveTime = keepAliveTime;
} }

@ -24,6 +24,7 @@ public final class EmailConstants {
public static final String USERNAME = "user-name"; public static final String USERNAME = "user-name";
public static final String DOwN_LOAD_URL = "downloadUrl"; public static final String DOwN_LOAD_URL = "downloadUrl";
public static final String ENCODED_SCHEME = "UTF-8"; public static final String ENCODED_SCHEME = "UTF-8";
public static final String ENROLMENT_MAIL_SUBJECT = "Enrol Your Device with wso2 MDM";
} }
} }

@ -38,7 +38,7 @@ public interface DeviceManagementService extends DeviceManager, LicenseManager,
List<Device> getDeviceListOfUser(String username) throws DeviceManagementException; List<Device> getDeviceListOfUser(String username) throws DeviceManagementException;
void sendEnrollInvitation(EmailMessageProperties config) throws DeviceManagementException; void sendEnrolmentInvitation(EmailMessageProperties config) throws DeviceManagementException;
FeatureManager getFeatureManager(String type) throws DeviceManagementException; FeatureManager getFeatureManager(String type) throws DeviceManagementException;

@ -136,9 +136,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
} }
@Override @Override
public void sendEnrollInvitation(EmailMessageProperties emailMessageProperties) throws DeviceManagementException { public void sendEnrolmentInvitation(EmailMessageProperties emailMessageProperties) throws DeviceManagementException {
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider() DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.sendEnrollInvitation(emailMessageProperties); .sendEnrolmentInvitation(emailMessageProperties);
} }
} }

Loading…
Cancel
Save