Refactor email functionality

4.x.x
manoj 10 years ago
parent ee6c067398
commit 55d57f6577

@ -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 + '\'' +
'}';
}
}

@ -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);
}

@ -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;
}

@ -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";
}
}

@ -38,7 +38,7 @@ public interface DeviceManagementService extends DeviceManager, LicenseManager,
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;

@ -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);
}
}

@ -23,9 +23,9 @@
<Body>You have been registered to the WSO2 MDM. Below is the link to enroll.</Body>
<Url>{downloadUrl}</Url>
<Footer>
Best Regards,
WSO2 Carbon Team
http://www.wso2.com
Best Regards,
WSO2 Carbon Team
http://www.wso2.com
</Footer>
<Subject>Enrol your device</Subject>
</EnrolmentNotifications>

Loading…
Cancel
Save